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 called_due_to_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 (called_due_to_focus || |
| 205 input.type() == metrics::OmniboxInputType::INVALID) { |
204 Stop(true); | 206 Stop(true); |
205 return; | 207 return; |
206 } | 208 } |
207 | 209 |
208 keyword_input_ = input; | 210 keyword_input_ = input; |
209 const TemplateURL* keyword_provider = | 211 const TemplateURL* keyword_provider = |
210 KeywordProvider::GetSubstitutingTemplateURLForInput(model, | 212 KeywordProvider::GetSubstitutingTemplateURLForInput(model, |
211 &keyword_input_); | 213 &keyword_input_); |
212 if (keyword_provider == NULL) | 214 if (keyword_provider == NULL) |
213 keyword_input_.Clear(); | 215 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) | 1451 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1450 matches.push_back(i->second); | 1452 matches.push_back(i->second); |
1451 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1453 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1452 | 1454 |
1453 // If there is a top scoring entry, find the corresponding answer. | 1455 // If there is a top scoring entry, find the corresponding answer. |
1454 if (!matches.empty()) | 1456 if (!matches.empty()) |
1455 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1457 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1456 | 1458 |
1457 return AnswersQueryData(); | 1459 return AnswersQueryData(); |
1458 } | 1460 } |
OLD | NEW |