| 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/sdch/sdch_owner.h" | 24 #include "net/sdch/sdch_owner.h" |
| 26 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 27 #include "net/url_request/url_request_context_builder.h" | 26 #include "net/url_request/url_request_context_builder.h" |
| 28 #include "net/url_request/url_request_interceptor.h" | 27 #include "net/url_request/url_request_interceptor.h" |
| 29 | 28 |
| 29 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 30 #include "components/cronet/android/cronet_data_reduction_proxy.h" |
| 31 #endif |
| 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 class BasicNetworkDelegate : public net::NetworkDelegateImpl { | 35 class BasicNetworkDelegate : public net::NetworkDelegateImpl { |
| 33 public: | 36 public: |
| 34 BasicNetworkDelegate() {} | 37 BasicNetworkDelegate() {} |
| 35 ~BasicNetworkDelegate() override {} | 38 ~BasicNetworkDelegate() override {} |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 // net::NetworkDelegate implementation. | 41 // net::NetworkDelegate implementation. |
| 39 int OnBeforeURLRequest(net::URLRequest* request, | 42 int OnBeforeURLRequest(net::URLRequest* request, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 const base::android::ScopedJavaGlobalRef<jobject>& | 153 const base::android::ScopedJavaGlobalRef<jobject>& |
| 151 jcronet_url_request_context) { | 154 jcronet_url_request_context) { |
| 152 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 155 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 153 DCHECK(!is_context_initialized_); | 156 DCHECK(!is_context_initialized_); |
| 154 DCHECK(proxy_config_service_); | 157 DCHECK(proxy_config_service_); |
| 155 // TODO(mmenke): Add method to have the builder enable SPDY. | 158 // TODO(mmenke): Add method to have the builder enable SPDY. |
| 156 net::URLRequestContextBuilder context_builder; | 159 net::URLRequestContextBuilder context_builder; |
| 157 | 160 |
| 158 scoped_ptr<net::NetLog> net_log(new net::NetLog); | 161 scoped_ptr<net::NetLog> net_log(new net::NetLog); |
| 159 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); | 162 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); |
| 163 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 160 DCHECK(!data_reduction_proxy_); | 164 DCHECK(!data_reduction_proxy_); |
| 161 // For now, the choice to enable the data reduction proxy happens once, | 165 // For now, the choice to enable the data reduction proxy happens once, |
| 162 // at initialization. It cannot be disabled thereafter. | 166 // at initialization. It cannot be disabled thereafter. |
| 163 if (!config->data_reduction_proxy_key.empty()) { | 167 if (!config->data_reduction_proxy_key.empty()) { |
| 164 data_reduction_proxy_.reset( | 168 data_reduction_proxy_.reset( |
| 165 new CronetDataReductionProxy( | 169 new CronetDataReductionProxy( |
| 166 config->data_reduction_proxy_key, | 170 config->data_reduction_proxy_key, |
| 167 config->data_reduction_primary_proxy, | 171 config->data_reduction_primary_proxy, |
| 168 config->data_reduction_fallback_proxy, | 172 config->data_reduction_fallback_proxy, |
| 169 config->data_reduction_secure_proxy_check_url, | 173 config->data_reduction_secure_proxy_check_url, |
| 170 config->user_agent, | 174 config->user_agent, |
| 171 GetNetworkTaskRunner(), | 175 GetNetworkTaskRunner(), |
| 172 net_log.get())); | 176 net_log.get())); |
| 173 network_delegate = | 177 network_delegate = |
| 174 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); | 178 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); |
| 175 ScopedVector<net::URLRequestInterceptor> interceptors; | 179 ScopedVector<net::URLRequestInterceptor> interceptors; |
| 176 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); | 180 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); |
| 177 context_builder.SetInterceptors(interceptors.Pass()); | 181 context_builder.SetInterceptors(interceptors.Pass()); |
| 178 } | 182 } |
| 183 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 179 context_builder.set_network_delegate(network_delegate.release()); | 184 context_builder.set_network_delegate(network_delegate.release()); |
| 180 context_builder.set_net_log(net_log.release()); | 185 context_builder.set_net_log(net_log.release()); |
| 181 context_builder.set_proxy_config_service(proxy_config_service_.release()); | 186 context_builder.set_proxy_config_service(proxy_config_service_.release()); |
| 182 config->ConfigureURLRequestContextBuilder(&context_builder); | 187 config->ConfigureURLRequestContextBuilder(&context_builder); |
| 183 context_.reset(context_builder.Build()); | 188 context_.reset(context_builder.Build()); |
| 184 | 189 |
| 185 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 190 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| 186 net::LOAD_DO_NOT_SEND_COOKIES; | 191 net::LOAD_DO_NOT_SEND_COOKIES; |
| 187 if (config->load_disable_cache) | 192 if (config->load_disable_cache) |
| 188 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 193 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 static_cast<uint16>(quic_hint.alternate_port)); | 239 static_cast<uint16>(quic_hint.alternate_port)); |
| 235 context_->http_server_properties()->SetAlternativeService( | 240 context_->http_server_properties()->SetAlternativeService( |
| 236 quic_hint_host_port_pair, alternative_service, 1.0f); | 241 quic_hint_host_port_pair, alternative_service, 1.0f); |
| 237 } | 242 } |
| 238 } | 243 } |
| 239 | 244 |
| 240 JNIEnv* env = base::android::AttachCurrentThread(); | 245 JNIEnv* env = base::android::AttachCurrentThread(); |
| 241 Java_CronetUrlRequestContext_initNetworkThread( | 246 Java_CronetUrlRequestContext_initNetworkThread( |
| 242 env, jcronet_url_request_context.obj()); | 247 env, jcronet_url_request_context.obj()); |
| 243 | 248 |
| 249 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 244 if (data_reduction_proxy_) | 250 if (data_reduction_proxy_) |
| 245 data_reduction_proxy_->Init(true, GetURLRequestContext()); | 251 data_reduction_proxy_->Init(true, GetURLRequestContext()); |
| 252 #endif |
| 246 is_context_initialized_ = true; | 253 is_context_initialized_ = true; |
| 247 while (!tasks_waiting_for_context_.empty()) { | 254 while (!tasks_waiting_for_context_.empty()) { |
| 248 tasks_waiting_for_context_.front().Run(); | 255 tasks_waiting_for_context_.front().Run(); |
| 249 tasks_waiting_for_context_.pop(); | 256 tasks_waiting_for_context_.pop(); |
| 250 } | 257 } |
| 251 } | 258 } |
| 252 | 259 |
| 253 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { | 260 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { |
| 254 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); | 261 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 255 // Stick network_thread_ in a local, as |this| may be destroyed from the | 262 // 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 Loading... |
| 363 } | 370 } |
| 364 | 371 |
| 365 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 372 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
| 366 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 373 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
| 367 // MinLogLevel is global, shared by all URLRequestContexts. | 374 // MinLogLevel is global, shared by all URLRequestContexts. |
| 368 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 375 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 369 return old_log_level; | 376 return old_log_level; |
| 370 } | 377 } |
| 371 | 378 |
| 372 } // namespace cronet | 379 } // namespace cronet |
| OLD | NEW |