summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 20:43:34 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 20:43:34 +0000
commit7f8a9933f3e80f70a398d06919403770ab16dbec (patch)
tree525fce1873ac0106b2f06917ddcca358cd5691d9
parent86327773b9cda750f363a40de9fe9c279f6e659e (diff)
downloadchromium_src-7f8a9933f3e80f70a398d06919403770ab16dbec.zip
chromium_src-7f8a9933f3e80f70a398d06919403770ab16dbec.tar.gz
chromium_src-7f8a9933f3e80f70a398d06919403770ab16dbec.tar.bz2
Append variations headers to youtube.<tld> in addition to google.<tld>.
BUG=263904 TEST=Unit tests. Review URL: https://chromiumcodereview.appspot.com/20318002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213983 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/google/google_util.h8
-rw-r--r--chrome/browser/metrics/variations/variations_http_header_provider.cc44
-rw-r--r--chrome/browser/metrics/variations/variations_http_header_provider.h8
-rw-r--r--chrome/browser/metrics/variations/variations_http_header_provider_unittest.cc42
-rw-r--r--chrome/chrome_tests_unit.gypi1
5 files changed, 89 insertions, 14 deletions
diff --git a/chrome/browser/google/google_util.h b/chrome/browser/google/google_util.h
index f3da3b4..99aedc5 100644
--- a/chrome/browser/google/google_util.h
+++ b/chrome/browser/google/google_util.h
@@ -83,15 +83,23 @@ bool StartsWithCommandLineGoogleBaseURL(const GURL& url);
// |subdomain_permission| is ignored.
bool IsGoogleHostname(const std::string& host,
SubdomainPermission subdomain_permission);
+
// True if |url| is a valid URL with a host that returns true for
// IsGoogleHostname(), and an HTTP or HTTPS scheme. If |port_permission| is
// DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard
// port for its scheme (80 for HTTP, 443 for HTTPS).
+//
+// Note that this only checks for google.<TLD> domains, but not other Google
+// properties. There is code in variations_http_header_provider.cc that checks
+// for additional Google properties, which can be moved here if more callers
+// are interested in this in the future.
bool IsGoogleDomainUrl(const GURL& url,
SubdomainPermission subdomain_permission,
PortPermission port_permission);
+
// True if |url| represents a valid Google home page URL.
bool IsGoogleHomePageUrl(const GURL& url);
+
// True if |url| represents a valid Google search URL.
bool IsGoogleSearchUrl(const GURL& url);
diff --git a/chrome/browser/metrics/variations/variations_http_header_provider.cc b/chrome/browser/metrics/variations/variations_http_header_provider.cc
index ebdf773..8142240 100644
--- a/chrome/browser/metrics/variations/variations_http_header_provider.cc
+++ b/chrome/browser/metrics/variations/variations_http_header_provider.cc
@@ -7,15 +7,13 @@
#include "base/base64.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram.h"
+#include "base/strings/string_util.h"
#include "chrome/browser/google/google_util.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/metrics/proto/chrome_experiments.pb.h"
#include "chrome/common/metrics/variations/variations_util.h"
-#include "content/public/browser/browser_thread.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_request_headers.h"
-
-using content::BrowserThread;
+#include "url/gurl.h"
namespace chrome_variations {
@@ -29,19 +27,13 @@ void VariationsHttpHeaderProvider::AppendHeaders(
bool uma_enabled,
net::HttpRequestHeaders* headers) {
// Note the criteria for attaching Chrome experiment headers:
- // 1. We only transmit to *.google.<TLD> domains. NOTE that this use of
- // google_util helpers to check this does not guarantee that the URL is
- // Google-owned, only that it is of the form *.google.<TLD>. In the future
- // we may choose to reinforce this check.
+ // 1. We only transmit to *.google.<TLD> or *.youtube.<TLD> domains.
// 2. Only transmit for non-Incognito profiles.
// 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled
// for this install of Chrome.
// 4. For the X-Chrome-Variations, only include non-empty variation IDs.
- if (incognito ||
- !google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
- google_util::ALLOW_NON_STANDARD_PORTS)) {
+ if (incognito || !ShouldAppendHeaders(url))
return;
- }
if (uma_enabled)
headers->SetHeaderIfMissing("X-Chrome-UMA-Enabled", "1");
@@ -148,7 +140,7 @@ void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() {
// If successful, swap the header value with the new one.
// Note that the list of IDs and the header could be temporarily out of sync
// if IDs are added as the header is recreated. The receiving servers are OK
- // with such descrepancies.
+ // with such discrepancies.
variation_ids_header_ = hashed;
} else {
NOTREACHED() << "Failed to base64 encode Variation IDs value: "
@@ -156,4 +148,28 @@ void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() {
}
}
+// static
+bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) {
+ if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
+ google_util::ALLOW_NON_STANDARD_PORTS)) {
+ return true;
+ }
+
+ // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>.
+ if (!url.is_valid() || !(url.SchemeIs("http") || url.SchemeIs("https")))
+ return false;
+
+ const std::string host = url.host();
+ const size_t tld_length = net::registry_controlled_domains::GetRegistryLength(
+ host,
+ net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
+ net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
+ if ((tld_length == 0) || (tld_length == std::string::npos))
+ return false;
+
+ const std::string host_minus_tld(host, 0, host.length() - tld_length);
+ return LowerCaseEqualsASCII(host_minus_tld, "youtube.") ||
+ EndsWith(host_minus_tld, ".youtube.", false);
+}
+
} // namespace chrome_variations
diff --git a/chrome/browser/metrics/variations/variations_http_header_provider.h b/chrome/browser/metrics/variations/variations_http_header_provider.h
index 0c7e3ac..2454149 100644
--- a/chrome/browser/metrics/variations/variations_http_header_provider.h
+++ b/chrome/browser/metrics/variations/variations_http_header_provider.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
#include "base/metrics/field_trial.h"
#include "base/synchronization/lock.h"
#include "chrome/common/metrics/variations/variation_ids.h"
@@ -48,6 +49,9 @@ class VariationsHttpHeaderProvider : base::FieldTrialList::Observer {
private:
friend struct DefaultSingletonTraits<VariationsHttpHeaderProvider>;
+ FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest,
+ ShouldAppendHeaders);
+
VariationsHttpHeaderProvider();
virtual ~VariationsHttpHeaderProvider();
@@ -68,6 +72,10 @@ class VariationsHttpHeaderProvider : base::FieldTrialList::Observer {
// held.
void UpdateVariationIDsHeaderValue();
+ // Checks whether variation headers should be appended to requests to the
+ // specified |url|. Returns true for google.<TLD> and youtube.<TLD> URLs.
+ static bool ShouldAppendHeaders(const GURL& url);
+
// Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and
// |variation_ids_header_|.
base::Lock lock_;
diff --git a/chrome/browser/metrics/variations/variations_http_header_provider_unittest.cc b/chrome/browser/metrics/variations/variations_http_header_provider_unittest.cc
new file mode 100644
index 0000000..9e997f9
--- /dev/null
+++ b/chrome/browser/metrics/variations/variations_http_header_provider_unittest.cc
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/variations/variations_http_header_provider.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace chrome_variations {
+
+TEST(VariationsHttpHeaderProviderTest, ShouldAppendHeaders) {
+ struct {
+ const char* url;
+ bool should_append_headers;
+ } cases[] = {
+ { "http://google.com", true },
+ { "http://www.google.com", true },
+ { "http://m.google.com", true },
+ { "http://google.ca", true },
+ { "https://google.ca", true },
+ { "http://google.co.uk", true },
+ { "http://google.co.uk:8080/", true },
+ { "http://www.google.co.uk:8080/", true },
+ { "http://youtube.com", true },
+ { "http://www.youtube.com", true },
+ { "http://www.youtube.ca", true },
+ { "http://www.youtube.co.uk:8080/", true },
+ { "https://www.youtube.com", true },
+ { "http://www.yahoo.com", false },
+ { "http://youtube", false },
+ { "http://google", false },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ const GURL url(cases[i].url);
+ EXPECT_EQ(cases[i].should_append_headers,
+ VariationsHttpHeaderProvider::ShouldAppendHeaders(url)) << url;
+ }
+}
+
+} // namespace chrome_variations
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 2573ec9..c3acb95 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -948,6 +948,7 @@
'browser/metrics/metrics_service_unittest.cc',
'browser/metrics/thread_watcher_unittest.cc',
'browser/metrics/time_ticks_experiment_unittest.cc',
+ 'browser/metrics/variations/variations_http_header_provider_unittest.cc',
'browser/metrics/variations/variations_seed_processor_unittest.cc',
'browser/metrics/variations/variations_service_unittest.cc',
'browser/metrics/variations/variations_request_scheduler_unittest.cc',