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

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

Issue 137623011: Switch to using the new Link Doctor API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Simulate click on more button Created 6 years, 10 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
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"
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" 17 #include "chrome/browser/google/google_url_tracker.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/installer/util/google_update_settings.h" 19 #include "chrome/installer/util/google_update_settings.h"
20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
21 #include "net/base/url_util.h" 21 #include "net/base/url_util.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
25 #include "chrome/browser/mac/keystone_glue.h" 25 #include "chrome/browser/mac/keystone_glue.h"
26 #elif defined(OS_CHROMEOS) 26 #elif defined(OS_CHROMEOS)
27 #include "chrome/browser/google/google_util_chromeos.h" 27 #include "chrome/browser/google/google_util_chromeos.h"
28 #endif 28 #endif
29 29
30 // Only use Link Doctor on official builds. It uses an API key, too, but
31 // seems best to just disable it, for more responsive error pages and to reduce
32 // server load.
30 #if defined(GOOGLE_CHROME_BUILD) 33 #if defined(GOOGLE_CHROME_BUILD)
31 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" 34 #define LINKDOCTOR_SERVER_REQUEST_URL "https://www.googleapis.com/rpc"
32 #endif 35 #else
33 36 #define LINKDOCTOR_SERVER_REQUEST_URL ""
34 #ifndef LINKDOCTOR_SERVER_REQUEST_URL
35 #define LINKDOCTOR_SERVER_REQUEST_URL std::string()
36 #endif 37 #endif
37 38
38 39
39 // Helpers -------------------------------------------------------------------- 40 // Helpers --------------------------------------------------------------------
40 41
41 namespace { 42 namespace {
42 43
43 const char* brand_for_testing = NULL; 44 const char* brand_for_testing = NULL;
44 bool gUseMockLinkDoctorBaseURLForTesting = false; 45 bool gUseMockLinkDoctorBaseURLForTesting = false;
45 46
(...skipping 21 matching lines...) Expand all
67 GURL LinkDoctorBaseURL() { 68 GURL LinkDoctorBaseURL() {
68 if (gUseMockLinkDoctorBaseURLForTesting) 69 if (gUseMockLinkDoctorBaseURLForTesting)
69 return GURL("http://mock.linkdoctor.url/for?testing"); 70 return GURL("http://mock.linkdoctor.url/for?testing");
70 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); 71 return GURL(LINKDOCTOR_SERVER_REQUEST_URL);
71 } 72 }
72 73
73 void SetMockLinkDoctorBaseURLForTesting() { 74 void SetMockLinkDoctorBaseURLForTesting() {
74 gUseMockLinkDoctorBaseURLForTesting = true; 75 gUseMockLinkDoctorBaseURLForTesting = true;
75 } 76 }
76 77
77 GURL AppendGoogleLocaleParam(const GURL& url) { 78 std::string GetGoogleLocale() {
78 // Google does not yet recognize 'nb' for Norwegian Bokmal, but it uses
79 // 'no' for that.
Peter Kasting 2014/02/04 22:49:04 Why did you remove this comment?
mmenke 2014/02/04 23:52:02 Mistake, thanks for catching that.
80 std::string locale = g_browser_process->GetApplicationLocale(); 79 std::string locale = g_browser_process->GetApplicationLocale();
81 if (locale == "nb") 80 if (locale == "nb")
82 locale = "no"; 81 return "no";
83 return net::AppendQueryParameter(url, "hl", locale); 82 return locale;
83 }
84
85 GURL AppendGoogleLocaleParam(const GURL& url) {
86 return net::AppendQueryParameter(url, "hl", GetGoogleLocale());
84 } 87 }
85 88
86 std::string StringAppendGoogleLocaleParam(const std::string& url) { 89 std::string StringAppendGoogleLocaleParam(const std::string& url) {
87 GURL original_url(url); 90 GURL original_url(url);
88 DCHECK(original_url.is_valid()); 91 DCHECK(original_url.is_valid());
89 GURL localized_url = AppendGoogleLocaleParam(original_url); 92 GURL localized_url = AppendGoogleLocaleParam(original_url);
90 return localized_url.spec(); 93 return localized_url.spec();
91 } 94 }
92 95
93 GURL AppendGoogleTLDParam(Profile* profile, const GURL& url) { 96 std::string GetGoogleCountryCodeCode(Profile* profile) {
94 const std::string google_domain( 97 const std::string google_domain(
95 net::registry_controlled_domains::GetDomainAndRegistry( 98 net::registry_controlled_domains::GetDomainAndRegistry(
96 GoogleURLTracker::GoogleURL(profile), 99 GoogleURLTracker::GoogleURL(profile),
97 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); 100 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES));
98 const size_t first_dot = google_domain.find('.'); 101 const size_t last_dot = google_domain.find_last_of('.');
99 if (first_dot == std::string::npos) { 102 if (last_dot == std::string::npos) {
100 NOTREACHED(); 103 NOTREACHED();
Peter Kasting 2014/02/04 22:49:04 Do not handle DCHECK failure. Instead of "if (...
mmenke 2014/02/04 23:52:02 Done. Looks like GoogleURLTracker is smart enough
Peter Kasting 2014/02/05 00:01:39 If that were the case, we wouldn't want NOTREACHED
mmenke 2014/02/05 00:04:56 Makes sense.
101 return url; 104 return "";
102 } 105 }
103 return net::AppendQueryParameter(url, "sd", 106 std::string tld = google_domain.substr(last_dot + 1);
Peter Kasting 2014/02/04 22:49:04 Nit: I'm uneasy calling this the "tld", since it's
mmenke 2014/02/04 23:52:02 Done, though per IANA, uk is a TLD: http://data.ia
104 google_domain.substr(first_dot + 1)); 107 // Assume the com TLD implies the US.
108 if (tld == "com")
109 return "us";
110 // The CLDR code for the UK is "GB".
Peter Kasting 2014/02/04 22:49:04 What does "CLDR" mean? Explain it or don't use th
mmenke 2014/02/04 23:52:02 Done.
111 if (tld == "uk")
112 return "gb";
113 // Catalonia does not have a CLDR country code, so use Spain instead.
114 if (tld == "cat")
115 return "es";
116 return tld;
117 }
118
119 GURL GetGoogleSearchURL(Profile* profile) {
120 GURL url = GoogleURLTracker::GoogleURL(profile);
Peter Kasting 2014/02/04 22:49:04 Nit: This can just be inlined into the last line o
mmenke 2014/02/04 23:52:02 Done.
121
122 // The url returned by the tracker does not include search path.
Peter Kasting 2014/02/04 22:49:04 Nit: search path -> the "/search" path
mmenke 2014/02/04 23:52:02 Done.
123 std::string search_path = "search";
124 GURL::Replacements replace_path;
125 replace_path.SetPathStr(search_path);
126 return url.ReplaceComponents(replace_path);
105 } 127 }
106 128
107 #if defined(OS_WIN) 129 #if defined(OS_WIN)
108 130
109 bool GetBrand(std::string* brand) { 131 bool GetBrand(std::string* brand) {
110 if (brand_for_testing) { 132 if (brand_for_testing) {
111 brand->assign(brand_for_testing); 133 brand->assign(brand_for_testing);
112 return true; 134 return true;
113 } 135 }
114 136
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 DCHECK(brand_for_testing == NULL); 308 DCHECK(brand_for_testing == NULL);
287 brand_for_testing = brand_.c_str(); 309 brand_for_testing = brand_.c_str();
288 } 310 }
289 311
290 BrandForTesting::~BrandForTesting() { 312 BrandForTesting::~BrandForTesting() {
291 brand_for_testing = NULL; 313 brand_for_testing = NULL;
292 } 314 }
293 315
294 316
295 } // namespace google_util 317 } // namespace google_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698