| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 base::string16::npos, input.parts()); | 176 base::string16::npos, input.parts()); |
| 191 return input; | 177 return input; |
| 192 } | 178 } |
| 193 | 179 |
| 194 bool ZeroSuggestProvider::ShouldAppendExtraParams( | 180 bool ZeroSuggestProvider::ShouldAppendExtraParams( |
| 195 const SuggestResult& result) const { | 181 const SuggestResult& result) const { |
| 196 // We always use the default provider for search, so append the params. | 182 // We always use the default provider for search, so append the params. |
| 197 return true; | 183 return true; |
| 198 } | 184 } |
| 199 | 185 |
| 186 void ZeroSuggestProvider::StopSuggest() { |
| 187 if (have_pending_request_) |
| 188 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); |
| 189 have_pending_request_ = false; |
| 190 fetcher_.reset(); |
| 191 } |
| 192 |
| 193 void ZeroSuggestProvider::ClearAllResults() { |
| 194 query_matches_map_.clear(); |
| 195 navigation_results_.clear(); |
| 196 current_query_.clear(); |
| 197 matches_.clear(); |
| 198 } |
| 199 |
| 200 void ZeroSuggestProvider::FillResults(const base::Value& root_val, | 200 void ZeroSuggestProvider::FillResults(const base::Value& root_val, |
| 201 int* verbatim_relevance, | 201 int* verbatim_relevance, |
| 202 SuggestResults* suggest_results, | 202 SuggestResults* suggest_results, |
| 203 NavigationResults* navigation_results) { | 203 NavigationResults* navigation_results) { |
| 204 base::string16 query; | 204 base::string16 query; |
| 205 const base::ListValue* root_list = NULL; | 205 const base::ListValue* root_list = NULL; |
| 206 const base::ListValue* results = NULL; | 206 const base::ListValue* results = NULL; |
| 207 const base::ListValue* relevances = NULL; | 207 const base::ListValue* relevances = NULL; |
| 208 // The response includes the query, which should be empty for ZeroSuggest | 208 // The response includes the query, which should be empty for ZeroSuggest |
| 209 // responses. | 209 // responses. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 match.is_history_what_you_typed_match = false; | 434 match.is_history_what_you_typed_match = false; |
| 435 match.allowed_to_be_default_match = true; | 435 match.allowed_to_be_default_match = true; |
| 436 | 436 |
| 437 // The placeholder suggestion for the current URL has high relevance so | 437 // The placeholder suggestion for the current URL has high relevance so |
| 438 // that it is in the first suggestion slot and inline autocompleted. It | 438 // that it is in the first suggestion slot and inline autocompleted. It |
| 439 // gets dropped as soon as the user types something. | 439 // gets dropped as soon as the user types something. |
| 440 match.relevance = verbatim_relevance_; | 440 match.relevance = verbatim_relevance_; |
| 441 | 441 |
| 442 return match; | 442 return match; |
| 443 } | 443 } |
| OLD | NEW |