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

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

Issue 171323002: Part 6 of search provider refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment on ClearAllResults Created 6 years, 10 months 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
« no previous file with comments | « no previous file | chrome/browser/autocomplete/zero_suggest_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 zero-suggest autocomplete provider. This experimental 5 // This file contains the zero-suggest autocomplete provider. This experimental
6 // provider is invoked when the user focuses in the omnibox prior to editing, 6 // provider is invoked when the user focuses in the omnibox prior to editing,
7 // and generates search query suggestions based on the current URL. To enable 7 // and generates search query suggestions based on the current URL. To enable
8 // this provider, point --experimental-zero-suggest-url-prefix at an 8 // this provider, point --experimental-zero-suggest-url-prefix at an
9 // appropriate suggestion service. 9 // appropriate suggestion service.
10 // 10 //
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // BaseSearchProvider: 74 // BaseSearchProvider:
75 virtual const TemplateURL* GetTemplateURL( 75 virtual const TemplateURL* GetTemplateURL(
76 const SuggestResult& result) const OVERRIDE; 76 const SuggestResult& result) const OVERRIDE;
77 virtual const AutocompleteInput GetInput( 77 virtual const AutocompleteInput GetInput(
78 const SuggestResult& result) const OVERRIDE; 78 const SuggestResult& result) const OVERRIDE;
79 virtual bool ShouldAppendExtraParams( 79 virtual bool ShouldAppendExtraParams(
80 const SuggestResult& result) const OVERRIDE; 80 const SuggestResult& result) const OVERRIDE;
81 virtual void StopSuggest() OVERRIDE; 81 virtual void StopSuggest() OVERRIDE;
82 virtual void ClearAllResults() OVERRIDE; 82 virtual void ClearAllResults() OVERRIDE;
83 83
84 // The 4 functions below (that take classes defined in SearchProvider as
85 // arguments) were copied and trimmed from SearchProvider.
86 // TODO(hfung): Refactor them into a new base class common to both
87 // ZeroSuggestProvider and SearchProvider.
88
89 // From the OpenSearch formatted response |root_val|, populate query
90 // suggestions into |suggest_results|, navigation suggestions into
91 // |navigation_results|, and the verbatim relevance score into
92 // |verbatim_relevance|.
93 void FillResults(const base::Value& root_val,
94 int* verbatim_relevance,
95 SuggestResults* suggest_results,
96 NavigationResults* navigation_results);
97
98 // Adds AutocompleteMatches for each of the suggestions in |results| to 84 // Adds AutocompleteMatches for each of the suggestions in |results| to
99 // |map|. 85 // |map|.
100 void AddSuggestResultsToMap(const SuggestResults& results, 86 void AddSuggestResultsToMap(const SuggestResults& results,
101 MatchMap* map); 87 MatchMap* map);
102 88
103 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. 89 // Returns an AutocompleteMatch for a navigational suggestion |navigation|.
104 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 90 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
105 91
106 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. 92 // Fetches zero-suggest suggestions by sending a request using |suggest_url|.
107 void Run(const GURL& suggest_url); 93 void Run(const GURL& suggest_url);
108 94
109 // Parses results from the zero-suggest server and updates results. 95 // Parses results from the zero-suggest server and updates |results_|.
110 void ParseSuggestResults(const base::Value& root_val); 96 void ParseSuggestResults(const base::Value& root_val);
111 97
112 // Converts the parsed results to a set of AutocompleteMatches and adds them 98 // Converts the parsed results to a set of AutocompleteMatches and adds them
113 // to |matches_|. Also update the histograms for how many results were 99 // to |matches_|. Also update the histograms for how many results were
114 // received. 100 // received.
115 void ConvertResultsToAutocompleteMatches(); 101 void ConvertResultsToAutocompleteMatches();
116 102
117 // Returns an AutocompleteMatch for the current URL. The match should be in 103 // Returns an AutocompleteMatch for the current URL. The match should be in
118 // the top position so that pressing enter has the effect of reloading the 104 // the top position so that pressing enter has the effect of reloading the
119 // page. 105 // page.
120 AutocompleteMatch MatchForCurrentURL(); 106 AutocompleteMatch MatchForCurrentURL();
121 107
122 // When the user is in the Most Visited field trial, we ask the TopSites 108 // When the user is in the Most Visited field trial, we ask the TopSites
123 // service for the most visited URLs during Run(). It calls back to this 109 // service for the most visited URLs during Run(). It calls back to this
124 // function to return those |urls|. 110 // function to return those |urls|.
125 void OnMostVisitedUrlsAvailable(const history::MostVisitedURLList& urls); 111 void OnMostVisitedUrlsAvailable(const history::MostVisitedURLList& urls);
126 112
113 // Returns the relevance score for the verbatim result.
114 int GetVerbatimRelevance() const;
115
127 // Used to build default search engine URLs for suggested queries. 116 // Used to build default search engine URLs for suggested queries.
128 TemplateURLService* template_url_service_; 117 TemplateURLService* template_url_service_;
129 118
130 // The URL for which a suggestion fetch is pending. 119 // The URL for which a suggestion fetch is pending.
131 std::string current_query_; 120 std::string current_query_;
132 121
133 // The type of page the user is viewing (a search results page doing search 122 // The type of page the user is viewing (a search results page doing search
134 // term replacement, an arbitrary URL, etc.). 123 // term replacement, an arbitrary URL, etc.).
135 AutocompleteInput::PageClassification current_page_classification_; 124 AutocompleteInput::PageClassification current_page_classification_;
136 125
137 // Copy of OmniboxEditModel::permanent_text_. 126 // Copy of OmniboxEditModel::permanent_text_.
138 base::string16 permanent_text_; 127 base::string16 permanent_text_;
139 128
140 // Fetcher used to retrieve results. 129 // Fetcher used to retrieve results.
141 scoped_ptr<net::URLFetcher> fetcher_; 130 scoped_ptr<net::URLFetcher> fetcher_;
142 // Whether there's a pending request in flight. 131 // Whether there's a pending request in flight.
143 bool have_pending_request_; 132 bool have_pending_request_;
144 133
145 // Suggestion for the current URL. 134 // Suggestion for the current URL.
146 AutocompleteMatch current_url_match_; 135 AutocompleteMatch current_url_match_;
147 // Navigation suggestions for the most recent ZeroSuggest input URL. 136
148 NavigationResults navigation_results_; 137 // Contains suggest and navigation results as well as relevance parsed from
149 // Query suggestions for the most recent ZeroSuggest input URL. 138 // the response for the most recent zero suggest input URL.
150 MatchMap query_matches_map_; 139 Results results_;
151 // The relevance score for the URL of the current page.
152 int verbatim_relevance_;
153 140
154 history::MostVisitedURLList most_visited_urls_; 141 history::MostVisitedURLList most_visited_urls_;
155 142
156 // For callbacks that may be run after destruction. 143 // For callbacks that may be run after destruction.
157 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; 144 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_;
158 145
159 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); 146 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider);
160 }; 147 };
161 148
162 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ 149 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/zero_suggest_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698