| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "components/omnibox/browser/autocomplete_match.h" | 23 #include "components/omnibox/browser/autocomplete_match.h" |
| 24 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 24 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 25 #include "components/omnibox/browser/history_url_provider.h" | 25 #include "components/omnibox/browser/history_url_provider.h" |
| 26 #include "components/omnibox/browser/omnibox_field_trial.h" | 26 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 27 #include "components/omnibox/browser/omnibox_pref_names.h" | 27 #include "components/omnibox/browser/omnibox_pref_names.h" |
| 28 #include "components/omnibox/browser/search_provider.h" | 28 #include "components/omnibox/browser/search_provider.h" |
| 29 #include "components/omnibox/browser/verbatim_match.h" | 29 #include "components/omnibox/browser/verbatim_match.h" |
| 30 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
| 31 #include "components/search_engines/template_url_service.h" | 31 #include "components/search_engines/template_url_service.h" |
| 32 #include "components/url_formatter/url_formatter.h" | 32 #include "components/url_formatter/url_formatter.h" |
| 33 #include "components/variations/net/variations_http_header_provider.h" | 33 #include "components/variations/net/variations_http_headers.h" |
| 34 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
| 35 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
| 36 #include "net/http/http_request_headers.h" | 36 #include "net/http/http_request_headers.h" |
| 37 #include "net/url_request/url_fetcher.h" | 37 #include "net/url_request/url_fetcher.h" |
| 38 #include "net/url_request/url_request_status.h" | 38 #include "net/url_request/url_request_status.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // TODO(hfung): The histogram code was copied and modified from | 43 // TODO(hfung): The histogram code was copied and modified from |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } else { | 319 } else { |
| 320 const int kFetcherID = 1; | 320 const int kFetcherID = 1; |
| 321 fetcher_ = net::URLFetcher::Create(kFetcherID, suggest_url, | 321 fetcher_ = net::URLFetcher::Create(kFetcherID, suggest_url, |
| 322 net::URLFetcher::GET, this); | 322 net::URLFetcher::GET, this); |
| 323 data_use_measurement::DataUseUserData::AttachToFetcher( | 323 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 324 fetcher_.get(), data_use_measurement::DataUseUserData::OMNIBOX); | 324 fetcher_.get(), data_use_measurement::DataUseUserData::OMNIBOX); |
| 325 fetcher_->SetRequestContext(client()->GetRequestContext()); | 325 fetcher_->SetRequestContext(client()->GetRequestContext()); |
| 326 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 326 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 327 // Add Chrome experiment state to the request headers. | 327 // Add Chrome experiment state to the request headers. |
| 328 net::HttpRequestHeaders headers; | 328 net::HttpRequestHeaders headers; |
| 329 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( | 329 variations::AppendVariationHeaders(fetcher_->GetOriginalURL(), |
| 330 fetcher_->GetOriginalURL(), client()->IsOffTheRecord(), false, | 330 client()->IsOffTheRecord(), false, |
| 331 &headers); | 331 &headers); |
| 332 fetcher_->SetExtraRequestHeaders(headers.ToString()); | 332 fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| 333 fetcher_->Start(); | 333 fetcher_->Start(); |
| 334 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT); | 334 LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT); |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ZeroSuggestProvider::OnMostVisitedUrlsAvailable( | 338 void ZeroSuggestProvider::OnMostVisitedUrlsAvailable( |
| 339 const history::MostVisitedURLList& urls) { | 339 const history::MostVisitedURLList& urls) { |
| 340 if (!waiting_for_most_visited_urls_request_) return; | 340 if (!waiting_for_most_visited_urls_request_) return; |
| 341 most_visited_urls_ = urls; | 341 most_visited_urls_ = urls; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 if (!json_data.empty()) { | 463 if (!json_data.empty()) { |
| 464 scoped_ptr<base::Value> data( | 464 scoped_ptr<base::Value> data( |
| 465 SearchSuggestionParser::DeserializeJsonData(json_data)); | 465 SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 466 if (data && ParseSuggestResults( | 466 if (data && ParseSuggestResults( |
| 467 *data, kDefaultZeroSuggestRelevance, false, &results_)) { | 467 *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
| 468 ConvertResultsToAutocompleteMatches(); | 468 ConvertResultsToAutocompleteMatches(); |
| 469 results_from_cache_ = !matches_.empty(); | 469 results_from_cache_ = !matches_.empty(); |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 } | 472 } |
| OLD | NEW |