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

Unified Diff: components/cronet/android/cronet_url_request_context_adapter.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_url_request_context_adapter.cc
diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc
index 39c585a84423e79b81ea0c700d5bc9536c7ff90f..6609246a620d8b2c8a438603ea4c66b9d7d00f0c 100644
--- a/components/cronet/android/cronet_url_request_context_adapter.cc
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc
@@ -7,10 +7,12 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "base/values.h"
+#include "components/cronet/android/cronet_data_reduction_proxy.h"
#include "components/cronet/url_request_context_config.h"
#include "jni/CronetUrlRequestContext_jni.h"
#include "net/base/load_flags.h"
@@ -22,6 +24,7 @@
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
+#include "net/url_request/url_request_interceptor.h"
namespace {
@@ -132,8 +135,7 @@ void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
jobject jcaller) {
base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
jcaller_ref.Reset(env, jcaller);
- proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
- GetNetworkTaskRunner(), nullptr));
mmenke 2015/03/13 18:16:48 Think a CL to fix this has already landed, make su
bengr 2015/03/19 01:03:51 Acknowledged, though I didn't see a fix yet.
+ base::CommandLine::Init(0, nullptr);
mmenke 2015/03/13 18:16:48 Hrm...Wonder if we should move command line checki
bengr 2015/03/19 01:03:51 Done.
GetNetworkTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
@@ -147,13 +149,33 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
jcronet_url_request_context) {
DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
DCHECK(!is_context_initialized_);
+ scoped_ptr<net::NetLog> net_log(new net::NetLog);
+ DCHECK(!data_reduction_proxy_);
+ // For now, the choice to enable the data reduction proxy happens once,
+ // at initialization. It cannot be disabled thereafter.
+ if (config->enable_data_reduction_proxy) {
+ data_reduction_proxy_.reset(new CronetDataReductionProxy(
+ config->data_reduction_proxy_key, GetNetworkTaskRunner(), net_log.get()));
+ }
mmenke 2015/03/13 18:16:48 Can we just merge this with the "if (DRP)" block b
bengr 2015/03/19 01:03:51 Done.
// TODO(mmenke): Add method to have the builder enable SPDY.
net::URLRequestContextBuilder context_builder;
- context_builder.set_network_delegate(new BasicNetworkDelegate());
- context_builder.set_proxy_config_service(
- new net::ProxyConfigServiceFixed(net::ProxyConfig()));
+ if (data_reduction_proxy_) {
+ context_builder.set_network_delegate(
+ data_reduction_proxy_->CreateNetworkDelegate(
+ make_scoped_ptr(new BasicNetworkDelegate())));
+ net::URLRequestContextBuilder::URLRequestInterceptors interceptors;
+ interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
+ context_builder.SetInterceptors(interceptors.Pass());
+ } else {
+ context_builder.set_network_delegate(new BasicNetworkDelegate());
+ }
+ context_builder.set_proxy_service(
+ net::ProxyService::CreateWithoutProxyResolver(
+ net::ProxyService::CreateSystemProxyConfigService(
+ GetNetworkTaskRunner(), nullptr),
+ net_log.get()));
config->ConfigureURLRequestContextBuilder(&context_builder);
-
+ context_builder.set_net_log(net_log.release());
context_.reset(context_builder.Build());
default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
@@ -214,6 +236,9 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
tasks_waiting_for_context_.front().Run();
tasks_waiting_for_context_.pop();
}
+ if (data_reduction_proxy_)
+ data_reduction_proxy_->Init(config->enable_data_reduction_proxy,
+ GetURLRequestContext());
mmenke 2015/03/13 18:16:48 nit: Use braces.
bengr 2015/03/19 01:03:51 Done.
}
void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) {

Powered by Google App Engine
This is Rietveld 408576698