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

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

Issue 131003011: Part 1 of search provider refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change wrapping back Created 6 years, 10 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 <map> 17 #include <map>
18 #include <string> 18 #include <string>
19 #include <vector> 19 #include <vector>
20 20
21 #include "base/basictypes.h" 21 #include "base/basictypes.h"
22 #include "base/compiler_specific.h" 22 #include "base/compiler_specific.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/strings/string16.h" 24 #include "base/strings/string16.h"
25 #include "chrome/browser/autocomplete/autocomplete_provider.h" 25 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
msw 2014/02/03 22:53:14 nit: remove redundant includes like this.
Maria 2014/02/04 03:16:39 Done.
26 #include "chrome/browser/autocomplete/base_search_provider.h"
26 #include "chrome/browser/autocomplete/search_provider.h" 27 #include "chrome/browser/autocomplete/search_provider.h"
27 #include "net/url_request/url_fetcher_delegate.h" 28 #include "net/url_request/url_fetcher_delegate.h"
28 29
29 class AutocompleteInput; 30 class AutocompleteInput;
msw 2014/02/03 22:53:14 nit: remove redundant forward declarations like th
Maria 2014/02/04 03:16:39 Done.
30 class GURL; 31 class GURL;
31 class TemplateURLService; 32 class TemplateURLService;
32 33
33 namespace base { 34 namespace base {
34 class ListValue; 35 class ListValue;
35 class Value; 36 class Value;
36 } 37 }
37 38
38 namespace net { 39 namespace net {
39 class URLFetcher; 40 class URLFetcher;
40 } 41 }
41 42
42 // Autocomplete provider for searches based on the current URL. 43 // Autocomplete provider for searches based on the current URL.
43 // 44 //
44 // The controller will call StartZeroSuggest when the user focuses in the 45 // The controller will call StartZeroSuggest when the user focuses in the
45 // omnibox. After construction, the autocomplete controller repeatedly calls 46 // omnibox. After construction, the autocomplete controller repeatedly calls
46 // Start() with some user input, each time expecting to receive an updated 47 // Start() with some user input, each time expecting to receive an updated
47 // set of matches. 48 // set of matches.
48 // 49 //
49 // TODO(jered): Consider deleting this class and building this functionality 50 // TODO(jered): Consider deleting this class and building this functionality
50 // into SearchProvider after dogfood and after we break the association between 51 // into SearchProvider after dogfood and after we break the association between
51 // omnibox text and suggestions. 52 // omnibox text and suggestions.
52 class ZeroSuggestProvider : public AutocompleteProvider, 53 class ZeroSuggestProvider : public BaseSearchProvider {
53 public net::URLFetcherDelegate {
54 public: 54 public:
55 // Creates and returns an instance of this provider. 55 // Creates and returns an instance of this provider.
56 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, 56 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener,
57 Profile* profile); 57 Profile* profile);
58 58
59 // AutocompleteProvider: 59 // AutocompleteProvider:
60 virtual void Start(const AutocompleteInput& input, 60 virtual void Start(const AutocompleteInput& input,
61 bool /*minimal_changes*/) OVERRIDE; 61 bool /*minimal_changes*/) OVERRIDE;
62 virtual void Stop(bool clear_cached_results) OVERRIDE; 62 virtual void Stop(bool clear_cached_results) OVERRIDE;
63 63
(...skipping 28 matching lines...) Expand all
92 // arguments) were copied and trimmed from SearchProvider. 92 // arguments) were copied and trimmed from SearchProvider.
93 // TODO(hfung): Refactor them into a new base class common to both 93 // TODO(hfung): Refactor them into a new base class common to both
94 // ZeroSuggestProvider and SearchProvider. 94 // ZeroSuggestProvider and SearchProvider.
95 95
96 // From the OpenSearch formatted response |root_val|, populate query 96 // From the OpenSearch formatted response |root_val|, populate query
97 // suggestions into |suggest_results|, navigation suggestions into 97 // suggestions into |suggest_results|, navigation suggestions into
98 // |navigation_results|, and the verbatim relevance score into 98 // |navigation_results|, and the verbatim relevance score into
99 // |verbatim_relevance|. 99 // |verbatim_relevance|.
100 void FillResults(const base::Value& root_val, 100 void FillResults(const base::Value& root_val,
101 int* verbatim_relevance, 101 int* verbatim_relevance,
102 SearchProvider::SuggestResults* suggest_results, 102 SuggestResults* suggest_results,
103 SearchProvider::NavigationResults* navigation_results); 103 NavigationResults* navigation_results);
104 104
105 // Creates AutocompleteMatches to search |template_url| for "<suggestion>" for 105 // Creates AutocompleteMatches to search |template_url| for "<suggestion>" for
106 // all suggestions in |results|, and adds them to |map|. 106 // all suggestions in |results|, and adds them to |map|.
107 void AddSuggestResultsToMap(const SearchProvider::SuggestResults& results, 107 void AddSuggestResultsToMap(const SuggestResults& results,
108 const TemplateURL* template_url, 108 const TemplateURL* template_url,
109 SearchProvider::MatchMap* map); 109 MatchMap* map);
110 110
111 // Creates an AutocompleteMatch with the provided |relevance| and |type| to 111 // Creates an AutocompleteMatch with the provided |relevance| and |type| to
112 // search |template_url| for |query_string|. |accepted_suggestion| will be 112 // search |template_url| for |query_string|. |accepted_suggestion| will be
113 // used to generate Assisted Query Stats. 113 // used to generate Assisted Query Stats.
114 // 114 //
115 // Adds this match to |map|; if such a match already exists, whichever one 115 // Adds this match to |map|; if such a match already exists, whichever one
116 // has lower relevance is eliminated. 116 // has lower relevance is eliminated.
117 void AddMatchToMap(int relevance, 117 void AddMatchToMap(int relevance,
118 AutocompleteMatch::Type type, 118 AutocompleteMatch::Type type,
119 const TemplateURL* template_url, 119 const TemplateURL* template_url,
120 const base::string16& query_string, 120 const base::string16& query_string,
121 int accepted_suggestion, 121 int accepted_suggestion,
122 SearchProvider::MatchMap* map); 122 MatchMap* map);
123 123
124 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. 124 // Returns an AutocompleteMatch for a navigational suggestion |navigation|.
125 AutocompleteMatch NavigationToMatch( 125 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
126 const SearchProvider::NavigationResult& navigation);
127 126
128 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. 127 // Fetches zero-suggest suggestions by sending a request using |suggest_url|.
129 void Run(const GURL& suggest_url); 128 void Run(const GURL& suggest_url);
130 129
131 // Parses results from the zero-suggest server and updates results. 130 // Parses results from the zero-suggest server and updates results.
132 void ParseSuggestResults(const base::Value& root_val); 131 void ParseSuggestResults(const base::Value& root_val);
133 132
134 // Converts the parsed results to a set of AutocompleteMatches and adds them 133 // Converts the parsed results to a set of AutocompleteMatches and adds them
135 // to |matches_|. Also update the histograms for how many results were 134 // to |matches_|. Also update the histograms for how many results were
136 // received. 135 // received.
(...skipping 23 matching lines...) Expand all
160 base::string16 permanent_text_; 159 base::string16 permanent_text_;
161 160
162 // Fetcher used to retrieve results. 161 // Fetcher used to retrieve results.
163 scoped_ptr<net::URLFetcher> fetcher_; 162 scoped_ptr<net::URLFetcher> fetcher_;
164 // Whether there's a pending request in flight. 163 // Whether there's a pending request in flight.
165 bool have_pending_request_; 164 bool have_pending_request_;
166 165
167 // Suggestion for the current URL. 166 // Suggestion for the current URL.
168 AutocompleteMatch current_url_match_; 167 AutocompleteMatch current_url_match_;
169 // Navigation suggestions for the most recent ZeroSuggest input URL. 168 // Navigation suggestions for the most recent ZeroSuggest input URL.
170 SearchProvider::NavigationResults navigation_results_; 169 NavigationResults navigation_results_;
171 // Query suggestions for the most recent ZeroSuggest input URL. 170 // Query suggestions for the most recent ZeroSuggest input URL.
172 SearchProvider::MatchMap query_matches_map_; 171 MatchMap query_matches_map_;
173 // The relevance score for the URL of the current page. 172 // The relevance score for the URL of the current page.
174 int verbatim_relevance_; 173 int verbatim_relevance_;
175 174
176 // Whether a field trial, if any, has triggered in the most recent 175 // Whether a field trial, if any, has triggered in the most recent
177 // autocomplete query. This field is set to true if the last request 176 // autocomplete query. This field is set to true if the last request
178 // was a zero suggest request, the provider has completed and their 177 // was a zero suggest request, the provider has completed and their
179 // corresponding response contained '"google:fieldtrialtriggered":true'. 178 // corresponding response contained '"google:fieldtrialtriggered":true'.
180 bool field_trial_triggered_; 179 bool field_trial_triggered_;
181 // Whether a zero suggest request triggered a field trial in the omnibox 180 // Whether a zero suggest request triggered a field trial in the omnibox
182 // session. The user could have clicked on a suggestion when zero suggest 181 // session. The user could have clicked on a suggestion when zero suggest
183 // triggered (same condition as field_trial_triggered_), or triggered zero 182 // triggered (same condition as field_trial_triggered_), or triggered zero
184 // suggest but kept typing. 183 // suggest but kept typing.
185 bool field_trial_triggered_in_session_; 184 bool field_trial_triggered_in_session_;
186 185
187 history::MostVisitedURLList most_visited_urls_; 186 history::MostVisitedURLList most_visited_urls_;
188 187
189 // For callbacks that may be run after destruction. 188 // For callbacks that may be run after destruction.
190 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; 189 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_;
191 190
192 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); 191 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider);
193 }; 192 };
194 193
195 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ 194 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698