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

Side by Side Diff: components/variations/net/variations_http_headers.cc

Issue 1530133005: Refactor VariationsHttpHeaderProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include to srt_fetcher_win.cc. Created 5 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/variations/net/variations_http_headers.h"
6
7 #include "base/strings/string_util.h"
8 #include "components/google/core/browser/google_util.h"
9 #include "components/variations/variations_http_header_provider.h"
10 #include "net/http/http_request_headers.h"
11 #include "url/gurl.h"
12
13 namespace variations {
14
15 namespace {
16
17 const char* kSuffixesToSetHeadersFor[] = {
18 ".android.com",
19 ".doubleclick.com",
20 ".doubleclick.net",
21 ".ggpht.com",
22 ".googleadservices.com",
23 ".googleapis.com",
24 ".googlesyndication.com",
25 ".googleusercontent.com",
26 ".googlevideo.com",
27 ".gstatic.com",
28 ".ytimg.com",
29 };
30
31 const char kChromeUMAEnabled[] = "X-Chrome-UMA-Enabled";
32 const char kClientData[] = "X-Client-Data";
33
34 } // namespace
35
36 void AppendVariationHeaders(const GURL& url,
37 bool incognito,
38 bool uma_enabled,
39 net::HttpRequestHeaders* headers) {
40 // Note the criteria for attaching client experiment headers:
41 // 1. We only transmit to Google owned domains which can evaluate experiments.
42 // 1a. These include hosts which have a standard postfix such as:
43 // *.doubleclick.net or *.googlesyndication.com or
44 // exactly www.googleadservices.com or
45 // international TLD domains *.google.<TLD> or *.youtube.<TLD>.
46 // 2. Only transmit for non-Incognito profiles.
47 // 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled
48 // for this install of Chrome.
49 // 4. For the X-Client-Data header, only include non-empty variation IDs.
50 if (incognito || !internal::ShouldAppendVariationHeaders(url))
51 return;
52
53 if (uma_enabled)
54 headers->SetHeaderIfMissing(kChromeUMAEnabled, "1");
55
56 const std::string variation_ids_header =
57 VariationsHttpHeaderProvider::GetInstance()->GetClientDataHeader();
58 if (!variation_ids_header.empty()) {
59 // Note that prior to M33 this header was named X-Chrome-Variations.
60 headers->SetHeaderIfMissing(kClientData, variation_ids_header);
61 }
62 }
63
64 std::set<std::string> GetVariationHeaderNames() {
65 std::set<std::string> headers;
66 headers.insert(kChromeUMAEnabled);
67 headers.insert(kClientData);
68 return headers;
69 }
70
71 namespace internal {
72
73 // static
74 bool ShouldAppendVariationHeaders(const GURL& url) {
75 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
76 google_util::ALLOW_NON_STANDARD_PORTS)) {
77 return true;
78 }
79
80 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
81 return false;
82
83 // Some domains don't have international TLD extensions, so testing for them
84 // is very straight forward.
85 const std::string host = url.host();
86 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
87 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
88 base::CompareCase::INSENSITIVE_ASCII))
89 return true;
90 }
91
92 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
93 google_util::ALLOW_NON_STANDARD_PORTS);
94 }
95
96 } // namespace internal
97
98 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/net/variations_http_headers.h ('k') | components/variations/net/variations_http_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698