Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1659)

Unified Diff: chrome/browser/metrics/variations/variations_http_header_provider.cc

Issue 307743003: Add more Google domains to the list of domains which should have (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more comments from avd Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/variations/variations_http_header_provider.cc
diff --git a/chrome/browser/metrics/variations/variations_http_header_provider.cc b/chrome/browser/metrics/variations/variations_http_header_provider.cc
index 90fde20a0df46a7ae25e8f91559fb7d89f735aa0..725852e4f7a8bb4fe81916ceeb176e9de9818c07 100644
--- a/chrome/browser/metrics/variations/variations_http_header_provider.cc
+++ b/chrome/browser/metrics/variations/variations_http_header_provider.cc
@@ -20,6 +20,24 @@
namespace chrome_variations {
+namespace {
+
+const char* kSuffixesToSetHeadersFor[] = {
+ "android.com",
+ "doubleclick.com",
+ "doubleclick.net",
+ "ggpht.com",
+ "googleadservices.com",
+ "googleapis.com",
+ "googlesyndication.com",
+ "googleusercontent.com",
+ "googlevideo.com",
+ "gstatic.com",
+ "ytimg.com",
+};
+
+} // namespace
+
VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() {
return Singleton<VariationsHttpHeaderProvider>::get();
}
@@ -95,6 +113,9 @@ bool VariationsHttpHeaderProvider::SetDefaultVariationIds(
VariationsHttpHeaderProvider::VariationsHttpHeaderProvider()
: variation_ids_cache_initialized_(false) {
+ for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
+ suffixes_to_set_headers_for_.insert(kSuffixesToSetHeadersFor[i]);
+ }
}
VariationsHttpHeaderProvider::~VariationsHttpHeaderProvider() {
@@ -216,7 +237,6 @@ void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() {
variation_ids_header_ = hashed;
}
-// static
bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) {
if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
google_util::ALLOW_NON_STANDARD_PORTS)) {
@@ -229,10 +249,27 @@ bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) {
// Some domains don't have international TLD extensions, so testing for them
// is very straight forward.
const std::string host = url.host();
- if (EndsWith(host, ".doubleclick.net", false) ||
- EndsWith(host, ".googlesyndication.com", false) ||
- LowerCaseEqualsASCII(host, "www.googleadservices.com")) {
- return true;
+ size_t suffix_start = host.length();
+ bool found_first_dot = false;
+ for (size_t i = host.length(); i > 0; --i) {
Alexei Svitkine (slow) 2014/05/30 17:23:10 Can you use string::find_last_of() instead? (the
Ryan Hamilton 2014/05/30 19:04:38 I tried that, but it doesn't seem to work. Here's
Alexei Svitkine (slow) 2014/05/30 19:06:19 I see. Perhaps just call it twice then?
Ryan Hamilton 2014/05/30 19:24:57 Heh, sure. Done.
+ if (host[i - 1] != '.') {
+ continue;
+ }
+
+ if (!found_first_dot) {
+ found_first_dot = true;
+ continue;
+ }
+
+ suffix_start = i;
+ break;
+ }
+
+ if (suffix_start != host.length()) {
+ std::string suffix = StringToLowerASCII(host.substr(suffix_start));
Alexei Svitkine (slow) 2014/05/30 17:23:10 Wait, what if it's not ASCII?
Ryan Hamilton 2014/05/30 19:04:38 All of the suffixes in "suffixes_to_set_headers_fo
+ if (ContainsKey(suffixes_to_set_headers_for_, suffix)) {
Alexei Svitkine (slow) 2014/05/30 17:23:10 Nit: No {}'s
Ryan Hamilton 2014/05/30 19:04:38 Done.
+ return true;
+ }
}
// The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>.

Powered by Google App Engine
This is Rietveld 408576698