| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 return net::AppendQueryParameter(url, "hl", GetGoogleLocale()); | 88 return net::AppendQueryParameter(url, "hl", GetGoogleLocale()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 std::string StringAppendGoogleLocaleParam(const std::string& url) { | 91 std::string StringAppendGoogleLocaleParam(const std::string& url) { |
| 92 GURL original_url(url); | 92 GURL original_url(url); |
| 93 DCHECK(original_url.is_valid()); | 93 DCHECK(original_url.is_valid()); |
| 94 GURL localized_url = AppendGoogleLocaleParam(original_url); | 94 GURL localized_url = AppendGoogleLocaleParam(original_url); |
| 95 return localized_url.spec(); | 95 return localized_url.spec(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 std::string GetGoogleCountryCode(Profile* profile) { | 98 std::string GetGoogleCountryCode(GURL google_homepage_url) { |
| 99 const std::string google_hostname = | 99 const std::string google_hostname = google_homepage_url.host(); |
| 100 GoogleURLTracker::GoogleURL(profile).host(); | |
| 101 const size_t last_dot = google_hostname.find_last_of('.'); | 100 const size_t last_dot = google_hostname.find_last_of('.'); |
| 102 if (last_dot == std::string::npos) { | 101 if (last_dot == std::string::npos) { |
| 103 NOTREACHED(); | 102 NOTREACHED(); |
| 104 } | 103 } |
| 105 std::string country_code = google_hostname.substr(last_dot + 1); | 104 std::string country_code = google_hostname.substr(last_dot + 1); |
| 106 // Assume the com TLD implies the US. | 105 // Assume the com TLD implies the US. |
| 107 if (country_code == "com") | 106 if (country_code == "com") |
| 108 return "us"; | 107 return "us"; |
| 109 // Google uses the Unicode Common Locale Data Repository (CLDR), and the CLDR | 108 // Google uses the Unicode Common Locale Data Repository (CLDR), and the CLDR |
| 110 // code for the UK is "gb". | 109 // code for the UK is "gb". |
| 111 if (country_code == "uk") | 110 if (country_code == "uk") |
| 112 return "gb"; | 111 return "gb"; |
| 113 // Catalonia does not have a CLDR country code, since it's a region in Spain, | 112 // Catalonia does not have a CLDR country code, since it's a region in Spain, |
| 114 // so use Spain instead. | 113 // so use Spain instead. |
| 115 if (country_code == "cat") | 114 if (country_code == "cat") |
| 116 return "es"; | 115 return "es"; |
| 117 return country_code; | 116 return country_code; |
| 118 } | 117 } |
| 119 | 118 |
| 120 GURL GetGoogleSearchURL(Profile* profile) { | 119 GURL GetGoogleSearchURL(GURL google_homepage_url) { |
| 121 // The url returned by the tracker does not include the "/search" or the | 120 // To transform the homepage URL into the corresponding search URL, add the |
| 122 // "q=" query string. | 121 // "search" and the "q=" query string. |
| 123 std::string search_path = "search"; | 122 std::string search_path = "search"; |
| 124 std::string query_string = "q="; | 123 std::string query_string = "q="; |
| 125 GURL::Replacements replacements; | 124 GURL::Replacements replacements; |
| 126 replacements.SetPathStr(search_path); | 125 replacements.SetPathStr(search_path); |
| 127 replacements.SetQueryStr(query_string); | 126 replacements.SetQueryStr(query_string); |
| 128 return GoogleURLTracker::GoogleURL(profile).ReplaceComponents(replacements); | 127 return google_homepage_url.ReplaceComponents(replacements); |
| 129 } | 128 } |
| 130 | 129 |
| 131 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
| 132 | 131 |
| 133 bool GetBrand(std::string* brand) { | 132 bool GetBrand(std::string* brand) { |
| 134 if (brand_for_testing) { | 133 if (brand_for_testing) { |
| 135 brand->assign(brand_for_testing); | 134 brand->assign(brand_for_testing); |
| 136 return true; | 135 return true; |
| 137 } | 136 } |
| 138 | 137 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 DCHECK(brand_for_testing == NULL); | 313 DCHECK(brand_for_testing == NULL); |
| 315 brand_for_testing = brand_.c_str(); | 314 brand_for_testing = brand_.c_str(); |
| 316 } | 315 } |
| 317 | 316 |
| 318 BrandForTesting::~BrandForTesting() { | 317 BrandForTesting::~BrandForTesting() { |
| 319 brand_for_testing = NULL; | 318 brand_for_testing = NULL; |
| 320 } | 319 } |
| 321 | 320 |
| 322 | 321 |
| 323 } // namespace google_util | 322 } // namespace google_util |
| OLD | NEW |