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

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 nit Created 5 years, 7 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/sdch/sdch_owner.h" 25 #include "net/sdch/sdch_owner.h"
24 #include "net/url_request/url_request_context.h" 26 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_builder.h" 27 #include "net/url_request/url_request_context_builder.h"
28 #include "net/url_request/url_request_interceptor.h"
26 29
27 namespace { 30 namespace {
28 31
29 class BasicNetworkDelegate : public net::NetworkDelegateImpl { 32 class BasicNetworkDelegate : public net::NetworkDelegateImpl {
30 public: 33 public:
31 BasicNetworkDelegate() {} 34 BasicNetworkDelegate() {}
32 ~BasicNetworkDelegate() override {} 35 ~BasicNetworkDelegate() override {}
33 36
34 private: 37 private:
35 // net::NetworkDelegate implementation. 38 // net::NetworkDelegate implementation.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 147
145 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 148 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
146 scoped_ptr<URLRequestContextConfig> config, 149 scoped_ptr<URLRequestContextConfig> config,
147 const base::android::ScopedJavaGlobalRef<jobject>& 150 const base::android::ScopedJavaGlobalRef<jobject>&
148 jcronet_url_request_context) { 151 jcronet_url_request_context) {
149 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 152 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
150 DCHECK(!is_context_initialized_); 153 DCHECK(!is_context_initialized_);
151 DCHECK(proxy_config_service_); 154 DCHECK(proxy_config_service_);
152 // TODO(mmenke): Add method to have the builder enable SPDY. 155 // TODO(mmenke): Add method to have the builder enable SPDY.
153 net::URLRequestContextBuilder context_builder; 156 net::URLRequestContextBuilder context_builder;
154 context_builder.set_network_delegate(new BasicNetworkDelegate()); 157
158 scoped_ptr<net::NetLog> net_log(new net::NetLog);
159 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate());
160 DCHECK(!data_reduction_proxy_);
161 // For now, the choice to enable the data reduction proxy happens once,
162 // at initialization. It cannot be disabled thereafter.
163 if (!config->data_reduction_proxy_key.empty()) {
164 data_reduction_proxy_.reset(
165 new CronetDataReductionProxy(
166 config->data_reduction_proxy_key,
167 config->data_reduction_primary_proxy,
168 config->data_reduction_fallback_proxy,
169 config->data_reduction_secure_proxy_check_url,
170 config->user_agent,
171 GetNetworkTaskRunner(),
172 net_log.get()));
173 network_delegate =
174 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass());
175 ScopedVector<net::URLRequestInterceptor> interceptors;
176 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
177 context_builder.SetInterceptors(interceptors.Pass());
178 }
179 context_builder.set_network_delegate(network_delegate.release());
180 context_builder.set_net_log(net_log.release());
155 context_builder.set_proxy_config_service(proxy_config_service_.release()); 181 context_builder.set_proxy_config_service(proxy_config_service_.release());
156 config->ConfigureURLRequestContextBuilder(&context_builder); 182 config->ConfigureURLRequestContextBuilder(&context_builder);
157
158 context_.reset(context_builder.Build()); 183 context_.reset(context_builder.Build());
159 184
160 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 185 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
161 net::LOAD_DO_NOT_SEND_COOKIES; 186 net::LOAD_DO_NOT_SEND_COOKIES;
162 if (config->load_disable_cache) 187 if (config->load_disable_cache)
163 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 188 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
164 189
165 if (config->enable_sdch) { 190 if (config->enable_sdch) {
166 DCHECK(context_->sdch_manager()); 191 DCHECK(context_->sdch_manager());
167 sdch_owner_.reset( 192 sdch_owner_.reset(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 static_cast<uint16>(quic_hint.alternate_port)); 234 static_cast<uint16>(quic_hint.alternate_port));
210 context_->http_server_properties()->SetAlternativeService( 235 context_->http_server_properties()->SetAlternativeService(
211 quic_hint_host_port_pair, alternative_service, 1.0f); 236 quic_hint_host_port_pair, alternative_service, 1.0f);
212 } 237 }
213 } 238 }
214 239
215 JNIEnv* env = base::android::AttachCurrentThread(); 240 JNIEnv* env = base::android::AttachCurrentThread();
216 Java_CronetUrlRequestContext_initNetworkThread( 241 Java_CronetUrlRequestContext_initNetworkThread(
217 env, jcronet_url_request_context.obj()); 242 env, jcronet_url_request_context.obj());
218 243
244 if (data_reduction_proxy_)
245 data_reduction_proxy_->Init(true, GetURLRequestContext());
219 is_context_initialized_ = true; 246 is_context_initialized_ = true;
220 while (!tasks_waiting_for_context_.empty()) { 247 while (!tasks_waiting_for_context_.empty()) {
221 tasks_waiting_for_context_.front().Run(); 248 tasks_waiting_for_context_.front().Run();
222 tasks_waiting_for_context_.pop(); 249 tasks_waiting_for_context_.pop();
223 } 250 }
224 } 251 }
225 252
226 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { 253 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) {
227 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); 254 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread());
228 // Stick network_thread_ in a local, as |this| may be destroyed from the 255 // Stick network_thread_ in a local, as |this| may be destroyed from the
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 363 }
337 364
338 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 365 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
339 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 366 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
340 // MinLogLevel is global, shared by all URLRequestContexts. 367 // MinLogLevel is global, shared by all URLRequestContexts.
341 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 368 logging::SetMinLogLevel(static_cast<int>(jlog_level));
342 return old_log_level; 369 return old_log_level;
343 } 370 }
344 371
345 } // namespace cronet 372 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698