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 "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 "components/data_use_measurement/core/data_use_user_data.h" | |
18 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
19 #include "components/history/core/browser/top_sites.h" | 18 #include "components/history/core/browser/top_sites.h" |
20 #include "components/metrics/proto/omnibox_input_type.pb.h" | 19 #include "components/metrics/proto/omnibox_input_type.pb.h" |
21 #include "components/omnibox/browser/autocomplete_classifier.h" | 20 #include "components/omnibox/browser/autocomplete_classifier.h" |
22 #include "components/omnibox/browser/autocomplete_input.h" | 21 #include "components/omnibox/browser/autocomplete_input.h" |
23 #include "components/omnibox/browser/autocomplete_match.h" | 22 #include "components/omnibox/browser/autocomplete_match.h" |
24 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 23 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
25 #include "components/omnibox/browser/history_url_provider.h" | 24 #include "components/omnibox/browser/history_url_provider.h" |
26 #include "components/omnibox/browser/omnibox_field_trial.h" | 25 #include "components/omnibox/browser/omnibox_field_trial.h" |
27 #include "components/omnibox/browser/omnibox_pref_names.h" | 26 #include "components/omnibox/browser/omnibox_pref_names.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 if (ts) { | 312 if (ts) { |
314 waiting_for_most_visited_urls_request_ = true; | 313 waiting_for_most_visited_urls_request_ = true; |
315 ts->GetMostVisitedURLs( | 314 ts->GetMostVisitedURLs( |
316 base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, | 315 base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, |
317 weak_ptr_factory_.GetWeakPtr()), false); | 316 weak_ptr_factory_.GetWeakPtr()), false); |
318 } | 317 } |
319 } else { | 318 } else { |
320 const int kFetcherID = 1; | 319 const int kFetcherID = 1; |
321 fetcher_ = net::URLFetcher::Create(kFetcherID, suggest_url, | 320 fetcher_ = net::URLFetcher::Create(kFetcherID, suggest_url, |
322 net::URLFetcher::GET, this); | 321 net::URLFetcher::GET, this); |
323 data_use_measurement::DataUseUserData::AttachToFetcher( | |
324 fetcher_.get(), data_use_measurement::DataUseUserData::OMNIBOX); | |
325 fetcher_->SetRequestContext(client()->GetRequestContext()); | 322 fetcher_->SetRequestContext(client()->GetRequestContext()); |
326 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 323 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
327 // Add Chrome experiment state to the request headers. | 324 // Add Chrome experiment state to the request headers. |
328 net::HttpRequestHeaders headers; | 325 net::HttpRequestHeaders headers; |
329 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( | 326 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( |
330 fetcher_->GetOriginalURL(), client()->IsOffTheRecord(), false, | 327 fetcher_->GetOriginalURL(), client()->IsOffTheRecord(), false, |
331 &headers); | 328 &headers); |
332 fetcher_->SetExtraRequestHeaders(headers.ToString()); | 329 fetcher_->SetExtraRequestHeaders(headers.ToString()); |
333 fetcher_->Start(); | 330 fetcher_->Start(); |
334 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT); | 331 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (!json_data.empty()) { | 460 if (!json_data.empty()) { |
464 scoped_ptr<base::Value> data( | 461 scoped_ptr<base::Value> data( |
465 SearchSuggestionParser::DeserializeJsonData(json_data)); | 462 SearchSuggestionParser::DeserializeJsonData(json_data)); |
466 if (data && ParseSuggestResults( | 463 if (data && ParseSuggestResults( |
467 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 464 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
468 ConvertResultsToAutocompleteMatches(); | 465 ConvertResultsToAutocompleteMatches(); |
469 results_from_cache_ = !matches_.empty(); | 466 results_from_cache_ = !matches_.empty(); |
470 } | 467 } |
471 } | 468 } |
472 } | 469 } |
OLD | NEW |