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" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/google/google_url_tracker.h" | |
18 #include "chrome/common/net/url_fixer_upper.h" | 17 #include "chrome/common/net/url_fixer_upper.h" |
19 #include "chrome/installer/util/google_update_settings.h" | |
20 #include "components/google/core/browser/google_switches.h" | 18 #include "components/google/core/browser/google_switches.h" |
21 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
22 #include "net/base/url_util.h" | 20 #include "net/base/url_util.h" |
23 #include "url/gurl.h" | 21 #include "url/gurl.h" |
24 | 22 |
25 #if defined(OS_MACOSX) | |
26 #include "chrome/browser/mac/keystone_glue.h" | |
27 #elif defined(OS_CHROMEOS) | |
28 #include "chrome/browser/google/google_util_chromeos.h" | |
29 #endif | |
30 | |
31 // Only use Link Doctor on official builds. It uses an API key, too, but | 23 // Only use Link Doctor on official builds. It uses an API key, too, but |
32 // seems best to just disable it, for more responsive error pages and to reduce | 24 // seems best to just disable it, for more responsive error pages and to reduce |
33 // server load. | 25 // server load. |
34 #if defined(GOOGLE_CHROME_BUILD) | 26 #if defined(GOOGLE_CHROME_BUILD) |
35 #define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc" | 27 #define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc" |
36 #else | 28 #else |
37 #define LINKDOCTOR_SERVER_REQUEST_URL "" | 29 #define LINKDOCTOR_SERVER_REQUEST_URL "" |
38 #endif | 30 #endif |
39 | 31 |
40 | 32 |
41 // Helpers -------------------------------------------------------------------- | 33 // Helpers -------------------------------------------------------------------- |
42 | 34 |
43 namespace { | 35 namespace { |
44 | 36 |
45 const char* brand_for_testing = NULL; | |
46 bool gUseMockLinkDoctorBaseURLForTesting = false; | 37 bool gUseMockLinkDoctorBaseURLForTesting = false; |
47 | 38 |
48 bool IsPathHomePageBase(const std::string& path) { | 39 bool IsPathHomePageBase(const std::string& path) { |
49 return (path == "/") || (path == "/webhp"); | 40 return (path == "/") || (path == "/webhp"); |
50 } | 41 } |
51 | 42 |
52 } // namespace | 43 } // namespace |
53 | 44 |
54 | 45 |
55 namespace google_util { | 46 namespace google_util { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // To transform the homepage URL into the corresponding search URL, add the | 111 // To transform the homepage URL into the corresponding search URL, add the |
121 // "search" and the "q=" query string. | 112 // "search" and the "q=" query string. |
122 std::string search_path = "search"; | 113 std::string search_path = "search"; |
123 std::string query_string = "q="; | 114 std::string query_string = "q="; |
124 GURL::Replacements replacements; | 115 GURL::Replacements replacements; |
125 replacements.SetPathStr(search_path); | 116 replacements.SetPathStr(search_path); |
126 replacements.SetQueryStr(query_string); | 117 replacements.SetQueryStr(query_string); |
127 return google_homepage_url.ReplaceComponents(replacements); | 118 return google_homepage_url.ReplaceComponents(replacements); |
128 } | 119 } |
129 | 120 |
130 #if defined(OS_WIN) | |
131 | |
132 bool GetBrand(std::string* brand) { | |
133 if (brand_for_testing) { | |
134 brand->assign(brand_for_testing); | |
135 return true; | |
136 } | |
137 | |
138 base::string16 brand16; | |
139 bool ret = GoogleUpdateSettings::GetBrand(&brand16); | |
140 if (ret) | |
141 brand->assign(base::UTF16ToASCII(brand16)); | |
142 return ret; | |
143 } | |
144 | |
145 bool GetReactivationBrand(std::string* brand) { | |
146 base::string16 brand16; | |
147 bool ret = GoogleUpdateSettings::GetReactivationBrand(&brand16); | |
148 if (ret) | |
149 brand->assign(base::UTF16ToASCII(brand16)); | |
150 return ret; | |
151 } | |
152 | |
153 #else | |
154 | |
155 bool GetBrand(std::string* brand) { | |
156 if (brand_for_testing) { | |
157 brand->assign(brand_for_testing); | |
158 return true; | |
159 } | |
160 | |
161 #if defined(OS_MACOSX) | |
162 brand->assign(keystone_glue::BrandCode()); | |
163 #elif defined(OS_CHROMEOS) | |
164 brand->assign(google_util::chromeos::GetBrand()); | |
165 #else | |
166 brand->clear(); | |
167 #endif | |
168 return true; | |
169 } | |
170 | |
171 bool GetReactivationBrand(std::string* brand) { | |
172 brand->clear(); | |
173 return true; | |
174 } | |
175 | |
176 #endif | |
177 | |
178 GURL CommandLineGoogleBaseURL() { | 121 GURL CommandLineGoogleBaseURL() { |
179 // Unit tests may add command-line flags after the first call to this | 122 // Unit tests may add command-line flags after the first call to this |
180 // function, so we don't simply initialize a static |base_url| directly and | 123 // function, so we don't simply initialize a static |base_url| directly and |
181 // then unconditionally return it. | 124 // then unconditionally return it. |
182 CR_DEFINE_STATIC_LOCAL(std::string, switch_value, ()); | 125 CR_DEFINE_STATIC_LOCAL(std::string, switch_value, ()); |
183 CR_DEFINE_STATIC_LOCAL(GURL, base_url, ()); | 126 CR_DEFINE_STATIC_LOCAL(GURL, base_url, ()); |
184 std::string current_switch_value( | 127 std::string current_switch_value( |
185 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 128 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
186 switches::kGoogleBaseURL)); | 129 switches::kGoogleBaseURL)); |
187 if (current_switch_value != switch_value) { | 130 if (current_switch_value != switch_value) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 bool is_home_page_base = IsPathHomePageBase(path); | 190 bool is_home_page_base = IsPathHomePageBase(path); |
248 if (!is_home_page_base && (path != "/search")) | 191 if (!is_home_page_base && (path != "/search")) |
249 return false; | 192 return false; |
250 | 193 |
251 // Check for query parameter in URL parameter and hash fragment, depending on | 194 // Check for query parameter in URL parameter and hash fragment, depending on |
252 // the path type. | 195 // the path type. |
253 return HasGoogleSearchQueryParam(url.ref()) || | 196 return HasGoogleSearchQueryParam(url.ref()) || |
254 (!is_home_page_base && HasGoogleSearchQueryParam(url.query())); | 197 (!is_home_page_base && HasGoogleSearchQueryParam(url.query())); |
255 } | 198 } |
256 | 199 |
257 bool IsOrganic(const std::string& brand) { | |
258 #if defined(OS_MACOSX) | |
259 if (brand.empty()) { | |
260 // An empty brand string on Mac is used for channels other than stable, | |
261 // which are always organic. | |
262 return true; | |
263 } | |
264 #endif | |
265 | |
266 const char* const kBrands[] = { | |
267 "CHCA", "CHCB", "CHCG", "CHCH", "CHCI", "CHCJ", "CHCK", "CHCL", | |
268 "CHFO", "CHFT", "CHHS", "CHHM", "CHMA", "CHMB", "CHME", "CHMF", | |
269 "CHMG", "CHMH", "CHMI", "CHMQ", "CHMV", "CHNB", "CHNC", "CHNG", | |
270 "CHNH", "CHNI", "CHOA", "CHOB", "CHOC", "CHON", "CHOO", "CHOP", | |
271 "CHOQ", "CHOR", "CHOS", "CHOT", "CHOU", "CHOX", "CHOY", "CHOZ", | |
272 "CHPD", "CHPE", "CHPF", "CHPG", "ECBA", "ECBB", "ECDA", "ECDB", | |
273 "ECSA", "ECSB", "ECVA", "ECVB", "ECWA", "ECWB", "ECWC", "ECWD", | |
274 "ECWE", "ECWF", "EUBB", "EUBC", "GGLA", "GGLS" | |
275 }; | |
276 const char* const* end = &kBrands[arraysize(kBrands)]; | |
277 const char* const* found = std::find(&kBrands[0], end, brand); | |
278 if (found != end) | |
279 return true; | |
280 | |
281 return StartsWithASCII(brand, "EUB", true) || | |
282 StartsWithASCII(brand, "EUC", true) || | |
283 StartsWithASCII(brand, "GGR", true); | |
284 } | |
285 | |
286 bool IsOrganicFirstRun(const std::string& brand) { | |
287 #if defined(OS_MACOSX) | |
288 if (brand.empty()) { | |
289 // An empty brand string on Mac is used for channels other than stable, | |
290 // which are always organic. | |
291 return true; | |
292 } | |
293 #endif | |
294 | |
295 return StartsWithASCII(brand, "GG", true) || | |
296 StartsWithASCII(brand, "EU", true); | |
297 } | |
298 | |
299 bool IsInternetCafeBrandCode(const std::string& brand) { | |
300 const char* const kBrands[] = { | |
301 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | |
302 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | |
303 }; | |
304 const char* const* end = &kBrands[arraysize(kBrands)]; | |
305 const char* const* found = std::find(&kBrands[0], end, brand); | |
306 return found != end; | |
307 } | |
308 | |
309 | |
310 // BrandForTesting ------------------------------------------------------------ | |
311 | |
312 BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { | |
313 DCHECK(brand_for_testing == NULL); | |
314 brand_for_testing = brand_.c_str(); | |
315 } | |
316 | |
317 BrandForTesting::~BrandForTesting() { | |
318 brand_for_testing = NULL; | |
319 } | |
320 | |
321 | |
322 } // namespace google_util | 200 } // namespace google_util |
OLD | NEW |