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_ |
(...skipping 21 matching lines...) Expand all Loading... | |
32 // Base functionality for receiving suggestions from a search engine. | 32 // Base functionality for receiving suggestions from a search engine. |
33 // This class is abstract and should only be used as a base for other | 33 // This class is abstract and should only be used as a base for other |
34 // autocomplete providers utilizing its functionality. | 34 // autocomplete providers utilizing its functionality. |
35 class BaseSearchProvider : public AutocompleteProvider, | 35 class BaseSearchProvider : public AutocompleteProvider, |
36 public net::URLFetcherDelegate { | 36 public net::URLFetcherDelegate { |
37 public: | 37 public: |
38 BaseSearchProvider(AutocompleteProviderListener* listener, | 38 BaseSearchProvider(AutocompleteProviderListener* listener, |
39 Profile* profile, | 39 Profile* profile, |
40 AutocompleteProvider::Type type); | 40 AutocompleteProvider::Type type); |
41 | 41 |
42 // Returns whether |match| is flagged as a query that should be prefetched. | |
43 static bool ShouldPrefetch(const AutocompleteMatch& match); | |
44 | |
42 // AutocompleteProvider: | 45 // AutocompleteProvider: |
43 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; | 46 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; |
44 | 47 |
45 bool field_trial_triggered_in_session() const { | 48 bool field_trial_triggered_in_session() const { |
46 return field_trial_triggered_in_session_; | 49 return field_trial_triggered_in_session_; |
47 } | 50 } |
48 | 51 |
49 protected: | 52 protected: |
50 virtual ~BaseSearchProvider(); | 53 virtual ~BaseSearchProvider(); |
51 | 54 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 // suppresses the verbatim result. | 250 // suppresses the verbatim result. |
248 int verbatim_relevance; | 251 int verbatim_relevance; |
249 | 252 |
250 // The JSON metadata associated with this server response. | 253 // The JSON metadata associated with this server response. |
251 std::string metadata; | 254 std::string metadata; |
252 | 255 |
253 private: | 256 private: |
254 DISALLOW_COPY_AND_ASSIGN(Results); | 257 DISALLOW_COPY_AND_ASSIGN(Results); |
255 }; | 258 }; |
256 | 259 |
260 // The following keys are used to record additional information on matches. | |
Mark P
2014/02/10 23:25:55
nit: I think static variables are supposed to go a
Maria
2014/02/11 21:42:32
Actually, according to Google style guide, the ord
| |
261 | |
262 // We annotate our AutocompleteMatches with whether their relevance scores | |
263 // were server-provided using this key in the |additional_info| field. | |
264 static const char kRelevanceFromServerKey[]; | |
265 | |
266 // Indicates whether the server said a match should be prefetched. | |
267 static const char kShouldPrefetchKey[]; | |
268 | |
269 // Used to store metadata from the server response, which is needed for | |
270 // prefetching. | |
271 static const char kSuggestMetadataKey[]; | |
272 | |
273 // Used to store a deletion request url for server-provided suggestions. | |
274 static const char kDeletionUrlKey[]; | |
275 | |
276 // These are the values for the above keys. | |
277 static const char kTrue[]; | |
278 static const char kFalse[]; | |
279 | |
257 // Returns an AutocompleteMatch with the given |autocomplete_provider| | 280 // Returns an AutocompleteMatch with the given |autocomplete_provider| |
258 // for the search |suggestion|, which represents a search via |template_url|. | 281 // for the search |suggestion|, which represents a search via |template_url|. |
259 // If |template_url| is NULL, returns a match with an invalid destination URL. | 282 // If |template_url| is NULL, returns a match with an invalid destination URL. |
260 // | 283 // |
261 // |input_text| is the original user input. This is used to highlight | 284 // |input_text| is the original user input. This is used to highlight |
262 // portions of the match contents to distinguish locally-typed text from | 285 // portions of the match contents to distinguish locally-typed text from |
263 // suggested text. | 286 // suggested text. |
264 // | 287 // |
265 // |input| is necessary for various other details, like whether we should | 288 // |input| is necessary for various other details, like whether we should |
266 // allow inline autocompletion and what the transition type should be. | 289 // allow inline autocompletion and what the transition type should be. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 // especially if we want to support suggest providers other than Google, we | 329 // especially if we want to support suggest providers other than Google, we |
307 // may change this to be a standalone setting or part of some explicit | 330 // may change this to be a standalone setting or part of some explicit |
308 // general opt-in. | 331 // general opt-in. |
309 static bool CanSendURL( | 332 static bool CanSendURL( |
310 const GURL& current_page_url, | 333 const GURL& current_page_url, |
311 const GURL& suggest_url, | 334 const GURL& suggest_url, |
312 const TemplateURL* template_url, | 335 const TemplateURL* template_url, |
313 AutocompleteInput::PageClassification page_classification, | 336 AutocompleteInput::PageClassification page_classification, |
314 Profile* profile); | 337 Profile* profile); |
315 | 338 |
339 // Creates an AutocompleteMatch from |result| to search |template_url| for | |
340 // |query_string|. |input|, |accepted_suggestion|, and | |
341 // |default_search_provider_result| are used for generating an | |
342 // AutocompleteMatch using CreateSearchSuggestion(). |metadata| is added to | |
343 // the match for prefetch queries only. | |
344 // Adds this match to |map|; if such a match already exists, whichever one | |
345 // has lower relevance is eliminated. | |
346 void AddMatchToMap(const SuggestResult& result, | |
Mark P
2014/02/10 23:25:55
This comment is somewhat backwards, as is the para
Maria
2014/02/11 21:42:32
Done.
| |
347 const AutocompleteInput input, | |
Mark P
2014/02/10 23:25:55
nit: why not &?
Maria
2014/02/11 21:42:32
Done.
| |
348 const base::string16& query_string, | |
349 const TemplateURL* template_url, | |
350 const std::string& metadata, | |
351 int accepted_suggestion, | |
352 bool default_search_provider_result, | |
353 MatchMap* map); | |
354 | |
316 // Whether a field trial, if any, has triggered in the most recent | 355 // Whether a field trial, if any, has triggered in the most recent |
317 // autocomplete query. This field is set to true only if the suggestion | 356 // autocomplete query. This field is set to true only if the suggestion |
318 // provider has completed and the response contained | 357 // provider has completed and the response contained |
319 // '"google:fieldtrialtriggered":true'. | 358 // '"google:fieldtrialtriggered":true'. |
320 bool field_trial_triggered_; | 359 bool field_trial_triggered_; |
321 | 360 |
322 // Same as above except that it is maintained across the current Omnibox | 361 // Same as above except that it is maintained across the current Omnibox |
323 // session. | 362 // session. |
324 bool field_trial_triggered_in_session_; | 363 bool field_trial_triggered_in_session_; |
325 | 364 |
326 private: | 365 private: |
327 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 366 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
328 }; | 367 }; |
329 | 368 |
330 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 369 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
OLD | NEW |