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/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/i18n/break_iterator.h" | 15 #include "base/i18n/break_iterator.h" |
16 #include "base/i18n/case_conversion.h" | 16 #include "base/i18n/case_conversion.h" |
17 #include "base/json/json_string_value_serializer.h" | 17 #include "base/json/json_string_value_serializer.h" |
18 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
19 #include "base/metrics/user_metrics.h" | 19 #include "base/metrics/user_metrics.h" |
20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/trace_event/trace_event.h" |
23 #include "components/data_use_measurement/core/data_use_user_data.h" | 24 #include "components/data_use_measurement/core/data_use_user_data.h" |
24 #include "components/history/core/browser/in_memory_database.h" | 25 #include "components/history/core/browser/in_memory_database.h" |
25 #include "components/history/core/browser/keyword_search_term.h" | 26 #include "components/history/core/browser/keyword_search_term.h" |
26 #include "components/metrics/proto/omnibox_input_type.pb.h" | 27 #include "components/metrics/proto/omnibox_input_type.pb.h" |
27 #include "components/omnibox/browser/autocomplete_provider_client.h" | 28 #include "components/omnibox/browser/autocomplete_provider_client.h" |
28 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 29 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
29 #include "components/omnibox/browser/autocomplete_result.h" | 30 #include "components/omnibox/browser/autocomplete_result.h" |
30 #include "components/omnibox/browser/keyword_provider.h" | 31 #include "components/omnibox/browser/keyword_provider.h" |
31 #include "components/omnibox/browser/omnibox_field_trial.h" | 32 #include "components/omnibox/browser/omnibox_field_trial.h" |
32 #include "components/omnibox/browser/suggestion_answer.h" | 33 #include "components/omnibox/browser/suggestion_answer.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // static | 213 // static |
213 ACMatches::iterator SearchProvider::FindTopMatch(ACMatches* matches) { | 214 ACMatches::iterator SearchProvider::FindTopMatch(ACMatches* matches) { |
214 ACMatches::iterator it = matches->begin(); | 215 ACMatches::iterator it = matches->begin(); |
215 while ((it != matches->end()) && !it->allowed_to_be_default_match) | 216 while ((it != matches->end()) && !it->allowed_to_be_default_match) |
216 ++it; | 217 ++it; |
217 return it; | 218 return it; |
218 } | 219 } |
219 | 220 |
220 void SearchProvider::Start(const AutocompleteInput& input, | 221 void SearchProvider::Start(const AutocompleteInput& input, |
221 bool minimal_changes) { | 222 bool minimal_changes) { |
| 223 TRACE_EVENT0("omnibox", "SearchProvider::Start"); |
222 // Do our best to load the model as early as possible. This will reduce | 224 // Do our best to load the model as early as possible. This will reduce |
223 // odds of having the model not ready when really needed (a non-empty input). | 225 // odds of having the model not ready when really needed (a non-empty input). |
224 TemplateURLService* model = client()->GetTemplateURLService(); | 226 TemplateURLService* model = client()->GetTemplateURLService(); |
225 DCHECK(model); | 227 DCHECK(model); |
226 model->Load(); | 228 model->Load(); |
227 | 229 |
228 matches_.clear(); | 230 matches_.clear(); |
229 set_field_trial_triggered(false); | 231 set_field_trial_triggered(false); |
230 | 232 |
231 // Can't return search/suggest results for bogus input. | 233 // Can't return search/suggest results for bogus input. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // Hence, it's always necessary to update matches to use the new template | 382 // Hence, it's always necessary to update matches to use the new template |
381 // URL. (One could cache the template URL and only call UpdateMatches() and | 383 // URL. (One could cache the template URL and only call UpdateMatches() and |
382 // OnProviderUpdate() if a keyword was deleted/renamed or the template URL | 384 // OnProviderUpdate() if a keyword was deleted/renamed or the template URL |
383 // was changed. That would save extra calls to these functions. However, | 385 // was changed. That would save extra calls to these functions. However, |
384 // this is uncommon and not likely to be worth the extra work.) | 386 // this is uncommon and not likely to be worth the extra work.) |
385 UpdateMatches(); | 387 UpdateMatches(); |
386 listener_->OnProviderUpdate(true); // always pretend something changed | 388 listener_->OnProviderUpdate(true); // always pretend something changed |
387 } | 389 } |
388 | 390 |
389 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { | 391 void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
| 392 TRACE_EVENT0("omnibox", "SearchProvider::OnURLFetchComplete"); |
390 DCHECK(!done_); | 393 DCHECK(!done_); |
391 const bool is_keyword = source == keyword_fetcher_.get(); | 394 const bool is_keyword = source == keyword_fetcher_.get(); |
392 | 395 |
393 // Ensure the request succeeded and that the provider used is still available. | 396 // Ensure the request succeeded and that the provider used is still available. |
394 // A verbatim match cannot be generated without this provider, causing errors. | 397 // A verbatim match cannot be generated without this provider, causing errors. |
395 const bool request_succeeded = | 398 const bool request_succeeded = |
396 source->GetStatus().is_success() && (source->GetResponseCode() == 200) && | 399 source->GetStatus().is_success() && (source->GetResponseCode() == 200) && |
397 GetTemplateURL(is_keyword); | 400 GetTemplateURL(is_keyword); |
398 | 401 |
399 LogFetchComplete(request_succeeded, is_keyword); | 402 LogFetchComplete(request_succeeded, is_keyword); |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1511 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1509 matches.push_back(i->second); | 1512 matches.push_back(i->second); |
1510 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1513 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1511 | 1514 |
1512 // If there is a top scoring entry, find the corresponding answer. | 1515 // If there is a top scoring entry, find the corresponding answer. |
1513 if (!matches.empty()) | 1516 if (!matches.empty()) |
1514 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1517 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1515 | 1518 |
1516 return AnswersQueryData(); | 1519 return AnswersQueryData(); |
1517 } | 1520 } |
OLD | NEW |