Skip to content

Commit

Permalink
[base] Remove base::StringPiece::as_string() usages.
Browse files Browse the repository at this point in the history
This API is not compliant with absl::/std::string_view.

Bug: 1049498
Change-Id: I4110deacd1ce01a99c8ae7ab657165c0deef5a7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2857054
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Karan Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#877543}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Apr 29, 2021
1 parent 5d5bf86 commit 8543dc6
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 42 deletions.
5 changes: 3 additions & 2 deletions extensions/browser/api/web_request/form_data_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/lazy_instance.h"
#include "base/notreached.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "net/base/escape.h"
Expand Down Expand Up @@ -552,11 +553,11 @@ bool FormDataParserMultipart::GetNextNameValue(Result* result) {
result->set_name(net::UnescapeBinaryURLComponent(name));
if (value_assigned) {
// Hold filename as value.
result->SetStringValue(value.as_string());
result->SetStringValue(std::string(value));
} else if (value_is_binary) {
result->SetBinaryValue(value);
} else {
result->SetStringValue(value.as_string());
result->SetStringValue(std::string(value));
}

return return_value;
Expand Down
5 changes: 3 additions & 2 deletions extensions/browser/url_request_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <string>

#include "base/strings/string_piece.h"
#include "extensions/browser/extension_navigation_ui_data.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
Expand Down Expand Up @@ -102,7 +103,7 @@ bool AllowCrossRendererResourceLoad(
// Allow web accessible extension resources to be loaded as
// subresources/sub-frames.
if (WebAccessibleResourcesInfo::IsResourceWebAccessible(
extension, resource_path.as_string(), request.request_initiator)) {
extension, std::string(resource_path), request.request_initiator)) {
*allowed = true;
return true;
}
Expand Down Expand Up @@ -137,7 +138,7 @@ bool AllowCrossRendererResourceLoadHelper(bool is_guest,
}

*allowed = WebviewInfo::IsResourceWebviewAccessible(
extension, partition_id, resource_path.as_string());
extension, partition_id, std::string(resource_path));
return true;
}

Expand Down
24 changes: 12 additions & 12 deletions extensions/common/csp_validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,17 @@ std::string GetSecureDirectiveValues(
if (is_secure_csp_token) {
sane_csp_parts.push_back(source_literal);
} else if (warnings) {
warnings->push_back(InstallWarning(
ErrorUtils::FormatErrorMessage(
manifest_errors::kInvalidCSPInsecureValueIgnored, manifest_key,
source_literal.as_string(), directive_name),
manifest_key));
warnings->push_back(
InstallWarning(ErrorUtils::FormatErrorMessage(
manifest_errors::kInvalidCSPInsecureValueIgnored,
manifest_key, source_literal, directive_name),
manifest_key));
}
}
// End of CSP directive that was started at the beginning of this method. If
// none of the values are secure, the policy will be empty and default to
// 'none', which is secure.
std::string last_part = sane_csp_parts.back().as_string();
std::string last_part(sane_csp_parts.back());
last_part.push_back(kDirectiveSeparator);
sane_csp_parts.back() = last_part;
return base::JoinString(sane_csp_parts, " ");
Expand Down Expand Up @@ -293,11 +293,11 @@ std::string GetAppSandboxSecureDirectiveValues(
seen_self_or_none |= source_lower == "'none'" || source_lower == "'self'";
sane_csp_parts.push_back(source_lower);
} else if (warnings) {
warnings->push_back(InstallWarning(
ErrorUtils::FormatErrorMessage(
manifest_errors::kInvalidCSPInsecureValueIgnored, manifest_key,
source_literal.as_string(), directive_name),
manifest_key));
warnings->push_back(
InstallWarning(ErrorUtils::FormatErrorMessage(
manifest_errors::kInvalidCSPInsecureValueIgnored,
manifest_key, source_literal, directive_name),
manifest_key));
}
}

Expand Down Expand Up @@ -351,7 +351,7 @@ class CSPDirectiveToken {
if (secure_value_)
return secure_value_.value();
// This token didn't require modification.
return directive_.directive_string.as_string() + kDirectiveSeparator;
return std::string(directive_.directive_string) + kDirectiveSeparator;
}

private:
Expand Down
3 changes: 2 additions & 1 deletion extensions/common/csp_validator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stddef.h>

#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -544,7 +545,7 @@ namespace csp_validator {

void PrintTo(const CSPParser::Directive& directive, ::std::ostream* os) {
*os << base::StringPrintf(
"[[%s] [%s] [%s]]", directive.directive_string.as_string().c_str(),
"[[%s] [%s] [%s]]", std::string(directive.directive_string).c_str(),
directive.directive_name.c_str(),
base::JoinString(directive.directive_values, ",").c_str());
}
Expand Down
3 changes: 2 additions & 1 deletion extensions/common/error_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <initializer_list>

