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

Unified Diff: chrome/browser/google/google_util.cc

Issue 10908226: Introduces a search term extraction mechanism working for arbitrary search providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed keyword_table_unittest Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google/google_util.cc
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc
index 013437ec00a71f0e88795690e6a3e22d8578bf56..1d20a2391eeace05f4287034f9bd37afce8e32e8 100644
--- a/chrome/browser/google/google_util.cc
+++ b/chrome/browser/google/google_util.cc
@@ -20,7 +20,6 @@
#include "chrome/installer/util/google_update_settings.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_parse.h"
Joao da Silva 2012/09/28 11:46:10 needed?
beaudoin 2012/10/02 17:43:29 Done.
-#include "net/base/escape.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#if defined(OS_MACOSX)
@@ -57,30 +56,6 @@ bool HasQueryParameter(const std::string& str) {
bool gUseMockLinkDoctorBaseURLForTesting = false;
-// Finds the first key-value pair where the key matches |query_key|. Returns
-// true if a match is found and sets |search_terms| to the value.
-bool ExtractSearchTermsFromComponent(const std::string& url,
- url_parse::Component* component,
- string16* search_terms) {
- const std::string query_key = "q";
- url_parse::Component key, value;
-
- while (url_parse::ExtractQueryKeyValue(url.c_str(), component,
- &key, &value)) {
- if (url.compare(key.begin, key.len, query_key) != 0)
- continue;
- std::string value_str = url.substr(value.begin, value.len);
- *search_terms = net::UnescapeAndDecodeUTF8URLComponent(
- value_str,
- net::UnescapeRule::SPACES |
- net::UnescapeRule::URL_SPECIAL_CHARS |
- net::UnescapeRule::REPLACE_PLUS_WITH_SPACE,
- NULL);
- return true;
- }
- return false;
-}
-
} // anonymous namespace
namespace google_util {
@@ -179,25 +154,6 @@ bool GetReactivationBrand(std::string* brand) {
#endif
-string16 GetSearchTermsFromGoogleSearchURL(const std::string& url) {
- if (!IsInstantExtendedAPIGoogleSearchUrl(url))
- return string16();
-
- url_parse::Parsed parsed_url;
- url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url);
-
- string16 search_terms;
- // The search terms can be in either the query or ref component - for
- // instance, in a regular Google search they'll be in the query but in a
- // Google Instant search they can be in both. The ref is the correct one to
- // return in this case, so test the ref component first.
- if (ExtractSearchTermsFromComponent(url, &parsed_url.ref, &search_terms) ||
- ExtractSearchTermsFromComponent(url, &parsed_url.query, &search_terms)) {
- return search_terms;
- }
- return string16();
-}
-
bool IsGoogleDomainUrl(const std::string& url,
SubdomainPermission subdomain_permission,
PortPermission port_permission) {
@@ -283,29 +239,6 @@ bool IsGoogleSearchUrl(const std::string& url) {
(!is_home_page_base && HasQueryParameter(query));
}
-bool IsInstantExtendedAPIGoogleSearchUrl(const std::string& url) {
- if (!IsGoogleSearchUrl(url))
- return false;
-
- const std::string embedded_search_key = kInstantExtendedAPIParam;
-
- url_parse::Parsed parsed_url;
- url_parse::ParseStandardURL(url.c_str(), url.length(), &parsed_url);
- url_parse::Component key, value;
- while (url_parse::ExtractQueryKeyValue(
- url.c_str(), &parsed_url.query, &key, &value)) {
- // If the parameter key is |embedded_search_key| and the value is not 0 this
- // is an Instant Extended API Google search URL.
- if (!url.compare(key.begin, key.len, embedded_search_key)) {
- int int_value = 0;
- if (value.is_nonempty())
- base::StringToInt(url.substr(value.begin, value.len), &int_value);
- return int_value != 0;
- }
- }
- return false;
-}
-
bool IsOrganic(const std::string& brand) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kOrganicInstall))

Powered by Google App Engine
This is Rietveld 408576698