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

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

Issue 10933023: Control zero suggest with a pref, not a switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 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/autocomplete/zero_suggest_provider.h" 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autocomplete/autocomplete_input.h" 13 #include "chrome/browser/autocomplete/autocomplete_input.h"
14 #include "chrome/browser/autocomplete/autocomplete_match.h" 14 #include "chrome/browser/autocomplete/autocomplete_match.h"
15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
16 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h" 19 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
20 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
21 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
22 #include "net/http/http_response_headers.h" 24 #include "net/http/http_response_headers.h"
23 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
24 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
25 27
26 namespace { 28 namespace {
27 // The relevance of the top match from this provider. 29 // The relevance of the top match from this provider.
28 const int kMaxZeroSuggestRelevance = 100; 30 const int kMaxZeroSuggestRelevance = 100;
29 } // namespace 31 } // namespace
30 32
33 // static
34 ZeroSuggestProvider* ZeroSuggestProvider::Create(
35 AutocompleteProviderListener* listener,
36 Profile* profile) {
37 if (profile && !profile->IsOffTheRecord() && profile->GetPrefs()) {
38 std::string url_prefix = profile->GetPrefs()->GetString(
39 prefs::kExperimentalZeroSuggestUrlPrefix);
40 if (!url_prefix.empty())
41 return new ZeroSuggestProvider(listener, profile, url_prefix);
42 }
43 return NULL;
44 }
45
31 ZeroSuggestProvider::ZeroSuggestProvider( 46 ZeroSuggestProvider::ZeroSuggestProvider(
32 AutocompleteProviderListener* listener, 47 AutocompleteProviderListener* listener,
33 Profile* profile, 48 Profile* profile,
34 const std::string& url_prefix) 49 const std::string& url_prefix)
35 : AutocompleteProvider(listener, profile, "ZeroSuggest"), 50 : AutocompleteProvider(listener, profile, "ZeroSuggest"),
36 url_prefix_(url_prefix), 51 url_prefix_(url_prefix),
37 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { 52 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)) {
38 } 53 }
39 54
55 // static
56 void ZeroSuggestProvider::RegisterUserPrefs(PrefService* user_prefs) {
57 user_prefs->RegisterStringPref(prefs::kExperimentalZeroSuggestUrlPrefix, "",
58 PrefService::UNSYNCABLE_PREF);
59 }
60
40 void ZeroSuggestProvider::Start(const AutocompleteInput& input, 61 void ZeroSuggestProvider::Start(const AutocompleteInput& input,
41 bool /*minimal_changes*/) { 62 bool /*minimal_changes*/) {
42 UpdateMatches(input.text()); 63 UpdateMatches(input.text());
43 } 64 }
44 65
45 void ZeroSuggestProvider::StartZeroSuggest(const GURL& url, 66 void ZeroSuggestProvider::StartZeroSuggest(const GURL& url,
46 const string16& user_text) { 67 const string16& user_text) {
47 DCHECK(url.is_valid()); 68 DCHECK(url.is_valid());
48 // Do not query non-http URLs. There will be no useful suggestions for https 69 // Do not query non-http URLs. There will be no useful suggestions for https
49 // or chrome URLs. 70 // or chrome URLs.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // Style to look like normal search suggestions. 235 // Style to look like normal search suggestions.
215 match.contents_class.push_back( 236 match.contents_class.push_back(
216 ACMatchClassification(0, ACMatchClassification::DIM)); 237 ACMatchClassification(0, ACMatchClassification::DIM));
217 match.contents_class.push_back( 238 match.contents_class.push_back(
218 ACMatchClassification(user_text_.length(), ACMatchClassification::NONE)); 239 ACMatchClassification(user_text_.length(), ACMatchClassification::NONE));
219 } 240 }
220 match.transition = content::PAGE_TRANSITION_GENERATED; 241 match.transition = content::PAGE_TRANSITION_GENERATED;
221 242
222 matches_.push_back(match); 243 matches_.push_back(match);
223 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698