#include "base/check_op.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
Expand All @@ -18,7 +19,7 @@ namespace {
std::string FormatErrorMessageInternal(
base::StringPiece format,
std::initializer_list<base::StringPiece> args) {
std::string format_str = format.as_string();
std::string format_str(format);
base::StringTokenizer tokenizer(format_str, "*");
tokenizer.set_options(base::StringTokenizer::RETURN_DELIMS);

Expand Down
9 changes: 5 additions & 4 deletions extensions/common/extension_l10n_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -560,13 +561,13 @@ ScopedLocaleForTest::ScopedLocaleForTest(base::StringPiece locale)
ScopedLocaleForTest::ScopedLocaleForTest(base::StringPiece process_locale,
base::StringPiece preferred_locale)
: ScopedLocaleForTest() {
SetProcessLocale(process_locale.as_string());
SetPreferredLocale(preferred_locale.as_string());
SetProcessLocale(std::string(process_locale));
SetPreferredLocale(std::string(preferred_locale));
}

ScopedLocaleForTest::~ScopedLocaleForTest() {
SetProcessLocale(process_locale_.as_string());
SetPreferredLocale(preferred_locale_.as_string());
SetProcessLocale(std::string(process_locale_));
SetPreferredLocale(std::string(preferred_locale_));
}

const std::string& GetPreferredLocaleForTest() {
Expand Down
7 changes: 4 additions & 3 deletions extensions/common/features/feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
Expand Down Expand Up @@ -48,15 +49,15 @@ Feature::Feature() : no_parent_(false) {}
Feature::~Feature() {}

void Feature::set_name(base::StringPiece name) {
name_ = name.as_string();
name_ = std::string(name);
}

void Feature::set_alias(base::StringPiece alias) {
alias_ = alias.as_string();
alias_ = std::string(alias);
}

void Feature::set_source(base::StringPiece source) {
source_ = source.as_string();
source_ = std::string(source);
}

} // namespace extensions
6 changes: 4 additions & 2 deletions extensions/common/features/feature_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "base/debug/alias.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h"
Expand Down Expand Up @@ -196,11 +198,11 @@ const FeatureMap& FeatureProvider::GetAllFeatures() const {

void FeatureProvider::AddFeature(base::StringPiece name,
std::unique_ptr<Feature> feature) {
features_[name.as_string()] = std::move(feature);
features_[std::string(name)] = std::move(feature);
}

void FeatureProvider::AddFeature(base::StringPiece name, Feature* feature) {
features_[name.as_string()] = std::unique_ptr<Feature>(feature);
features_[std::string(name)] = base::WrapUnique(feature);
}

} // namespace extensions
5 changes: 3 additions & 2 deletions extensions/common/features/simple_feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/containers/contains.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "components/crx_file/id_util.h"
Expand Down Expand Up @@ -531,7 +532,7 @@ void SimpleFeature::set_blocklist(

void SimpleFeature::set_command_line_switch(
base::StringPiece command_line_switch) {
command_line_switch_ = command_line_switch.as_string();
command_line_switch_ = std::string(command_line_switch);
}

void SimpleFeature::set_contexts(std::initializer_list<Context> contexts) {
Expand All @@ -549,7 +550,7 @@ void SimpleFeature::set_extension_types(
}

void SimpleFeature::set_feature_flag(base::StringPiece feature_flag) {
feature_flag_ = feature_flag.as_string();
feature_flag_ = std::string(feature_flag);
}

void SimpleFeature::set_session_types(
Expand Down
7 changes: 4 additions & 3 deletions extensions/common/manifest_handlers/csp_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
Expand Down Expand Up @@ -253,7 +254,7 @@ bool CSPHandler::ParseExtensionPagesCSP(

std::vector<InstallWarning> warnings;
std::string sanitized_content_security_policy = SanitizeContentSecurityPolicy(
content_security_policy_str, manifest_key.as_string(),
content_security_policy_str, std::string(manifest_key),
GetValidatorOptions(extension), &warnings);
extension->AddInstallWarnings(std::move(warnings));

Expand Down Expand Up @@ -287,7 +288,7 @@ bool CSPHandler::ParseSandboxCSP(Extension* extension,
std::vector<InstallWarning> warnings;
std::string effective_sandbox_csp =
csp_validator::GetEffectiveSandoxedPageCSP(
sandbox_csp_str, manifest_key.as_string(), &warnings);
sandbox_csp_str, std::string(manifest_key), &warnings);
SetSandboxCSP(extension, std::move(effective_sandbox_csp));
extension->AddInstallWarnings(std::move(warnings));
return true;
Expand All @@ -304,7 +305,7 @@ bool CSPHandler::SetExtensionPagesCSP(Extension* extension,
} else {
DCHECK_EQ(content_security_policy,
SanitizeContentSecurityPolicy(
content_security_policy, manifest_key.as_string(),
content_security_policy, std::string(manifest_key),
GetValidatorOptions(extension), nullptr));
}

Expand Down
5 changes: 3 additions & 2 deletions extensions/common/manifest_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
#include "base/strings/pattern.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
Expand Down Expand Up @@ -67,11 +68,11 @@ ManifestTest::~ManifestTest() {
// Helper class that simplifies creating methods that take either a filename
// to a manifest or the manifest itself.
ManifestTest::ManifestData::ManifestData(base::StringPiece name)
: name_(name.as_string()) {}
: name_(name) {}

ManifestTest::ManifestData::ManifestData(base::Value manifest,
base::StringPiece name)
: name_(name.as_string()), manifest_(std::move(manifest)) {
: name_(name), manifest_(std::move(manifest)) {
CHECK(manifest_.is_dict()) << "Manifest must be a dictionary. " << name_;
}

Expand Down
3 changes: 2 additions & 1 deletion extensions/common/url_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -308,7 +309,7 @@ URLPattern::ParseResult URLPattern::Parse(base::StringPiece pattern) {
host_piece = host_piece.substr(2);
}

host_ = host_piece.as_string();
host_ = std::string(host_piece);

path_start_pos = host_end_pos;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "extensions/renderer/bindings/api_binding_hooks_test_delegate.h"

#include "base/strings/string_piece.h"

namespace extensions {

APIBindingHooksTestDelegate::APIBindingHooksTestDelegate() {}
Expand All @@ -22,7 +24,7 @@ bool APIBindingHooksTestDelegate::CreateCustomEvent(

void APIBindingHooksTestDelegate::AddHandler(base::StringPiece name,
RequestHandler handler) {
request_handlers_[name.as_string()] = std::move(handler);
request_handlers_[std::string(name)] = std::move(handler);
}

void APIBindingHooksTestDelegate::SetCustomEvent(
Expand Down
3 changes: 2 additions & 1 deletion extensions/renderer/bindings/api_binding_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "content/public/renderer/v8_value_converter.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ bool RunFunctionImpl(v8::Local<v8::Function> function,

std::string ReplaceSingleQuotes(base::StringPiece str) {
std::string result;
base::ReplaceChars(str.as_string(), "'", "\"", &result);
base::ReplaceChars(str, "'", "\"", &result);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/renderer/bindings/argument_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class ArgumentSpec {
ArgumentType type() const { return type_; }
const std::set<std::string>& enum_values() const { return enum_values_; }

void set_name(base::StringPiece name) { name_ = name.as_string(); }
void set_name(base::StringPiece name) { name_ = std::string(name); }
void set_optional(bool optional) { optional_ = optional; }
void set_ref(base::StringPiece ref) { ref_ = ref.as_string(); }
void set_ref(base::StringPiece ref) { ref_ = std::string(ref); }
void set_minimum(int minimum) { minimum_ = minimum; }
void set_properties(PropertiesMap properties) {
properties_ = std::move(properties);
Expand Down
3 changes: 2 additions & 1 deletion extensions/renderer/bindings/argument_spec_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "extensions/renderer/bindings/argument_spec_builder.h"

#include "base/strings/string_piece.h"

namespace extensions {

Expand All @@ -27,7 +28,7 @@ ArgumentSpecBuilder& ArgumentSpecBuilder::MakeOptional() {
ArgumentSpecBuilder& ArgumentSpecBuilder::AddProperty(
base::StringPiece property_name,
std::unique_ptr<ArgumentSpec> property_spec) {
properties_[property_name.as_string()] = std::move(property_spec);
properties_[std::string(property_name)] = std::move(property_spec);
return *this;
}

Expand Down
3 changes: 2 additions & 1 deletion extensions/renderer/content_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <set>

#include "base/strings/string_piece.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h"
Expand Down Expand Up @@ -129,7 +130,7 @@ void FrameContentWatcher::NotifyBrowserOfChange() {

std::vector<std::string> selector_strings;
for (const base::StringPiece& selector : transitive_selectors)
selector_strings.push_back(selector.as_string());
selector_strings.push_back(std::string(selector));

ExtensionFrameHelper::Get(render_frame())
->GetLocalFrameHost()
Expand Down
Loading

0 comments on commit 8543dc6

Please sign in to comment.