0

Convert base::StringPiece to std::string_view in //content

The changes of this CL are made using the following script.
Script: https://issues.chromium.org/issues/40506050#comment344

Bug: 40506050
Change-Id: Ic19c285872eadf7f45c7b010d8b6ec5e29cd5ccd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5463138
Commit-Queue: Helmut Januschka <helmut@januschka.com>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1290216}
This commit is contained in:
Helmut Januschka
2024-04-19 22:25:08 +00:00
committed by Chromium LUCI CQ
parent 758da8669e
commit 61db50b711
13 changed files with 28 additions and 25 deletions

@ -2931,7 +2931,7 @@ ChildProcessSecurityPolicyImpl::ParseIsolatedOrigins(
std::vector<IsolatedOriginPattern> patterns;
patterns.reserve(origin_strings.size());
for (const std::string_view& origin_string : origin_strings) {
for (std::string_view origin_string : origin_strings) {
patterns.emplace_back(origin_string);
}

@ -545,7 +545,7 @@ class TargetHandler::Session : public DevToolsAgentHostClient {
// TODO(johannes): For now, We need to copy here because
// ReceivedMessageFromTarget is generated code and we're using const
// std::string& for such parameters. Perhaps we should switch this to
// base::StringPiece?
// std::string_view?
std::string message_copy(message.begin(), message.end());
handler_->frontend_->ReceivedMessageFromTarget(id_, message_copy,
agent_host_->GetId());

@ -31,7 +31,7 @@ namespace {
// static variable.
static void CheckPreloadingPredictorValidity(PreloadingPredictor predictor) {
#if DCHECK_IS_ON()
// Use `std::string` because we can't guarantee base::StringPiece has a static
// Use `std::string` because we can't guarantee std::string_view has a static
// lifetime.
static base::NoDestructor<std::vector<std::pair<int64_t, std::string>>>
seen_predictors;

@ -10285,7 +10285,7 @@ WebContentsImpl::ParseDownloadHeaders(const std::string& headers) {
OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::ParseDownloadHeaders",
"headers", headers);
download::DownloadUrlParameters::RequestHeadersType request_headers;
for (const std::string_view& key_value : base::SplitStringPiece(
for (std::string_view key_value : base::SplitStringPiece(
headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
std::vector<std::string> pair = base::SplitString(
key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);

@ -186,7 +186,7 @@ class SignedExchangeCertFetcherTest : public testing::Test {
return net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
}
static std::string CreateCertMessage(const std::string_view& cert_data) {
static std::string CreateCertMessage(std::string_view cert_data) {
cbor::Value::MapValue cbor_map;
cbor_map[cbor::Value("sct")] =
cbor::Value("SCT", cbor::Value::Type::BYTE_STRING);

@ -3,14 +3,16 @@
// found in the LICENSE file.
#include "content/common/input/web_input_event_builders_mac.h"
#include "base/check.h"
#include <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#include <stddef.h>
#import <string_view>
#include "base/apple/owned_objc.h"
#include "base/apple/scoped_cftyperef.h"
#include "base/check.h"
#include "base/mac/mac_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversion_utils.h"
@ -55,7 +57,7 @@ const ModifierKey kModifierKeys[] = {
};
NSEvent* BuildFakeKeyEvent(NSUInteger key_code,
base::StringPiece16 character,
std::u16string_view character,
NSUInteger modifier_flags,
NSEventType event_type) {
NSString* string = base::SysUTF16ToNSString(character);
@ -75,7 +77,7 @@ NSEvent* BuildFakeKeyEvent(NSUInteger key_code,
char16_t code_point,
NSUInteger modifier_flags,
NSEventType event_type) {
return BuildFakeKeyEvent(key_code, base::StringPiece16(&code_point, 1),
return BuildFakeKeyEvent(key_code, std::u16string_view(&code_point, 1),
modifier_flags, event_type);
}

@ -166,7 +166,8 @@ class CONTENT_EXPORT ContentClient {
virtual std::u16string GetLocalizedString(int message_id,
const std::u16string& replacement);
// Return the contents of a resource in a StringPiece given the resource id.
// Return the contents of a resource in a std::string_view given the resource
// id.
virtual std::string_view GetDataResource(
int resource_id,
ui::ResourceScaleFactor scale_factor);

@ -1549,7 +1549,7 @@ std::string AnnotateAndAdjustJsStackTraces(std::string_view js_error,
// Loop over each line of |js_error|, and append each to |annotated_error| --
// possibly rewriting to include extra context.
std::ostringstream annotated_error;
for (const std::string_view& error_line : base::SplitStringPiece(
for (std::string_view error_line : base::SplitStringPiece(
js_error, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)) {
// Does this look like a stack frame whose URL source matches |source_name|?
if (base::MatchPattern(error_line, source_frame_pattern)) {

@ -630,8 +630,8 @@ void ExecuteScriptAsyncWithoutUserGesture(const ToRenderFrameHost& adapter,
std::string_view script);
// JsLiteralHelper is a helper class that determines what types are legal to
// pass to StringifyJsLiteral. Legal types include int, string, StringPiece,
// char*, bool, double, GURL, url::Origin, and base::Value&&.
// pass to StringifyJsLiteral. Legal types include int, string,
// std::string_view, char*, bool, double, GURL, url::Origin, and base::Value&&.
template <typename T>
struct JsLiteralHelper {
// This generic version enables passing any type from which base::Value can be
@ -663,7 +663,7 @@ struct JsLiteralHelper<url::Origin> {
// Construct a list-type base::Value from a mix of arguments.
//
// Each |arg| can be any type explicitly convertible to base::Value
// (including int/string/StringPiece/char*/double/bool), or any type that
// (including int/string/std::string_view/char*/double/bool), or any type that
// JsLiteralHelper is specialized for -- like URL and url::Origin, which emit
// string literals. |args| can be a mix of different types.
template <typename... Args>
@ -683,7 +683,7 @@ base::Value ListValueOf(Args&&... args) {
// escape string content, even if it contains slashes or quotation marks.
//
// Each |arg| can be any type explicitly convertible to base::Value
// (including int/string/StringPiece/char*/double/bool), or any type that
// (including int/string/std::string_view/char*/double/bool), or any type that
// JsLiteralHelper is specialized for -- like URL and url::Origin, which emit
// string literals. |args| can be a mix of different types.
//

@ -503,10 +503,10 @@ AXImageStopwords& AXImageStopwords::GetInstance() {
AXImageStopwords::AXImageStopwords() {
// Parse the newline-delimited stopwords from kImageStopwordsUtf8 and store
// them as a flat_set of type StringPiece. This is very memory-efficient
// because it avoids ever needing to copy any of the strings; each StringPiece
// is just a pointer into kImageStopwordsUtf8 and flat_set acts like a set but
// basically just does a binary search.
// them as a flat_set of type string_view. This is very memory-efficient
// because it avoids ever needing to copy any of the strings; each
// string_view is just a pointer into kImageStopwordsUtf8 and flat_set
// acts like a set but basically just does a binary search.
std::vector<std::string_view> stopwords =
base::SplitStringPiece(kImageStopwordsUtf8, "\n", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);

@ -353,7 +353,7 @@ std::optional<gfx::Vector2dF> ToVector(const std::string& direction,
return std::nullopt;
}
int ToKeyModifiers(const std::string_view& key) {
int ToKeyModifiers(std::string_view key) {
if (key == "Alt")
return blink::WebInputEvent::kAltKey;
if (key == "Control")
@ -372,7 +372,7 @@ int ToKeyModifiers(const std::string_view& key) {
return 0;
}
int ToButtonModifiers(const std::string_view& button) {
int ToButtonModifiers(std::string_view button) {
if (button == "Left")
return blink::WebMouseEvent::kLeftButtonDown;
if (button == "Middle")
@ -854,7 +854,7 @@ bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) {
int modifiers = 0;
std::vector<std::string_view> key_list = base::SplitStringPiece(
keys_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const std::string_view& key : key_list) {
for (std::string_view key : key_list) {
int key_modifier = ToKeyModifiers(key);
if (key_modifier == 0) {
return false;
@ -942,7 +942,7 @@ bool GpuBenchmarking::SmoothScrollByXY(gin::Arguments* args) {
int modifiers = 0;
std::vector<std::string_view> key_list = base::SplitStringPiece(
keys_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const std::string_view& key : key_list) {
for (std::string_view key : key_list) {
int key_modifier = ToKeyModifiers(key);
if (key_modifier == 0) {
return false;
@ -952,7 +952,7 @@ bool GpuBenchmarking::SmoothScrollByXY(gin::Arguments* args) {
std::vector<std::string_view> button_list = base::SplitStringPiece(
buttons_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const std::string_view& button : button_list) {
for (std::string_view button : button_list) {
int button_modifier = ToButtonModifiers(button);
if (button_modifier == 0) {
return false;

@ -243,7 +243,7 @@ base::flat_set<url::Origin> GetIsolatedContextOriginSetFromFlag() {
cmdline_origins, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
base::flat_set<url::Origin> origin_set;
for (const std::string_view& origin_string : origin_strings) {
for (std::string_view origin_string : origin_strings) {
url::Origin allowed_origin = url::Origin::Create(GURL(origin_string));
if (!allowed_origin.opaque()) {
origin_set.insert(allowed_origin);

@ -2786,7 +2786,7 @@ printing::PageRanges TestRunner::GetPrintingPageRanges(
base::SPLIT_WANT_NONEMPTY);
printing::PageRanges result;
for (const std::string_view& range_string : range_strings) {
for (std::string_view range_string : range_strings) {
// The format for each range is "<int> | <int>? - <int>?" where the page
// numbers are 1-indexed.
const std::vector<std::string_view> page_strings = base::SplitStringPiece(