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/memory/scoped_vector.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "components/cronet/android/cronet_data_reduction_proxy.h" | |
17 #include "components/cronet/url_request_context_config.h" | 16 #include "components/cronet/url_request_context_config.h" |
18 #include "jni/CronetUrlRequestContext_jni.h" | 17 #include "jni/CronetUrlRequestContext_jni.h" |
19 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
20 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
21 #include "net/base/network_delegate_impl.h" | 20 #include "net/base/network_delegate_impl.h" |
22 #include "net/http/http_auth_handler_factory.h" | 21 #include "net/http/http_auth_handler_factory.h" |
23 #include "net/log/write_to_file_net_log_observer.h" | 22 #include "net/log/write_to_file_net_log_observer.h" |
24 #include "net/proxy/proxy_service.h" | 23 #include "net/proxy/proxy_service.h" |
25 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
26 #include "net/url_request/url_request_context_builder.h" | 25 #include "net/url_request/url_request_context_builder.h" |
27 #include "net/url_request/url_request_interceptor.h" | 26 #include "net/url_request/url_request_interceptor.h" |
28 | 27 |
| 28 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 29 #include "components/cronet/android/cronet_data_reduction_proxy.h" |
| 30 #endif |
| 31 |
29 namespace { | 32 namespace { |
30 | 33 |
31 class BasicNetworkDelegate : public net::NetworkDelegateImpl { | 34 class BasicNetworkDelegate : public net::NetworkDelegateImpl { |
32 public: | 35 public: |
33 BasicNetworkDelegate() {} | 36 BasicNetworkDelegate() {} |
34 ~BasicNetworkDelegate() override {} | 37 ~BasicNetworkDelegate() override {} |
35 | 38 |
36 private: | 39 private: |
37 // net::NetworkDelegate implementation. | 40 // net::NetworkDelegate implementation. |
38 int OnBeforeURLRequest(net::URLRequest* request, | 41 int OnBeforeURLRequest(net::URLRequest* request, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 scoped_ptr<URLRequestContextConfig> config, | 151 scoped_ptr<URLRequestContextConfig> config, |
149 const base::android::ScopedJavaGlobalRef<jobject>& | 152 const base::android::ScopedJavaGlobalRef<jobject>& |
150 jcronet_url_request_context) { | 153 jcronet_url_request_context) { |
151 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 154 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
152 DCHECK(!is_context_initialized_); | 155 DCHECK(!is_context_initialized_); |
153 DCHECK(proxy_config_service_); | 156 DCHECK(proxy_config_service_); |
154 // TODO(mmenke): Add method to have the builder enable SPDY. | 157 // TODO(mmenke): Add method to have the builder enable SPDY. |
155 net::URLRequestContextBuilder context_builder; | 158 net::URLRequestContextBuilder context_builder; |
156 scoped_ptr<net::NetLog> net_log(new net::NetLog); | 159 scoped_ptr<net::NetLog> net_log(new net::NetLog); |
157 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); | 160 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); |
| 161 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
158 DCHECK(!data_reduction_proxy_); | 162 DCHECK(!data_reduction_proxy_); |
159 // For now, the choice to enable the data reduction proxy happens once, | 163 // For now, the choice to enable the data reduction proxy happens once, |
160 // at initialization. It cannot be disabled thereafter. | 164 // at initialization. It cannot be disabled thereafter. |
161 if (!config->data_reduction_proxy_key.empty()) { | 165 if (!config->data_reduction_proxy_key.empty()) { |
162 data_reduction_proxy_.reset( | 166 data_reduction_proxy_.reset( |
163 new CronetDataReductionProxy( | 167 new CronetDataReductionProxy( |
164 config->data_reduction_proxy_key, | 168 config->data_reduction_proxy_key, |
165 config->data_reduction_primary_proxy, | 169 config->data_reduction_primary_proxy, |
166 config->data_reduction_fallback_proxy, | 170 config->data_reduction_fallback_proxy, |
167 config->data_reduction_secure_proxy_check_url, | 171 config->data_reduction_secure_proxy_check_url, |
168 config->user_agent, | 172 config->user_agent, |
169 GetNetworkTaskRunner(), | 173 GetNetworkTaskRunner(), |
170 net_log.get())); | 174 net_log.get())); |
171 network_delegate = | 175 network_delegate = |
172 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); | 176 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); |
173 ScopedVector<net::URLRequestInterceptor> interceptors; | 177 ScopedVector<net::URLRequestInterceptor> interceptors; |
174 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); | 178 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); |
175 context_builder.SetInterceptors(interceptors.Pass()); | 179 context_builder.SetInterceptors(interceptors.Pass()); |
176 } | 180 } |
| 181 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) |
177 context_builder.set_network_delegate(network_delegate.release()); | 182 context_builder.set_network_delegate(network_delegate.release()); |
178 context_builder.set_net_log(net_log.release()); | 183 context_builder.set_net_log(net_log.release()); |
179 context_builder.set_proxy_config_service(proxy_config_service_.release()); | 184 context_builder.set_proxy_config_service(proxy_config_service_.release()); |
180 config->ConfigureURLRequestContextBuilder(&context_builder); | 185 config->ConfigureURLRequestContextBuilder(&context_builder); |
181 context_.reset(context_builder.Build()); | 186 context_.reset(context_builder.Build()); |
182 | 187 |
183 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 188 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
184 net::LOAD_DO_NOT_SEND_COOKIES; | 189 net::LOAD_DO_NOT_SEND_COOKIES; |
185 if (config->load_disable_cache) | 190 if (config->load_disable_cache) |
186 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 191 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 static_cast<uint16>(quic_hint.alternate_port)); | 231 static_cast<uint16>(quic_hint.alternate_port)); |
227 context_->http_server_properties()->SetAlternativeService( | 232 context_->http_server_properties()->SetAlternativeService( |
228 quic_hint_host_port_pair, alternative_service, 1.0f); | 233 quic_hint_host_port_pair, alternative_service, 1.0f); |
229 } | 234 } |
230 } | 235 } |
231 | 236 |
232 JNIEnv* env = base::android::AttachCurrentThread(); | 237 JNIEnv* env = base::android::AttachCurrentThread(); |
233 Java_CronetUrlRequestContext_initNetworkThread( | 238 Java_CronetUrlRequestContext_initNetworkThread( |
234 env, jcronet_url_request_context.obj()); | 239 env, jcronet_url_request_context.obj()); |
235 | 240 |
| 241 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
236 if (data_reduction_proxy_) | 242 if (data_reduction_proxy_) |
237 data_reduction_proxy_->Init(true, GetURLRequestContext()); | 243 data_reduction_proxy_->Init(true, GetURLRequestContext()); |
| 244 #endif |
238 is_context_initialized_ = true; | 245 is_context_initialized_ = true; |
239 while (!tasks_waiting_for_context_.empty()) { | 246 while (!tasks_waiting_for_context_.empty()) { |
240 tasks_waiting_for_context_.front().Run(); | 247 tasks_waiting_for_context_.front().Run(); |
241 tasks_waiting_for_context_.pop(); | 248 tasks_waiting_for_context_.pop(); |
242 } | 249 } |
243 } | 250 } |
244 | 251 |
245 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { | 252 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { |
246 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); | 253 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); |
247 // Stick network_thread_ in a local, as |this| may be destroyed from the | 254 // 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... |
350 } | 357 } |
351 | 358 |
352 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 359 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
353 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 360 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
354 // MinLogLevel is global, shared by all URLRequestContexts. | 361 // MinLogLevel is global, shared by all URLRequestContexts. |
355 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 362 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
356 return old_log_level; | 363 return old_log_level; |
357 } | 364 } |
358 | 365 |
359 } // namespace cronet | 366 } // namespace cronet |
OLD | NEW |