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

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

Issue 436833002: Stop sharing BaseSearchProvider::OnURLFetchComplete between 2 providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 4 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 // This file contains the zero-suggest autocomplete provider. This experimental 5 // This file contains the zero-suggest autocomplete provider. This experimental
6 // provider is invoked when the user focuses in the omnibox prior to editing, 6 // provider is invoked when the user focuses in the omnibox prior to editing,
7 // and generates search query suggestions based on the current URL. To enable 7 // and generates search query suggestions based on the current URL. To enable
8 // this provider, point --experimental-zero-suggest-url-prefix at an 8 // this provider, point --experimental-zero-suggest-url-prefix at an
9 // appropriate suggestion service. 9 // appropriate suggestion service.
10 // 10 //
11 // HUGE DISCLAIMER: This is just here for experimenting and will probably be 11 // HUGE DISCLAIMER: This is just here for experimenting and will probably be
12 // deleted entirely as we revise how suggestions work with the omnibox. 12 // deleted entirely as we revise how suggestions work with the omnibox.
13 13
14 #ifndef CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ 14 #ifndef CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_
15 #define CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ 15 #define CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "chrome/browser/autocomplete/base_search_provider.h" 20 #include "chrome/browser/autocomplete/base_search_provider.h"
21 #include "chrome/browser/autocomplete/search_provider.h" 21 #include "chrome/browser/autocomplete/search_provider.h"
22 #include "chrome/browser/history/history_types.h" 22 #include "chrome/browser/history/history_types.h"
23 #include "components/metrics/proto/omnibox_event.pb.h" 23 #include "components/metrics/proto/omnibox_event.pb.h"
24 #include "net/url_request/url_fetcher_delegate.h"
24 25
26 class AutocompleteProviderListener;
25 class TemplateURLService; 27 class TemplateURLService;
26 28
27 namespace base { 29 namespace base {
28 class ListValue; 30 class ListValue;
29 class Value; 31 class Value;
30 } 32 }
31 33
32 namespace net { 34 namespace net {
33 class URLFetcher; 35 class URLFetcher;
34 } 36 }
35 37
36 namespace user_prefs { 38 namespace user_prefs {
37 class PrefRegistrySyncable; 39 class PrefRegistrySyncable;
38 } 40 }
39 41
40 // Autocomplete provider for searches based on the current URL. 42 // Autocomplete provider for searches based on the current URL.
41 // 43 //
42 // The controller will call StartZeroSuggest when the user focuses in the 44 // The controller will call StartZeroSuggest when the user focuses in the
43 // omnibox. After construction, the autocomplete controller repeatedly calls 45 // omnibox. After construction, the autocomplete controller repeatedly calls
44 // Start() with some user input, each time expecting to receive an updated 46 // Start() with some user input, each time expecting to receive an updated
45 // set of matches. 47 // set of matches.
46 // 48 //
47 // TODO(jered): Consider deleting this class and building this functionality 49 // TODO(jered): Consider deleting this class and building this functionality
48 // into SearchProvider after dogfood and after we break the association between 50 // into SearchProvider after dogfood and after we break the association between
49 // omnibox text and suggestions. 51 // omnibox text and suggestions.
50 class ZeroSuggestProvider : public BaseSearchProvider { 52 class ZeroSuggestProvider : public BaseSearchProvider,
53 public net::URLFetcherDelegate {
51 public: 54 public:
52 // Creates and returns an instance of this provider. 55 // Creates and returns an instance of this provider.
53 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, 56 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener,
54 TemplateURLService* template_url_service, 57 TemplateURLService* template_url_service,
55 Profile* profile); 58 Profile* profile);
56 59
57 // Registers a preference used to cache zero suggest results. 60 // Registers a preference used to cache zero suggest results.
58 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 61 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
59 62
60 // AutocompleteProvider: 63 // AutocompleteProvider:
(...skipping 10 matching lines...) Expand all
71 metrics::OmniboxEventProto_ProviderInfo* provider_info) const OVERRIDE; 74 metrics::OmniboxEventProto_ProviderInfo* provider_info) const OVERRIDE;
72 75
73 private: 76 private:
74 ZeroSuggestProvider(AutocompleteProviderListener* listener, 77 ZeroSuggestProvider(AutocompleteProviderListener* listener,
75 TemplateURLService* template_url_service, 78 TemplateURLService* template_url_service,
76 Profile* profile); 79 Profile* profile);
77 80
78 virtual ~ZeroSuggestProvider(); 81 virtual ~ZeroSuggestProvider();
79 82
80 // BaseSearchProvider: 83 // BaseSearchProvider:
81 virtual bool StoreSuggestionResponse(const std::string& json_data,
82 const base::Value& parsed_data) OVERRIDE;
83 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; 84 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE;
84 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; 85 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE;
85 virtual SearchSuggestionParser::Results* GetResultsToFill(
86 bool is_keyword) OVERRIDE;
87 virtual bool ShouldAppendExtraParams( 86 virtual bool ShouldAppendExtraParams(
88 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; 87 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE;
89 virtual void StopSuggest() OVERRIDE; 88 virtual void StopSuggest() OVERRIDE;
90 virtual void ClearAllResults() OVERRIDE; 89 virtual void ClearAllResults() OVERRIDE;
91 virtual int GetDefaultResultRelevance() const OVERRIDE;
92 virtual void RecordDeletionResult(bool success) OVERRIDE; 90 virtual void RecordDeletionResult(bool success) OVERRIDE;
93 virtual void LogFetchComplete(bool success, bool is_keyword) OVERRIDE; 91
94 virtual bool IsKeywordFetcher(const net::URLFetcher* fetcher) const OVERRIDE; 92 // net::URLFetcherDelegate:
95 virtual void UpdateMatches() OVERRIDE; 93 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
94
95 // Optionally, cache the received |json_data| and return true if we want
96 // to stop processing results at this point. The |parsed_data| is the parsed
97 // version of |json_data| used to determine if we received an empty result.
98 bool StoreSuggestionResponse(const std::string& json_data,
99 const base::Value& parsed_data);
96 100
97 // Adds AutocompleteMatches for each of the suggestions in |results| to 101 // Adds AutocompleteMatches for each of the suggestions in |results| to
98 // |map|. 102 // |map|.
99 void AddSuggestResultsToMap( 103 void AddSuggestResultsToMap(
100 const SearchSuggestionParser::SuggestResults& results, 104 const SearchSuggestionParser::SuggestResults& results,
101 MatchMap* map); 105 MatchMap* map);
102 106
103 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. 107 // Returns an AutocompleteMatch for a navigational suggestion |navigation|.
104 AutocompleteMatch NavigationToMatch( 108 AutocompleteMatch NavigationToMatch(
105 const SearchSuggestionParser::NavigationResult& navigation); 109 const SearchSuggestionParser::NavigationResult& navigation);
(...skipping 21 matching lines...) Expand all
127 131
128 // Whether we can show zero suggest on |current_page_url| without 132 // Whether we can show zero suggest on |current_page_url| without
129 // sending |current_page_url| as a parameter to the server at |suggest_url|. 133 // sending |current_page_url| as a parameter to the server at |suggest_url|.
130 bool CanShowZeroSuggestWithoutSendingURL(const GURL& suggest_url, 134 bool CanShowZeroSuggestWithoutSendingURL(const GURL& suggest_url,
131 const GURL& current_page_url) const; 135 const GURL& current_page_url) const;
132 136
133 // Checks whether we have a set of zero suggest results cached, and if so 137 // Checks whether we have a set of zero suggest results cached, and if so
134 // populates |matches_| with cached results. 138 // populates |matches_| with cached results.
135 void MaybeUseCachedSuggestions(); 139 void MaybeUseCachedSuggestions();
136 140
141 AutocompleteProviderListener* listener_;
142
137 // The URL for which a suggestion fetch is pending. 143 // The URL for which a suggestion fetch is pending.
138 std::string current_query_; 144 std::string current_query_;
139 145
140 // The type of page the user is viewing (a search results page doing search 146 // The type of page the user is viewing (a search results page doing search
141 // term replacement, an arbitrary URL, etc.). 147 // term replacement, an arbitrary URL, etc.).
142 metrics::OmniboxEventProto::PageClassification current_page_classification_; 148 metrics::OmniboxEventProto::PageClassification current_page_classification_;
143 149
144 // Copy of OmniboxEditModel::permanent_text_. 150 // Copy of OmniboxEditModel::permanent_text_.
145 base::string16 permanent_text_; 151 base::string16 permanent_text_;
146 152
(...skipping 12 matching lines...) Expand all
159 165
160 history::MostVisitedURLList most_visited_urls_; 166 history::MostVisitedURLList most_visited_urls_;
161 167
162 // For callbacks that may be run after destruction. 168 // For callbacks that may be run after destruction.
163 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; 169 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_;
164 170
165 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); 171 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider);
166 }; 172 };
167 173
168 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ 174 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | chrome/browser/autocomplete/zero_suggest_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698