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 "components/omnibox/browser/zero_suggest_provider.h" | 5 #include "components/omnibox/browser/zero_suggest_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/trace_event/trace_event.h" | |
19 #include "components/data_use_measurement/core/data_use_user_data.h" | 18 #include "components/data_use_measurement/core/data_use_user_data.h" |
20 #include "components/history/core/browser/history_types.h" | 19 #include "components/history/core/browser/history_types.h" |
21 #include "components/history/core/browser/top_sites.h" | 20 #include "components/history/core/browser/top_sites.h" |
22 #include "components/metrics/proto/omnibox_input_type.pb.h" | 21 #include "components/metrics/proto/omnibox_input_type.pb.h" |
23 #include "components/omnibox/browser/autocomplete_classifier.h" | 22 #include "components/omnibox/browser/autocomplete_classifier.h" |
24 #include "components/omnibox/browser/autocomplete_input.h" | 23 #include "components/omnibox/browser/autocomplete_input.h" |
25 #include "components/omnibox/browser/autocomplete_match.h" | 24 #include "components/omnibox/browser/autocomplete_match.h" |
26 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 25 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
27 #include "components/omnibox/browser/history_url_provider.h" | 26 #include "components/omnibox/browser/history_url_provider.h" |
28 #include "components/omnibox/browser/omnibox_field_trial.h" | 27 #include "components/omnibox/browser/omnibox_field_trial.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 78 |
80 // static | 79 // static |
81 void ZeroSuggestProvider::RegisterProfilePrefs( | 80 void ZeroSuggestProvider::RegisterProfilePrefs( |
82 user_prefs::PrefRegistrySyncable* registry) { | 81 user_prefs::PrefRegistrySyncable* registry) { |
83 registry->RegisterStringPref(omnibox::kZeroSuggestCachedResults, | 82 registry->RegisterStringPref(omnibox::kZeroSuggestCachedResults, |
84 std::string()); | 83 std::string()); |
85 } | 84 } |
86 | 85 |
87 void ZeroSuggestProvider::Start(const AutocompleteInput& input, | 86 void ZeroSuggestProvider::Start(const AutocompleteInput& input, |
88 bool minimal_changes) { | 87 bool minimal_changes) { |
89 TRACE_EVENT0("omnibox", "ZeroSuggestProvider::Start"); | |
90 matches_.clear(); | 88 matches_.clear(); |
91 if (!input.from_omnibox_focus() || | 89 if (!input.from_omnibox_focus() || |
92 input.type() == metrics::OmniboxInputType::INVALID) | 90 input.type() == metrics::OmniboxInputType::INVALID) |
93 return; | 91 return; |
94 | 92 |
95 Stop(true, false); | 93 Stop(true, false); |
96 set_field_trial_triggered(false); | 94 set_field_trial_triggered(false); |
97 set_field_trial_triggered_in_session(false); | 95 set_field_trial_triggered_in_session(false); |
98 results_from_cache_ = false; | 96 results_from_cache_ = false; |
99 permanent_text_ = input.text(); | 97 permanent_text_ = input.text(); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!json_data.empty()) { | 465 if (!json_data.empty()) { |
468 scoped_ptr<base::Value> data( | 466 scoped_ptr<base::Value> data( |
469 SearchSuggestionParser::DeserializeJsonData(json_data)); | 467 SearchSuggestionParser::DeserializeJsonData(json_data)); |
470 if (data && ParseSuggestResults( | 468 if (data && ParseSuggestResults( |
471 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 469 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
472 ConvertResultsToAutocompleteMatches(); | 470 ConvertResultsToAutocompleteMatches(); |
473 results_from_cache_ = !matches_.empty(); | 471 results_from_cache_ = !matches_.empty(); |
474 } | 472 } |
475 } | 473 } |
476 } | 474 } |
OLD | NEW |