summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2015-07-23 14:56:35 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-23 21:57:37 +0000
commit85111674b30562ab0ba3a0f7d3b09761fdc09e00 (patch)
treea8ac1e3a51e6322156244b9b86516ccaccb2507d /components
parent666686c757e8c17d47ec2036e718eb85ca26fb1c (diff)
downloadchromium_src-85111674b30562ab0ba3a0f7d3b09761fdc09e00.zip
chromium_src-85111674b30562ab0ba3a0f7d3b09761fdc09e00.tar.gz
chromium_src-85111674b30562ab0ba3a0f7d3b09761fdc09e00.tar.bz2
Unify LowerCaseEqualsASCII and EqualsASCII functions.
This removes the many overrides and unifies on StringPIece implementations. StringPiece did not exist when these functions were written. The lack of StringPiece versions make it difficult to use when (typically newer) code has a StringPiece (for example, see affiliation_utils.cc), and StringPiece versions can't be added because it will be ambiguous with the std::string versions. There are a few dozen places where a WebString is passed into these functions. A WebString can not be implicitly converted into a StringPiece, so I added explicit base::StringPiece16 wrappers around the necessary parameters. This is actually nice because it emphasizes that a temporary is created. In a few places it does this redundantly and I pulled a string16 out (for example, drop_data_builder.cc). Callers that were using the iterator versions got converted to constructing a StringPiece with iterators. This was the case mostly for net where this pattern seems common. A few cases, such as data_reduction_proxy_config.cc were actually trying to do prefix matches. I converted these to StartsWith (cur current, more- convenient version of StartsWith is relatively new). Theoretically these aren't equivalent because StartsWith doesn't assume a previously-lower-cased 2nd argument. But the strings are short and the convenience makes up for the difference. I converted the define HTTP_LWS to a constant kHttpLinearWhitespace to avoid polluting the global namespace. This traces back to the original commit with a vague comment about overriding at buildtime (which can't happen). I kept the define in the .cc file because header pollution is less and C constant concatenation is used with this in a few places that would require a constant with confusing description or a temporary to be created. http_response_headers.cc: changed some functions to StringPIeces that used iterators for convenience and clarity. Added a TrimLWSPiece to NetUtil for convenience in the header parsing code. Significantly updated HttpUtil::ParseContentType to use StringPieces. Review URL: https://codereview.chromium.org/1242673002 Cr-Commit-Position: refs/heads/master@{#340176}
Diffstat (limited to 'components')
-rw-r--r--components/autofill/content/renderer/form_autofill_util.cc3
-rw-r--r--components/autofill/content/renderer/password_form_conversion_utils.cc5
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc7
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc14
-rw-r--r--components/history/core/browser/visitsegment_database.cc3
-rw-r--r--components/password_manager/core/browser/affiliation_utils.cc6
-rw-r--r--components/translate/content/renderer/translate_helper.cc3
7 files changed, 18 insertions, 23 deletions
diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc
index 2d43a30..7e96dd7 100644
--- a/components/autofill/content/renderer/form_autofill_util.cc
+++ b/components/autofill/content/renderer/form_autofill_util.cc
@@ -1182,7 +1182,8 @@ void WebFormControlElementToFormField(const WebFormControlElement& element,
// attribute was present.
field->autocomplete_attribute = "x-max-data-length-exceeded";
}
- if (base::LowerCaseEqualsASCII(element.getAttribute(kRole), "presentation"))
+ if (base::LowerCaseEqualsASCII(
+ base::StringPiece16(element.getAttribute(kRole)), "presentation"))
field->role = FormFieldData::ROLE_ATTRIBUTE_PRESENTATION;
if (!IsAutofillableElement(element))
diff --git a/components/autofill/content/renderer/password_form_conversion_utils.cc b/components/autofill/content/renderer/password_form_conversion_utils.cc
index 22be42e..a50fb03e 100644
--- a/components/autofill/content/renderer/password_form_conversion_utils.cc
+++ b/components/autofill/content/renderer/password_form_conversion_utils.cc
@@ -101,8 +101,9 @@ PasswordForm::Layout SequenceToLayout(base::StringPiece layout_sequence) {
// |element| is present and has the specified |value_in_lowercase|.
bool HasAutocompleteAttributeValue(const WebInputElement& element,
const char* value_in_lowercase) {
- return base::LowerCaseEqualsASCII(element.getAttribute("autocomplete"),
- value_in_lowercase);
+ return base::LowerCaseEqualsASCII(
+ base::StringPiece16(element.getAttribute("autocomplete")),
+ value_in_lowercase);
}
// Helper to determine which password is the main (current) one, and which is
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
index 6916e40..36f09fb 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
@@ -831,11 +831,8 @@ bool DataReductionProxyConfig::MaybeDisableIfVPN() {
// Data Saver will not be disabled on any other platform on VPN.
const std::string vpn_interface_name_prefix = "tun";
for (size_t i = 0; i < network_interfaces.size(); ++i) {
- std::string interface_name = network_interfaces[i].name;
- if (base::LowerCaseEqualsASCII(
- interface_name.begin(),
- interface_name.begin() + vpn_interface_name_prefix.size(),
- vpn_interface_name_prefix.c_str())) {
+ if (base::StartsWith(network_interfaces[i].name, vpn_interface_name_prefix,
+ base::CompareCase::INSENSITIVE_ASCII)) {
disabled_on_vpn_ = true;
ReloadConfig();
RecordNetworkChangeEvent(DISABLED_ON_VPN);
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
index b423275..0edb70f 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_headers.cc
@@ -74,8 +74,8 @@ bool GetDataReductionProxyActionValue(
while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) {
if (value.size() > prefix.size()) {
- if (base::LowerCaseEqualsASCII(
- value.begin(), value.begin() + prefix.size(), prefix.c_str())) {
+ if (base::StartsWith(value, prefix,
+ base::CompareCase::INSENSITIVE_ASCII)) {
if (action_value)
*action_value = value.substr(prefix.size());
return true;
@@ -98,8 +98,8 @@ bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers,
while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) {
if (value.size() > prefix.size()) {
- if (base::LowerCaseEqualsASCII(
- value.begin(), value.begin() + prefix.size(), prefix.c_str())) {
+ if (base::StartsWith(value, prefix,
+ base::CompareCase::INSENSITIVE_ASCII)) {
int64 seconds;
if (!base::StringToInt64(
StringPiece(value.begin() + prefix.size(), value.end()),
@@ -303,10 +303,8 @@ void GetDataReductionProxyHeaderWithFingerprintRemoved(
void* iter = NULL;
while (headers->EnumerateHeader(&iter, kChromeProxyHeader, &value)) {
if (value.size() > chrome_proxy_fingerprint_prefix.size()) {
- if (base::LowerCaseEqualsASCII(
- value.begin(),
- value.begin() + chrome_proxy_fingerprint_prefix.size(),
- chrome_proxy_fingerprint_prefix.c_str())) {
+ if (base::StartsWith(value, chrome_proxy_fingerprint_prefix,
+ base::CompareCase::INSENSITIVE_ASCII)) {
continue;
}
}
diff --git a/components/history/core/browser/visitsegment_database.cc b/components/history/core/browser/visitsegment_database.cc
index 891c1b5..afeecb7 100644
--- a/components/history/core/browser/visitsegment_database.cc
+++ b/components/history/core/browser/visitsegment_database.cc
@@ -105,10 +105,9 @@ std::string VisitSegmentDatabase::ComputeSegmentName(const GURL& url) {
const int kWWWDotLen = arraysize(kWWWDot) - 1;
std::string host = url.host();
- const char* host_c = host.c_str();
// Remove www. to avoid some dups.
if (static_cast<int>(host.size()) > kWWWDotLen &&
- base::LowerCaseEqualsASCII(host_c, host_c + kWWWDotLen, kWWWDot)) {
+ base::StartsWith(host, kWWWDot, base::CompareCase::INSENSITIVE_ASCII)) {
r.SetHost(host.c_str(),
url::Component(kWWWDotLen,
static_cast<int>(host.size()) - kWWWDotLen));
diff --git a/components/password_manager/core/browser/affiliation_utils.cc b/components/password_manager/core/browser/affiliation_utils.cc
index 2b16e8b..49b25c2 100644
--- a/components/password_manager/core/browser/affiliation_utils.cc
+++ b/components/password_manager/core/browser/affiliation_utils.cc
@@ -182,11 +182,9 @@ bool ParseAndCanonicalizeFacetURI(const std::string& input_uri,
url::ParseStandardURL(input_uri.c_str(), input_uri.size(), &input_parsed);
base::StringPiece scheme = ComponentString(input_uri, input_parsed.scheme);
- if (base::LowerCaseEqualsASCII(scheme.begin(), scheme.end(),
- url::kHttpsScheme)) {
+ if (base::LowerCaseEqualsASCII(scheme, url::kHttpsScheme)) {
return CanonicalizeWebFacetURI(input_uri, input_parsed, canonical_uri);
- } else if (base::LowerCaseEqualsASCII(scheme.begin(), scheme.end(),
- kAndroidAppScheme)) {
+ } else if (base::LowerCaseEqualsASCII(scheme, kAndroidAppScheme)) {
return CanonicalizeAndroidFacetURI(input_uri, input_parsed, canonical_uri);
}
return false;
diff --git a/components/translate/content/renderer/translate_helper.cc b/components/translate/content/renderer/translate_helper.cc
index 121cc32..41531bd 100644
--- a/components/translate/content/renderer/translate_helper.cc
+++ b/components/translate/content/renderer/translate_helper.cc
@@ -116,7 +116,8 @@ bool HasNoTranslateMeta(WebDocument* document) {
attribute = element.getAttribute(content);
if (attribute.isNull())
continue;
- if (base::LowerCaseEqualsASCII(attribute, "notranslate"))
+ if (base::LowerCaseEqualsASCII(base::StringPiece16(attribute),
+ "notranslate"))
return true;
}
return false;