| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 // static | 183 // static |
| 184 ACMatches::iterator SearchProvider::FindTopMatch(ACMatches* matches) { | 184 ACMatches::iterator SearchProvider::FindTopMatch(ACMatches* matches) { |
| 185 ACMatches::iterator it = matches->begin(); | 185 ACMatches::iterator it = matches->begin(); |
| 186 while ((it != matches->end()) && !it->allowed_to_be_default_match) | 186 while ((it != matches->end()) && !it->allowed_to_be_default_match) |
| 187 ++it; | 187 ++it; |
| 188 return it; | 188 return it; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void SearchProvider::Start(const AutocompleteInput& input, | 191 void SearchProvider::Start(const AutocompleteInput& input, |
| 192 bool minimal_changes) { | 192 bool minimal_changes, |
| 193 bool on_focus) { |
| 193 // Do our best to load the model as early as possible. This will reduce | 194 // Do our best to load the model as early as possible. This will reduce |
| 194 // odds of having the model not ready when really needed (a non-empty input). | 195 // odds of having the model not ready when really needed (a non-empty input). |
| 195 TemplateURLService* model = providers_.template_url_service(); | 196 TemplateURLService* model = providers_.template_url_service(); |
| 196 DCHECK(model); | 197 DCHECK(model); |
| 197 model->Load(); | 198 model->Load(); |
| 198 | 199 |
| 199 matches_.clear(); | 200 matches_.clear(); |
| 200 field_trial_triggered_ = false; | 201 field_trial_triggered_ = false; |
| 201 | 202 |
| 202 // Can't return search/suggest results for bogus input. | 203 // Can't return search/suggest results for bogus input. |
| 203 if (input.type() == metrics::OmniboxInputType::INVALID) { | 204 if (on_focus || input.type() == metrics::OmniboxInputType::INVALID) { |
| 204 Stop(true); | 205 Stop(true); |
| 205 return; | 206 return; |
| 206 } | 207 } |
| 207 | 208 |
| 208 keyword_input_ = input; | 209 keyword_input_ = input; |
| 209 const TemplateURL* keyword_provider = | 210 const TemplateURL* keyword_provider = |
| 210 KeywordProvider::GetSubstitutingTemplateURLForInput(model, | 211 KeywordProvider::GetSubstitutingTemplateURLForInput(model, |
| 211 &keyword_input_); | 212 &keyword_input_); |
| 212 if (keyword_provider == NULL) | 213 if (keyword_provider == NULL) |
| 213 keyword_input_.Clear(); | 214 keyword_input_.Clear(); |
| (...skipping 1235 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 |