Chromium Code Reviews| Index: components/cronet/android/cronet_url_request_context_adapter.cc |
| diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc |
| index ec52c9a4c1721a4219f836f1ef40024629276dd0..f71f10ca55c3995465b775a1d742ea1c0e51588c 100644 |
| --- a/components/cronet/android/cronet_url_request_context_adapter.cc |
| +++ b/components/cronet/android/cronet_url_request_context_adapter.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_file.h" |
| #include "base/logging.h" |
| +#include "base/prefs/pref_filter.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/values.h" |
| #include "components/cronet/url_request_context_config.h" |
| @@ -103,6 +104,12 @@ class BasicNetworkDelegate : public net::NetworkDelegateImpl { |
| DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| }; |
| +void CreatePrefFileIfNeeded(base::FilePath filepath) { |
| + if (base::PathExists(filepath)) |
| + return; |
| + base::WriteFile(filepath, "{}", 2); |
|
mmenke
2015/05/11 17:16:19
Is this really needed? I don't see any documentat
xunjieli
2015/05/12 19:17:50
Done. Thanks! I saw an error from json pref store
|
| +} |
| + |
| } // namespace |
| namespace cronet { |
| @@ -155,6 +162,23 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| context_builder.set_proxy_config_service(proxy_config_service_.release()); |
| config->ConfigureURLRequestContextBuilder(&context_builder); |
| + // Only set up pref file if http disk cache is enabled. |
|
mef
2015/05/12 16:39:17
I think we should set pref file if storage_path is
xunjieli
2015/05/12 19:17:49
Done.
|
| + if (!config->storage_path.empty() && !config->load_disable_cache) { |
| + base::FilePath filepath(config->storage_path); |
| + filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); |
| + if (!file_thread_) { |
| + file_thread_.reset(new base::Thread("Network File Thread")); |
| + file_thread_->StartWithOptions( |
| + base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); |
| + } |
| + file_thread_->task_runner()->PostTask( |
| + FROM_HERE, base::Bind(&CreatePrefFileIfNeeded, filepath)); |
| + network_json_store_ = new JsonPrefStore( |
| + filepath, file_thread_->task_runner(), scoped_ptr<PrefFilter>()); |
| + network_json_store_->ReadPrefsAsync(nullptr); |
|
mef
2015/05/12 16:39:17
It seems that prefstore should just fallback to em
xunjieli
2015/05/12 19:17:50
Done. Yes, you and Matt are both right about this
|
| + context_builder.SetFileTaskRunner(file_thread_->task_runner()); |
| + } |
| + |
| context_.reset(context_builder.Build()); |
| default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| @@ -166,6 +190,8 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| DCHECK(context_->sdch_manager()); |
| sdch_owner_.reset( |
| new net::SdchOwner(context_->sdch_manager(), context_.get())); |
| + if (network_json_store_) |
| + sdch_owner_->EnablePersistentStorage(network_json_store_.get()); |
| } |
| // Currently (circa M39) enabling QUIC requires setting probability threshold. |