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..7885ddbad6daeeda33673b9ff3c06678796b65e3 |
--- /dev/null |
+++ b/components/cronet/android/cronet_data_reduction_proxy.cc |
@@ -0,0 +1,121 @@ |
+// 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 <string> |
+#include <vector> |
+ |
+#include "base/command_line.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 "base/strings/string_split.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 "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.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 { |
+namespace { |
+scoped_ptr<PrefService> 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(); |
+} |
+ |
+void AddOptionsToCommandLine(const std::string& options, |
+ base::CommandLine* command_line) { |
+ if (options.empty()) |
+ return; |
+ std::vector<std::string> option; |
+ base::SplitString(options, ',', &option); |
+ DCHECK_EQ(3u, option.size()); |
+ command_line->AppendSwitchASCII( |
+ data_reduction_proxy::switches::kDataReductionProxy, option[0]); |
+ command_line->AppendSwitchASCII( |
+ data_reduction_proxy::switches::kDataReductionProxyFallback,option[1]); |
+ command_line->AppendSwitchASCII( |
+ data_reduction_proxy::switches::kDataReductionProxySecureProxyCheckURL, |
+ option[2]); |
+} |
+} // namespace |
+ |
+CronetDataReductionProxy::CronetDataReductionProxy( |
+ const std::string& key, |
+ const std::string& options, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
+ net::NetLog* net_log) |
+ : task_runner_(task_runner) { |
+ AddOptionsToCommandLine(options, base::CommandLine::ForCurrentProcess()); |
+ 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(); |
+} |
+ |
+scoped_ptr<net::NetworkDelegate> |
+CronetDataReductionProxy::CreateNetworkDelegate( |
+ scoped_ptr<net::NetworkDelegate> wrapped_network_delegate) { |
+ return io_data_->CreateNetworkDelegate(wrapped_network_delegate.Pass(), |
+ false /* No bypass UMA */ ); |
+} |
+ |
+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_); |
+ scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> |
+ statistics_prefs( |
+ new data_reduction_proxy::DataReductionProxyStatisticsPrefs( |
+ prefs_.get(), task_runner_, base::TimeDelta())); |
+ 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())); |
mmenke
2015/04/01 15:46:14
Before landing this, could you land a small CL tha
bengr
2015/04/24 02:30:42
We can't because we get it as a raw pointer in Chr
|
+ 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 |