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

Side by Side Diff: chrome/browser/google/google_util.cc

Issue 10264023: Revert 134625 - Transmit a X-Chrome-UMA-Enabled bit to Google domains from clients that have UMA en… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/google/google_util.h" 5 #include "chrome/browser/google/google_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 26 matching lines...) Expand all
37 base::SplitString(str, '&', &parameters); 37 base::SplitString(str, '&', &parameters);
38 for (std::vector<std::string>::const_iterator itr = parameters.begin(); 38 for (std::vector<std::string>::const_iterator itr = parameters.begin();
39 itr != parameters.end(); 39 itr != parameters.end();
40 ++itr) { 40 ++itr) {
41 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) 41 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2)
42 return true; 42 return true;
43 } 43 }
44 return false; 44 return false;
45 } 45 }
46 46
47 // True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no
48 // explicit port.
49 bool IsGoogleDomainUrl(const GURL& url) {
50 return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
51 url.port().empty() && google_util::IsGoogleHostname(url.host());
52 }
53
47 } // anonymous namespace 54 } // anonymous namespace
48 55
49 namespace google_util { 56 namespace google_util {
50 57
51 const char kLinkDoctorBaseURL[] = 58 const char kLinkDoctorBaseURL[] =
52 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; 59 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl";
53 60
54 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { 61 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) {
55 DCHECK(brand_for_testing == NULL); 62 DCHECK(brand_for_testing == NULL);
56 brand_for_testing = brand_.c_str(); 63 brand_for_testing = brand_.c_str();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return true; 135 return true;
129 } 136 }
130 137
131 bool GetReactivationBrand(std::string* brand) { 138 bool GetReactivationBrand(std::string* brand) {
132 brand->clear(); 139 brand->clear();
133 return true; 140 return true;
134 } 141 }
135 142
136 #endif 143 #endif
137 144
138 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { 145 bool IsGoogleHostname(const std::string& host) {
139 GURL original_url(url);
140 return original_url.is_valid() && original_url.port().empty() &&
141 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) &&
142 google_util::IsGoogleHostname(original_url.host(), permission);
143 }
144
145 bool IsGoogleHostname(const std::string& host,
146 SubdomainPermission permission) {
147 size_t tld_length = 146 size_t tld_length =
148 net::RegistryControlledDomainService::GetRegistryLength(host, false); 147 net::RegistryControlledDomainService::GetRegistryLength(host, false);
149 if ((tld_length == 0) || (tld_length == std::string::npos)) 148 if ((tld_length == 0) || (tld_length == std::string::npos))
150 return false; 149 return false;
151 std::string host_minus_tld(host, 0, host.length() - tld_length); 150 std::string host_minus_tld(host, 0, host.length() - tld_length);
152 if (LowerCaseEqualsASCII(host_minus_tld, "google.")) 151 return LowerCaseEqualsASCII(host_minus_tld, "www.google.") ||
153 return true; 152 LowerCaseEqualsASCII(host_minus_tld, "google.");
154 if (permission == ALLOW_SUBDOMAIN)
155 return EndsWith(host_minus_tld, ".google.", false);
156 return LowerCaseEqualsASCII(host_minus_tld, "www.google.");
157 } 153 }
158 154
159 bool IsGoogleHomePageUrl(const std::string& url) { 155 bool IsGoogleHomePageUrl(const std::string& url) {
160 GURL original_url(url); 156 GURL original_url(url);
161 157
162 // First check to see if this has a Google domain. 158 // First check to see if this has a Google domain.
163 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) 159 if (!IsGoogleDomainUrl(original_url))
164 return false; 160 return false;
165 161
166 // Make sure the path is a known home page path. 162 // Make sure the path is a known home page path.
167 std::string path(original_url.path()); 163 std::string path(original_url.path());
168 if (path != "/" && path != "/webhp" && 164 if (path != "/" && path != "/webhp" &&
169 !StartsWithASCII(path, "/ig", false)) { 165 !StartsWithASCII(path, "/ig", false)) {
170 return false; 166 return false;
171 } 167 }
172 168
173 return true; 169 return true;
174 } 170 }
175 171
176 bool IsGoogleSearchUrl(const std::string& url) { 172 bool IsGoogleSearchUrl(const std::string& url) {
177 GURL original_url(url); 173 GURL original_url(url);
178 174
179 // First check to see if this has a Google domain. 175 // First check to see if this has a Google domain.
180 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) 176 if (!IsGoogleDomainUrl(original_url))
181 return false; 177 return false;
182 178
183 // Make sure the path is a known search path. 179 // Make sure the path is a known search path.
184 std::string path(original_url.path()); 180 std::string path(original_url.path());
185 bool has_valid_path = false; 181 bool has_valid_path = false;
186 bool is_home_page_base = false; 182 bool is_home_page_base = false;
187 if (path == "/search") { 183 if (path == "/search") {
188 has_valid_path = true; 184 has_valid_path = true;
189 } else if (path == "/webhp" || path == "/") { 185 } else if (path == "/webhp" || path == "/") {
190 // Note that we allow both "/" and "" paths, but GURL spits them 186 // Note that we allow both "/" and "" paths, but GURL spits them
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 const char* const kBrands[] = { 254 const char* const kBrands[] = {
259 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 255 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
260 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 256 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
261 }; 257 };
262 const char* const* end = &kBrands[arraysize(kBrands)]; 258 const char* const* end = &kBrands[arraysize(kBrands)];
263 const char* const* found = std::find(&kBrands[0], end, brand); 259 const char* const* found = std::find(&kBrands[0], end, brand);
264 return found != end; 260 return found != end;
265 } 261 }
266 262
267 } // namespace google_util 263 } // namespace google_util
OLDNEW
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698