OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 // net::URLFetcherDelegate | 70 // net::URLFetcherDelegate |
71 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 71 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
72 | 72 |
73 // Initiates a new fetch for the given |url| of classification | 73 // Initiates a new fetch for the given |url| of classification |
74 // |page_classification|. |permanent_text| is the omnibox text | 74 // |page_classification|. |permanent_text| is the omnibox text |
75 // for the current page. | 75 // for the current page. |
76 void StartZeroSuggest( | 76 void StartZeroSuggest( |
77 const GURL& curent_page_url, | 77 const GURL& curent_page_url, |
78 AutocompleteInput::PageClassification page_classification, | 78 AutocompleteInput::PageClassification page_classification, |
79 const string16& permanent_text); | 79 const base::string16& permanent_text); |
80 | 80 |
81 bool field_trial_triggered_in_session() const { | 81 bool field_trial_triggered_in_session() const { |
82 return field_trial_triggered_in_session_; | 82 return field_trial_triggered_in_session_; |
83 } | 83 } |
84 | 84 |
85 private: | 85 private: |
86 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 86 ZeroSuggestProvider(AutocompleteProviderListener* listener, |
87 Profile* profile); | 87 Profile* profile); |
88 | 88 |
89 virtual ~ZeroSuggestProvider(); | 89 virtual ~ZeroSuggestProvider(); |
(...skipping 20 matching lines...) Expand all Loading... |
110 | 110 |
111 // Creates an AutocompleteMatch with the provided |relevance| and |type| to | 111 // Creates an AutocompleteMatch with the provided |relevance| and |type| to |
112 // search |template_url| for |query_string|. |accepted_suggestion| will be | 112 // search |template_url| for |query_string|. |accepted_suggestion| will be |
113 // used to generate Assisted Query Stats. | 113 // used to generate Assisted Query Stats. |
114 // | 114 // |
115 // Adds this match to |map|; if such a match already exists, whichever one | 115 // Adds this match to |map|; if such a match already exists, whichever one |
116 // has lower relevance is eliminated. | 116 // has lower relevance is eliminated. |
117 void AddMatchToMap(int relevance, | 117 void AddMatchToMap(int relevance, |
118 AutocompleteMatch::Type type, | 118 AutocompleteMatch::Type type, |
119 const TemplateURL* template_url, | 119 const TemplateURL* template_url, |
120 const string16& query_string, | 120 const base::string16& query_string, |
121 int accepted_suggestion, | 121 int accepted_suggestion, |
122 SearchProvider::MatchMap* map); | 122 SearchProvider::MatchMap* map); |
123 | 123 |
124 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. | 124 // Returns an AutocompleteMatch for a navigational suggestion |navigation|. |
125 AutocompleteMatch NavigationToMatch( | 125 AutocompleteMatch NavigationToMatch( |
126 const SearchProvider::NavigationResult& navigation); | 126 const SearchProvider::NavigationResult& navigation); |
127 | 127 |
128 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. | 128 // Fetches zero-suggest suggestions by sending a request using |suggest_url|. |
129 void Run(const GURL& suggest_url); | 129 void Run(const GURL& suggest_url); |
130 | 130 |
(...skipping 19 matching lines...) Expand all Loading... |
150 TemplateURLService* template_url_service_; | 150 TemplateURLService* template_url_service_; |
151 | 151 |
152 // The URL for which a suggestion fetch is pending. | 152 // The URL for which a suggestion fetch is pending. |
153 std::string current_query_; | 153 std::string current_query_; |
154 | 154 |
155 // The type of page the user is viewing (a search results page doing search | 155 // The type of page the user is viewing (a search results page doing search |
156 // term replacement, an arbitrary URL, etc.). | 156 // term replacement, an arbitrary URL, etc.). |
157 AutocompleteInput::PageClassification current_page_classification_; | 157 AutocompleteInput::PageClassification current_page_classification_; |
158 | 158 |
159 // Copy of OmniboxEditModel::permanent_text_. | 159 // Copy of OmniboxEditModel::permanent_text_. |
160 string16 permanent_text_; | 160 base::string16 permanent_text_; |
161 | 161 |
162 // Fetcher used to retrieve results. | 162 // Fetcher used to retrieve results. |
163 scoped_ptr<net::URLFetcher> fetcher_; | 163 scoped_ptr<net::URLFetcher> fetcher_; |
164 // Whether there's a pending request in flight. | 164 // Whether there's a pending request in flight. |
165 bool have_pending_request_; | 165 bool have_pending_request_; |
166 | 166 |
167 // Suggestion for the current URL. | 167 // Suggestion for the current URL. |
168 AutocompleteMatch current_url_match_; | 168 AutocompleteMatch current_url_match_; |
169 // Navigation suggestions for the most recent ZeroSuggest input URL. | 169 // Navigation suggestions for the most recent ZeroSuggest input URL. |
170 SearchProvider::NavigationResults navigation_results_; | 170 SearchProvider::NavigationResults navigation_results_; |
(...skipping 15 matching lines...) Expand all Loading... |
186 | 186 |
187 history::MostVisitedURLList most_visited_urls_; | 187 history::MostVisitedURLList most_visited_urls_; |
188 | 188 |
189 // For callbacks that may be run after destruction. | 189 // For callbacks that may be run after destruction. |
190 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; | 190 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; |
191 | 191 |
192 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 192 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
193 }; | 193 }; |
194 | 194 |
195 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 195 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
OLD | NEW |