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

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

Issue 54203008: Store xsrf token received with psuggest results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Anuj's comments Created 7 years, 1 month 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 Search autocomplete provider. This provider is 5 // This file contains the Search autocomplete provider. This provider is
6 // responsible for all autocomplete entries that start with "Search <engine> 6 // responsible for all autocomplete entries that start with "Search <engine>
7 // for ...", including searching for the current input string, search 7 // for ...", including searching for the current input string, search
8 // history, and search suggestions. An instance of it gets created and 8 // history, and search suggestions. An instance of it gets created and
9 // managed by the autocomplete controller. 9 // managed by the autocomplete controller.
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // suggestions. 51 // suggestions.
52 class SearchProvider : public AutocompleteProvider, 52 class SearchProvider : public AutocompleteProvider,
53 public net::URLFetcherDelegate { 53 public net::URLFetcherDelegate {
54 public: 54 public:
55 // ID used in creating URLFetcher for default provider's suggest results. 55 // ID used in creating URLFetcher for default provider's suggest results.
56 static const int kDefaultProviderURLFetcherID; 56 static const int kDefaultProviderURLFetcherID;
57 57
58 // ID used in creating URLFetcher for keyword provider's suggest results. 58 // ID used in creating URLFetcher for keyword provider's suggest results.
59 static const int kKeywordProviderURLFetcherID; 59 static const int kKeywordProviderURLFetcherID;
60 60
61 // ID used in creating URLFetcher for deleting suggestion results.
62 static const int kDeletionURLFetcherID;
63
61 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); 64 SearchProvider(AutocompleteProviderListener* listener, Profile* profile);
62 65
63 // Returns an AutocompleteMatch with the given |autocomplete_provider|, 66 // Returns an AutocompleteMatch with the given |autocomplete_provider|,
64 // |relevance|, and |type|, which represents a search via |template_url| for 67 // |relevance|, and |type|, which represents a search via |template_url| for
65 // |query_string|. If |template_url| is NULL, returns a match with an invalid 68 // |query_string|. If |template_url| is NULL, returns a match with an invalid
66 // destination URL. 69 // destination URL.
67 // 70 //
68 // |input_text| is the original user input, which may differ from 71 // |input_text| is the original user input, which may differ from
69 // |query_string|; e.g. the user typed "foo" and got a search suggestion of 72 // |query_string|; e.g. the user typed "foo" and got a search suggestion of
70 // "food", which we're now marking up. This is used to highlight portions of 73 // "food", which we're now marking up. This is used to highlight portions of
(...skipping 25 matching lines...) Expand all
96 // Returns whether the SearchProvider previously flagged |match| as a query 99 // Returns whether the SearchProvider previously flagged |match| as a query
97 // that should be prefetched. 100 // that should be prefetched.
98 static bool ShouldPrefetch(const AutocompleteMatch& match); 101 static bool ShouldPrefetch(const AutocompleteMatch& match);
99 102
100 // Extracts the suggest response metadata which SearchProvider previously 103 // Extracts the suggest response metadata which SearchProvider previously
101 // stored for |match|. 104 // stored for |match|.
102 static std::string GetSuggestMetadata(const AutocompleteMatch& match); 105 static std::string GetSuggestMetadata(const AutocompleteMatch& match);
103 106
104 // AutocompleteProvider: 107 // AutocompleteProvider:
105 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; 108 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE;
109 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE;
106 virtual void ResetSession() OVERRIDE; 110 virtual void ResetSession() OVERRIDE;
107 111
108 bool field_trial_triggered_in_session() const { 112 bool field_trial_triggered_in_session() const {
109 return field_trial_triggered_in_session_; 113 return field_trial_triggered_in_session_;
110 } 114 }
111 115
112 // This URL may be sent with suggest requests; see comments on CanSendURL(). 116 // This URL may be sent with suggest requests; see comments on CanSendURL().
113 void set_current_page_url(const GURL& current_page_url) { 117 void set_current_page_url(const GURL& current_page_url) {
114 current_page_url_ = current_page_url; 118 current_page_url_ = current_page_url;
115 } 119 }
116 120
117 private: 121 private:
118 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after 122 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after
119 // refactoring common code to a new base class. 123 // refactoring common code to a new base class.
120 friend class SearchProviderTest; 124 friend class SearchProviderTest;
121 friend class ZeroSuggestProvider; 125 friend class ZeroSuggestProvider;
122 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, CanSendURL); 126 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, CanSendURL);
123 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); 127 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline);
124 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); 128 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify);
125 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); 129 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring);
126 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveStaleResultsTest); 130 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveStaleResultsTest);
127 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); 131 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment);
132 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
133 TestDeleteMatch_HasDeletionUrlSuccess);
134 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
135 TestDeleteMatch_HasDeletionUrlFailure);
128 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); 136 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL);
129 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); 137 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults);
130 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); 138 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery);
131 139
132 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers 140 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers
133 // may be used: 141 // may be used:
134 // . The default provider. This corresponds to the user's default search 142 // . The default provider. This corresponds to the user's default search
135 // engine. This is always used, except for the rare case of no default 143 // engine. This is always used, except for the rare case of no default
136 // engine. 144 // engine.
137 // . The keyword provider. This is used if the user has typed in a keyword. 145 // . The keyword provider. This is used if the user has typed in a keyword.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // there. 234 // there.
227 bool relevance_from_server_; 235 bool relevance_from_server_;
228 }; 236 };
229 237
230 class SuggestResult : public Result { 238 class SuggestResult : public Result {
231 public: 239 public:
232 SuggestResult(const string16& suggestion, 240 SuggestResult(const string16& suggestion,
233 const string16& match_contents, 241 const string16& match_contents,
234 const string16& annotation, 242 const string16& annotation,
235 const std::string& suggest_query_params, 243 const std::string& suggest_query_params,
244 const std::string& deletion_url,
236 bool from_keyword_provider, 245 bool from_keyword_provider,
237 int relevance, 246 int relevance,
238 bool relevance_from_server, 247 bool relevance_from_server,
239 bool should_prefetch); 248 bool should_prefetch);
240 virtual ~SuggestResult(); 249 virtual ~SuggestResult();
241 250
242 const string16& suggestion() const { return suggestion_; } 251 const string16& suggestion() const { return suggestion_; }
243 const string16& match_contents() const { return match_contents_; } 252 const string16& match_contents() const { return match_contents_; }
244 const string16& annotation() const { return annotation_; } 253 const string16& annotation() const { return annotation_; }
245 const std::string& suggest_query_params() const { 254 const std::string& suggest_query_params() const {
246 return suggest_query_params_; 255 return suggest_query_params_;
247 } 256 }
257 const std::string& deletion_url() const { return deletion_url_; }
248 bool should_prefetch() const { return should_prefetch_; } 258 bool should_prefetch() const { return should_prefetch_; }
249 259
250 // Result: 260 // Result:
251 virtual bool IsInlineable(const string16& input) const OVERRIDE; 261 virtual bool IsInlineable(const string16& input) const OVERRIDE;
252 virtual int CalculateRelevance( 262 virtual int CalculateRelevance(
253 const AutocompleteInput& input, 263 const AutocompleteInput& input,
254 bool keyword_provider_requested) const OVERRIDE; 264 bool keyword_provider_requested) const OVERRIDE;
255 265
256 private: 266 private:
257 // The search terms to be used for this suggestion. 267 // The search terms to be used for this suggestion.
258 string16 suggestion_; 268 string16 suggestion_;
259 269
260 // The contents to be displayed in the autocomplete match. 270 // The contents to be displayed in the autocomplete match.
261 string16 match_contents_; 271 string16 match_contents_;
262 272
263 // Optional annotation for the |match_contents_| for disambiguation. 273 // Optional annotation for the |match_contents_| for disambiguation.
264 // This may be displayed in the autocomplete match contents, but is defined 274 // This may be displayed in the autocomplete match contents, but is defined
265 // separately to facilitate different formatting. 275 // separately to facilitate different formatting.
266 string16 annotation_; 276 string16 annotation_;
267 277
268 // Optional additional parameters to be added to the search URL. 278 // Optional additional parameters to be added to the search URL.
269 std::string suggest_query_params_; 279 std::string suggest_query_params_;
270 280
281 // Optional deletion url provided with psuggest results to delete a
Peter Kasting 2013/11/23 00:08:43 Nit: Don't use "psuggest" in code (not a well-unde
Maria 2013/11/26 02:36:27 Done.
282 // particular suggestion from personal history.
283 std::string deletion_url_;
284
271 // Should this result be prefetched? 285 // Should this result be prefetched?
272 bool should_prefetch_; 286 bool should_prefetch_;
273 }; 287 };
274 288
275 class NavigationResult : public Result { 289 class NavigationResult : public Result {
276 public: 290 public:
277 // |provider| is necessary to use StringForURLDisplay() in order to 291 // |provider| is necessary to use StringForURLDisplay() in order to
278 // compute |formatted_url_|. 292 // compute |formatted_url_|.
279 NavigationResult(const AutocompleteProvider& provider, 293 NavigationResult(const AutocompleteProvider& provider,
280 const GURL& url, 294 const GURL& url,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // suppresses the verbatim result. 356 // suppresses the verbatim result.
343 int verbatim_relevance; 357 int verbatim_relevance;
344 358
345 // The JSON metadata associated with this server response. 359 // The JSON metadata associated with this server response.
346 std::string metadata; 360 std::string metadata;
347 361
348 private: 362 private:
349 DISALLOW_COPY_AND_ASSIGN(Results); 363 DISALLOW_COPY_AND_ASSIGN(Results);
350 }; 364 };
351 365
366 class SuggestionDeletionHandler : public net::URLFetcherDelegate {
Peter Kasting 2013/11/23 00:08:43 Declare this class in the .cc file, since nothing
Maria 2013/11/26 02:36:27 Since I added a ScopedVector<SuggestionDeletionHan
Peter Kasting 2013/11/26 02:46:22 You can just forward-declare for that, you don't n
Maria 2013/11/27 02:18:06 Done.
367 public:
368 SuggestionDeletionHandler();
369 virtual void StartRequest(const std::string& deletion_url, Profile* profile,
Peter Kasting 2013/11/23 00:08:43 Nit: One arg per line Is this an override? If so
Maria 2013/11/26 02:36:27 Done with args. this is not an override.
Peter Kasting 2013/11/26 02:46:22 Why is it virtual then?
370 const base::Callback<void(bool)>& callback);
371 private:
Peter Kasting 2013/11/23 00:08:43 Nit: Blank line above this
Maria 2013/11/26 02:36:27 Done.
372 // The class takes care of deleting itself when it's done.
Peter Kasting 2013/11/23 00:08:43 Nit: This kind of comment should either be stated
Maria 2013/11/26 02:36:27 Done.
373 virtual ~SuggestionDeletionHandler();
374 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
Peter Kasting 2013/11/23 00:08:43 Nit: Again, put a blank line and a parent-class co
Maria 2013/11/26 02:36:27 Done.
375 scoped_ptr<net::URLFetcher> deletion_fetcher_;
Peter Kasting 2013/11/23 00:08:43 Nit: Blank line above this
Maria 2013/11/26 02:36:27 Done.
376 base::Callback<void(bool)> callback_;
377
378 DISALLOW_COPY_AND_ASSIGN(SuggestionDeletionHandler);
379 };
380
352 virtual ~SearchProvider(); 381 virtual ~SearchProvider();
353 382
354 // Removes non-inlineable results until either the top result can inline 383 // Removes non-inlineable results until either the top result can inline
355 // autocomplete the current input or verbatim outscores the top result. 384 // autocomplete the current input or verbatim outscores the top result.
356 static void RemoveStaleResults(const string16& input, 385 static void RemoveStaleResults(const string16& input,
357 int verbatim_relevance, 386 int verbatim_relevance,
358 SuggestResults* suggest_results, 387 SuggestResults* suggest_results,
359 NavigationResults* navigation_results); 388 NavigationResults* navigation_results);
360 389
361 // Calculates the relevance score for the keyword verbatim result (if the 390 // Calculates the relevance score for the keyword verbatim result (if the
362 // input matches one of the profile's keyword). 391 // input matches one of the profile's keyword).
363 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type, 392 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type,
364 bool prefer_keyword); 393 bool prefer_keyword);
365 394
366 // AutocompleteProvider: 395 // AutocompleteProvider:
367 virtual void Start(const AutocompleteInput& input, 396 virtual void Start(const AutocompleteInput& input,
368 bool minimal_changes) OVERRIDE; 397 bool minimal_changes) OVERRIDE;
369 virtual void Stop(bool clear_cached_results) OVERRIDE; 398 virtual void Stop(bool clear_cached_results) OVERRIDE;
370 399
371 // net::URLFetcherDelegate: 400 // net::URLFetcherDelegate:
372 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 401 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
373 402
403 // Callback for deletion request
Peter Kasting 2013/11/23 00:08:43 Nit: This comment is too vague, and doesn't have t
Maria 2013/11/26 02:36:27 Done.
404 virtual void OnDeletionComplete(bool success);
405
406 // Removes the deleted match from the list of matches.
Peter Kasting 2013/11/23 00:08:43 Nit: ...from |matches_|.
Maria 2013/11/26 02:36:27 Done.
407 virtual void DeleteMatchFromMatches(const AutocompleteMatch& match);
408
374 // Called when timer_ expires. 409 // Called when timer_ expires.
375 void Run(); 410 void Run();
376 411
377 // Runs the history query, if necessary. The history query is synchronous. 412 // Runs the history query, if necessary. The history query is synchronous.
378 // This does not update |done_|. 413 // This does not update |done_|.
379 void DoHistoryQuery(bool minimal_changes); 414 void DoHistoryQuery(bool minimal_changes);
380 415
381 // Determines whether an asynchronous subcomponent query should run for the 416 // Determines whether an asynchronous subcomponent query should run for the
382 // current input. If so, starts it if necessary; otherwise stops it. 417 // current input. If so, starts it if necessary; otherwise stops it.
383 // NOTE: This function does not update |done_|. Callers must do so. 418 // NOTE: This function does not update |done_|. Callers must do so.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 bool relevance_from_server, 545 bool relevance_from_server,
511 bool should_prefetch, 546 bool should_prefetch,
512 const std::string& metadata, 547 const std::string& metadata,
513 AutocompleteMatch::Type type, 548 AutocompleteMatch::Type type,
514 bool is_keyword, 549 bool is_keyword,
515 const string16& match_contents, 550 const string16& match_contents,
516 const string16& annotation, 551 const string16& annotation,
517 const string16& query_string, 552 const string16& query_string,
518 int accepted_suggestion, 553 int accepted_suggestion,
519 const std::string& suggest_query_params, 554 const std::string& suggest_query_params,
555 const std::string& deletion_url,
520 MatchMap* map); 556 MatchMap* map);
521 557
522 // Returns an AutocompleteMatch for a navigational suggestion. 558 // Returns an AutocompleteMatch for a navigational suggestion.
523 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 559 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
524 560
525 // Resets the scores of all |keyword_navigation_results_| matches to 561 // Resets the scores of all |keyword_navigation_results_| matches to
526 // be below that of the top keyword query match (the verbatim match 562 // be below that of the top keyword query match (the verbatim match
527 // as expressed by |keyword_verbatim_relevance_| or keyword query 563 // as expressed by |keyword_verbatim_relevance_| or keyword query
528 // suggestions stored in |keyword_suggest_results_|). If there 564 // suggestions stored in |keyword_suggest_results_|). If there
529 // are no keyword suggestions and keyword verbatim is suppressed, 565 // are no keyword suggestions and keyword verbatim is suppressed,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // were server-provided using this key in the |additional_info| field. 610 // were server-provided using this key in the |additional_info| field.
575 static const char kRelevanceFromServerKey[]; 611 static const char kRelevanceFromServerKey[];
576 612
577 // Indicates whether the server said a match should be prefetched. 613 // Indicates whether the server said a match should be prefetched.
578 static const char kShouldPrefetchKey[]; 614 static const char kShouldPrefetchKey[];
579 615
580 // Used to store metadata from the server response, which is needed for 616 // Used to store metadata from the server response, which is needed for
581 // prefetching. 617 // prefetching.
582 static const char kSuggestMetadataKey[]; 618 static const char kSuggestMetadataKey[];
583 619
620 // Used to store a deletion request url for psuggest autocomplete matches.
Peter Kasting 2013/11/23 00:08:43 Nit: Don't use "psuggest"; try "for server-provide
Maria 2013/11/26 02:36:27 Done.
621 static const char kDeletionUrlKey[];
622
584 // These are the values for the above keys. 623 // These are the values for the above keys.
585 static const char kTrue[]; 624 static const char kTrue[];
586 static const char kFalse[]; 625 static const char kFalse[];
587 626
588 // Maintains the TemplateURLs used. 627 // Maintains the TemplateURLs used.
589 Providers providers_; 628 Providers providers_;
590 629
591 // The user's input. 630 // The user's input.
592 AutocompleteInput input_; 631 AutocompleteInput input_;
593 632
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 // If true, search history query suggestions will score low enough that 671 // If true, search history query suggestions will score low enough that
633 // they will not be inlined. 672 // they will not be inlined.
634 bool prevent_search_history_inlining_; 673 bool prevent_search_history_inlining_;
635 674
636 GURL current_page_url_; 675 GURL current_page_url_;
637 676
638 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 677 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
639 }; 678 };
640 679
641 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 680 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider.cc » ('j') | chrome/browser/autocomplete/search_provider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698