Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc

Issue 893003002: Data Reduction Proxy class ownership updates and Settings cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sgurun CR comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..08ff314b5b3cfe06a46dffba672ca4a3bc068204
--- /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_getter)
+ : url_request_context_getter_(request_context_getter),
+ 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) {
+ 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) {
+ DCHECK(CalledOnValidThread());
+ net::URLFetcher* fetcher = GetURLFetcherForProbe(probe_url);
+ if (!fetcher)
+ return;
+ fetcher_.reset(fetcher);
+ fetcher_callback_ = fetcher_callback;
+ fetcher_->Start();
+}
+
+} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698