Chromium Code Reviews| Index: chrome/browser/google/google_util.cc |
| =================================================================== |
| --- chrome/browser/google/google_util.cc (revision 248295) |
| +++ chrome/browser/google/google_util.cc (working copy) |
| @@ -27,15 +27,16 @@ |
| #include "chrome/browser/google/google_util_chromeos.h" |
| #endif |
| +// Only use Link Doctor on official builds. It uses an API key, too, but |
| +// seems best to just disable it, for more responsive error pages and to reduce |
| +// server load. |
| #if defined(GOOGLE_CHROME_BUILD) |
| -#include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" |
| +#define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc" |
| +#else |
| +#define LINKDOCTOR_SERVER_REQUEST_URL "" |
| #endif |
| -#ifndef LINKDOCTOR_SERVER_REQUEST_URL |
| -#define LINKDOCTOR_SERVER_REQUEST_URL std::string() |
| -#endif |
| - |
| // Helpers -------------------------------------------------------------------- |
| namespace { |
| @@ -74,15 +75,19 @@ |
| gUseMockLinkDoctorBaseURLForTesting = true; |
| } |
| -GURL AppendGoogleLocaleParam(const GURL& url) { |
| +std::string GetGoogleLocale() { |
| // Google does not yet recognize 'nb' for Norwegian Bokmal, but it uses |
| // 'no' for that. |
| std::string locale = g_browser_process->GetApplicationLocale(); |
| if (locale == "nb") |
| - locale = "no"; |
| - return net::AppendQueryParameter(url, "hl", locale); |
| + return "no"; |
| + return locale; |
| } |
| +GURL AppendGoogleLocaleParam(const GURL& url) { |
| + return net::AppendQueryParameter(url, "hl", GetGoogleLocale()); |
| +} |
| + |
| std::string StringAppendGoogleLocaleParam(const std::string& url) { |
| GURL original_url(url); |
| DCHECK(original_url.is_valid()); |
| @@ -90,20 +95,35 @@ |
| return localized_url.spec(); |
| } |
| -GURL AppendGoogleTLDParam(Profile* profile, const GURL& url) { |
| - const std::string google_domain( |
| - net::registry_controlled_domains::GetDomainAndRegistry( |
| - GoogleURLTracker::GoogleURL(profile), |
| - net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); |
| - const size_t first_dot = google_domain.find('.'); |
| - if (first_dot == std::string::npos) { |
| +std::string GetGoogleCountryCode(Profile* profile) { |
| + const std::string google_domain = GoogleURLTracker::GoogleURL(profile).host(); |
|
Peter Kasting
2014/02/05 00:01:39
Nit: Perhaps |google_hostname| might be less confu
mmenke
2014/02/05 00:04:56
Done.
|
| + const size_t last_dot = google_domain.find_last_of('.'); |
| + if (last_dot == std::string::npos) { |
| NOTREACHED(); |
| - return url; |
| } |
| - return net::AppendQueryParameter(url, "sd", |
| - google_domain.substr(first_dot + 1)); |
| + std::string country_code = google_domain.substr(last_dot + 1); |
| + // Assume the com TLD implies the US. |
| + if (country_code == "com") |
| + return "us"; |
| + // Google uses the Unicode Common Locale Data Repository (CLDR), and the CLDR |
| + // code for the UK is "gb". |
| + if (country_code == "uk") |
| + return "gb"; |
| + // Catalonia does not have a CLDR country code, since it's a region in Spain, |
| + // so use Spain instead. |
| + if (country_code == "cat") |
| + return "es"; |
| + return country_code; |
| } |
| +GURL GetGoogleSearchURL(Profile* profile) { |
| + // The url returned by the tracker does not include "/search" path. |
|
Peter Kasting
2014/02/05 00:01:39
Nit: include -> include the
mmenke
2014/02/05 00:04:56
Done.
|
| + std::string search_path = "search"; |
| + GURL::Replacements replace_path; |
| + replace_path.SetPathStr(search_path); |
| + return GoogleURLTracker::GoogleURL(profile).ReplaceComponents(replace_path); |
| +} |
| + |
| #if defined(OS_WIN) |
| bool GetBrand(std::string* brand) { |