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

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: Remove match from matches_ when deletion is requested 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
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 {
367 public:
368 SuggestionDeletionHandler();
369 virtual ~SuggestionDeletionHandler();
370 virtual void StartRequest(const std::string& deletion_url, Profile* profile,
371 const base::Callback<void(bool)>& callback);
372 private:
373 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
Anuj 2013/11/21 17:27:52 Probably an empty line is needed - here between me
374 scoped_ptr<net::URLFetcher> deletion_fetcher_;
375 base::Callback<void(bool)> callback_;
376
377 DISALLOW_COPY_AND_ASSIGN(SuggestionDeletionHandler);
378 };
379
352 virtual ~SearchProvider(); 380 virtual ~SearchProvider();
353 381
354 // Removes non-inlineable results until either the top result can inline 382 // Removes non-inlineable results until either the top result can inline
355 // autocomplete the current input or verbatim outscores the top result. 383 // autocomplete the current input or verbatim outscores the top result.
356 static void RemoveStaleResults(const string16& input, 384 static void RemoveStaleResults(const string16& input,
357 int verbatim_relevance, 385 int verbatim_relevance,
358 SuggestResults* suggest_results, 386 SuggestResults* suggest_results,
359 NavigationResults* navigation_results); 387 NavigationResults* navigation_results);
360 388
361 // Calculates the relevance score for the keyword verbatim result (if the 389 // Calculates the relevance score for the keyword verbatim result (if the
362 // input matches one of the profile's keyword). 390 // input matches one of the profile's keyword).
363 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type, 391 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type,
364 bool prefer_keyword); 392 bool prefer_keyword);
365 393
366 // AutocompleteProvider: 394 // AutocompleteProvider:
367 virtual void Start(const AutocompleteInput& input, 395 virtual void Start(const AutocompleteInput& input,
368 bool minimal_changes) OVERRIDE; 396 bool minimal_changes) OVERRIDE;
369 virtual void Stop(bool clear_cached_results) OVERRIDE; 397 virtual void Stop(bool clear_cached_results) OVERRIDE;
370 398
371 // net::URLFetcherDelegate: 399 // net::URLFetcherDelegate:
372 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 400 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
373 401
402 // Callback for deletion request
403 virtual void OnDeletionComplete(bool success);
404
405 // Removes the deleted match from the list of matches.
406 virtual void DeleteMatchFromMatches(const AutocompleteMatch& match);
407
374 // Called when timer_ expires. 408 // Called when timer_ expires.
375 void Run(); 409 void Run();
376 410
377 // Runs the history query, if necessary. The history query is synchronous. 411 // Runs the history query, if necessary. The history query is synchronous.
378 // This does not update |done_|. 412 // This does not update |done_|.
379 void DoHistoryQuery(bool minimal_changes); 413 void DoHistoryQuery(bool minimal_changes);
380 414
381 // Determines whether an asynchronous subcomponent query should run for the 415 // Determines whether an asynchronous subcomponent query should run for the
382 // current input. If so, starts it if necessary; otherwise stops it. 416 // current input. If so, starts it if necessary; otherwise stops it.
383 // NOTE: This function does not update |done_|. Callers must do so. 417 // 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, 544 bool relevance_from_server,
511 bool should_prefetch, 545 bool should_prefetch,
512 const std::string& metadata, 546 const std::string& metadata,
513 AutocompleteMatch::Type type, 547 AutocompleteMatch::Type type,
514 bool is_keyword, 548 bool is_keyword,
515 const string16& match_contents, 549 const string16& match_contents,
516 const string16& annotation, 550 const string16& annotation,
517 const string16& query_string, 551 const string16& query_string,
518 int accepted_suggestion, 552 int accepted_suggestion,
519 const std::string& suggest_query_params, 553 const std::string& suggest_query_params,
554 const std::string& deletion_url,
520 MatchMap* map); 555 MatchMap* map);
521 556
522 // Returns an AutocompleteMatch for a navigational suggestion. 557 // Returns an AutocompleteMatch for a navigational suggestion.
523 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 558 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
524 559
525 // Resets the scores of all |keyword_navigation_results_| matches to 560 // Resets the scores of all |keyword_navigation_results_| matches to
526 // be below that of the top keyword query match (the verbatim match 561 // be below that of the top keyword query match (the verbatim match
527 // as expressed by |keyword_verbatim_relevance_| or keyword query 562 // as expressed by |keyword_verbatim_relevance_| or keyword query
528 // suggestions stored in |keyword_suggest_results_|). If there 563 // suggestions stored in |keyword_suggest_results_|). If there
529 // are no keyword suggestions and keyword verbatim is suppressed, 564 // 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. 609 // were server-provided using this key in the |additional_info| field.
575 static const char kRelevanceFromServerKey[]; 610 static const char kRelevanceFromServerKey[];
576 611
577 // Indicates whether the server said a match should be prefetched. 612 // Indicates whether the server said a match should be prefetched.
578 static const char kShouldPrefetchKey[]; 613 static const char kShouldPrefetchKey[];
579 614
580 // Used to store metadata from the server response, which is needed for 615 // Used to store metadata from the server response, which is needed for
581 // prefetching. 616 // prefetching.
582 static const char kSuggestMetadataKey[]; 617 static const char kSuggestMetadataKey[];
583 618
619 // Used to store a deletion request url for psuggest autocomplete matches.
620 static const char kDeletionUrlKey[];
621
584 // These are the values for the above keys. 622 // These are the values for the above keys.
585 static const char kTrue[]; 623 static const char kTrue[];
586 static const char kFalse[]; 624 static const char kFalse[];
587 625
588 // Maintains the TemplateURLs used. 626 // Maintains the TemplateURLs used.
589 Providers providers_; 627 Providers providers_;
590 628
591 // The user's input. 629 // The user's input.
592 AutocompleteInput input_; 630 AutocompleteInput input_;
593 631
(...skipping 12 matching lines...) Expand all
606 // typing for long enough. 644 // typing for long enough.
607 base::OneShotTimer<SearchProvider> timer_; 645 base::OneShotTimer<SearchProvider> timer_;
608 646
609 // The time at which we sent a query to the suggest server. 647 // The time at which we sent a query to the suggest server.
610 base::TimeTicks time_suggest_request_sent_; 648 base::TimeTicks time_suggest_request_sent_;
611 649
612 // Fetchers used to retrieve results for the keyword and default providers. 650 // Fetchers used to retrieve results for the keyword and default providers.
613 scoped_ptr<net::URLFetcher> keyword_fetcher_; 651 scoped_ptr<net::URLFetcher> keyword_fetcher_;
614 scoped_ptr<net::URLFetcher> default_fetcher_; 652 scoped_ptr<net::URLFetcher> default_fetcher_;
615 653
654 // A handler for making requests to delete personalized suggestions.
655 scoped_ptr<SuggestionDeletionHandler> deletion_handler_;
656
616 // Results from the default and keyword search providers. 657 // Results from the default and keyword search providers.
617 Results default_results_; 658 Results default_results_;
618 Results keyword_results_; 659 Results keyword_results_;
619 660
620 // Whether a field trial, if any, has triggered in the most recent 661 // Whether a field trial, if any, has triggered in the most recent
621 // autocomplete query. This field is set to false in Start() and may be set 662 // autocomplete query. This field is set to false in Start() and may be set
622 // to true if either the default provider or keyword provider has completed 663 // to true if either the default provider or keyword provider has completed
623 // and their corresponding suggest response contained 664 // and their corresponding suggest response contained
624 // '"google:fieldtrialtriggered":true'. 665 // '"google:fieldtrialtriggered":true'.
625 // If the autocomplete query has not returned, this field is set to false. 666 // If the autocomplete query has not returned, this field is set to false.
626 bool field_trial_triggered_; 667 bool field_trial_triggered_;
627 668
628 // Same as above except that it is maintained across the current Omnibox 669 // Same as above except that it is maintained across the current Omnibox
629 // session. 670 // session.
630 bool field_trial_triggered_in_session_; 671 bool field_trial_triggered_in_session_;
631 672
632 // If true, search history query suggestions will score low enough that 673 // If true, search history query suggestions will score low enough that
633 // they will not be inlined. 674 // they will not be inlined.
634 bool prevent_search_history_inlining_; 675 bool prevent_search_history_inlining_;
635 676
636 GURL current_page_url_; 677 GURL current_page_url_;
637 678
638 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 679 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
639 }; 680 };
640 681
641 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 682 #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