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 "chrome/browser/autocomplete/zero_suggest_provider.h" | 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
19 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 19 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
21 #include "chrome/browser/autocomplete/history_url_provider.h" | 21 #include "chrome/browser/autocomplete/history_url_provider.h" |
22 #include "chrome/browser/history/top_sites.h" | 22 #include "chrome/browser/history/top_sites.h" |
| 23 #include "chrome/browser/history/top_sites_factory.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/search_engines/template_url_service_factory.h" | 25 #include "chrome/browser/search_engines/template_url_service_factory.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "components/history/core/browser/history_types.h" | 27 #include "components/history/core/browser/history_types.h" |
27 #include "components/metrics/proto/omnibox_input_type.pb.h" | 28 #include "components/metrics/proto/omnibox_input_type.pb.h" |
28 #include "components/omnibox/autocomplete_input.h" | 29 #include "components/omnibox/autocomplete_input.h" |
29 #include "components/omnibox/autocomplete_match.h" | 30 #include "components/omnibox/autocomplete_match.h" |
30 #include "components/omnibox/autocomplete_provider_listener.h" | 31 #include "components/omnibox/autocomplete_provider_listener.h" |
31 #include "components/omnibox/omnibox_field_trial.h" | 32 #include "components/omnibox/omnibox_field_trial.h" |
32 #include "components/omnibox/search_provider.h" | 33 #include "components/omnibox/search_provider.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 AutocompleteMatch::SanitizeString(navigation.description()); | 312 AutocompleteMatch::SanitizeString(navigation.description()); |
312 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 313 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
313 match.description.length(), ACMatchClassification::NONE, | 314 match.description.length(), ACMatchClassification::NONE, |
314 &match.description_class); | 315 &match.description_class); |
315 return match; | 316 return match; |
316 } | 317 } |
317 | 318 |
318 void ZeroSuggestProvider::Run(const GURL& suggest_url) { | 319 void ZeroSuggestProvider::Run(const GURL& suggest_url) { |
319 if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) { | 320 if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) { |
320 most_visited_urls_.clear(); | 321 most_visited_urls_.clear(); |
321 history::TopSites* ts = profile_->GetTopSites(); | 322 scoped_refptr<history::TopSites> ts = |
| 323 TopSitesFactory::GetForProfile(profile_); |
322 if (ts) { | 324 if (ts) { |
323 waiting_for_most_visited_urls_request_ = true; | 325 waiting_for_most_visited_urls_request_ = true; |
324 ts->GetMostVisitedURLs( | 326 ts->GetMostVisitedURLs( |
325 base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, | 327 base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, |
326 weak_ptr_factory_.GetWeakPtr()), false); | 328 weak_ptr_factory_.GetWeakPtr()), false); |
327 } | 329 } |
328 } else { | 330 } else { |
329 const int kFetcherID = 1; | 331 const int kFetcherID = 1; |
330 fetcher_.reset( | 332 fetcher_.reset( |
331 net::URLFetcher::Create(kFetcherID, | 333 net::URLFetcher::Create(kFetcherID, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 if (!json_data.empty()) { | 482 if (!json_data.empty()) { |
481 scoped_ptr<base::Value> data( | 483 scoped_ptr<base::Value> data( |
482 SearchSuggestionParser::DeserializeJsonData(json_data)); | 484 SearchSuggestionParser::DeserializeJsonData(json_data)); |
483 if (data && ParseSuggestResults( | 485 if (data && ParseSuggestResults( |
484 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 486 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
485 ConvertResultsToAutocompleteMatches(); | 487 ConvertResultsToAutocompleteMatches(); |
486 results_from_cache_ = !matches_.empty(); | 488 results_from_cache_ = !matches_.empty(); |
487 } | 489 } |
488 } | 490 } |
489 } | 491 } |
OLD | NEW |