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

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

Issue 10644002: Add core plumbing for Instant Extended work (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address pkasting, tfarina, and remaining nits. Created 8 years, 6 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
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/string16.h" 11 #include "base/string16.h"
12 #include "base/string_number_conversions.h"
12 #include "base/string_split.h" 13 #include "base/string_split.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/google/google_url_tracker.h" 17 #include "chrome/browser/google/google_url_tracker.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/net/url_util.h" 19 #include "chrome/common/net/url_util.h"
19 #include "chrome/installer/util/google_update_settings.h" 20 #include "chrome/installer/util/google_update_settings.h"
20 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "googleurl/src/url_parse.h"
21 #include "net/base/registry_controlled_domain.h" 23 #include "net/base/registry_controlled_domain.h"
22 24
23 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
24 #include "chrome/browser/mac/keystone_glue.h" 26 #include "chrome/browser/mac/keystone_glue.h"
25 #endif 27 #endif
26 28
27 namespace { 29 namespace {
28 30
29 const char* brand_for_testing = NULL; 31 const char* brand_for_testing = NULL;
30 32
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return false; 198 return false;
197 199
198 // Check for query parameter in URL parameter and hash fragment, depending on 200 // Check for query parameter in URL parameter and hash fragment, depending on
199 // the path type. 201 // the path type.
200 std::string query(original_url.query()); 202 std::string query(original_url.query());
201 std::string ref(original_url.ref()); 203 std::string ref(original_url.ref());
202 return HasQueryParameter(ref) || 204 return HasQueryParameter(ref) ||
203 (!is_home_page_base && HasQueryParameter(query)); 205 (!is_home_page_base && HasQueryParameter(query));
204 } 206 }
205 207
208 bool IsInstantExtendedAPIGoogleSearchUrl(const std::string& url) {
209 if (!IsGoogleSearchUrl(url))
210 return false;
211
212 const std::string embedded_search_key = "espv";
213
214 url_parse::Parsed parsed_url;
215 url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url);
216 url_parse::Component key, value;
217 while (url_parse::ExtractQueryKeyValue(
218 url.c_str(), &parsed_url.query, &key, &value)) {
219 // If the parameter key is |embedded_search_key| and the value is not 0 this
220 // is an Instant Extended API Google search URL.
221 if (!url.compare(key.begin, key.len, embedded_search_key)) {
222 int int_value = 0;
223 if (value.is_nonempty())
224 base::StringToInt(url.substr(value.begin, value.len), &int_value);
225 return int_value != 0;
226 }
227 }
228 return false;
229 }
230
206 bool IsOrganic(const std::string& brand) { 231 bool IsOrganic(const std::string& brand) {
207 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 232 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
208 if (command_line.HasSwitch(switches::kOrganicInstall)) 233 if (command_line.HasSwitch(switches::kOrganicInstall))
209 return true; 234 return true;
210 235
211 #if defined(OS_MACOSX) 236 #if defined(OS_MACOSX)
212 if (brand.empty()) { 237 if (brand.empty()) {
213 // An empty brand string on Mac is used for channels other than stable, 238 // An empty brand string on Mac is used for channels other than stable,
214 // which are always organic. 239 // which are always organic.
215 return true; 240 return true;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 const char* const kBrands[] = { 283 const char* const kBrands[] = {
259 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 284 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
260 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 285 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
261 }; 286 };
262 const char* const* end = &kBrands[arraysize(kBrands)]; 287 const char* const* end = &kBrands[arraysize(kBrands)];
263 const char* const* found = std::find(&kBrands[0], end, brand); 288 const char* const* found = std::find(&kBrands[0], end, brand);
264 return found != end; 289 return found != end;
265 } 290 }
266 291
267 } // namespace google_util 292 } // namespace google_util
OLDNEW
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698