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 if (!config->storage_path.empty()) { | |
| 192 base::FilePath filepath(config->storage_path); | |
| 193 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); | |
| 194 if (!file_thread_) { | |
| 195 file_thread_.reset(new base::Thread("Network File Thread")); | |
| 196 file_thread_->Start(); | |
| 197 } | |
| 198 json_pref_store_ = new JsonPrefStore(filepath, file_thread_->task_runner(), | |
| 199 scoped_ptr<PrefFilter>()); | |
| 200 json_pref_store_->ReadPrefsAsync(nullptr); | |
| 201 context_builder.SetFileTaskRunner(file_thread_->task_runner()); | |
| 202 } | |
| 203 | |
| 188 context_.reset(context_builder.Build()); | 204 context_.reset(context_builder.Build()); |
| 189 | 205 |
| 190 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 206 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| 191 net::LOAD_DO_NOT_SEND_COOKIES; | 207 net::LOAD_DO_NOT_SEND_COOKIES; |
| 192 if (config->load_disable_cache) | 208 if (config->load_disable_cache) |
| 193 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 209 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| 194 | 210 |
| 195 if (config->enable_sdch) { | 211 if (config->enable_sdch) { |
| 196 DCHECK(context_->sdch_manager()); | 212 DCHECK(context_->sdch_manager()); |
| 197 sdch_owner_.reset( | 213 sdch_owner_.reset( |
| 198 new net::SdchOwner(context_->sdch_manager(), context_.get())); | 214 new net::SdchOwner(context_->sdch_manager(), context_.get())); |
| 215 if (json_pref_store_) | |
| 216 sdch_owner_->EnablePersistentStorage(json_pref_store_.get()); | |
| 199 } | 217 } |
| 200 | 218 |
| 201 // Currently (circa M39) enabling QUIC requires setting probability threshold. | 219 // Currently (circa M39) enabling QUIC requires setting probability threshold. |
| 202 if (config->enable_quic) { | 220 if (config->enable_quic) { |
| 203 context_->http_server_properties() | 221 context_->http_server_properties() |
| 204 ->SetAlternativeServiceProbabilityThreshold(0.0f); | 222 ->SetAlternativeServiceProbabilityThreshold(0.0f); |
| 205 for (auto hint = config->quic_hints.begin(); | 223 for (auto hint = config->quic_hints.begin(); |
| 206 hint != config->quic_hints.end(); ++hint) { | 224 hint != config->quic_hints.end(); ++hint) { |
| 207 const URLRequestContextConfig::QuicHint& quic_hint = **hint; | 225 const URLRequestContextConfig::QuicHint& quic_hint = **hint; |
| 208 if (quic_hint.host.empty()) { | 226 if (quic_hint.host.empty()) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 data_reduction_proxy_->Init(true, GetURLRequestContext()); | 269 data_reduction_proxy_->Init(true, GetURLRequestContext()); |
| 252 #endif | 270 #endif |
| 253 is_context_initialized_ = true; | 271 is_context_initialized_ = true; |
| 254 while (!tasks_waiting_for_context_.empty()) { | 272 while (!tasks_waiting_for_context_.empty()) { |
| 255 tasks_waiting_for_context_.front().Run(); | 273 tasks_waiting_for_context_.front().Run(); |
| 256 tasks_waiting_for_context_.pop(); | 274 tasks_waiting_for_context_.pop(); |
| 257 } | 275 } |
| 258 } | 276 } |
| 259 | 277 |
| 260 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { | 278 void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { |
| 261 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); | 279 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); |
|
mef
2015/05/15 14:30:39
Is there some way to flush json_pref_store_ here?
xunjieli
2015/05/15 16:28:03
Since Destroy is called on a Java thread, and Json
mef
2015/05/19 21:39:43
I think you are right, thanks for explanation!
| |
| 262 // Stick network_thread_ in a local, as |this| may be destroyed from the | 280 // Stick network_thread_ in a local, as |this| may be destroyed from the |
| 263 // network thread before delete network_thread is called. | 281 // network thread before delete network_thread is called. |
| 264 base::Thread* network_thread = network_thread_; | 282 base::Thread* network_thread = network_thread_; |
| 265 GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this); | 283 GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this); |
| 266 // Deleting thread stops it after all tasks are completed. | 284 // Deleting thread stops it after all tasks are completed. |
| 267 delete network_thread; | 285 delete network_thread; |
| 268 } | 286 } |
| 269 | 287 |
| 270 net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() { | 288 net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() { |
| 271 if (!context_) { | 289 if (!context_) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 } | 388 } |
| 371 | 389 |
| 372 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 390 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
| 373 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 391 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
| 374 // MinLogLevel is global, shared by all URLRequestContexts. | 392 // MinLogLevel is global, shared by all URLRequestContexts. |
| 375 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 393 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 376 return old_log_level; | 394 return old_log_level; |
| 377 } | 395 } |
| 378 | 396 |
| 379 } // namespace cronet | 397 } // namespace cronet |
| OLD | NEW |