Chromium Code Reviews| 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: |
| 53 // The following keys are used to record additional information on matches. | |
| 54 | |
| 55 // We annotate our AutocompleteMatches with whether their relevance scores | |
| 56 // were server-provided using this key in the |additional_info| field. | |
| 57 static const char kRelevanceFromServerKey[]; | |
| 58 | |
| 59 // Indicates whether the server said a match should be prefetched. | |
| 60 static const char kShouldPrefetchKey[]; | |
| 61 | |
| 62 // Used to store metadata from the server response, which is needed for | |
| 63 // prefetching. | |
| 64 static const char kSuggestMetadataKey[]; | |
| 65 | |
| 66 // Used to store a deletion request url for server-provided suggestions. | |
| 67 static const char kDeletionUrlKey[]; | |
| 68 | |
| 69 // These are the values for the above keys. | |
| 70 static const char kTrue[]; | |
| 71 static const char kFalse[]; | |
| 72 | |
| 50 virtual ~BaseSearchProvider(); | 73 virtual ~BaseSearchProvider(); |
| 51 | 74 |
| 52 // The Result classes are intermediate representations of AutocompleteMatches, | 75 // The Result classes are intermediate representations of AutocompleteMatches, |
| 53 // simply containing relevance-ranked search and navigation suggestions. | 76 // simply containing relevance-ranked search and navigation suggestions. |
| 54 // They may be cached to provide some synchronous matches while requests for | 77 // They may be cached to provide some synchronous matches while requests for |
| 55 // new suggestions from updated input are in flight. | 78 // new suggestions from updated input are in flight. |
| 56 // TODO(msw) Extend these classes to generate their corresponding matches and | 79 // TODO(msw) Extend these classes to generate their corresponding matches and |
| 57 // other requisite data, in order to consolidate and simplify the | 80 // other requisite data, in order to consolidate and simplify the |
| 58 // highly fragmented SearchProvider logic for each Result type. | 81 // highly fragmented SearchProvider logic for each Result type. |
| 59 class Result { | 82 class Result { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 std::string metadata; | 274 std::string metadata; |
| 252 | 275 |
| 253 private: | 276 private: |
| 254 DISALLOW_COPY_AND_ASSIGN(Results); | 277 DISALLOW_COPY_AND_ASSIGN(Results); |
| 255 }; | 278 }; |
| 256 | 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| is the original user input. Text in the input 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 also 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. |
| 267 // |accepted_suggestion| and |omnibox_start_margin| are used along with | 290 // |accepted_suggestion| and |omnibox_start_margin| are used to generate |
| 268 // |input_text| to generate Assisted Query Stats. | 291 // Assisted Query Stats. |
| 269 // |append_extra_query_params| should be set if |template_url| is the default | 292 // |append_extra_query_params| should be set if |template_url| is the default |
| 270 // search engine, so the destination URL will contain any | 293 // search engine, so the destination URL will contain any |
| 271 // command-line-specified query params. | 294 // command-line-specified query params. |
| 272 static AutocompleteMatch CreateSearchSuggestion( | 295 static AutocompleteMatch CreateSearchSuggestion( |
| 273 AutocompleteProvider* autocomplete_provider, | 296 AutocompleteProvider* autocomplete_provider, |
| 274 const AutocompleteInput& input, | 297 const AutocompleteInput& input, |
| 275 const base::string16& input_text, | |
| 276 const SuggestResult& suggestion, | 298 const SuggestResult& suggestion, |
| 277 const TemplateURL* template_url, | 299 const TemplateURL* template_url, |
| 278 int accepted_suggestion, | 300 int accepted_suggestion, |
| 279 int omnibox_start_margin, | 301 int omnibox_start_margin, |
| 280 bool append_extra_query_params); | 302 bool append_extra_query_params); |
| 281 | 303 |
| 282 // Parses JSON response received from the provider, stripping XSSI | 304 // Parses JSON response received from the provider, stripping XSSI |
| 283 // protection if needed. Returns the parsed data if successful, NULL | 305 // protection if needed. Returns the parsed data if successful, NULL |
| 284 // otherwise. | 306 // otherwise. |
| 285 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); | 307 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 306 // especially if we want to support suggest providers other than Google, we | 328 // 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 | 329 // may change this to be a standalone setting or part of some explicit |
| 308 // general opt-in. | 330 // general opt-in. |
| 309 static bool CanSendURL( | 331 static bool CanSendURL( |
| 310 const GURL& current_page_url, | 332 const GURL& current_page_url, |
| 311 const GURL& suggest_url, | 333 const GURL& suggest_url, |
| 312 const TemplateURL* template_url, | 334 const TemplateURL* template_url, |
| 313 AutocompleteInput::PageClassification page_classification, | 335 AutocompleteInput::PageClassification page_classification, |
| 314 Profile* profile); | 336 Profile* profile); |
| 315 | 337 |
| 338 // Creates an AutocompleteMatch from |result| to search |template_url| for | |
|
H Fung
2014/02/13 22:52:39
template_url and input are not parameters anymore.
Maria
2014/02/13 23:19:23
Done.
| |
| 339 // the query in |result|. Adds the created match to |map|; if such a match | |
| 340 // already exists, whichever one has lower relevance is eliminated. | |
| 341 // |input|, |metadata| and |accepted_suggestion| are used for generating an | |
| 342 // AutocompleteMatch. | |
| 343 void AddMatchToMap(const SuggestResult& result, | |
| 344 const std::string& metadata, | |
| 345 int accepted_suggestion, | |
| 346 MatchMap* map); | |
| 347 | |
| 348 // Returns the TemplateURL based on whether the |result| is from the default | |
|
msw
2014/02/13 22:47:18
nit: consider "Returns the TemplateURL for the giv
Mark P
2014/02/13 23:01:53
I am okay with this suggestion. (I mention this b
Maria
2014/02/13 23:19:23
Done.
| |
| 349 // provider or from the keyword provider. | |
| 350 virtual const TemplateURL* GetTemplateURL( | |
| 351 const SuggestResult& result) const = 0; | |
| 352 | |
| 353 // Returns the AutocompleteInput based on whether the |result| is from the | |
|
msw
2014/02/13 22:47:18
ditto nit: consider "Returns the AutocompleteInput
Mark P
2014/02/13 23:01:53
I disagree. There's no natural notion for the Aut
msw
2014/02/13 23:04:49
That's a good point; this doesn't return the input
Maria
2014/02/13 23:19:23
Done.
| |
| 354 // default provider or from the keyword provider. | |
| 355 virtual const AutocompleteInput GetInput( | |
| 356 const SuggestResult& result) const = 0; | |
| 357 | |
| 358 // Returns whether the destination URL corresponding to the given |result| | |
| 359 // should contain command-line-specified query params. | |
| 360 virtual bool ShouldAppendExtraParams(const SuggestResult& result) const = 0; | |
| 361 | |
| 316 // Whether a field trial, if any, has triggered in the most recent | 362 // 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 | 363 // autocomplete query. This field is set to true only if the suggestion |
| 318 // provider has completed and the response contained | 364 // provider has completed and the response contained |
| 319 // '"google:fieldtrialtriggered":true'. | 365 // '"google:fieldtrialtriggered":true'. |
| 320 bool field_trial_triggered_; | 366 bool field_trial_triggered_; |
| 321 | 367 |
| 322 // Same as above except that it is maintained across the current Omnibox | 368 // Same as above except that it is maintained across the current Omnibox |
| 323 // session. | 369 // session. |
| 324 bool field_trial_triggered_in_session_; | 370 bool field_trial_triggered_in_session_; |
| 325 | 371 |
| 326 private: | 372 private: |
| 327 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 373 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
| 328 }; | 374 }; |
| 329 | 375 |
| 330 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 376 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
| OLD | NEW |