summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authorjeremyim <jeremyim@chromium.org>2015-04-28 13:41:37 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-28 20:42:39 +0000
commitc1fe98e261ba2dea61a291b3f0b4f9afa2f2ddec (patch)
treedc51dde861c2ae4cd4d58d3aba92cda4287bdbb6 /components/data_reduction_proxy
parentb49e1f973408dbb482d374ef57a31f3fd6a1641f (diff)
downloadchromium_src-c1fe98e261ba2dea61a291b3f0b4f9afa2f2ddec.zip
chromium_src-c1fe98e261ba2dea61a291b3f0b4f9afa2f2ddec.tar.gz
chromium_src-c1fe98e261ba2dea61a291b3f0b4f9afa2f2ddec.tar.bz2
Remove usage of SingleThreadTaskRunner from DataReductionProxyConfig.
With the removal using the DataReductionProxyService class to perform the secure proxy check, there is no longer a need to post tasks to the UI thread. This effectively makes DataReductionProxyConfig an IO thread only class, and does not need to have pointers to task runners. BUG=472290 Review URL: https://codereview.chromium.org/1052583005 Cr-Commit-Position: refs/heads/master@{#327360}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc38
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h13
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc14
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc8
7 files changed, 34 insertions, 59 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 9b9ba22..fe8b897 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
@@ -10,7 +10,6 @@
#include "base/bind_helpers.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
-#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h"
@@ -54,7 +53,8 @@ namespace data_reduction_proxy {
// Checks if the secure proxy is allowed by the carrier by sending a probe.
class SecureProxyChecker : public net::URLFetcherDelegate {
public:
- SecureProxyChecker(net::URLRequestContextGetter* url_request_context_getter)
+ SecureProxyChecker(const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter)
: url_request_context_getter_(url_request_context_getter) {}
void OnURLFetchComplete(const net::URLFetcher* source) override {
@@ -101,7 +101,6 @@ class SecureProxyChecker : public net::URLFetcherDelegate {
};
DataReductionProxyConfig::DataReductionProxyConfig(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
net::NetLog* net_log,
scoped_ptr<DataReductionProxyConfigValues> config_values,
DataReductionProxyConfigurator* configurator,
@@ -112,24 +111,23 @@ DataReductionProxyConfig::DataReductionProxyConfig(
enabled_by_user_(false),
alternative_enabled_by_user_(false),
config_values_(config_values.Pass()),
- io_task_runner_(io_task_runner),
net_log_(net_log),
configurator_(configurator),
- event_creator_(event_creator),
- url_request_context_getter_(nullptr) {
- DCHECK(io_task_runner);
+ event_creator_(event_creator) {
DCHECK(configurator);
DCHECK(event_creator);
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyConfig::~DataReductionProxyConfig() {
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
-void DataReductionProxyConfig::InitializeOnIOThread(
- net::URLRequestContextGetter* url_request_context_getter) {
- DCHECK(url_request_context_getter);
- url_request_context_getter_ = url_request_context_getter;
+void DataReductionProxyConfig::InitializeOnIOThread(const scoped_refptr<
+ net::URLRequestContextGetter>& url_request_context_getter) {
+ secure_proxy_checker_.reset(
+ new SecureProxyChecker(url_request_context_getter));
if (!config_values_->allowed())
return;
@@ -139,7 +137,7 @@ void DataReductionProxyConfig::InitializeOnIOThread(
}
void DataReductionProxyConfig::ReloadConfig() {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_,
restricted_by_carrier_, false /* at_startup */);
}
@@ -147,6 +145,7 @@ void DataReductionProxyConfig::ReloadConfig() {
bool DataReductionProxyConfig::WasDataReductionProxyUsed(
const net::URLRequest* request,
DataReductionProxyTypeInfo* proxy_info) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(request);
return IsDataReductionProxy(request->proxy_server(), proxy_info);
}
@@ -154,12 +153,14 @@ bool DataReductionProxyConfig::WasDataReductionProxyUsed(
bool DataReductionProxyConfig::IsDataReductionProxy(
const net::HostPortPair& host_port_pair,
DataReductionProxyTypeInfo* proxy_info) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
return config_values_->IsDataReductionProxy(host_port_pair, proxy_info);
}
bool DataReductionProxyConfig::IsBypassedByDataReductionProxyLocalRules(
const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(request.context());
DCHECK(request.context()->proxy_service());
net::ProxyInfo result;
@@ -176,6 +177,7 @@ bool DataReductionProxyConfig::AreDataReductionProxiesBypassed(
const net::URLRequest& request,
const net::ProxyConfig& data_reduction_proxy_config,
base::TimeDelta* min_retry_delay) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (request.context() != NULL &&
request.context()->proxy_service() != NULL) {
return AreProxiesBypassed(
@@ -231,6 +233,7 @@ bool DataReductionProxyConfig::IsProxyBypassed(
const net::ProxyRetryInfoMap& retry_map,
const net::ProxyServer& proxy_server,
base::TimeDelta* retry_delay) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
net::ProxyRetryInfoMap::const_iterator found =
retry_map.find(proxy_server.ToURI());
@@ -247,6 +250,7 @@ bool DataReductionProxyConfig::IsProxyBypassed(
bool DataReductionProxyConfig::ContainsDataReductionProxy(
const net::ProxyConfig::ProxyRules& proxy_rules) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
// Data Reduction Proxy configurations are always TYPE_PROXY_PER_SCHEME.
if (proxy_rules.type != net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME)
return false;
@@ -272,6 +276,7 @@ bool DataReductionProxyConfig::ContainsDataReductionProxy(
bool DataReductionProxyConfig::UsingHTTPTunnel(
const net::HostPortPair& proxy_server) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
return config_values_->UsingHTTPTunnel(proxy_server);
}
@@ -294,6 +299,7 @@ bool DataReductionProxyConfig::promo_allowed() const {
void DataReductionProxyConfig::SetProxyConfig(
bool enabled, bool alternative_enabled, bool at_startup) {
+ DCHECK(thread_checker_.CalledOnValidThread());
enabled_by_user_ = enabled;
alternative_enabled_by_user_ = alternative_enabled;
UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_,
@@ -317,7 +323,6 @@ void DataReductionProxyConfig::UpdateConfigurator(bool enabled,
bool alternative_enabled,
bool restricted,
bool at_startup) {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
DCHECK(configurator_);
LogProxyState(enabled, restricted, at_startup);
// The alternative is only configured if the standard configuration is
@@ -375,7 +380,6 @@ void DataReductionProxyConfig::HandleSecureProxyCheckResponse(
const std::string& response,
const net::URLRequestStatus& status,
int http_response_code) {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
bool success_response = ("OK" == response.substr(0, 2));
if (event_creator_)
event_creator_->EndSecureProxyCheck(bound_net_log_, status.error(),
@@ -428,7 +432,6 @@ void DataReductionProxyConfig::HandleSecureProxyCheckResponse(
}
void DataReductionProxyConfig::OnIPAddressChanged() {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
if (enabled_by_user_) {
DCHECK(config_values_->allowed());
RecordNetworkChangeEvent(IP_CHANGED);
@@ -484,7 +487,6 @@ void DataReductionProxyConfig::RecordSecureProxyCheckFetchResult(
void DataReductionProxyConfig::SecureProxyCheck(
const GURL& secure_proxy_check_url,
FetcherResponseCallback fetcher_callback) {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
bound_net_log_ = net::BoundNetLog::Make(
net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY);
if (event_creator_) {
@@ -492,10 +494,6 @@ void DataReductionProxyConfig::SecureProxyCheck(
bound_net_log_, config_values_->secure_proxy_check_url());
}
- if (!secure_proxy_checker_) {
- secure_proxy_checker_.reset(
- new SecureProxyChecker(url_request_context_getter_));
- }
secure_proxy_checker_->CheckIfSecureProxyIsAllowed(secure_proxy_check_url,
fetcher_callback);
}
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 4499ee4..64f7589 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
@@ -23,7 +23,6 @@
class GURL;
namespace base {
-class SingleThreadTaskRunner;
class TimeDelta;
}
@@ -90,7 +89,6 @@ class DataReductionProxyConfig
// |config_values| contains the Data Reduction Proxy configuration values.
// |configurator| is the target for a configuration update.
DataReductionProxyConfig(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
net::NetLog* net_log,
scoped_ptr<DataReductionProxyConfigValues> config_values,
DataReductionProxyConfigurator* configurator,
@@ -98,8 +96,8 @@ class DataReductionProxyConfig
~DataReductionProxyConfig() override;
// Performs initialization on the IO thread.
- void InitializeOnIOThread(
- net::URLRequestContextGetter* url_request_context_getter);
+ void InitializeOnIOThread(const scoped_refptr<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
@@ -270,10 +268,6 @@ class DataReductionProxyConfig
// Contains the configuration data being used.
scoped_ptr<DataReductionProxyConfigValues> config_values_;
- // |io_task_runner_| should be the task runner for running operations on the
- // IO thread.
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
-
// The caller must ensure that the |net_log_|, if set, outlives this instance.
// It is used to create new instances of |bound_net_log_| on secure proxy
// checks. |bound_net_log_| permits the correlation of the begin and end
@@ -288,9 +282,6 @@ class DataReductionProxyConfig
// The caller must ensure that the |event_creator_| outlives this instance.
DataReductionProxyEventCreator* event_creator_;
- // Used for performing the secure proxy check.
- net::URLRequestContextGetter* url_request_context_getter_;
-
// Enforce usage on the IO thread.
base::ThreadChecker thread_checker_;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
index 43b5140..f614e93 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
@@ -18,7 +18,6 @@ namespace data_reduction_proxy {
TestDataReductionProxyConfig::TestDataReductionProxyConfig(
int params_flags,
unsigned int params_definitions,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
net::NetLog* net_log,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventCreator* event_creator)
@@ -26,7 +25,6 @@ TestDataReductionProxyConfig::TestDataReductionProxyConfig(
make_scoped_ptr(new TestDataReductionProxyParams(params_flags,
params_definitions))
.Pass(),
- task_runner,
net_log,
configurator,
event_creator) {
@@ -34,12 +32,10 @@ TestDataReductionProxyConfig::TestDataReductionProxyConfig(
TestDataReductionProxyConfig::TestDataReductionProxyConfig(
scoped_ptr<DataReductionProxyConfigValues> config_values,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
net::NetLog* net_log,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventCreator* event_creator)
- : DataReductionProxyConfig(task_runner,
- net_log,
+ : DataReductionProxyConfig(net_log,
config_values.Pass(),
configurator,
event_creator) {
@@ -89,12 +85,10 @@ void TestDataReductionProxyConfig::SetStateForTest(
MockDataReductionProxyConfig::MockDataReductionProxyConfig(
scoped_ptr<DataReductionProxyConfigValues> config_values,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
net::NetLog* net_log,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventCreator* event_creator)
: TestDataReductionProxyConfig(config_values.Pass(),
- task_runner,
net_log,
configurator,
event_creator) {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
index a07dc59..d5c4a49 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
@@ -5,16 +5,11 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_TEST_UTILS_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_TEST_UTILS_H_
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "net/base/net_util.h"
#include "testing/gmock/include/gmock/gmock.h"
-namespace base {
-class SingleThreadTaskRunner;
-}
-
namespace net {
class NetLog;
}
@@ -36,7 +31,6 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig {
TestDataReductionProxyConfig(
int params_flags,
unsigned int params_definitions,
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
net::NetLog* net_log,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventCreator* event_creator);
@@ -46,7 +40,6 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig {
// DataReductionProxyParams or DataReductionProxyMutableConfigValues).
TestDataReductionProxyConfig(
scoped_ptr<DataReductionProxyConfigValues> config_values,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
net::NetLog* net_log,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventCreator* event_creator);
@@ -89,7 +82,6 @@ class MockDataReductionProxyConfig : public TestDataReductionProxyConfig {
// Creates a |MockDataReductionProxyConfig|.
MockDataReductionProxyConfig(
scoped_ptr<DataReductionProxyConfigValues> config_values,
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
net::NetLog* net_log,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventCreator* event_creator);
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
index 504d956..7a73126 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
@@ -162,8 +162,8 @@ class DataReductionProxyConfigTest : public testing::Test {
scoped_ptr<DataReductionProxyParams> params) {
params->EnableQuic(false);
return make_scoped_ptr(new DataReductionProxyConfig(
- test_context_->task_runner(), test_context_->net_log(), params.Pass(),
- test_context_->configurator(), test_context_->event_creator()));
+ test_context_->net_log(), params.Pass(), test_context_->configurator(),
+ test_context_->event_creator()));
}
MockDataReductionProxyConfig* config() {
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 37ecf96..9245544 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
@@ -117,13 +117,12 @@ DataReductionProxyIOData::DataReductionProxyIOData(
scoped_ptr<DataReductionProxyMutableConfigValues> mutable_config =
DataReductionProxyMutableConfigValues::CreateFromParams(params.get());
raw_mutable_config = mutable_config.get();
- config_.reset(new DataReductionProxyConfig(
- io_task_runner_, net_log, mutable_config.Pass(), configurator_.get(),
- event_creator_.get()));
+ config_.reset(new DataReductionProxyConfig(net_log, mutable_config.Pass(),
+ configurator_.get(),
+ event_creator_.get()));
} else {
config_.reset(new DataReductionProxyConfig(
- io_task_runner_, net_log, params.Pass(), configurator_.get(),
- event_creator_.get()));
+ net_log, params.Pass(), configurator_.get(), event_creator_.get()));
}
// It is safe to use base::Unretained here, since it gets executed
@@ -146,7 +145,10 @@ DataReductionProxyIOData::DataReductionProxyIOData(
}
DataReductionProxyIOData::DataReductionProxyIOData()
- : url_request_context_getter_(nullptr), weak_factory_(this) {
+ : client_(Client::UNKNOWN),
+ net_log_(nullptr),
+ url_request_context_getter_(nullptr),
+ weak_factory_(this) {
}
DataReductionProxyIOData::~DataReductionProxyIOData() {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
index f71ce8d..71dec53 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
@@ -340,17 +340,15 @@ DataReductionProxyTestContext::Builder::Build() {
DataReductionProxyMutableConfigValues::CreateFromParams(params.get());
raw_mutable_config = mutable_config.get();
config.reset(new TestDataReductionProxyConfig(
- mutable_config.Pass(), task_runner, net_log.get(), configurator.get(),
+ mutable_config.Pass(), net_log.get(), configurator.get(),
event_creator.get()));
} else if (use_mock_config_) {
test_context_flags |= USE_MOCK_CONFIG;
config.reset(new MockDataReductionProxyConfig(
- params.Pass(), task_runner, net_log.get(), configurator.get(),
- event_creator.get()));
+ params.Pass(), net_log.get(), configurator.get(), event_creator.get()));
} else {
config.reset(new TestDataReductionProxyConfig(
- params.Pass(), task_runner, net_log.get(), configurator.get(),
- event_creator.get()));
+ params.Pass(), net_log.get(), configurator.get(), event_creator.get()));
}
scoped_ptr<DataReductionProxyRequestOptions> request_options;