Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 return false; | 196 return false; |
| 197 | 197 |
| 198 // Check for query parameter in URL parameter and hash fragment, depending on | 198 // Check for query parameter in URL parameter and hash fragment, depending on |
| 199 // the path type. | 199 // the path type. |
| 200 std::string query(original_url.query()); | 200 std::string query(original_url.query()); |
| 201 std::string ref(original_url.ref()); | 201 std::string ref(original_url.ref()); |
| 202 return HasQueryParameter(ref) || | 202 return HasQueryParameter(ref) || |
| 203 (!is_home_page_base && HasQueryParameter(query)); | 203 (!is_home_page_base && HasQueryParameter(query)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool IsEmbeddedGoogleSearchUrl(const std::string& url) { | |
| 207 if (!IsGoogleSearchUrl(url)) | |
| 208 return false; | |
| 209 | |
| 210 const std::string embedded_search_key = "espv="; | |
| 211 | |
| 212 GURL original_url(url); | |
| 213 std::vector<std::string> parameters; | |
| 214 base::SplitString(original_url.query(), '&', ¶meters); | |
| 215 for (std::vector<std::string>::const_iterator it = parameters.begin(); | |
| 216 it != parameters.end(); ++it) { | |
| 217 // If the parameter key is |embedded_search_key| and the value is not 0 this | |
| 218 // is an embedded Google search URL. | |
| 219 if (StartsWithASCII(*it, embedded_search_key, true)) { | |
| 220 std::string value = it->substr(embedded_search_key.length()); | |
| 221 return value.length() > 0 && value != "0"; | |
|
Ilya Sherman
2012/06/21 17:46:58
Optional nit: "value.length() > 0" -> "!value.empt
dhollowa
2012/06/21 22:16:43
Done. Rephrased with |Component| terminology.
| |
| 222 } | |
| 223 } | |
|
Ilya Sherman
2012/06/21 17:46:58
You might want to use GURL's implementation [1] fo
dhollowa
2012/06/21 22:16:43
Much better. Thanks for the tip!
On 2012/06/21 1
| |
| 224 return false; | |
| 225 } | |
| 226 | |
| 206 bool IsOrganic(const std::string& brand) { | 227 bool IsOrganic(const std::string& brand) { |
| 207 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 228 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 208 if (command_line.HasSwitch(switches::kOrganicInstall)) | 229 if (command_line.HasSwitch(switches::kOrganicInstall)) |
| 209 return true; | 230 return true; |
| 210 | 231 |
| 211 #if defined(OS_MACOSX) | 232 #if defined(OS_MACOSX) |
| 212 if (brand.empty()) { | 233 if (brand.empty()) { |
| 213 // An empty brand string on Mac is used for channels other than stable, | 234 // An empty brand string on Mac is used for channels other than stable, |
| 214 // which are always organic. | 235 // which are always organic. |
| 215 return true; | 236 return true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 const char* const kBrands[] = { | 279 const char* const kBrands[] = { |
| 259 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 280 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 260 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 281 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 261 }; | 282 }; |
| 262 const char* const* end = &kBrands[arraysize(kBrands)]; | 283 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 263 const char* const* found = std::find(&kBrands[0], end, brand); | 284 const char* const* found = std::find(&kBrands[0], end, brand); |
| 264 return found != end; | 285 return found != end; |
| 265 } | 286 } |
| 266 | 287 |
| 267 } // namespace google_util | 288 } // namespace google_util |
| OLD | NEW |