Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..369bb1cba771f38f072cf6f94ce1457406cac7b1 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc |
| @@ -0,0 +1,85 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
| + |
| +#include "base/sequenced_task_runner.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_request_status.h" |
| + |
| +namespace data_reduction_proxy { |
| + |
| +DataReductionProxyService::DataReductionProxyService( |
| + scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, |
| + DataReductionProxySettings* settings, |
| + net::URLRequestContextGetter* request_context) |
| + : url_request_context_getter_(request_context), |
| + settings_(settings), |
| + weak_factory_(this) { |
| + DCHECK(settings); |
| + statistics_prefs_ = statistics_prefs.Pass(); |
| +} |
| + |
| +DataReductionProxyService::~DataReductionProxyService() { |
| +} |
| + |
| +void DataReductionProxyService::Shutdown() { |
| + DCHECK(CalledOnValidThread()); |
| + weak_factory_.InvalidateWeakPtrs(); |
| +} |
| + |
| +void DataReductionProxyService::EnableCompressionStatisticsLogging( |
| + PrefService* prefs, |
| + scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| + const base::TimeDelta& commit_delay) { |
| + DCHECK(!statistics_prefs_); |
| + statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs( |
| + prefs, ui_task_runner, commit_delay)); |
| +} |
| + |
| +base::WeakPtr<DataReductionProxyService> |
| +DataReductionProxyService::GetWeakPtr() { |
| + DCHECK(CalledOnValidThread()); |
| + return weak_factory_.GetWeakPtr(); |
| +} |
| + |
| +void DataReductionProxyService::OnURLFetchComplete( |
| + const net::URLFetcher* source) { |
|
bengr
2015/02/20 00:00:37
Can this function be const?
jeremyim
2015/02/20 02:17:17
No, because it is an override.
bengr
2015/02/20 20:26:45
Acknowledged.
|
| + DCHECK(source == fetcher_.get()); |
| + net::URLRequestStatus status = source->GetStatus(); |
| + |
| + std::string response; |
| + source->GetResponseAsString(&response); |
| + |
| + fetcher_callback_.Run(response, status); |
| +} |
| + |
| +net::URLFetcher* DataReductionProxyService::GetURLFetcherForProbe( |
| + const GURL& probe_url) { |
| + net::URLFetcher* fetcher = |
| + net::URLFetcher::Create(probe_url, net::URLFetcher::GET, this); |
| + fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); |
| + DCHECK(url_request_context_getter_); |
| + fetcher->SetRequestContext(url_request_context_getter_); |
| + // Configure max retries to be at most kMaxRetries times for 5xx errors. |
| + static const int kMaxRetries = 5; |
| + fetcher->SetMaxRetriesOn5xx(kMaxRetries); |
| + fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); |
| + return fetcher; |
| +} |
| + |
| +void DataReductionProxyService::CheckProbeURL(const GURL& probe_url, |
| + FetcherResponseCallback fetcher_callback) { |
|
bengr
2015/02/20 00:00:37
Bad indentation.
jeremyim
2015/02/20 02:17:17
Done.
|
| + DCHECK(CalledOnValidThread()); |
| + net::URLFetcher* fetcher = GetURLFetcherForProbe(probe_url); |
| + if (!fetcher) |
| + return; |
| + fetcher_.reset(fetcher); |
| + fetcher_callback_ = fetcher_callback; |
| + fetcher_->Start(); |
| +} |
| + |
| +} // namespace data_reduction_proxy |