summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authorjeremyim <jeremyim@chromium.org>2015-04-13 17:39:46 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-14 00:40:10 +0000
commit1e38d46eb6b018a05aacaa7ced991d83e1dfc210 (patch)
treeeeb32baaf803cf131939a766cc9c7479b4f819d3 /components/data_reduction_proxy
parente2d2da005017c164c9a1e4b5fe9f1c54455bb86d (diff)
downloadchromium_src-1e38d46eb6b018a05aacaa7ced991d83e1dfc210.zip
chromium_src-1e38d46eb6b018a05aacaa7ced991d83e1dfc210.tar.gz
chromium_src-1e38d46eb6b018a05aacaa7ced991d83e1dfc210.tar.bz2
Remove some usages of SingleThreadTaskRunner in DataReductionProxy
- DataReductionProxyIOData::InitializeOnIOThread should be the single place for IO objects to initialize, instead of having each class post to the IO thread. - IO objects should only be used on the IO thread (outside of construction) and shouldn't need to check that they are only being used on the IO thread. BUG=472290 Review URL: https://codereview.chromium.org/1082883002 Cr-Commit-Position: refs/heads/master@{#324962}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc15
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h13
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc17
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc36
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h27
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.cc3
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h3
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc2
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc15
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc19
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h15
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc23
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc25
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h23
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc6
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc1
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h1
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc37
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h19
20 files changed, 117 insertions, 191 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
index 59081c3..f8e3d9e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
@@ -12,7 +12,6 @@
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/logging.h"
-#include "base/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
@@ -86,22 +85,17 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
const net::BackoffEntry::Policy& backoff_policy,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+ DataReductionProxyConfig* config)
: params_(params.Pass()),
request_options_(request_options),
config_values_(config_values),
config_(config),
- io_task_runner_(io_task_runner),
backoff_entry_(&backoff_policy) {
DCHECK(request_options);
DCHECK(config_values);
DCHECK(config);
- DCHECK(io_task_runner.get());
- io_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&DataReductionProxyConfigServiceClient::RetrieveConfig,
- base::Unretained(this)));
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyConfigServiceClient::
@@ -109,8 +103,7 @@ DataReductionProxyConfigServiceClient::
}
void DataReductionProxyConfigServiceClient::RetrieveConfig() {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
-
+ DCHECK(thread_checker_.CalledOnValidThread());
std::string static_response = ConstructStaticResponse();
ClientConfig config;
bool succeeded = false;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h
index 3f6ae23..e51ea83 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h
@@ -9,13 +9,12 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "net/base/backoff_entry.h"
namespace base {
-class SingleThreadTaskRunner;
class Time;
class TimeDelta;
}
@@ -43,8 +42,7 @@ class DataReductionProxyConfigServiceClient {
const net::BackoffEntry::Policy& backoff_policy,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
+ DataReductionProxyConfig* config);
virtual ~DataReductionProxyConfigServiceClient();
@@ -86,10 +84,6 @@ class DataReductionProxyConfigServiceClient {
// The caller must ensure that the |config_| outlives this instance.
DataReductionProxyConfig* config_;
- // |io_task_runner_| should be the task runner for running operations on the
- // IO thread.
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
-
// Used to calculate the backoff time on request failures.
net::BackoffEntry backoff_entry_;
@@ -98,6 +92,9 @@ class DataReductionProxyConfigServiceClient {
base::OneShotTimer<DataReductionProxyConfigServiceClient>
config_refresh_timer_;
+ // Enforce usage on the IO thread.
+ base::ThreadChecker thread_checker_;
+
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigServiceClient);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
index f8e7c0f..b72ee57 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client_unittest.cc
@@ -75,16 +75,13 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
DataReductionProxyParams::kAllowed |
DataReductionProxyParams::kFallbackAllowed |
DataReductionProxyParams::kPromoAllowed));
- request_options_.reset(
- new DataReductionProxyRequestOptions(Client::UNKNOWN,
- test_context_->io_data()->config(),
- test_context_->task_runner()));
+ request_options_.reset(new DataReductionProxyRequestOptions(
+ Client::UNKNOWN, test_context_->io_data()->config()));
return scoped_ptr<DataReductionProxyConfigServiceClient>(
new DataReductionProxyConfigServiceClient(
- params.Pass(), GetBackoffPolicy(),
- request_options_.get(),
+ params.Pass(), GetBackoffPolicy(), request_options_.get(),
test_context_->mutable_config_values(),
- test_context_->io_data()->config(), test_context_->task_runner()));
+ test_context_->io_data()->config()));
}
DataReductionProxyParams* params() {
@@ -133,7 +130,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, SuccessfulLoop) {
.WillRepeatedly(
testing::Invoke(&populator,
&RequestOptionsPopulator::PopulateResponse));
- RunUntilIdle();
+ config_client()->RetrieveConfig();
EXPECT_EQ(base::TimeDelta::FromDays(1), config_client()->GetDelay());
EXPECT_EQ(params()->origin().ToURI(), configurator()->origin());
EXPECT_EQ(params()->fallback_origin().ToURI(),
@@ -162,7 +159,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, SuccessfulLoopShortDuration) {
.Times(1)
.WillOnce(testing::Invoke(&populator,
&RequestOptionsPopulator::PopulateResponse));
- RunUntilIdle();
+ config_client()->RetrieveConfig();
EXPECT_EQ(base::TimeDelta::FromSeconds(10), config_client()->GetDelay());
EXPECT_EQ(params()->origin().ToURI(), configurator()->origin());
EXPECT_EQ(params()->fallback_origin().ToURI(),
@@ -202,7 +199,7 @@ TEST_F(DataReductionProxyConfigServiceClientTest, ConfigDisabled) {
.Times(1)
.WillOnce(testing::Invoke(&populator,
&RequestOptionsPopulator::PopulateResponse));
- RunUntilIdle();
+ config_client()->RetrieveConfig();
EXPECT_TRUE(configurator()->origin().empty());
EXPECT_TRUE(configurator()->fallback_origin().empty());
EXPECT_TRUE(configurator()->ssl_origin().empty());
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc
index 4009c21..2a804f1 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.cc
@@ -4,7 +4,6 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
-#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
@@ -13,15 +12,13 @@
namespace data_reduction_proxy {
DataReductionProxyConfigurator::DataReductionProxyConfigurator(
- scoped_refptr<base::SequencedTaskRunner> network_task_runner,
net::NetLog* net_log,
DataReductionProxyEventStore* event_store)
- : network_task_runner_(network_task_runner),
- net_log_(net_log),
- data_reduction_proxy_event_store_(event_store) {
- DCHECK(network_task_runner.get());
+ : net_log_(net_log), data_reduction_proxy_event_store_(event_store) {
DCHECK(net_log);
DCHECK(event_store);
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyConfigurator::~DataReductionProxyConfigurator() {
@@ -33,6 +30,7 @@ void DataReductionProxyConfigurator::Enable(
const std::string& primary_origin,
const std::string& fallback_origin,
const std::string& ssl_origin) {
+ DCHECK(thread_checker_.CalledOnValidThread());
std::vector<std::string> proxies;
if (!primary_restricted) {
std::string trimmed_primary;
@@ -68,32 +66,25 @@ void DataReductionProxyConfigurator::Enable(
data_reduction_proxy_event_store_->AddProxyEnabledEvent(
net_log_, primary_restricted, fallback_restricted, primary_origin,
fallback_origin, ssl_origin);
- network_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(
- &DataReductionProxyConfigurator::UpdateProxyConfigOnIOThread,
- base::Unretained(this),
- config));
+ config_ = config;
}
void DataReductionProxyConfigurator::Disable() {
+ DCHECK(thread_checker_.CalledOnValidThread());
net::ProxyConfig config = net::ProxyConfig::CreateDirect();
data_reduction_proxy_event_store_->AddProxyDisabledEvent(net_log_);
- network_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(
- &DataReductionProxyConfigurator::UpdateProxyConfigOnIOThread,
- base::Unretained(this),
- config));
+ config_ = config;
}
void DataReductionProxyConfigurator::AddHostPatternToBypass(
const std::string& pattern) {
+ DCHECK(thread_checker_.CalledOnValidThread());
bypass_rules_.push_back(pattern);
}
void DataReductionProxyConfigurator::AddURLPatternToBypass(
const std::string& pattern) {
+ DCHECK(thread_checker_.CalledOnValidThread());
size_t pos = pattern.find('/');
if (pattern.find('/', pos + 1) == pos + 1)
pos = pattern.find('/', pos + 2);
@@ -107,13 +98,8 @@ void DataReductionProxyConfigurator::AddURLPatternToBypass(
AddHostPatternToBypass(host_pattern);
}
-void DataReductionProxyConfigurator::UpdateProxyConfigOnIOThread(
- const net::ProxyConfig& config) {
- config_ = config;
-}
-
-const net::ProxyConfig&
-DataReductionProxyConfigurator::GetProxyConfigOnIOThread() const {
+const net::ProxyConfig& DataReductionProxyConfigurator::GetProxyConfig() const {
+ DCHECK(thread_checker_.CalledOnValidThread());
return config_;
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h
index 82b1d09..e239b54 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h
@@ -9,13 +9,9 @@
#include <vector>
#include "base/gtest_prod_util.h"
-#include "base/task_runner.h"
+#include "base/threading/thread_checker.h"
#include "net/proxy/proxy_config.h"
-namespace base {
-class SequencedTaskRunner;
-}
-
namespace net {
class NetLog;
class ProxyInfo;
@@ -30,23 +26,15 @@ class DataReductionProxyEventStore;
class DataReductionProxyConfigurator {
public:
- // Constructs a configurator. |network_task_runner| should be the task runner
- // for running network operations, |net_log| and |event_store| are used to
+ // Constructs a configurator. |net_log| and |event_store| are used to
// track network and Data Reduction Proxy events respectively, must not be
// null, and must outlive this instance.
DataReductionProxyConfigurator(
- scoped_refptr<base::SequencedTaskRunner> network_task_runner,
net::NetLog* net_log,
DataReductionProxyEventStore* event_store);
virtual ~DataReductionProxyConfigurator();
- void set_net_log(net::NetLog* net_log) {
- DCHECK(!net_log_);
- net_log_ = net_log;
- DCHECK(net_log_);
- }
-
// Constructs a proxy configuration suitable for enabling the Data Reduction
// proxy.
virtual void Enable(bool primary_restricted,
@@ -71,19 +59,13 @@ class DataReductionProxyConfigurator {
// as a hostname pattern.
virtual void AddURLPatternToBypass(const std::string& pattern);
- // Updates the config for use on the IO thread.
- void UpdateProxyConfigOnIOThread(const net::ProxyConfig& config);
-
// Returns the current data reduction proxy config, even if it is not the
// effective configuration used by the proxy service.
- const net::ProxyConfig& GetProxyConfigOnIOThread() const;
+ const net::ProxyConfig& GetProxyConfig() const;
private:
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfiguratorTest, TestBypassList);
- // Used for updating the proxy config on the IO thread.
- scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
-
// Rules for bypassing the Data Reduction Proxy.
std::vector<std::string> bypass_rules_;
@@ -96,6 +78,9 @@ class DataReductionProxyConfigurator {
net::NetLog* net_log_;
DataReductionProxyEventStore* data_reduction_proxy_event_store_;
+ // Enforce usage on the IO thread.
+ base::ThreadChecker thread_checker_;
+
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfigurator);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.cc
index a86845f..e373aad 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.cc
@@ -7,10 +7,9 @@
namespace data_reduction_proxy {
TestDataReductionProxyConfigurator::TestDataReductionProxyConfigurator(
- scoped_refptr<base::SequencedTaskRunner> network_task_runner,
net::NetLog* net_log,
DataReductionProxyEventStore* event_store)
- : DataReductionProxyConfigurator(network_task_runner, net_log, event_store),
+ : DataReductionProxyConfigurator(net_log, event_store),
enabled_(false),
restricted_(false),
fallback_restricted_(false) {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h
index 5b0a82c..bcfccd5 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h
@@ -7,8 +7,6 @@
#include <string>
-#include "base/memory/ref_counted.h"
-#include "base/sequenced_task_runner.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
namespace net {
@@ -23,7 +21,6 @@ class TestDataReductionProxyConfigurator
: public DataReductionProxyConfigurator {
public:
TestDataReductionProxyConfigurator(
- scoped_refptr<base::SequencedTaskRunner> network_task_runner,
net::NetLog* net_log,
DataReductionProxyEventStore* event_store);
~TestDataReductionProxyConfigurator() override;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
index b821a25..bb8fb3d 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_unittest.cc
@@ -23,10 +23,8 @@ class DataReductionProxyConfiguratorTest : public testing::Test {
net_log_.reset(new net::CapturingNetLog());
data_reduction_proxy_event_store_.reset(
new data_reduction_proxy::DataReductionProxyEventStore(task_runner_));
- config_.reset(
- new DataReductionProxyConfigurator(
- task_runner_, net_log_.get(),
- data_reduction_proxy_event_store_.get()));
+ config_.reset(new DataReductionProxyConfigurator(
+ net_log_.get(), data_reduction_proxy_event_store_.get()));
}
void CheckProxyConfig(
@@ -36,7 +34,7 @@ class DataReductionProxyConfiguratorTest : public testing::Test {
const std::string& expected_bypass_list) {
task_runner_->RunUntilIdle();
const net::ProxyConfig::ProxyRules& rules =
- config_->GetProxyConfigOnIOThread().proxy_rules();
+ config_->GetProxyConfig().proxy_rules();
ASSERT_EQ(expected_rules_type, rules.type);
if (net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME ==
expected_rules_type) {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
index c257d67..8475211 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
@@ -302,7 +302,7 @@ class DataReductionProxyInterceptorEndToEndTest : public testing::Test {
// Three proxies should be available for use: primary, fallback, and direct.
const net::ProxyConfig& proxy_config =
- drp_test_context_->configurator()->GetProxyConfigOnIOThread();
+ drp_test_context_->configurator()->GetProxyConfig();
EXPECT_EQ(3U, proxy_config.proxy_rules().proxies_for_http.size());
}
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 8fd3ef5..d025624 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
@@ -48,14 +48,13 @@ DataReductionProxyIOData::DataReductionProxyIOData(
new DataReductionProxyParams(param_flags));
params->EnableQuic(enable_quic);
event_store_.reset(new DataReductionProxyEventStore(ui_task_runner));
- configurator_.reset(new DataReductionProxyConfigurator(
- io_task_runner, net_log, event_store_.get()));
+ configurator_.reset(
+ new DataReductionProxyConfigurator(net_log, event_store_.get()));
bool use_config_client = DataReductionProxyParams::IsConfigClientEnabled();
DataReductionProxyMutableConfigValues* raw_mutable_config = nullptr;
if (use_config_client) {
scoped_ptr<DataReductionProxyMutableConfigValues> mutable_config =
- DataReductionProxyMutableConfigValues::CreateFromParams(io_task_runner_,
- params.get());
+ DataReductionProxyMutableConfigValues::CreateFromParams(params.get());
raw_mutable_config = mutable_config.get();
config_.reset(new DataReductionProxyConfig(
io_task_runner_, ui_task_runner_, net_log, mutable_config.Pass(),
@@ -72,13 +71,13 @@ DataReductionProxyIOData::DataReductionProxyIOData(
bypass_stats_.reset(new DataReductionProxyBypassStats(
config_.get(), base::Bind(&DataReductionProxyIOData::SetUnreachable,
base::Unretained(this))));
- request_options_.reset(new DataReductionProxyRequestOptions(
- client_, config_.get(), io_task_runner_));
+ request_options_.reset(
+ new DataReductionProxyRequestOptions(client_, config_.get()));
request_options_->Init();
if (use_config_client) {
config_client_.reset(new DataReductionProxyConfigServiceClient(
params.Pass(), GetBackoffPolicy(), request_options_.get(),
- raw_mutable_config, config_.get(), io_task_runner_));
+ raw_mutable_config, config_.get()));
}
proxy_delegate_.reset(
@@ -122,6 +121,8 @@ void DataReductionProxyIOData::SetDataReductionProxyService(
void DataReductionProxyIOData::InitializeOnIOThread() {
DCHECK(io_task_runner_->BelongsToCurrentThread());
+ if (config_client_.get())
+ config_client_->RetrieveConfig();
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyService::SetIOData,
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc
index cebbdaca..19f935e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.cc
@@ -4,17 +4,15 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h"
-#include "base/single_thread_task_runner.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
namespace data_reduction_proxy {
scoped_ptr<DataReductionProxyMutableConfigValues>
DataReductionProxyMutableConfigValues::CreateFromParams(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
const DataReductionProxyParams* params) {
scoped_ptr<DataReductionProxyMutableConfigValues> config_values(
- new DataReductionProxyMutableConfigValues(io_task_runner));
+ new DataReductionProxyMutableConfigValues());
config_values->promo_allowed_ = params->promo_allowed();
config_values->holdback_ = params->holdback();
config_values->allowed_ = params->allowed();
@@ -23,17 +21,16 @@ DataReductionProxyMutableConfigValues::CreateFromParams(
return config_values.Pass();
}
-DataReductionProxyMutableConfigValues::DataReductionProxyMutableConfigValues(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+DataReductionProxyMutableConfigValues::DataReductionProxyMutableConfigValues()
: empty_origin_(),
promo_allowed_(false),
holdback_(false),
allowed_(false),
fallback_allowed_(false),
origin_(empty_origin_),
- fallback_origin_(empty_origin_),
- io_task_runner_(io_task_runner) {
- DCHECK(io_task_runner.get());
+ fallback_origin_(empty_origin_) {
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyMutableConfigValues::
@@ -99,13 +96,13 @@ bool DataReductionProxyMutableConfigValues::IsDataReductionProxy(
}
const net::ProxyServer& DataReductionProxyMutableConfigValues::origin() const {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
return origin_;
}
const net::ProxyServer& DataReductionProxyMutableConfigValues::fallback_origin()
const {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
return fallback_origin_;
}
@@ -132,7 +129,7 @@ const GURL& DataReductionProxyMutableConfigValues::secure_proxy_check_url()
void DataReductionProxyMutableConfigValues::UpdateValues(
const net::ProxyServer& origin,
const net::ProxyServer& fallback_origin) {
- DCHECK(io_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
origin_ = origin;
fallback_origin_ = fallback_origin;
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h
index 6897cb9..264ef17 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h
@@ -6,16 +6,12 @@
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_MUTABLE_CONFIG_VALUES_H_
#include "base/macros.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread_checker.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h"
#include "net/proxy/proxy_server.h"
#include "url/gurl.h"
-namespace base {
-class SingleThreadTaskRunner;
-}
-
namespace data_reduction_proxy {
class DataReductionProxyParams;
@@ -28,7 +24,6 @@ class DataReductionProxyMutableConfigValues
// Creates a new |DataReductionProxyMutableConfigValues| using |params| as
// the basis for its initial values.
static scoped_ptr<DataReductionProxyMutableConfigValues> CreateFromParams(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
const DataReductionProxyParams* params);
~DataReductionProxyMutableConfigValues() override;
@@ -57,8 +52,7 @@ class DataReductionProxyMutableConfigValues
const GURL& secure_proxy_check_url() const override;
protected:
- DataReductionProxyMutableConfigValues(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
+ DataReductionProxyMutableConfigValues();
private:
net::ProxyServer empty_origin_;
@@ -70,9 +64,8 @@ class DataReductionProxyMutableConfigValues
net::ProxyServer fallback_origin_;
GURL secure_proxy_check_url_;
- // |io_task_runner_| should be the task runner for running operations on the
- // IO thread.
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+ // Enforce usage on the IO thread.
+ base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMutableConfigValues);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
index c9b9cb1..6ef70dc 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
@@ -81,10 +81,11 @@ DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
: LayeredNetworkDelegate(network_delegate.Pass()),
received_content_length_(0),
original_content_length_(0),
- data_reduction_proxy_enabled_(NULL),
+ data_reduction_proxy_enabled_(nullptr),
data_reduction_proxy_config_(config),
- data_reduction_proxy_bypass_stats_(NULL),
+ data_reduction_proxy_bypass_stats_(nullptr),
data_reduction_proxy_request_options_(request_options),
+ data_reduction_proxy_io_data_(nullptr),
configurator_(configurator) {
DCHECK(data_reduction_proxy_config_);
DCHECK(data_reduction_proxy_request_options_);
@@ -121,9 +122,9 @@ void DataReductionProxyNetworkDelegate::OnResolveProxyInternal(
const net::ProxyService& proxy_service,
net::ProxyInfo* result) {
if (configurator_) {
- OnResolveProxyHandler(
- url, load_flags, configurator_->GetProxyConfigOnIOThread(),
- proxy_service.proxy_retry_info(), data_reduction_proxy_config_, result);
+ OnResolveProxyHandler(url, load_flags, configurator_->GetProxyConfig(),
+ proxy_service.proxy_retry_info(),
+ data_reduction_proxy_config_, result);
}
}
@@ -175,10 +176,9 @@ void DataReductionProxyNetworkDelegate::OnCompletedInternal(
request->response_info().headers->GetFreshnessLifetimes(
request->response_info().response_time).freshness;
DataReductionProxyRequestType request_type =
- GetDataReductionProxyRequestType(
- *request,
- configurator_->GetProxyConfigOnIOThread(),
- *data_reduction_proxy_config_);
+ GetDataReductionProxyRequestType(*request,
+ configurator_->GetProxyConfig(),
+ *data_reduction_proxy_config_);
int64 adjusted_original_content_length =
GetAdjustedOriginalContentLength(request_type,
@@ -194,9 +194,8 @@ void DataReductionProxyNetworkDelegate::OnCompletedInternal(
if (data_reduction_proxy_enabled_ &&
data_reduction_proxy_bypass_stats_) {
data_reduction_proxy_bypass_stats_->RecordBytesHistograms(
- *request,
- *data_reduction_proxy_enabled_,
- configurator_->GetProxyConfigOnIOThread());
+ *request, *data_reduction_proxy_enabled_,
+ configurator_->GetProxyConfig());
}
DVLOG(2) << __FUNCTION__
<< " received content length: " << received_content_length
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
index 1b95890..8bd3d23 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
@@ -96,25 +96,25 @@ bool DataReductionProxyRequestOptions::ParseLocalSessionKey(
DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
+ DataReductionProxyConfig* config)
: client_(GetString(client)),
use_assigned_credentials_(false),
- data_reduction_proxy_config_(config),
- network_task_runner_(network_task_runner) {
+ data_reduction_proxy_config_(config) {
GetChromiumBuildAndPatch(ChromiumVersion(), &build_, &patch_);
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
const std::string& version,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
+ DataReductionProxyConfig* config)
: client_(GetString(client)),
use_assigned_credentials_(false),
- data_reduction_proxy_config_(config),
- network_task_runner_(network_task_runner) {
+ data_reduction_proxy_config_(config) {
GetChromiumBuildAndPatch(version, &build_, &patch_);
+ // Constructed on the UI thread, but should be checked on the IO thread.
+ thread_checker_.DetachFromThread();
}
DataReductionProxyRequestOptions::~DataReductionProxyRequestOptions() {
@@ -208,7 +208,7 @@ void DataReductionProxyRequestOptions::MaybeAddRequestHeader(
net::URLRequest* request,
const net::ProxyServer& proxy_server,
net::HttpRequestHeaders* request_headers) {
- DCHECK(network_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
if (!proxy_server.is_valid())
return;
if (proxy_server.is_direct())
@@ -221,7 +221,7 @@ void DataReductionProxyRequestOptions::MaybeAddRequestHeader(
void DataReductionProxyRequestOptions::MaybeAddProxyTunnelRequestHandler(
const net::HostPortPair& proxy_server,
net::HttpRequestHeaders* request_headers) {
- DCHECK(network_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
MaybeAddRequestHeaderImpl(proxy_server, true, request_headers);
}
@@ -273,6 +273,7 @@ void DataReductionProxyRequestOptions::UpdateCredentials() {
}
void DataReductionProxyRequestOptions::SetKeyOnIO(const std::string& key) {
+ DCHECK(thread_checker_.CalledOnValidThread());
if(!key.empty()) {
key_ = key;
UpdateCredentials();
@@ -281,7 +282,7 @@ void DataReductionProxyRequestOptions::SetKeyOnIO(const std::string& key) {
void DataReductionProxyRequestOptions::PopulateConfigResponse(
base::DictionaryValue* response) const {
- DCHECK(network_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
std::string session;
std::string credentials;
base::Time now = Now();
@@ -296,7 +297,7 @@ void DataReductionProxyRequestOptions::PopulateConfigResponse(
void DataReductionProxyRequestOptions::SetCredentials(
const std::string& session,
const std::string& credentials) {
- DCHECK(network_task_runner_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
session_ = session;
credentials_ = credentials;
// Force skipping of credential regeneration. It should be handled by the
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h
index 8d6c289..2aa8dce 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h
@@ -9,13 +9,12 @@
#include <vector>
#include "base/gtest_prod_util.h"
-#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
+#include "base/threading/thread_checker.h"
#include "base/time/time.h"
namespace base {
class DictionaryValue;
-class SingleThreadTaskRunner;
}
namespace net {
@@ -83,11 +82,9 @@ class DataReductionProxyRequestOptions {
std::string* credentials);
// Constructs a DataReductionProxyRequestOptions object with the given
- // client type, config, and network task runner.
- DataReductionProxyRequestOptions(
- Client client,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner);
+ // client type, and config.
+ DataReductionProxyRequestOptions(Client client,
+ DataReductionProxyConfig* config);
virtual ~DataReductionProxyRequestOptions();
@@ -145,11 +142,9 @@ class DataReductionProxyRequestOptions {
virtual std::string GetDefaultKey() const;
// Visible for testing.
- DataReductionProxyRequestOptions(
- Client client,
- const std::string& version,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner);
+ DataReductionProxyRequestOptions(Client client,
+ const std::string& version,
+ DataReductionProxyConfig* config);
private:
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyRequestOptionsTest,
@@ -219,9 +214,11 @@ class DataReductionProxyRequestOptions {
// |SetCredentials|.
bool use_assigned_credentials_;
+ // Must outlive |this|.
DataReductionProxyConfig* data_reduction_proxy_config_;
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+ // Enforce usage on the IO thread.
+ base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyRequestOptions);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
index d34ebf2..95c3465 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
@@ -135,10 +135,8 @@ class DataReductionProxyRequestOptionsTest : public testing::Test {
}
void CreateRequestOptions(const std::string& version) {
- request_options_.reset(
- new TestDataReductionProxyRequestOptions(
- kClient, version, test_context_->config(),
- test_context_->task_runner()));
+ request_options_.reset(new TestDataReductionProxyRequestOptions(
+ kClient, version, test_context_->config()));
request_options_->Init();
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
index 91a71cb..7d04b1e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
@@ -13,7 +13,6 @@
#include "base/time/time.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
index 5c6eef6..bfe3947 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
@@ -23,7 +23,6 @@ class TestingPrefServiceSimple;
namespace data_reduction_proxy {
-class DataReductionProxyConfigurator;
class DataReductionProxyTestContext;
class MockDataReductionProxyConfig;
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 f479053..921a99a 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
@@ -45,9 +45,8 @@ namespace data_reduction_proxy {
TestDataReductionProxyRequestOptions::TestDataReductionProxyRequestOptions(
Client client,
const std::string& version,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : DataReductionProxyRequestOptions(client, version, config, task_runner) {
+ DataReductionProxyConfig* config)
+ : DataReductionProxyRequestOptions(client, version, config) {
}
std::string TestDataReductionProxyRequestOptions::GetDefaultKey() const {
@@ -75,9 +74,8 @@ void TestDataReductionProxyRequestOptions::set_offset(
MockDataReductionProxyRequestOptions::MockDataReductionProxyRequestOptions(
Client client,
const std::string& version,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : DataReductionProxyRequestOptions(client, version, config, task_runner) {
+ DataReductionProxyConfig* config)
+ : DataReductionProxyRequestOptions(client, version, config) {
}
MockDataReductionProxyRequestOptions::~MockDataReductionProxyRequestOptions() {
@@ -88,14 +86,12 @@ TestDataReductionProxyConfigServiceClient::
scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+ DataReductionProxyConfig* config)
: DataReductionProxyConfigServiceClient(params.Pass(),
kTestBackoffPolicy,
request_options,
config_values,
- config,
- io_task_runner),
+ config),
tick_clock_(base::Time::UnixEpoch()),
test_backoff_entry_(&kTestBackoffPolicy, &tick_clock_) {
}
@@ -320,10 +316,10 @@ DataReductionProxyTestContext::Builder::Build() {
if (use_test_configurator_) {
test_context_flags |= USE_TEST_CONFIGURATOR;
configurator.reset(new TestDataReductionProxyConfigurator(
- task_runner, net_log.get(), event_store.get()));
+ net_log.get(), event_store.get()));
} else {
- configurator.reset(new DataReductionProxyConfigurator(
- task_runner, net_log.get(), event_store.get()));
+ configurator.reset(
+ new DataReductionProxyConfigurator(net_log.get(), event_store.get()));
}
scoped_ptr<TestDataReductionProxyConfig> config;
@@ -335,8 +331,7 @@ DataReductionProxyTestContext::Builder::Build() {
if (use_config_client_) {
test_context_flags |= USE_CONFIG_CLIENT;
scoped_ptr<DataReductionProxyMutableConfigValues> mutable_config =
- DataReductionProxyMutableConfigValues::CreateFromParams(task_runner,
- params.get());
+ DataReductionProxyMutableConfigValues::CreateFromParams(params.get());
raw_mutable_config = mutable_config.get();
config.reset(new TestDataReductionProxyConfig(
mutable_config.Pass(), task_runner, net_log.get(), configurator.get(),
@@ -356,21 +351,21 @@ DataReductionProxyTestContext::Builder::Build() {
if (use_mock_request_options_) {
test_context_flags |= USE_MOCK_REQUEST_OPTIONS;
request_options.reset(new MockDataReductionProxyRequestOptions(
- client_, std::string(), config.get(), task_runner));
+ client_, std::string(), config.get()));
} else {
- request_options.reset(new DataReductionProxyRequestOptions(
- client_, config.get(), task_runner));
+ request_options.reset(
+ new DataReductionProxyRequestOptions(client_, config.get()));
}
if (use_test_config_client_) {
test_context_flags |= USE_TEST_CONFIG_CLIENT;
config_client.reset(new TestDataReductionProxyConfigServiceClient(
- params.Pass(), request_options.get(), raw_mutable_config, config.get(),
- task_runner));
+ params.Pass(), request_options.get(), raw_mutable_config,
+ config.get()));
} else if (use_config_client_) {
config_client.reset(new DataReductionProxyConfigServiceClient(
params.Pass(), GetBackoffPolicy(), request_options.get(),
- raw_mutable_config, config.get(), task_runner));
+ raw_mutable_config, config.get()));
}
scoped_ptr<DataReductionProxySettings> settings(
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h
index 5cc6dfb..7b2add4 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h
@@ -53,11 +53,9 @@ class TestDataReductionProxyParams;
class TestDataReductionProxyRequestOptions
: public DataReductionProxyRequestOptions {
public:
- TestDataReductionProxyRequestOptions(
- Client client,
- const std::string& version,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ TestDataReductionProxyRequestOptions(Client client,
+ const std::string& version,
+ DataReductionProxyConfig* config);
// Overrides of DataReductionProxyRequestOptions.
std::string GetDefaultKey() const override;
@@ -75,11 +73,9 @@ class TestDataReductionProxyRequestOptions
class MockDataReductionProxyRequestOptions
: public DataReductionProxyRequestOptions {
public:
- MockDataReductionProxyRequestOptions(
- Client client,
- const std::string& version,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ MockDataReductionProxyRequestOptions(Client client,
+ const std::string& version,
+ DataReductionProxyConfig* config);
~MockDataReductionProxyRequestOptions();
@@ -96,8 +92,7 @@ class TestDataReductionProxyConfigServiceClient
scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
- DataReductionProxyConfig* config,
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
+ DataReductionProxyConfig* config);
~TestDataReductionProxyConfigServiceClient() override;