| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/omnibox/search_provider.h" | 5 #include "components/omnibox/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 TemplateURLService* model = providers_.template_url_service(); | 196 TemplateURLService* model = providers_.template_url_service(); |
| 197 DCHECK(model); | 197 DCHECK(model); |
| 198 model->Load(); | 198 model->Load(); |
| 199 | 199 |
| 200 matches_.clear(); | 200 matches_.clear(); |
| 201 field_trial_triggered_ = false; | 201 field_trial_triggered_ = false; |
| 202 | 202 |
| 203 // Can't return search/suggest results for bogus input. | 203 // Can't return search/suggest results for bogus input. |
| 204 if (called_due_to_focus || | 204 if (called_due_to_focus || |
| 205 input.type() == metrics::OmniboxInputType::INVALID) { | 205 input.type() == metrics::OmniboxInputType::INVALID) { |
| 206 Stop(true); | 206 Stop(true, false); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 keyword_input_ = input; | 210 keyword_input_ = input; |
| 211 const TemplateURL* keyword_provider = | 211 const TemplateURL* keyword_provider = |
| 212 KeywordProvider::GetSubstitutingTemplateURLForInput(model, | 212 KeywordProvider::GetSubstitutingTemplateURLForInput(model, |
| 213 &keyword_input_); | 213 &keyword_input_); |
| 214 if (keyword_provider == NULL) | 214 if (keyword_provider == NULL) |
| 215 keyword_input_.Clear(); | 215 keyword_input_.Clear(); |
| 216 else if (keyword_input_.text().empty()) | 216 else if (keyword_input_.text().empty()) |
| 217 keyword_provider = NULL; | 217 keyword_provider = NULL; |
| 218 | 218 |
| 219 const TemplateURL* default_provider = model->GetDefaultSearchProvider(); | 219 const TemplateURL* default_provider = model->GetDefaultSearchProvider(); |
| 220 if (default_provider && | 220 if (default_provider && |
| 221 !default_provider->SupportsReplacement(model->search_terms_data())) | 221 !default_provider->SupportsReplacement(model->search_terms_data())) |
| 222 default_provider = NULL; | 222 default_provider = NULL; |
| 223 | 223 |
| 224 if (keyword_provider == default_provider) | 224 if (keyword_provider == default_provider) |
| 225 default_provider = NULL; // No use in querying the same provider twice. | 225 default_provider = NULL; // No use in querying the same provider twice. |
| 226 | 226 |
| 227 if (!default_provider && !keyword_provider) { | 227 if (!default_provider && !keyword_provider) { |
| 228 // No valid providers. | 228 // No valid providers. |
| 229 Stop(true); | 229 Stop(true, false); |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // If we're still running an old query but have since changed the query text | 233 // If we're still running an old query but have since changed the query text |
| 234 // or the providers, abort the query. | 234 // or the providers, abort the query. |
| 235 base::string16 default_provider_keyword(default_provider ? | 235 base::string16 default_provider_keyword(default_provider ? |
| 236 default_provider->keyword() : base::string16()); | 236 default_provider->keyword() : base::string16()); |
| 237 base::string16 keyword_provider_keyword(keyword_provider ? | 237 base::string16 keyword_provider_keyword(keyword_provider ? |
| 238 keyword_provider->keyword() : base::string16()); | 238 keyword_provider->keyword() : base::string16()); |
| 239 if (!minimal_changes || | 239 if (!minimal_changes || |
| 240 !providers_.equal(default_provider_keyword, keyword_provider_keyword)) { | 240 !providers_.equal(default_provider_keyword, keyword_provider_keyword)) { |
| 241 // Cancel any in-flight suggest requests. | 241 // Cancel any in-flight suggest requests. |
| 242 if (!done_) | 242 if (!done_) |
| 243 Stop(false); | 243 Stop(false, false); |
| 244 } | 244 } |
| 245 | 245 |
| 246 providers_.set(default_provider_keyword, keyword_provider_keyword); | 246 providers_.set(default_provider_keyword, keyword_provider_keyword); |
| 247 | 247 |
| 248 if (input.text().empty()) { | 248 if (input.text().empty()) { |
| 249 // User typed "?" alone. Give them a placeholder result indicating what | 249 // User typed "?" alone. Give them a placeholder result indicating what |
| 250 // this syntax does. | 250 // this syntax does. |
| 251 if (default_provider) { | 251 if (default_provider) { |
| 252 AutocompleteMatch match; | 252 AutocompleteMatch match; |
| 253 match.provider = this; | 253 match.provider = this; |
| 254 match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)); | 254 match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)); |
| 255 match.contents_class.push_back( | 255 match.contents_class.push_back( |
| 256 ACMatchClassification(0, ACMatchClassification::NONE)); | 256 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 257 match.keyword = providers_.default_provider(); | 257 match.keyword = providers_.default_provider(); |
| 258 match.allowed_to_be_default_match = true; | 258 match.allowed_to_be_default_match = true; |
| 259 matches_.push_back(match); | 259 matches_.push_back(match); |
| 260 } | 260 } |
| 261 Stop(true); | 261 Stop(true, false); |
| 262 return; | 262 return; |
| 263 } | 263 } |
| 264 | 264 |
| 265 input_ = input; | 265 input_ = input; |
| 266 | 266 |
| 267 DoHistoryQuery(minimal_changes); | 267 DoHistoryQuery(minimal_changes); |
| 268 // Answers needs scored history results before any suggest query has been | 268 // Answers needs scored history results before any suggest query has been |
| 269 // started, since the query for answer-bearing results needs additional | 269 // started, since the query for answer-bearing results needs additional |
| 270 // prefetch information based on the highest-scored local history result. | 270 // prefetch information based on the highest-scored local history result. |
| 271 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { | 271 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { |
| 272 ScoreHistoryResults(raw_default_history_results_, | 272 ScoreHistoryResults(raw_default_history_results_, |
| 273 false, | 273 false, |
| 274 &transformed_default_history_results_); | 274 &transformed_default_history_results_); |
| 275 ScoreHistoryResults(raw_keyword_history_results_, | 275 ScoreHistoryResults(raw_keyword_history_results_, |
| 276 true, | 276 true, |
| 277 &transformed_keyword_history_results_); | 277 &transformed_keyword_history_results_); |
| 278 prefetch_data_ = FindAnswersPrefetchData(); | 278 prefetch_data_ = FindAnswersPrefetchData(); |
| 279 | 279 |
| 280 // Raw results are not needed any more. | 280 // Raw results are not needed any more. |
| 281 raw_default_history_results_.clear(); | 281 raw_default_history_results_.clear(); |
| 282 raw_keyword_history_results_.clear(); | 282 raw_keyword_history_results_.clear(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 StartOrStopSuggestQuery(minimal_changes); | 285 StartOrStopSuggestQuery(minimal_changes); |
| 286 UpdateMatches(); | 286 UpdateMatches(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void SearchProvider::Stop(bool clear_cached_results) { | 289 void SearchProvider::Stop(bool clear_cached_results, |
| 290 bool user_inactivity_timer) { |
| 290 StopSuggest(); | 291 StopSuggest(); |
| 291 done_ = true; | 292 done_ = true; |
| 292 | 293 |
| 293 if (clear_cached_results) | 294 if (clear_cached_results) |
| 294 ClearAllResults(); | 295 ClearAllResults(); |
| 295 } | 296 } |
| 296 | 297 |
| 297 const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const { | 298 const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const { |
| 298 return is_keyword ? providers_.GetKeywordProviderURL() | 299 return is_keyword ? providers_.GetKeywordProviderURL() |
| 299 : providers_.GetDefaultProviderURL(); | 300 : providers_.GetDefaultProviderURL(); |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1450 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1450 matches.push_back(i->second); | 1451 matches.push_back(i->second); |
| 1451 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1452 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| 1452 | 1453 |
| 1453 // If there is a top scoring entry, find the corresponding answer. | 1454 // If there is a top scoring entry, find the corresponding answer. |
| 1454 if (!matches.empty()) | 1455 if (!matches.empty()) |
| 1455 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1456 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
| 1456 | 1457 |
| 1457 return AnswersQueryData(); | 1458 return AnswersQueryData(); |
| 1458 } | 1459 } |
| OLD | NEW |