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

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: Addressed comments Created 5 years, 8 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 5a1f56921a8d34720f8aea0ad9a9780ff18cc234..1f2b29f9497506f20b8f6c2b0f591948ae1b91df 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 {
@@ -150,10 +153,32 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
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());
+ 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) {
mmenke 2015/04/24 19:10:28 Wasn't there a decision to make it so Cronet could
bengr 2015/04/24 21:13:51 Yes. I'm going to write that CL write after this o
+ data_reduction_proxy_.reset(
+ new CronetDataReductionProxy(
+ config->data_reduction_proxy_key,
+ config->data_reduction_primary_proxy,
+ config->data_reduction_fallback_proxy,
+ config->data_reduction_secure_proxy_check_url,
+ config->user_agent,
+ 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());
+ }
mmenke 2015/04/24 19:27:23 optional: Think this may be a little cleaner as:
bengr 2015/04/24 21:13:51 Done.
+ context_builder.set_net_log(net_log.release());
context_builder.set_proxy_config_service(proxy_config_service_.release());
config->ConfigureURLRequestContextBuilder(&context_builder);
-
context_.reset(context_builder.Build());
default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
@@ -214,6 +239,10 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
tasks_waiting_for_context_.front().Run();
tasks_waiting_for_context_.pop();
}
+ if (data_reduction_proxy_) {
mmenke 2015/04/24 19:27:23 This should probably go just before the "is_contex
bengr 2015/04/24 21:13:50 Done.
+ data_reduction_proxy_->Init(config->enable_data_reduction_proxy,
+ GetURLRequestContext());
+ }
}
void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) {

Powered by Google App Engine
This is Rietveld 408576698