OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 class contains common functionality for search-based autocomplete | 5 // This class contains common functionality for search-based autocomplete |
6 // providers. Search provider and zero suggest provider both use it for common | 6 // providers. Search provider and zero suggest provider both use it for common |
7 // functionality. | 7 // functionality. |
8 | 8 |
9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/metrics/user_metrics_action.h" | |
18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
19 #include "components/metrics/proto/omnibox_event.pb.h" | 20 #include "components/metrics/proto/omnibox_event.pb.h" |
20 #include "components/omnibox/autocomplete_input.h" | 21 #include "components/omnibox/autocomplete_input.h" |
21 #include "components/omnibox/autocomplete_match.h" | 22 #include "components/omnibox/autocomplete_match.h" |
22 #include "components/omnibox/autocomplete_provider.h" | 23 #include "components/omnibox/autocomplete_provider.h" |
23 #include "components/omnibox/search_suggestion_parser.h" | 24 #include "components/omnibox/search_suggestion_parser.h" |
24 | 25 |
25 class GURL; | 26 class GURL; |
26 class Profile; | 27 class Profile; |
27 class SearchTermsData; | 28 class SearchTermsData; |
(...skipping 16 matching lines...) Expand all Loading... | |
44 static const int kDefaultProviderURLFetcherID; | 45 static const int kDefaultProviderURLFetcherID; |
45 | 46 |
46 // ID used in creating URLFetcher for keyword provider's suggest results. | 47 // ID used in creating URLFetcher for keyword provider's suggest results. |
47 static const int kKeywordProviderURLFetcherID; | 48 static const int kKeywordProviderURLFetcherID; |
48 | 49 |
49 // ID used in creating URLFetcher for deleting suggestion results. | 50 // ID used in creating URLFetcher for deleting suggestion results. |
50 static const int kDeletionURLFetcherID; | 51 static const int kDeletionURLFetcherID; |
51 | 52 |
52 BaseSearchProvider(TemplateURLService* template_url_service, | 53 BaseSearchProvider(TemplateURLService* template_url_service, |
53 Profile* profile, | 54 Profile* profile, |
55 const base::UserMetricsAction& uma_deletion_success, | |
56 const base::UserMetricsAction& uma_deletion_failure, | |
Peter Kasting
2014/08/12 18:31:18
Unfortunately you can't pass in UMAs like this. R
hashimoto
2014/08/13 05:21:22
Ugh, you're right.
I should have carefully read th
| |
54 AutocompleteProvider::Type type); | 57 AutocompleteProvider::Type type); |
55 | 58 |
56 // Returns whether |match| is flagged as a query that should be prefetched. | 59 // Returns whether |match| is flagged as a query that should be prefetched. |
57 static bool ShouldPrefetch(const AutocompleteMatch& match); | 60 static bool ShouldPrefetch(const AutocompleteMatch& match); |
58 | 61 |
59 // Returns a simpler AutocompleteMatch suitable for persistence like in | 62 // Returns a simpler AutocompleteMatch suitable for persistence like in |
60 // ShortcutsDatabase. | 63 // ShortcutsDatabase. |
61 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion | 64 // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion |
62 // with protected access. | 65 // with protected access. |
63 static AutocompleteMatch CreateSearchSuggestion( | 66 static AutocompleteMatch CreateSearchSuggestion( |
64 const base::string16& suggestion, | 67 const base::string16& suggestion, |
65 AutocompleteMatchType::Type type, | 68 AutocompleteMatchType::Type type, |
66 bool from_keyword_provider, | 69 bool from_keyword_provider, |
67 const TemplateURL* template_url, | 70 const TemplateURL* template_url, |
68 const SearchTermsData& search_terms_data); | 71 const SearchTermsData& search_terms_data); |
69 | 72 |
70 // AutocompleteProvider: | 73 // AutocompleteProvider: |
71 virtual void Stop(bool clear_cached_results) OVERRIDE; | |
72 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 74 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
73 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; | 75 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; |
74 | 76 |
75 bool field_trial_triggered_in_session() const { | 77 bool field_trial_triggered_in_session() const { |
76 return field_trial_triggered_in_session_; | 78 return field_trial_triggered_in_session_; |
77 } | 79 } |
78 | 80 |
79 protected: | 81 protected: |
80 // The following keys are used to record additional information on matches. | 82 // The following keys are used to record additional information on matches. |
81 | 83 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 void SetDeletionURL(const std::string& deletion_url, | 176 void SetDeletionURL(const std::string& deletion_url, |
175 AutocompleteMatch* match); | 177 AutocompleteMatch* match); |
176 | 178 |
177 // Creates an AutocompleteMatch from |result| to search for the query in | 179 // Creates an AutocompleteMatch from |result| to search for the query in |
178 // |result|. Adds the created match to |map|; if such a match | 180 // |result|. Adds the created match to |map|; if such a match |
179 // already exists, whichever one has lower relevance is eliminated. | 181 // already exists, whichever one has lower relevance is eliminated. |
180 // |metadata| and |accepted_suggestion| are used for generating an | 182 // |metadata| and |accepted_suggestion| are used for generating an |
181 // AutocompleteMatch. | 183 // AutocompleteMatch. |
182 // |mark_as_deletable| indicates whether the match should be marked deletable. | 184 // |mark_as_deletable| indicates whether the match should be marked deletable. |
183 // NOTE: Any result containing a deletion URL is always marked deletable. | 185 // NOTE: Any result containing a deletion URL is always marked deletable. |
184 void AddMatchToMap(const SearchSuggestionParser::SuggestResult& result, | 186 void AddMatchToMap(const AutocompleteInput& input, |
187 const SearchSuggestionParser::SuggestResult& result, | |
188 const TemplateURL* template_url, | |
185 const std::string& metadata, | 189 const std::string& metadata, |
186 int accepted_suggestion, | 190 int accepted_suggestion, |
191 bool should_append_extra_params, | |
187 bool mark_as_deletable, | 192 bool mark_as_deletable, |
188 MatchMap* map); | 193 MatchMap* map); |
189 | 194 |
190 // Parses results from the suggest server and updates the appropriate suggest | 195 // Parses results from the suggest server and updates the appropriate suggest |
191 // and navigation result lists in |results|. |default_result_relevance| is | 196 // and navigation result lists in |results|. |default_result_relevance| is |
192 // the relevance to use if it was not explicitly set by the server. | 197 // the relevance to use if it was not explicitly set by the server. |
193 // |is_keyword_result| indicates whether the response was received from the | 198 // |is_keyword_result| indicates whether the response was received from the |
194 // keyword provider. | 199 // keyword provider. |
195 // Returns whether the appropriate result list members were updated. | 200 // Returns whether the appropriate result list members were updated. |
196 bool ParseSuggestResults(const base::Value& root_val, | 201 bool ParseSuggestResults(const base::Value& root_val, |
202 const AutocompleteInput& input, | |
197 int default_result_relevance, | 203 int default_result_relevance, |
198 bool is_keyword_result, | 204 bool is_keyword_result, |
199 SearchSuggestionParser::Results* results); | 205 SearchSuggestionParser::Results* results); |
200 | 206 |
201 // Returns the TemplateURL corresponding to the keyword or default | |
202 // provider based on the value of |is_keyword|. | |
203 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const = 0; | |
204 | |
205 // Returns the AutocompleteInput for keyword provider or default provider | |
206 // based on the value of |is_keyword|. | |
207 virtual const AutocompleteInput GetInput(bool is_keyword) const = 0; | |
208 | |
209 // Returns whether the destination URL corresponding to the given |result| | |
210 // should contain command-line-specified query params. | |
211 virtual bool ShouldAppendExtraParams( | |
212 const SearchSuggestionParser::SuggestResult& result) const = 0; | |
213 | |
214 // Stops the suggest query. | |
215 // NOTE: This does not update |done_|. Callers must do so. | |
216 virtual void StopSuggest() = 0; | |
217 | |
218 // Clears the current results. | |
219 virtual void ClearAllResults() = 0; | |
220 | |
221 // Records in UMA whether the deletion request resulted in success. | |
222 virtual void RecordDeletionResult(bool success) = 0; | |
223 | |
224 // Modify provider-specific UMA statistics. | |
225 virtual void ModifyProviderInfo( | |
226 metrics::OmniboxEventProto_ProviderInfo* provider_info) const; | |
227 | |
228 TemplateURLService* template_url_service_; | 207 TemplateURLService* template_url_service_; |
229 Profile* profile_; | 208 Profile* profile_; |
230 | 209 |
231 // Whether a field trial, if any, has triggered in the most recent | 210 // Whether a field trial, if any, has triggered in the most recent |
232 // autocomplete query. This field is set to true only if the suggestion | 211 // autocomplete query. This field is set to true only if the suggestion |
233 // provider has completed and the response contained | 212 // provider has completed and the response contained |
234 // '"google:fieldtrialtriggered":true'. | 213 // '"google:fieldtrialtriggered":true'. |
235 bool field_trial_triggered_; | 214 bool field_trial_triggered_; |
236 | 215 |
237 // Same as above except that it is maintained across the current Omnibox | 216 // Same as above except that it is maintained across the current Omnibox |
238 // session. | 217 // session. |
239 bool field_trial_triggered_in_session_; | 218 bool field_trial_triggered_in_session_; |
240 | 219 |
241 private: | 220 private: |
242 friend class SearchProviderTest; | 221 friend class SearchProviderTest; |
243 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); | 222 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); |
244 | 223 |
245 // Removes the deleted |match| from the list of |matches_|. | 224 // Removes the deleted |match| from the list of |matches_|. |
246 void DeleteMatchFromMatches(const AutocompleteMatch& match); | 225 void DeleteMatchFromMatches(const AutocompleteMatch& match); |
247 | 226 |
248 // This gets called when we have requested a suggestion deletion from the | 227 // This gets called when we have requested a suggestion deletion from the |
249 // server to handle the results of the deletion. It will be called after the | 228 // server to handle the results of the deletion. It will be called after the |
250 // deletion request completes. | 229 // deletion request completes. |
251 void OnDeletionComplete(bool success, | 230 void OnDeletionComplete(bool success, |
252 SuggestionDeletionHandler* handler); | 231 SuggestionDeletionHandler* handler); |
253 | 232 |
233 base::UserMetricsAction uma_deletion_success_; | |
234 base::UserMetricsAction uma_deletion_failure_; | |
235 | |
254 // Each deletion handler in this vector corresponds to an outstanding request | 236 // Each deletion handler in this vector corresponds to an outstanding request |
255 // that a server delete a personalized suggestion. Making this a ScopedVector | 237 // that a server delete a personalized suggestion. Making this a ScopedVector |
256 // causes us to auto-cancel all such requests on shutdown. | 238 // causes us to auto-cancel all such requests on shutdown. |
257 SuggestionDeletionHandlers deletion_handlers_; | 239 SuggestionDeletionHandlers deletion_handlers_; |
258 | 240 |
259 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 241 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
260 }; | 242 }; |
261 | 243 |
262 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 244 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
OLD | NEW |