| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/search/suggestions/suggestions_service.h" | 5 #include "chrome/browser/search/suggestions/suggestions_service.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | |
| 17 #include "chrome/browser/search/suggestions/blacklist_store.h" | 16 #include "chrome/browser/search/suggestions/blacklist_store.h" |
| 18 #include "chrome/browser/search/suggestions/suggestions_store.h" | 17 #include "chrome/browser/search/suggestions/suggestions_store.h" |
| 19 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
| 20 #include "components/variations/variations_associated_data.h" | 19 #include "components/variations/variations_associated_data.h" |
| 20 #include "components/variations/variations_http_header_provider.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/base/url_util.h" | 25 #include "net/base/url_util.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
| 28 #include "net/http/http_util.h" | 28 #include "net/http/http_util.h" |
| 29 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
| 30 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 last_request_started_time_ = base::TimeTicks::Now(); | 241 last_request_started_time_ = base::TimeTicks::Now(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 net::URLFetcher* SuggestionsService::CreateSuggestionsRequest(const GURL& url) { | 244 net::URLFetcher* SuggestionsService::CreateSuggestionsRequest(const GURL& url) { |
| 245 net::URLFetcher* request = | 245 net::URLFetcher* request = |
| 246 net::URLFetcher::Create(0, url, net::URLFetcher::GET, this); | 246 net::URLFetcher::Create(0, url, net::URLFetcher::GET, this); |
| 247 request->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 247 request->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 248 request->SetRequestContext(url_request_context_); | 248 request->SetRequestContext(url_request_context_); |
| 249 // Add Chrome experiment state to the request headers. | 249 // Add Chrome experiment state to the request headers. |
| 250 net::HttpRequestHeaders headers; | 250 net::HttpRequestHeaders headers; |
| 251 chrome_variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( | 251 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( |
| 252 request->GetOriginalURL(), false, false, &headers); | 252 request->GetOriginalURL(), false, false, &headers); |
| 253 request->SetExtraRequestHeaders(headers.ToString()); | 253 request->SetExtraRequestHeaders(headers.ToString()); |
| 254 return request; | 254 return request; |
| 255 } | 255 } |
| 256 | 256 |
| 257 void SuggestionsService::OnRequestTimeout() { | 257 void SuggestionsService::OnRequestTimeout() { |
| 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 259 ServeFromCache(); | 259 ServeFromCache(); |
| 260 } | 260 } |
| 261 | 261 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 if (last_request_successful) { | 382 if (last_request_successful) { |
| 383 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; | 383 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; |
| 384 } else { | 384 } else { |
| 385 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; | 385 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; |
| 386 if (candidate_delay < kBlacklistMaxDelaySec) | 386 if (candidate_delay < kBlacklistMaxDelaySec) |
| 387 blacklist_delay_sec_ = candidate_delay; | 387 blacklist_delay_sec_ = candidate_delay; |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace suggestions | 391 } // namespace suggestions |
| OLD | NEW |