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

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

Issue 2563103002: Switch variations http headers to only be reported over https. (Closed)
Patch Set: comment fixes Created 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/variations/net/variations_http_headers.h" 5 #include "components/variations/net/variations_http_headers.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "components/google/core/browser/google_util.h" 12 #include "components/google/core/browser/google_util.h"
12 #include "components/variations/variations_http_header_provider.h" 13 #include "components/variations/variations_http_header_provider.h"
13 #include "net/http/http_request_headers.h" 14 #include "net/http/http_request_headers.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace variations { 17 namespace variations {
17 18
18 namespace { 19 namespace {
19 20
(...skipping 12 matching lines...) Expand all
32 }; 33 };
33 34
34 // Exact hostnames in lowercase to set headers for. 35 // Exact hostnames in lowercase to set headers for.
35 const char* kHostsToSetHeadersFor[] = { 36 const char* kHostsToSetHeadersFor[] = {
36 "googleweblight.com", 37 "googleweblight.com",
37 }; 38 };
38 39
39 const char kChromeUMAEnabled[] = "X-Chrome-UMA-Enabled"; 40 const char kChromeUMAEnabled[] = "X-Chrome-UMA-Enabled";
40 const char kClientData[] = "X-Client-Data"; 41 const char kClientData[] = "X-Client-Data";
41 42
43 // The result of checking if a URL should have variations headers appended.
44 // This enum is used to record UMA histogram values, and should not be
45 // reordered.
46 enum URLValidationResult {
47 INVALID_URL,
48 NOT_HTTPS,
49 NOT_GOOGLE_DOMAIN,
50 SHOULD_APPEND,
51 URL_VALIDATION_RESULT_SIZE,
52 };
53
54 // Checks whether headers should be appended to the |url|, based on the domain
55 // of |url|. |url| is assumed to be valid, and to have the https scheme.
56 bool IsGoogleDomain(const GURL& url) {
57 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
58 google_util::ALLOW_NON_STANDARD_PORTS)) {
59 return true;
60 }
61 if (google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
62 google_util::ALLOW_NON_STANDARD_PORTS)) {
63 return true;
64 }
65
66 // Some domains don't have international TLD extensions, so testing for them
67 // is very straight forward.
68 const std::string host = url.host();
69 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
70 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
71 base::CompareCase::INSENSITIVE_ASCII))
72 return true;
73 }
74 for (size_t i = 0; i < arraysize(kHostsToSetHeadersFor); ++i) {
75 if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i]))
76 return true;
77 }
78
79 return false;
80 }
81
42 } // namespace 82 } // namespace
43 83
44 void AppendVariationHeaders(const GURL& url, 84 void AppendVariationHeaders(const GURL& url,
45 bool incognito, 85 bool incognito,
46 bool uma_enabled, 86 bool uma_enabled,
47 net::HttpRequestHeaders* headers) { 87 net::HttpRequestHeaders* headers) {
48 // Note the criteria for attaching client experiment headers: 88 // Note the criteria for attaching client experiment headers:
49 // 1. We only transmit to Google owned domains which can evaluate experiments. 89 // 1. We only transmit to Google owned domains which can evaluate experiments.
50 // 1a. These include hosts which have a standard postfix such as: 90 // 1a. These include hosts which have a standard postfix such as:
51 // *.doubleclick.net or *.googlesyndication.com or 91 // *.doubleclick.net or *.googlesyndication.com or
(...skipping 21 matching lines...) Expand all
73 std::set<std::string> headers; 113 std::set<std::string> headers;
74 headers.insert(kChromeUMAEnabled); 114 headers.insert(kChromeUMAEnabled);
75 headers.insert(kClientData); 115 headers.insert(kClientData);
76 return headers; 116 return headers;
77 } 117 }
78 118
79 namespace internal { 119 namespace internal {
80 120
81 // static 121 // static
82 bool ShouldAppendVariationHeaders(const GURL& url) { 122 bool ShouldAppendVariationHeaders(const GURL& url) {
83 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 123 const char kURLValidationResultHistogram[] =
84 google_util::ALLOW_NON_STANDARD_PORTS)) { 124 "Variations.Headers.URLValidationResult";
85 return true; 125 if (!url.is_valid()) {
126 UMA_HISTOGRAM_ENUMERATION(kURLValidationResultHistogram, INVALID_URL,
127 URL_VALIDATION_RESULT_SIZE);
128 return false;
129 }
130 if (!url.SchemeIs("https")) {
131 UMA_HISTOGRAM_ENUMERATION(kURLValidationResultHistogram, NOT_HTTPS,
132 URL_VALIDATION_RESULT_SIZE);
133 return false;
134 }
135 if (!IsGoogleDomain(url)) {
136 UMA_HISTOGRAM_ENUMERATION(kURLValidationResultHistogram, NOT_GOOGLE_DOMAIN,
137 URL_VALIDATION_RESULT_SIZE);
138 return false;
86 } 139 }
87 140
88 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) 141 UMA_HISTOGRAM_ENUMERATION(kURLValidationResultHistogram, SHOULD_APPEND,
89 return false; 142 URL_VALIDATION_RESULT_SIZE);
Alexei Svitkine (slow) 2016/12/12 20:41:16 Nit: Make a helper function for logging this - sin
jwd 2016/12/12 20:58:09 Done.
90 143 return true;
91 // Some domains don't have international TLD extensions, so testing for them
92 // is very straight forward.
93 const std::string host = url.host();
94 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
95 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
96 base::CompareCase::INSENSITIVE_ASCII))
97 return true;
98 }
99 for (size_t i = 0; i < arraysize(kHostsToSetHeadersFor); ++i) {
100 if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i]))
101 return true;
102 }
103
104 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
105 google_util::ALLOW_NON_STANDARD_PORTS);
106 } 144 }
107 145
108 } // namespace internal 146 } // namespace internal
109 147
110 } // namespace variations 148 } // 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