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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 23621037: Send URLs on non-zero prefix suggest requests also. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/i18n/break_iterator.h" 11 #include "base/i18n/break_iterator.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/i18n/icu_string_conversions.h" 13 #include "base/i18n/icu_string_conversions.h"
14 #include "base/json/json_string_value_serializer.h" 14 #include "base/json/json_string_value_serializer.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 21 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
22 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 22 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
23 #include "chrome/browser/autocomplete/autocomplete_match.h" 23 #include "chrome/browser/autocomplete/autocomplete_match.h"
24 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 24 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
25 #include "chrome/browser/autocomplete/autocomplete_result.h" 25 #include "chrome/browser/autocomplete/autocomplete_result.h"
26 #include "chrome/browser/autocomplete/keyword_provider.h" 26 #include "chrome/browser/autocomplete/keyword_provider.h"
27 #include "chrome/browser/autocomplete/url_prefix.h" 27 #include "chrome/browser/autocomplete/url_prefix.h"
28 #include "chrome/browser/google/google_util.h"
28 #include "chrome/browser/history/history_service.h" 29 #include "chrome/browser/history/history_service.h"
29 #include "chrome/browser/history/history_service_factory.h" 30 #include "chrome/browser/history/history_service_factory.h"
30 #include "chrome/browser/history/in_memory_database.h" 31 #include "chrome/browser/history/in_memory_database.h"
31 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" 32 #include "chrome/browser/metrics/variations/variations_http_header_provider.h"
32 #include "chrome/browser/omnibox/omnibox_field_trial.h" 33 #include "chrome/browser/omnibox/omnibox_field_trial.h"
33 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/search/search.h" 35 #include "chrome/browser/search/search.h"
35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
36 #include "chrome/browser/search_engines/template_url_service.h" 37 #include "chrome/browser/search_engines/template_url_service.h"
37 #include "chrome/browser/search_engines/template_url_service_factory.h" 38 #include "chrome/browser/search_engines/template_url_service_factory.h"
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 NavigationResults* list) { 834 NavigationResults* list) {
834 for (size_t i = 0; i < list->size(); ++i) { 835 for (size_t i = 0; i < list->size(); ++i) {
835 NavigationResult& result = (*list)[i]; 836 NavigationResult& result = (*list)[i];
836 result.set_relevance( 837 result.set_relevance(
837 result.CalculateRelevance(input_, providers_.has_keyword_provider()) + 838 result.CalculateRelevance(input_, providers_.has_keyword_provider()) +
838 (list->size() - i - 1)); 839 (list->size() - i - 1));
839 result.set_relevance_from_server(false); 840 result.set_relevance_from_server(false);
840 } 841 }
841 } 842 }
842 843
844 bool SearchProvider::CanSendURL(const GURL& url, Profile *profile){
Peter Kasting 2013/09/19 21:20:06 * goes on typename.
H Fung 2013/09/21 01:13:25 Done.
845 if (!url.is_valid())
846 return false;
847
848 // Only allow HTTP URLs or Google HTTPS URLs (including Google search
849 // result pages). For the latter case, Google was already sent the HTTPS
850 // URLs when requesting the page, so the information is just re-sent.
Peter Kasting 2013/09/19 21:20:06 (1) It seems like instead of checking if this is a
Peter Kasting 2013/10/08 01:10:25 You don't seem to have addressed this?
H Fung 2013/10/30 23:56:15 So I should get the domain of the search provider
Peter Kasting 2013/10/30 23:58:43 Look at registry_controlled_domains::SameDomainOrH
851 if ((url.scheme() != content::kHttpScheme) &&
852 !google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
853 google_util::ALLOW_NON_STANDARD_PORTS))
854 return false;
855
856 // Don't run if there's no profile or in incognito mode.
857 if (profile == NULL || profile->IsOffTheRecord())
Peter Kasting 2013/09/19 21:20:06 Isn't the incognito check here already handled by
H Fung 2013/09/21 01:13:25 Yes, but ZeroSuggestProvider (which also calls thi
858 return false;
859
860 // Don't run if we can't get preferences or search suggest is not enabled.
861 PrefService* prefs = profile->GetPrefs();
862 if (prefs == NULL || !prefs->GetBoolean(prefs::kSearchSuggestEnabled))
Peter Kasting 2013/09/19 21:20:06 When is prefs NULL? In tests?
H Fung 2013/09/21 01:13:25 I don't know. I think I was told to check for it
863 return false;
864
865 #if 0
Peter Kasting 2013/09/19 21:20:06 Obviously, this shouldn't land in its current form
H Fung 2013/09/21 01:13:25 Removed. (I didn't know about Chrome API keys bef
866 ProfileSyncService* service =
867 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
868 browser_sync::SyncPrefs sync_prefs(prefs);
869 // The user has needs to have Chrome Sync enabled (for permissions to
870 // transmit their current URL), not use a custom sync passphrase, and be in
871 // the field trial.
872 if (service == NULL ||
873 !service->IsSyncEnabledAndLoggedIn() ||
874 // TODO(hfung): Sync after issue 23819051 is committed.
875 !sync_prefs.HasKeepEverythingSynced() ||
876 (service->GetPassphraseType() == syncer::CUSTOM_PASSPHRASE)) {
877 return false;
878 }
879 #endif
880 return true;
881 }
882
883 void SearchProvider::SetCurrentPageUrl(const GURL& url) {
Peter Kasting 2013/09/19 21:20:06 Definition order must match declaration order.
H Fung 2013/09/21 01:13:25 I inlined the function per your comment below.
884 current_page_url_ = url;
Peter Kasting 2013/09/19 21:20:06 Functions this simple should be inlined unix_hacke
H Fung 2013/09/21 01:13:25 Done.
885 }
886
843 net::URLFetcher* SearchProvider::CreateSuggestFetcher( 887 net::URLFetcher* SearchProvider::CreateSuggestFetcher(
844 int id, 888 int id,
845 const TemplateURL* template_url, 889 const TemplateURL* template_url,
846 const AutocompleteInput& input) { 890 const AutocompleteInput& input) {
847 if (!template_url || template_url->suggestions_url().empty()) 891 if (!template_url || template_url->suggestions_url().empty())
848 return NULL; 892 return NULL;
849 893
850 // Bail if the suggestion URL is invalid with the given replacements. 894 // Bail if the suggestion URL is invalid with the given replacements.
851 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); 895 TemplateURLRef::SearchTermsArgs search_term_args(input.text());
852 search_term_args.cursor_position = input.cursor_position(); 896 search_term_args.cursor_position = input.cursor_position();
853 search_term_args.page_classification = input.current_page_classification(); 897 search_term_args.page_classification = input.current_page_classification();
898 if (CanSendURL(current_page_url_, profile_) &&
899 OmniboxFieldTrial::InZeroSuggestFieldTrial())
Peter Kasting 2013/09/19 21:20:06 It's not at all obvious why we are gating this sea
H Fung 2013/09/21 01:13:25 I used a different prefix. The original idea was
900 search_term_args.current_page_url = current_page_url_.spec();
854 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( 901 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms(
855 search_term_args)); 902 search_term_args));
856 if (!suggest_url.is_valid()) 903 if (!suggest_url.is_valid())
857 return NULL; 904 return NULL;
858 905
859 suggest_results_pending_++; 906 suggest_results_pending_++;
860 LogOmniboxSuggestRequest(REQUEST_SENT); 907 LogOmniboxSuggestRequest(REQUEST_SENT);
861 908
862 net::URLFetcher* fetcher = 909 net::URLFetcher* fetcher =
863 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this); 910 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this);
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 it->set_relevance(max_query_relevance); 1664 it->set_relevance(max_query_relevance);
1618 it->set_relevance_from_server(relevance_from_server); 1665 it->set_relevance_from_server(relevance_from_server);
1619 } 1666 }
1620 } 1667 }
1621 1668
1622 void SearchProvider::UpdateDone() { 1669 void SearchProvider::UpdateDone() {
1623 // We're done when the timer isn't running, there are no suggest queries 1670 // We're done when the timer isn't running, there are no suggest queries
1624 // pending, and we're not waiting on Instant. 1671 // pending, and we're not waiting on Instant.
1625 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1672 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1626 } 1673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698