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

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: 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 ShouldAppendHeadersResult {
47 NOT_GOOGLE_DOMAIN,
48 GOOGLE_NOT_HTTPS,
49 SHOULD_APPEND,
50 SHOULD_APPEND_HEADERS_RESULT_SIZE,
51 };
52
53 // Checks whether headers should be appended to the |url|, based on the domain
54 // of |url|, and if it's an http/https spec.
rkaplow 2016/12/12 18:25:05 this method doesn't care about the ssl-ness
jwd 2016/12/12 19:23:08 Changed code.
55 bool ShouldAppendForDomain(const GURL& url) {
56 // IsGoogleDomainUrl checks if the url is valid and is http/https.
rkaplow 2016/12/12 18:25:05 I don't quite get the comment - this doesn't fully
jwd 2016/12/12 19:23:08 Changed code.
57 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
58 google_util::ALLOW_NON_STANDARD_PORTS)) {
59 return true;
60 }
61
62 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
rkaplow 2016/12/12 18:25:05 i realize this is just refactored, but it seems od
jwd 2016/12/12 19:23:08 Pulled check out to calling function.
63 return false;
64
65 // Some domains don't have international TLD extensions, so testing for them
66 // is very straight forward.
67 const std::string host = url.host();
68 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
69 if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
70 base::CompareCase::INSENSITIVE_ASCII))
71 return true;
72 }
73 for (size_t i = 0; i < arraysize(kHostsToSetHeadersFor); ++i) {
74 if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i]))
75 return true;
76 }
77
78 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
rkaplow 2016/12/12 18:25:05 this is a minor nit, but seems strange that this i
jwd 2016/12/12 19:23:08 Done.
79 google_util::ALLOW_NON_STANDARD_PORTS);
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 kShouldAppendResultHistogram[] =
84 google_util::ALLOW_NON_STANDARD_PORTS)) { 124 "Variations.Headers.ShouldAppendResult";
rkaplow 2016/12/12 18:25:05 I don't love the name of the histogram - it seems
jwd 2016/12/12 19:23:08 Done.
85 return true; 125 if (!ShouldAppendForDomain(url)) {
126 UMA_HISTOGRAM_ENUMERATION(kShouldAppendResultHistogram, NOT_GOOGLE_DOMAIN,
127 SHOULD_APPEND_HEADERS_RESULT_SIZE);
128 return false;
86 } 129 }
87 130
88 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) 131 bool isHttps = url.SchemeIs("https");
89 return false; 132 UMA_HISTOGRAM_ENUMERATION(kShouldAppendResultHistogram,
90 133 isHttps ? SHOULD_APPEND : GOOGLE_NOT_HTTPS,
91 // Some domains don't have international TLD extensions, so testing for them 134 SHOULD_APPEND_HEADERS_RESULT_SIZE);
92 // is very straight forward. 135 return isHttps;
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 } 136 }
107 137
108 } // namespace internal 138 } // namespace internal
109 139
110 } // namespace variations 140 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698