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 #include "chrome/browser/autocomplete/zero_suggest_provider.h" | 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 ZeroSuggestProvider* ZeroSuggestProvider::Create( | 77 ZeroSuggestProvider* ZeroSuggestProvider::Create( |
78 AutocompleteProviderListener* listener, | 78 AutocompleteProviderListener* listener, |
79 Profile* profile) { | 79 Profile* profile) { |
80 return new ZeroSuggestProvider(listener, profile); | 80 return new ZeroSuggestProvider(listener, profile); |
81 } | 81 } |
82 | 82 |
83 void ZeroSuggestProvider::Start(const AutocompleteInput& input, | 83 void ZeroSuggestProvider::Start(const AutocompleteInput& input, |
84 bool /*minimal_changes*/) { | 84 bool /*minimal_changes*/) { |
85 } | 85 } |
86 | 86 |
87 void ZeroSuggestProvider::Stop(bool clear_cached_results) { | |
88 if (have_pending_request_) | |
89 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); | |
90 have_pending_request_ = false; | |
91 fetcher_.reset(); | |
92 done_ = true; | |
93 if (clear_cached_results) { | |
94 query_matches_map_.clear(); | |
95 navigation_results_.clear(); | |
96 current_query_.clear(); | |
97 matches_.clear(); | |
98 } | |
99 } | |
100 | |
101 void ZeroSuggestProvider::ResetSession() { | 87 void ZeroSuggestProvider::ResetSession() { |
102 // The user has started editing in the omnibox, so leave | 88 // The user has started editing in the omnibox, so leave |
103 // |field_trial_triggered_in_session_| unchanged and set | 89 // |field_trial_triggered_in_session_| unchanged and set |
104 // |field_trial_triggered_| to false since zero suggest is inactive now. | 90 // |field_trial_triggered_| to false since zero suggest is inactive now. |
105 field_trial_triggered_ = false; | 91 field_trial_triggered_ = false; |
106 Stop(true); | 92 Stop(true); |
107 } | 93 } |
108 | 94 |
109 void ZeroSuggestProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 95 void ZeroSuggestProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
110 have_pending_request_ = false; | 96 have_pending_request_ = false; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 input.UpdateText(result.suggestion(), base::string16::npos, input.parts()); | 175 input.UpdateText(result.suggestion(), base::string16::npos, input.parts()); |
190 return input; | 176 return input; |
191 } | 177 } |
192 | 178 |
193 bool ZeroSuggestProvider::ShouldAppendExtraParams( | 179 bool ZeroSuggestProvider::ShouldAppendExtraParams( |
194 const SuggestResult& result) const { | 180 const SuggestResult& result) const { |
195 // We always use the default provider for search, so append the params. | 181 // We always use the default provider for search, so append the params. |
196 return true; | 182 return true; |
197 } | 183 } |
198 | 184 |
| 185 void ZeroSuggestProvider::StopSuggest() { |
| 186 if (have_pending_request_) |
| 187 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); |
| 188 have_pending_request_ = false; |
| 189 fetcher_.reset(); |
| 190 } |
| 191 |
| 192 void ZeroSuggestProvider::ClearAllResults() { |
| 193 query_matches_map_.clear(); |
| 194 navigation_results_.clear(); |
| 195 current_query_.clear(); |
| 196 matches_.clear(); |
| 197 } |
| 198 |
199 void ZeroSuggestProvider::FillResults(const base::Value& root_val, | 199 void ZeroSuggestProvider::FillResults(const base::Value& root_val, |
200 int* verbatim_relevance, | 200 int* verbatim_relevance, |
201 SuggestResults* suggest_results, | 201 SuggestResults* suggest_results, |
202 NavigationResults* navigation_results) { | 202 NavigationResults* navigation_results) { |
203 base::string16 query; | 203 base::string16 query; |
204 const base::ListValue* root_list = NULL; | 204 const base::ListValue* root_list = NULL; |
205 const base::ListValue* results = NULL; | 205 const base::ListValue* results = NULL; |
206 const base::ListValue* relevances = NULL; | 206 const base::ListValue* relevances = NULL; |
207 // The response includes the query, which should be empty for ZeroSuggest | 207 // The response includes the query, which should be empty for ZeroSuggest |
208 // responses. | 208 // responses. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 match.is_history_what_you_typed_match = false; | 433 match.is_history_what_you_typed_match = false; |
434 match.allowed_to_be_default_match = true; | 434 match.allowed_to_be_default_match = true; |
435 | 435 |
436 // The placeholder suggestion for the current URL has high relevance so | 436 // The placeholder suggestion for the current URL has high relevance so |
437 // that it is in the first suggestion slot and inline autocompleted. It | 437 // that it is in the first suggestion slot and inline autocompleted. It |
438 // gets dropped as soon as the user types something. | 438 // gets dropped as soon as the user types something. |
439 match.relevance = verbatim_relevance_; | 439 match.relevance = verbatim_relevance_; |
440 | 440 |
441 return match; | 441 return match; |
442 } | 442 } |
OLD | NEW |