| OLD | NEW |
| 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/metrics/histogram_macros.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const char kClientData[] = "X-Client-Data"; | 41 const char kClientData[] = "X-Client-Data"; |
| 42 | 42 |
| 43 // The result of checking if a URL should have variations headers appended. | 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 | 44 // This enum is used to record UMA histogram values, and should not be |
| 45 // reordered. | 45 // reordered. |
| 46 enum URLValidationResult { | 46 enum URLValidationResult { |
| 47 INVALID_URL, | 47 INVALID_URL, |
| 48 NOT_HTTPS, | 48 NOT_HTTPS, |
| 49 NOT_GOOGLE_DOMAIN, | 49 NOT_GOOGLE_DOMAIN, |
| 50 SHOULD_APPEND, | 50 SHOULD_APPEND, |
| 51 NEITHER_HTTP_HTTPS, |
| 52 IS_GOOGLE_NOT_HTTPS, |
| 51 URL_VALIDATION_RESULT_SIZE, | 53 URL_VALIDATION_RESULT_SIZE, |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 // Checks whether headers should be appended to the |url|, based on the domain | 56 // 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. | 57 // of |url|. |url| is assumed to be valid, and to have an http/https scheme. |
| 56 bool IsGoogleDomain(const GURL& url) { | 58 bool IsGoogleDomain(const GURL& url) { |
| 57 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, | 59 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
| 58 google_util::ALLOW_NON_STANDARD_PORTS)) { | 60 google_util::ALLOW_NON_STANDARD_PORTS)) { |
| 59 return true; | 61 return true; |
| 60 } | 62 } |
| 61 if (google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, | 63 if (google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
| 62 google_util::ALLOW_NON_STANDARD_PORTS)) { | 64 google_util::ALLOW_NON_STANDARD_PORTS)) { |
| 63 return true; | 65 return true; |
| 64 } | 66 } |
| 65 | 67 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 126 } |
| 125 | 127 |
| 126 namespace internal { | 128 namespace internal { |
| 127 | 129 |
| 128 // static | 130 // static |
| 129 bool ShouldAppendVariationHeaders(const GURL& url) { | 131 bool ShouldAppendVariationHeaders(const GURL& url) { |
| 130 if (!url.is_valid()) { | 132 if (!url.is_valid()) { |
| 131 LogUrlValidationHistogram(INVALID_URL); | 133 LogUrlValidationHistogram(INVALID_URL); |
| 132 return false; | 134 return false; |
| 133 } | 135 } |
| 134 if (!url.SchemeIs("https")) { | 136 if (!url.SchemeIsHTTPOrHTTPS()) { |
| 135 LogUrlValidationHistogram(NOT_HTTPS); | 137 LogUrlValidationHistogram(NEITHER_HTTP_HTTPS); |
| 136 return false; | 138 return false; |
| 137 } | 139 } |
| 138 if (!IsGoogleDomain(url)) { | 140 if (!IsGoogleDomain(url)) { |
| 139 LogUrlValidationHistogram(NOT_GOOGLE_DOMAIN); | 141 LogUrlValidationHistogram(NOT_GOOGLE_DOMAIN); |
| 140 return false; | 142 return false; |
| 141 } | 143 } |
| 142 | 144 // We check https here, rather than before the IsGoogleDomain() check, to know |
| 145 // how many Google domains are being rejected by the change to https only. |
| 146 if (!url.SchemeIs("https")) { |
| 147 LogUrlValidationHistogram(IS_GOOGLE_NOT_HTTPS); |
| 148 return false; |
| 149 } |
| 143 LogUrlValidationHistogram(SHOULD_APPEND); | 150 LogUrlValidationHistogram(SHOULD_APPEND); |
| 144 return true; | 151 return true; |
| 145 } | 152 } |
| 146 | 153 |
| 147 } // namespace internal | 154 } // namespace internal |
| 148 | 155 |
| 149 } // namespace variations | 156 } // namespace variations |
| OLD | NEW |