OLD | NEW |
---|---|
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 145 } |
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; |
mmenke
2015/05/07 20:22:18
Suggest a blank line here.
bengr
2015/05/08 22:41:02
Done.
| |
153 context_builder.set_network_delegate(new BasicNetworkDelegate()); | 156 scoped_ptr<net::NetLog> net_log(new net::NetLog); |
157 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); | |
158 DCHECK(!data_reduction_proxy_); | |
159 // For now, the choice to enable the data reduction proxy happens once, | |
160 // at initialization. It cannot be disabled thereafter. | |
161 if (!config->data_reduction_proxy_key.empty()) { | |
162 data_reduction_proxy_.reset( | |
163 new CronetDataReductionProxy( | |
164 config->data_reduction_proxy_key, | |
165 config->data_reduction_primary_proxy, | |
166 config->data_reduction_fallback_proxy, | |
167 config->data_reduction_secure_proxy_check_url, | |
168 config->user_agent, | |
169 GetNetworkTaskRunner(), | |
170 net_log.get())); | |
171 network_delegate = | |
172 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); | |
173 ScopedVector<net::URLRequestInterceptor> interceptors; | |
174 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); | |
175 context_builder.SetInterceptors(interceptors.Pass()); | |
176 } | |
177 context_builder.set_network_delegate(network_delegate.release()); | |
178 context_builder.set_net_log(net_log.release()); | |
154 context_builder.set_proxy_config_service(proxy_config_service_.release()); | 179 context_builder.set_proxy_config_service(proxy_config_service_.release()); |
155 config->ConfigureURLRequestContextBuilder(&context_builder); | 180 config->ConfigureURLRequestContextBuilder(&context_builder); |
156 | |
157 context_.reset(context_builder.Build()); | 181 context_.reset(context_builder.Build()); |
158 | 182 |
159 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 183 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
160 net::LOAD_DO_NOT_SEND_COOKIES; | 184 net::LOAD_DO_NOT_SEND_COOKIES; |
161 if (config->load_disable_cache) | 185 if (config->load_disable_cache) |
162 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 186 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
163 | 187 |
164 // Currently (circa M39) enabling QUIC requires setting probability threshold. | 188 // Currently (circa M39) enabling QUIC requires setting probability threshold. |
165 if (config->enable_quic) { | 189 if (config->enable_quic) { |
166 context_->http_server_properties() | 190 context_->http_server_properties() |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 static_cast<uint16>(quic_hint.alternate_port)); | 226 static_cast<uint16>(quic_hint.alternate_port)); |
203 context_->http_server_properties()->SetAlternativeService( | 227 context_->http_server_properties()->SetAlternativeService( |
204 quic_hint_host_port_pair, alternative_service, 1.0f); | 228 quic_hint_host_port_pair, alternative_service, 1.0f); |
205 } | 229 } |
206 } | 230 } |
207 | 231 |
208 JNIEnv* env = base::android::AttachCurrentThread(); | 232 JNIEnv* env = base::android::AttachCurrentThread(); |
209 Java_CronetUrlRequestContext_initNetworkThread( | 233 Java_CronetUrlRequestContext_initNetworkThread( |
210 env, jcronet_url_request_context.obj()); | 234 env, jcronet_url_request_context.obj()); |
211 | 235 |
236 if (data_reduction_proxy_) | |
237 data_reduction_proxy_->Init(true, GetURLRequestContext()); | |
212 is_context_initialized_ = true; | 238 is_context_initialized_ = true; |
213 while (!tasks_waiting_for_context_.empty()) { | 239 while (!tasks_waiting_for_context_.empty()) { |
214 tasks_waiting_for_context_.front().Run(); | 240 tasks_waiting_for_context_.front().Run(); |
215 tasks_waiting_for_context_.pop(); | 241 tasks_waiting_for_context_.pop(); |
216 } | 242 } |
217 } | 243 } |
218 | 244 |
219 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { | 245 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { |
220 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); | 246 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); |
221 // Stick network_thread_ in a local, as |this| may be destroyed from the | 247 // Stick network_thread_ in a local, as |this| may be destroyed from the |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 } | 350 } |
325 | 351 |
326 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 352 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
327 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 353 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
328 // MinLogLevel is global, shared by all URLRequestContexts. | 354 // MinLogLevel is global, shared by all URLRequestContexts. |
329 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 355 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
330 return old_log_level; | 356 return old_log_level; |
331 } | 357 } |
332 | 358 |
333 } // namespace cronet | 359 } // namespace cronet |
OLD | NEW |