diff options
author | jeremyim <jeremyim@chromium.org> | 2015-04-14 11:14:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-14 18:24:24 +0000 |
commit | bf05debe46eded45124f3af3363a84ba9b67fdca (patch) | |
tree | 7747d7a93a562263907c3a7f54e7ba09a924baf2 /components/data_reduction_proxy | |
parent | 8ba74a178e16f8356b4d28ae2e2848a7ec6a1403 (diff) | |
download | chromium_src-bf05debe46eded45124f3af3363a84ba9b67fdca.zip chromium_src-bf05debe46eded45124f3af3363a84ba9b67fdca.tar.gz chromium_src-bf05debe46eded45124f3af3363a84ba9b67fdca.tar.bz2 |
Refactor DataReductionProxyConfig initialization for injecting a URLRequestContextGetter
- The URLRequestContextGetter is read in DRPIOData::SetDataReductionProxyService on the UI thread
- The URLRequestContextGetter is passed to DRPConfig in DRPIOData::InitializeOnIOThread on the IO thread
- InitializeOnIOThread isn't executed until SetDataReductionProxyService completes, so the read is safe
BUG=472290
Review URL: https://codereview.chromium.org/1080083006
Cr-Commit-Position: refs/heads/master@{#325085}
Diffstat (limited to 'components/data_reduction_proxy')
5 files changed, 38 insertions, 23 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc index 75ee7c3..9ee5108 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc @@ -63,12 +63,12 @@ DataReductionProxyConfig::DataReductionProxyConfig( ui_task_runner_(ui_task_runner), net_log_(net_log), configurator_(configurator), - event_store_(event_store) { + event_store_(event_store), + url_request_context_getter_(nullptr) { DCHECK(io_task_runner); DCHECK(ui_task_runner); DCHECK(configurator); DCHECK(event_store); - InitOnIOThread(); } DataReductionProxyConfig::~DataReductionProxyConfig() { @@ -80,6 +80,17 @@ void DataReductionProxyConfig::SetDataReductionProxyService( data_reduction_proxy_service_ = data_reduction_proxy_service; } +void DataReductionProxyConfig::InitializeOnIOThread( + net::URLRequestContextGetter* url_request_context_getter) { + DCHECK(url_request_context_getter); + url_request_context_getter_ = url_request_context_getter; + if (!config_values_->allowed()) + return; + + AddDefaultProxyBypassRules(); + net::NetworkChangeNotifier::AddIPAddressObserver(this); +} + void DataReductionProxyConfig::ReloadConfig() { DCHECK(io_task_runner_->BelongsToCurrentThread()); UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_, @@ -389,21 +400,6 @@ void DataReductionProxyConfig::OnIPAddressChanged() { } } -void DataReductionProxyConfig::InitOnIOThread() { - if (!io_task_runner_->BelongsToCurrentThread()) { - io_task_runner_->PostTask( - FROM_HERE, base::Bind(&DataReductionProxyConfig::InitOnIOThread, - base::Unretained(this))); - return; - } - - if (!config_values_->allowed()) - return; - - AddDefaultProxyBypassRules(); - net::NetworkChangeNotifier::AddIPAddressObserver(this); -} - void DataReductionProxyConfig::AddDefaultProxyBypassRules() { // localhost DCHECK(configurator_); diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h index 7692f6b..770c032 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h @@ -26,6 +26,7 @@ namespace net { class HostPortPair; class NetLog; class URLRequest; +class URLRequestContextGetter; class URLRequestStatus; } @@ -84,6 +85,10 @@ class DataReductionProxyConfig void SetDataReductionProxyService( base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service); + // Performs initialization on the IO thread. + void InitializeOnIOThread( + net::URLRequestContextGetter* url_request_context_getter); + // Sets the proxy configs, enabling or disabling the proxy according to // the value of |enabled| and |alternative_enabled|. Use the alternative // configuration only if |enabled| and |alternative_enabled| are true. If @@ -204,9 +209,6 @@ class DataReductionProxyConfig // NetworkChangeNotifier::IPAddressObserver: void OnIPAddressChanged() override; - // Performs initialization on the IO thread. - void InitOnIOThread(); - // Updates the Data Reduction Proxy configurator with the current config. virtual void UpdateConfigurator(bool enabled, bool alternative_enabled, @@ -275,6 +277,10 @@ class DataReductionProxyConfig // The caller must ensure that the |event_store_| outlives this instance. DataReductionProxyEventStore* event_store_; + // Used for performing the secure proxy check. + net::URLRequestContextGetter* url_request_context_getter_; + + // Enforce usage on the IO thread. base::ThreadChecker thread_checker_; // A weak pointer to a |DataReductionProxyService| to perform secure proxy diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc index d025624..52340f7 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc @@ -40,6 +40,7 @@ DataReductionProxyIOData::DataReductionProxyIOData( io_task_runner_(io_task_runner), ui_task_runner_(ui_task_runner), shutdown_on_ui_(false), + url_request_context_getter_(nullptr), weak_factory_(this) { DCHECK(net_log); DCHECK(io_task_runner_); @@ -84,9 +85,10 @@ DataReductionProxyIOData::DataReductionProxyIOData( new DataReductionProxyDelegate(request_options_.get(), config_.get())); } -DataReductionProxyIOData::DataReductionProxyIOData() - : shutdown_on_ui_(false), - weak_factory_(this) { + DataReductionProxyIOData::DataReductionProxyIOData() + : shutdown_on_ui_(false), + url_request_context_getter_(nullptr), + weak_factory_(this) { } DataReductionProxyIOData::~DataReductionProxyIOData() { @@ -108,7 +110,9 @@ void DataReductionProxyIOData::ShutdownOnUIThread() { void DataReductionProxyIOData::SetDataReductionProxyService( base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service) { + DCHECK(ui_task_runner_->BelongsToCurrentThread()); service_ = data_reduction_proxy_service; + url_request_context_getter_ = service_->url_request_context_getter(); config()->SetDataReductionProxyService(data_reduction_proxy_service); // Using base::Unretained is safe here, unless the browser is being shut down // before the Initialize task can be executed. The task is only created as @@ -121,6 +125,7 @@ void DataReductionProxyIOData::SetDataReductionProxyService( void DataReductionProxyIOData::InitializeOnIOThread() { DCHECK(io_task_runner_->BelongsToCurrentThread()); + config_->InitializeOnIOThread(url_request_context_getter_); if (config_client_.get()) config_client_->RetrieveConfig(); ui_task_runner_->PostTask( diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h index f95790e..7e45c16 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h @@ -16,6 +16,7 @@ namespace net { class NetLog; +class URLRequestContextGetter; class URLRequestInterceptor; } @@ -188,6 +189,9 @@ class DataReductionProxyIOData { // by the user. In practice, this can be overridden by the command line. BooleanPrefMember enabled_; + // The net::URLRequestContextGetter used for making URL requests. + net::URLRequestContextGetter* url_request_context_getter_; + base::WeakPtrFactory<DataReductionProxyIOData> weak_factory_; DISALLOW_COPY_AND_ASSIGN(DataReductionProxyIOData); diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h index 40ed379..0f9aed7 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h @@ -108,6 +108,10 @@ class DataReductionProxyService : public base::NonThreadSafe, return settings_; } + net::URLRequestContextGetter* url_request_context_getter() const { + return url_request_context_getter_; + } + base::WeakPtr<DataReductionProxyService> GetWeakPtr(); protected: |