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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cronet/android/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_file.h" 11 #include "base/files/scoped_file.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_vector.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/cronet/android/cronet_data_reduction_proxy.h"
15 #include "components/cronet/url_request_context_config.h" 17 #include "components/cronet/url_request_context_config.h"
16 #include "jni/CronetUrlRequestContext_jni.h" 18 #include "jni/CronetUrlRequestContext_jni.h"
17 #include "net/base/load_flags.h" 19 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
19 #include "net/base/network_delegate_impl.h" 21 #include "net/base/network_delegate_impl.h"
20 #include "net/http/http_auth_handler_factory.h" 22 #include "net/http/http_auth_handler_factory.h"
21 #include "net/log/write_to_file_net_log_observer.h" 23 #include "net/log/write_to_file_net_log_observer.h"
22 #include "net/proxy/proxy_service.h" 24 #include "net/proxy/proxy_service.h"
23 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
24 #include "net/url_request/url_request_context_builder.h" 26 #include "net/url_request/url_request_context_builder.h"
27 #include "net/url_request/url_request_interceptor.h"
25 28
26 namespace { 29 namespace {
27 30
28 class BasicNetworkDelegate : public net::NetworkDelegateImpl { 31 class BasicNetworkDelegate : public net::NetworkDelegateImpl {
29 public: 32 public:
30 BasicNetworkDelegate() {} 33 BasicNetworkDelegate() {}
31 ~BasicNetworkDelegate() override {} 34 ~BasicNetworkDelegate() override {}
32 35
33 private: 36 private:
34 // net::NetworkDelegate implementation. 37 // net::NetworkDelegate implementation.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 146
144 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 147 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
145 scoped_ptr<URLRequestContextConfig> config, 148 scoped_ptr<URLRequestContextConfig> config,
146 const base::android::ScopedJavaGlobalRef<jobject>& 149 const base::android::ScopedJavaGlobalRef<jobject>&
147 jcronet_url_request_context) { 150 jcronet_url_request_context) {
148 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 151 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
149 DCHECK(!is_context_initialized_); 152 DCHECK(!is_context_initialized_);
150 DCHECK(proxy_config_service_); 153 DCHECK(proxy_config_service_);
151 // TODO(mmenke): Add method to have the builder enable SPDY. 154 // TODO(mmenke): Add method to have the builder enable SPDY.
152 net::URLRequestContextBuilder context_builder; 155 net::URLRequestContextBuilder context_builder;
153 context_builder.set_network_delegate(new BasicNetworkDelegate()); 156 scoped_ptr<net::NetLog> net_log(new net::NetLog);
157 DCHECK(!data_reduction_proxy_);
158 // For now, the choice to enable the data reduction proxy happens once,
159 // at initialization. It cannot be disabled thereafter.
160 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
161 data_reduction_proxy_.reset(
162 new CronetDataReductionProxy(
163 config->data_reduction_proxy_key,
164 config->data_reduction_primary_proxy,
165 config->data_reduction_fallback_proxy,
166 config->data_reduction_secure_proxy_check_url,
167 config->user_agent,
168 GetNetworkTaskRunner(),
169 net_log.get()));
170 context_builder.set_network_delegate(
171 data_reduction_proxy_->CreateNetworkDelegate(
172 make_scoped_ptr(new BasicNetworkDelegate())).release());
173 ScopedVector<net::URLRequestInterceptor> interceptors;
174 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
175 context_builder.SetInterceptors(interceptors.Pass());
176 } else {
177 context_builder.set_network_delegate(new BasicNetworkDelegate());
178 }
mmenke 2015/04/24 19:27:23 optional: Think this may be a little cleaner as:
bengr 2015/04/24 21:13:51 Done.
179 context_builder.set_net_log(net_log.release());
154 context_builder.set_proxy_config_service(proxy_config_service_.release()); 180 context_builder.set_proxy_config_service(proxy_config_service_.release());
155 config->ConfigureURLRequestContextBuilder(&context_builder); 181 config->ConfigureURLRequestContextBuilder(&context_builder);
156
157 context_.reset(context_builder.Build()); 182 context_.reset(context_builder.Build());
158 183
159 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 184 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
160 net::LOAD_DO_NOT_SEND_COOKIES; 185 net::LOAD_DO_NOT_SEND_COOKIES;
161 if (config->load_disable_cache) 186 if (config->load_disable_cache)
162 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 187 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
163 188
164 // Currently (circa M39) enabling QUIC requires setting probability threshold. 189 // Currently (circa M39) enabling QUIC requires setting probability threshold.
165 if (config->enable_quic) { 190 if (config->enable_quic) {
166 context_->http_server_properties() 191 context_->http_server_properties()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 232
208 JNIEnv* env = base::android::AttachCurrentThread(); 233 JNIEnv* env = base::android::AttachCurrentThread();
209 Java_CronetUrlRequestContext_initNetworkThread( 234 Java_CronetUrlRequestContext_initNetworkThread(
210 env, jcronet_url_request_context.obj()); 235 env, jcronet_url_request_context.obj());
211 236
212 is_context_initialized_ = true; 237 is_context_initialized_ = true;
213 while (!tasks_waiting_for_context_.empty()) { 238 while (!tasks_waiting_for_context_.empty()) {
214 tasks_waiting_for_context_.front().Run(); 239 tasks_waiting_for_context_.front().Run();
215 tasks_waiting_for_context_.pop(); 240 tasks_waiting_for_context_.pop();
216 } 241 }
242 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.
243 data_reduction_proxy_->Init(config->enable_data_reduction_proxy,
244 GetURLRequestContext());
245 }
217 } 246 }
218 247
219 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { 248 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) {
220 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); 249 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread());
221 // Stick network_thread_ in a local, as |this| may be destroyed from the 250 // Stick network_thread_ in a local, as |this| may be destroyed from the
222 // network thread before delete network_thread is called. 251 // network thread before delete network_thread is called.
223 base::Thread* network_thread = network_thread_; 252 base::Thread* network_thread = network_thread_;
224 GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this); 253 GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this);
225 // Deleting thread stops it after all tasks are completed. 254 // Deleting thread stops it after all tasks are completed.
226 delete network_thread; 255 delete network_thread;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 353 }
325 354
326 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 355 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
327 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 356 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
328 // MinLogLevel is global, shared by all URLRequestContexts. 357 // MinLogLevel is global, shared by all URLRequestContexts.
329 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 358 logging::SetMinLogLevel(static_cast<int>(jlog_level));
330 return old_log_level; 359 return old_log_level;
331 } 360 }
332 361
333 } // namespace cronet 362 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698