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

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

Issue 2587513002: Switch variations http headers to only be reported over https. (Closed)
Patch Set: 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
82 void LogUrlValidationHistogram(URLValidationResult result) {
83 UMA_HISTOGRAM_ENUMERATION("Variations.Headers.URLValidationResult", result,
84 URL_VALIDATION_RESULT_SIZE);
85 }
86
42 } // namespace 87 } // namespace
43 88
44 void AppendVariationHeaders(const GURL& url, 89 void AppendVariationHeaders(const GURL& url,
45 bool incognito, 90 bool incognito,
46 bool uma_enabled, 91 bool uma_enabled,
47 bool is_signed_in, 92 bool is_signed_in,
48 net::HttpRequestHeaders* headers) { 93 net::HttpRequestHeaders* headers) {
49 // Note the criteria for attaching client experiment headers: 94 // Note the criteria for attaching client experiment headers:
50 // 1. We only transmit to Google owned domains which can evaluate experiments. 95 // 1. We only transmit to Google owned domains which can evaluate experiments.
51 // 1a. These include hosts which have a standard postfix such as: 96 // 1a. These include hosts which have a standard postfix such as:
(...skipping 23 matching lines...) Expand all
75 std::set<std::string> headers; 120 std::set<std::string> headers;
76 headers.insert(kChromeUMAEnabled); 121 headers.insert(kChromeUMAEnabled);
77 headers.insert(kClientData); 122 headers.insert(kClientData);
78 return headers; 123 return headers;
79 } 124 }
80 125
81 namespace internal { 126 namespace internal {
82 127
83 // static 128 // static
84 bool ShouldAppendVariationHeaders(const GURL& url) { 129 bool ShouldAppendVariationHeaders(const GURL& url) {
85 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 130 if (!url.is_valid()) {
86 google_util::ALLOW_NON_STANDARD_PORTS)) { 131 LogUrlValidationHistogram(INVALID_URL);
87 return true; 132 return false;
133 }
134 if (!url.SchemeIs("https")) {
135 LogUrlValidationHistogram(NOT_HTTPS);
136 return false;
137 }
138 if (!IsGoogleDomain(url)) {
139 LogUrlValidationHistogram(NOT_GOOGLE_DOMAIN);
140 return false;
88 } 141 }
89 142
90 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) 143 LogUrlValidationHistogram(SHOULD_APPEND);
91 return false; 144 return true;
92
93 // Some domains don't have international TLD extensions, so testing for them
94 // is very straight forward.
95 const std::string host = url.host();
96 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
97 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
98 base::CompareCase::INSENSITIVE_ASCII))
99 return true;
100 }
101 for (size_t i = 0; i < arraysize(kHostsToSetHeadersFor); ++i) {
102 if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i]))
103 return true;
104 }
105
106 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
107 google_util::ALLOW_NON_STANDARD_PORTS);
108 } 145 }
109 146
110 } // namespace internal 147 } // namespace internal
111 148
112 } // namespace variations 149 } // 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