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 843d9a97d0e09600dc911358f3795321dbb72b24..a712019841eba16448807bd211214a6f4cc96d53 100644 |
--- a/components/cronet/android/cronet_url_request_context_adapter.cc |
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc |
@@ -10,8 +10,10 @@ |
#include "base/files/file_util.h" |
#include "base/files/scoped_file.h" |
#include "base/logging.h" |
+#include "base/memory/scoped_vector.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,6 @@ 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)); |
GetNetworkTaskRunner()->PostTask( |
FROM_HERE, |
base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
@@ -147,13 +148,35 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
jcronet_url_request_context) { |
DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
DCHECK(!is_context_initialized_); |
- DCHECK(proxy_config_service_); |
// 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(proxy_config_service_.release()); |
+ 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, |
+ config->data_reduction_proxy_options, |
+ GetNetworkTaskRunner(), |
+ net_log.get())); |
+ context_builder.set_network_delegate( |
+ data_reduction_proxy_->CreateNetworkDelegate( |
+ make_scoped_ptr(new BasicNetworkDelegate())).release()); |
+ ScopedVector<net::URLRequestInterceptor> 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( |
mmenke
2015/04/01 15:46:14
Why aren't you using CreateUsingSystemProxyResolve
bengr
2015/04/24 02:30:43
Done.
|
+ net::ProxyService::CreateSystemProxyConfigService( |
mmenke
2015/04/01 15:46:14
It's my understanding that the Java proxy config s
bengr
2015/04/24 02:30:43
Done.
|
+ 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 +237,10 @@ 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()); |
+ } |
} |
void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { |