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

Unified Diff: components/cronet/android/cronet_data_reduction_proxy.cc

Issue 937513003: Add Data Saver support to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 9 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/cronet/android/cronet_data_reduction_proxy.cc
diff --git a/components/cronet/android/cronet_data_reduction_proxy.cc b/components/cronet/android/cronet_data_reduction_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..beed46c06e1787a448355f905beb70152835bfce
--- /dev/null
+++ b/components/cronet/android/cronet_data_reduction_proxy.cc
@@ -0,0 +1,99 @@
+// 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/cronet/android/cronet_data_reduction_proxy.h"
+
+#include "base/prefs/pref_registry_simple.h"
+#include "base/prefs/pref_service.h"
+#include "base/prefs/pref_service_factory.h"
+#include "base/single_thread_task_runner.h"
+#include "components/cronet/android/cronet_pref_store.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "net/base/net_log.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_interceptor.h"
+
+namespace {
+// Shows notifications which correspond to PersistentPrefStore's reading errors.
+void HandleReadError(PersistentPrefStore::PrefReadError error) {
+}
+} // namespace
+
+namespace cronet {
+
+// static
+scoped_ptr<PrefService>
+CronetDataReductionProxy::CreatePrefService() {
+ PrefRegistrySimple* pref_registry = new PrefRegistrySimple();
+ data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry);
+ base::PrefServiceFactory pref_service_factory;
+ pref_service_factory.set_user_prefs(
+ make_scoped_refptr(new CronetPrefStore()));
+ pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError));
+ return pref_service_factory.Create(pref_registry).Pass();
+}
+
+CronetDataReductionProxy::CronetDataReductionProxy(
+ const std::string& key,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ net::NetLog* net_log)
+ : task_runner_(task_runner) {
+ prefs_ = CreatePrefService();
+ settings_.reset(
+ new data_reduction_proxy::DataReductionProxySettings());
+ io_data_.reset(
+ new data_reduction_proxy::DataReductionProxyIOData(
+ data_reduction_proxy::Client::CRONET_ANDROID,
+ data_reduction_proxy::DataReductionProxyParams::kAllowed |
+ data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed,
+ net_log, task_runner, task_runner, false));
+ io_data_->request_options()->SetKeyOnIO(key);
+}
+
+CronetDataReductionProxy::~CronetDataReductionProxy() {
+ io_data_->ShutdownOnUIThread();
+}
+
+net::NetworkDelegate* CronetDataReductionProxy::CreateNetworkDelegate(
+ scoped_ptr<net::NetworkDelegate> wrapped_network_delegate) {
+ return io_data_->CreateNetworkDelegate(
+ wrapped_network_delegate.Pass(),
+ false /* No UMA is produced to track bypasses*/ ).release();
+}
+
+scoped_ptr<net::URLRequestInterceptor>
+CronetDataReductionProxy::CreateInterceptor() {
+ return io_data_->CreateInterceptor();
+}
+
+void CronetDataReductionProxy::Init(bool enable,
+ net::URLRequestContext* context) {
+ url_request_context_getter_ =
+ new net::TrivialURLRequestContextGetter(
+ context, task_runner_);
+ base::TimeDelta commit_delay = base::TimeDelta();
mmenke 2015/03/13 18:16:47 explicit initialization not needed. Suggest just
bengr 2015/03/19 01:03:50 Done.
+ scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
+ statistics_prefs = make_scoped_ptr(
mmenke 2015/03/13 18:16:47 "make_scoped_ptr(" not needed. Can just use scop
bengr 2015/03/19 01:03:50 I thought make_scoped pointer was just shorthand f
mmenke 2015/03/19 02:50:17 You're missing that the "shorthand" is longer in t
bengr 2015/03/19 17:56:24 Oh. I misread my own code. Yes, of course. I compl
+ new data_reduction_proxy::DataReductionProxyStatisticsPrefs(
+ prefs_.get(), task_runner_, commit_delay));
+ scoped_ptr<data_reduction_proxy::DataReductionProxyService>
+ data_reduction_proxy_service(
+ new data_reduction_proxy::DataReductionProxyService(
+ statistics_prefs.Pass(), settings_.get(),
+ url_request_context_getter_.get()));
+ io_data_->SetDataReductionProxyService(
+ data_reduction_proxy_service->GetWeakPtr());
+ settings_->InitDataReductionProxySettings(
+ prefs_.get(), io_data_.get(), data_reduction_proxy_service.Pass());
+ settings_->SetDataReductionProxyEnabled(enable);
+}
+
+} // namespace cronet

Powered by Google App Engine
This is Rietveld 408576698