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_service_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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 AutocompleteMatch::SanitizeString(navigation.description()); | 310 AutocompleteMatch::SanitizeString(navigation.description()); |
310 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 311 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
311 match.description.length(), ACMatchClassification::NONE, | 312 match.description.length(), ACMatchClassification::NONE, |
312 &match.description_class); | 313 &match.description_class); |
313 return match; | 314 return match; |
314 } | 315 } |
315 | 316 |
316 void ZeroSuggestProvider::Run(const GURL& suggest_url) { | 317 void ZeroSuggestProvider::Run(const GURL& suggest_url) { |
317 if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) { | 318 if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) { |
318 most_visited_urls_.clear(); | 319 most_visited_urls_.clear(); |
319 history::TopSites* ts = profile_->GetTopSites(); | 320 scoped_refptr<history::TopSites> ts = |
320 if (ts) { | 321 TopSitesServiceFactory::GetForProfile(profile_); |
| 322 if (ts.get()) { |
321 waiting_for_most_visited_urls_request_ = true; | 323 waiting_for_most_visited_urls_request_ = true; |
322 ts->GetMostVisitedURLs( | 324 ts->GetMostVisitedURLs( |
323 base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, | 325 base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, |
324 weak_ptr_factory_.GetWeakPtr()), false); | 326 weak_ptr_factory_.GetWeakPtr()), false); |
325 } | 327 } |
326 } else { | 328 } else { |
327 const int kFetcherID = 1; | 329 const int kFetcherID = 1; |
328 fetcher_.reset( | 330 fetcher_.reset( |
329 net::URLFetcher::Create(kFetcherID, | 331 net::URLFetcher::Create(kFetcherID, |
330 suggest_url, | 332 suggest_url, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (!json_data.empty()) { | 480 if (!json_data.empty()) { |
479 scoped_ptr<base::Value> data( | 481 scoped_ptr<base::Value> data( |
480 SearchSuggestionParser::DeserializeJsonData(json_data)); | 482 SearchSuggestionParser::DeserializeJsonData(json_data)); |
481 if (data && ParseSuggestResults( | 483 if (data && ParseSuggestResults( |
482 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 484 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
483 ConvertResultsToAutocompleteMatches(); | 485 ConvertResultsToAutocompleteMatches(); |
484 results_from_cache_ = !matches_.empty(); | 486 results_from_cache_ = !matches_.empty(); |
485 } | 487 } |
486 } | 488 } |
487 } | 489 } |
OLD | NEW |