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 7cab0d9e281c190994deaa35c41974a1acb13c9f..af225b47cf5397523e859fea95192c85668883b9 100644 |
| --- a/components/cronet/android/cronet_url_request_context_adapter.cc |
| +++ b/components/cronet/android/cronet_url_request_context_adapter.cc |
| @@ -12,6 +12,9 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_vector.h" |
| #include "base/prefs/pref_filter.h" |
| +#include "base/prefs/pref_registry_simple.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/prefs/pref_service_factory.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/values.h" |
| #include "components/cronet/url_request_context_config.h" |
| @@ -20,6 +23,7 @@ |
| #include "net/base/net_errors.h" |
| #include "net/base/network_delegate_impl.h" |
| #include "net/http/http_auth_handler_factory.h" |
| +#include "net/http/http_server_properties_manager.h" |
| #include "net/log/write_to_file_net_log_observer.h" |
| #include "net/proxy/proxy_service.h" |
| #include "net/sdch/sdch_owner.h" |
| @@ -33,6 +37,8 @@ |
| namespace { |
| +const char kHttpServerProperties[] = "net.http_server_properties"; |
| + |
| class BasicNetworkDelegate : public net::NetworkDelegateImpl { |
| public: |
| BasicNetworkDelegate() {} |
| @@ -188,14 +194,27 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| config->ConfigureURLRequestContextBuilder(&context_builder); |
| // Set up pref file if storage path is specified. |
| - // TODO(xunjieli): maybe get rid of the condition on sdch. |
| - if (!config->storage_path.empty() && config->enable_sdch) { |
| + if (!config->storage_path.empty()) { |
| base::FilePath filepath(config->storage_path); |
| filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); |
| json_pref_store_ = new JsonPrefStore( |
| filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); |
| - json_pref_store_->ReadPrefsAsync(nullptr); |
| context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); |
| + |
| + // Set up HttpServerPropertiesManager. |
| + base::PrefServiceFactory factory; |
| + factory.set_user_prefs(json_pref_store_); |
| + scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple; |
| + registry->RegisterDictionaryPref(kHttpServerProperties, |
| + new base::DictionaryValue()); |
| + pref_service_ = factory.Create(registry.get()).Pass(); |
|
pauljensen
2015/06/15 15:57:42
I don't know much about PrefService. Cronet could
mmenke
2015/06/15 16:36:27
Each context must have its own cache directory.
I
xunjieli
2015/06/15 18:41:36
Just for the record. Talked to Paul offline, and w
|
| + |
| + http_server_properties_manager_.reset(new net::HttpServerPropertiesManager( |
| + pref_service_.get(), kHttpServerProperties, |
| + base::MessageLoopProxy::current())); |
| + http_server_properties_manager_->InitializeOnNetworkThread(); |
| + context_builder.set_http_server_properties( |
| + http_server_properties_manager_->GetWeakPtr()); |
| } |
| context_.reset(context_builder.Build()); |
| @@ -277,11 +296,21 @@ void CronetURLRequestContextAdapter::Destroy(JNIEnv* env, jobject jcaller) { |
| // Stick network_thread_ in a local, as |this| may be destroyed from the |
| // network thread before delete network_thread is called. |
| base::Thread* network_thread = network_thread_; |
| - GetNetworkTaskRunner()->DeleteSoon(FROM_HERE, this); |
| + PostTaskToNetworkThread( |
| + FROM_HERE, |
| + base::Bind(&CronetURLRequestContextAdapter::DestroyOnNetworkThread, |
| + base::Unretained(this))); |
| // Deleting thread stops it after all tasks are completed. |
| delete network_thread; |
| } |
| +void CronetURLRequestContextAdapter::DestroyOnNetworkThread() { |
|
pauljensen
2015/06/15 15:57:42
Why is this function needed? Can this be moved to
xunjieli
2015/06/15 18:41:36
Done. Oops. Didn't realize that we can do that.
|
| + DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| + if (http_server_properties_manager_) |
| + http_server_properties_manager_->ShutdownOnPrefThread(); |
| + delete this; |
| +} |
| + |
| net::URLRequestContext* CronetURLRequestContextAdapter::GetURLRequestContext() { |
| if (!context_) { |
| LOG(ERROR) << "URLRequestContext is not set up"; |