Chromium Code Reviews| 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/prefs/pref_filter.h" | |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "components/cronet/url_request_context_config.h" | 17 #include "components/cronet/url_request_context_config.h" |
| 17 #include "jni/CronetUrlRequestContext_jni.h" | 18 #include "jni/CronetUrlRequestContext_jni.h" |
| 18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/base/network_delegate_impl.h" | 21 #include "net/base/network_delegate_impl.h" |
| 21 #include "net/http/http_auth_handler_factory.h" | 22 #include "net/http/http_auth_handler_factory.h" |
| 22 #include "net/log/write_to_file_net_log_observer.h" | 23 #include "net/log/write_to_file_net_log_observer.h" |
| 23 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); | 179 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); |
| 179 ScopedVector<net::URLRequestInterceptor> interceptors; | 180 ScopedVector<net::URLRequestInterceptor> interceptors; |
| 180 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); | 181 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); |
| 181 context_builder.SetInterceptors(interceptors.Pass()); | 182 context_builder.SetInterceptors(interceptors.Pass()); |
| 182 } | 183 } |
| 183 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) | 184 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 184 context_builder.set_network_delegate(network_delegate.release()); | 185 context_builder.set_network_delegate(network_delegate.release()); |
| 185 context_builder.set_net_log(net_log.release()); | 186 context_builder.set_net_log(net_log.release()); |
| 186 context_builder.set_proxy_config_service(proxy_config_service_.release()); | 187 context_builder.set_proxy_config_service(proxy_config_service_.release()); |
| 187 config->ConfigureURLRequestContextBuilder(&context_builder); | 188 config->ConfigureURLRequestContextBuilder(&context_builder); |
| 189 | |
| 190 // Set up pref file if storage path is specified. | |
| 191 // TODO(xunjieli): maybe get rid of the condition on sdch. | |
| 192 if (!config->storage_path.empty() && config->enable_sdch) { | |
| 193 base::FilePath filepath(config->storage_path); | |
| 194 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); | |
| 195 json_pref_store_ = new JsonPrefStore( | |
| 196 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); | |
| 197 json_pref_store_->ReadPrefsAsync(nullptr); | |
| 198 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); | |
| 199 } | |
| 200 | |
| 188 context_.reset(context_builder.Build()); | 201 context_.reset(context_builder.Build()); |
| 189 | 202 |
| 190 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 203 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| 191 net::LOAD_DO_NOT_SEND_COOKIES; | 204 net::LOAD_DO_NOT_SEND_COOKIES; |
| 192 if (config->load_disable_cache) | 205 if (config->load_disable_cache) |
| 193 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 206 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| 194 | 207 |
| 195 if (config->enable_sdch) { | 208 if (config->enable_sdch) { |
| 196 DCHECK(context_->sdch_manager()); | 209 DCHECK(context_->sdch_manager()); |
| 197 sdch_owner_.reset( | 210 sdch_owner_.reset( |
| 198 new net::SdchOwner(context_->sdch_manager(), context_.get())); | 211 new net::SdchOwner(context_->sdch_manager(), context_.get())); |
| 212 if (json_pref_store_) | |
| 213 sdch_owner_->EnablePersistentStorage(json_pref_store_.get()); | |
| 199 } | 214 } |
| 200 | 215 |
| 201 // Currently (circa M39) enabling QUIC requires setting probability threshold. | 216 // Currently (circa M39) enabling QUIC requires setting probability threshold. |
| 202 if (config->enable_quic) { | 217 if (config->enable_quic) { |
| 203 context_->http_server_properties() | 218 context_->http_server_properties() |
| 204 ->SetAlternativeServiceProbabilityThreshold(0.0f); | 219 ->SetAlternativeServiceProbabilityThreshold(0.0f); |
| 205 for (auto hint = config->quic_hints.begin(); | 220 for (auto hint = config->quic_hints.begin(); |
| 206 hint != config->quic_hints.end(); ++hint) { | 221 hint != config->quic_hints.end(); ++hint) { |
| 207 const URLRequestContextConfig::QuicHint& quic_hint = **hint; | 222 const URLRequestContextConfig::QuicHint& quic_hint = **hint; |
| 208 if (quic_hint.host.empty()) { | 223 if (quic_hint.host.empty()) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 } | 360 } |
| 346 | 361 |
| 347 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { | 362 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { |
| 348 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 363 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 349 if (write_to_file_observer_) { | 364 if (write_to_file_observer_) { |
| 350 write_to_file_observer_->StopObserving(context_.get()); | 365 write_to_file_observer_->StopObserving(context_.get()); |
| 351 write_to_file_observer_.reset(); | 366 write_to_file_observer_.reset(); |
| 352 } | 367 } |
| 353 } | 368 } |
| 354 | 369 |
| 370 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { | |
|
mef
2015/05/28 15:18:54
add DCHECK(GetNetworkTaskRunner()->BelongsToCurren
xunjieli
2015/05/28 15:25:55
Done.
| |
| 371 if (!file_thread_) { | |
| 372 file_thread_.reset(new base::Thread("Network File Thread")); | |
| 373 file_thread_->Start(); | |
| 374 } | |
| 375 return file_thread_.get(); | |
| 376 } | |
| 377 | |
| 355 // Creates RequestContextAdater if config is valid URLRequestContextConfig, | 378 // Creates RequestContextAdater if config is valid URLRequestContextConfig, |
| 356 // returns 0 otherwise. | 379 // returns 0 otherwise. |
| 357 static jlong CreateRequestContextAdapter(JNIEnv* env, | 380 static jlong CreateRequestContextAdapter(JNIEnv* env, |
| 358 jclass jcaller, | 381 jclass jcaller, |
| 359 jstring jconfig) { | 382 jstring jconfig) { |
| 360 std::string config_string = | 383 std::string config_string = |
| 361 base::android::ConvertJavaStringToUTF8(env, jconfig); | 384 base::android::ConvertJavaStringToUTF8(env, jconfig); |
| 362 scoped_ptr<URLRequestContextConfig> context_config( | 385 scoped_ptr<URLRequestContextConfig> context_config( |
| 363 new URLRequestContextConfig()); | 386 new URLRequestContextConfig()); |
| 364 if (!context_config->LoadFromJSON(config_string)) | 387 if (!context_config->LoadFromJSON(config_string)) |
| 365 return 0; | 388 return 0; |
| 366 | 389 |
| 367 CronetURLRequestContextAdapter* context_adapter = | 390 CronetURLRequestContextAdapter* context_adapter = |
| 368 new CronetURLRequestContextAdapter(context_config.Pass()); | 391 new CronetURLRequestContextAdapter(context_config.Pass()); |
| 369 return reinterpret_cast<jlong>(context_adapter); | 392 return reinterpret_cast<jlong>(context_adapter); |
| 370 } | 393 } |
| 371 | 394 |
| 372 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 395 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
| 373 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 396 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
| 374 // MinLogLevel is global, shared by all URLRequestContexts. | 397 // MinLogLevel is global, shared by all URLRequestContexts. |
| 375 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 398 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 376 return old_log_level; | 399 return old_log_level; |
| 377 } | 400 } |
| 378 | 401 |
| 379 } // namespace cronet | 402 } // namespace cronet |
| OLD | NEW |