| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
|
| 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 0fbd744faeea3d609014ad8e2274aa32618e2758..b950cd31a5d0c4b4181f032fcfe9e0b5cdab4235 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
|
| @@ -44,63 +44,67 @@ void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
|
| namespace data_reduction_proxy {
|
|
|
| DataReductionProxyConfig::DataReductionProxyConfig(
|
| - scoped_ptr<DataReductionProxyParams> params)
|
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
|
| + net::NetLog* net_log,
|
| + scoped_ptr<DataReductionProxyParams> params,
|
| + DataReductionProxyConfigurator* configurator,
|
| + DataReductionProxyEventStore* event_store)
|
| : restricted_by_carrier_(false),
|
| disabled_on_vpn_(false),
|
| unreachable_(false),
|
| enabled_by_user_(false),
|
| alternative_enabled_by_user_(false),
|
| - net_log_(nullptr),
|
| + params_(params.release()),
|
| + io_task_runner_(io_task_runner),
|
| + net_log_(net_log),
|
| url_request_context_getter_(nullptr),
|
| - configurator_(nullptr),
|
| - event_store_(nullptr) {
|
| - params_.reset(params.release());
|
| + configurator_(configurator),
|
| + event_store_(event_store) {
|
| + DCHECK(io_task_runner);
|
| + DCHECK(configurator);
|
| + DCHECK(event_store);
|
| + InitOnIOThread();
|
| }
|
|
|
| DataReductionProxyConfig::~DataReductionProxyConfig() {
|
| net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
|
| }
|
|
|
| -void DataReductionProxyConfig::InitDataReductionProxyConfig(
|
| - scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
|
| - net::NetLog* net_log,
|
| - net::URLRequestContextGetter* url_request_context_getter,
|
| - DataReductionProxyConfigurator* configurator,
|
| - DataReductionProxyEventStore* event_store) {
|
| - DCHECK(io_task_runner);
|
| - DCHECK(configurator);
|
| - DCHECK(event_store);
|
| - DCHECK(io_task_runner->BelongsToCurrentThread());
|
| - io_task_runner_ = io_task_runner;
|
| - net_log_ = net_log;
|
| +void DataReductionProxyConfig::InitURLRequestContext(
|
| + net::URLRequestContextGetter* url_request_context_getter) {
|
| url_request_context_getter_ = url_request_context_getter;
|
| - configurator_ = configurator;
|
| - event_store_ = event_store;
|
| - net::NetworkChangeNotifier::AddIPAddressObserver(this);
|
| }
|
|
|
| -void DataReductionProxyConfig::SetProxyConfigs(bool enabled,
|
| - bool alternative_enabled,
|
| - bool restricted,
|
| - bool at_startup) {
|
| - DCHECK(configurator_);
|
| +void DataReductionProxyConfig::SetProxyPrefs(bool enabled,
|
| + bool alternative_enabled,
|
| + bool at_startup) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + io_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&DataReductionProxyConfig::SetProxyPrefsOnIOThread,
|
| + base::Unretained(this), enabled,
|
| + alternative_enabled, at_startup));
|
| +}
|
|
|
| - LogProxyState(enabled, restricted, at_startup);
|
| - // The alternative is only configured if the standard configuration is
|
| - // is enabled.
|
| - if (enabled & !params()->holdback()) {
|
| - if (alternative_enabled) {
|
| - configurator_->Enable(restricted,
|
| - !params()->alternative_fallback_allowed(),
|
| - params()->alt_origin().spec(), std::string(),
|
| - params()->ssl_origin().spec());
|
| - } else {
|
| - configurator_->Enable(restricted, !params()->fallback_allowed(),
|
| - params()->origin().spec(),
|
| - params()->fallback_origin().spec(), std::string());
|
| - }
|
| - } else {
|
| - configurator_->Disable();
|
| +void DataReductionProxyConfig::ResetParamsForTest(
|
| + scoped_ptr<DataReductionProxyParams> params) {
|
| + params_.reset(params.release());
|
| +}
|
| +
|
| +void DataReductionProxyConfig::SetProxyPrefsOnIOThread(bool enabled,
|
| + bool alternative_enabled,
|
| + bool at_startup) {
|
| + enabled_by_user_ = enabled;
|
| + alternative_enabled_by_user_ = alternative_enabled;
|
| + SetProxyConfigs(enabled_by_user_,
|
| + alternative_enabled_by_user_,
|
| + restricted_by_carrier_,
|
| + at_startup);
|
| +
|
| + // Check if the proxy has been restricted explicitly by the carrier.
|
| + if (enabled &&
|
| + !(alternative_enabled &&
|
| + !params()->alternative_fallback_allowed())) {
|
| + ProbeWhetherDataReductionProxyIsAvailable();
|
| }
|
| }
|
|
|
| @@ -125,6 +129,8 @@ void DataReductionProxyConfig::LogProxyState(bool enabled,
|
|
|
| void DataReductionProxyConfig::OnURLFetchComplete(
|
| const net::URLFetcher* source) {
|
| + DCHECK(io_task_runner_->BelongsToCurrentThread());
|
| +
|
| DCHECK(source == fetcher_.get());
|
| net::URLRequestStatus status = source->GetStatus();
|
|
|
| @@ -182,6 +188,7 @@ void DataReductionProxyConfig::OnURLFetchComplete(
|
| }
|
|
|
| void DataReductionProxyConfig::OnIPAddressChanged() {
|
| + DCHECK(io_task_runner_->BelongsToCurrentThread());
|
| if (enabled_by_user_) {
|
| DCHECK(params()->allowed());
|
| RecordNetworkChangeEvent(IP_CHANGED);
|
| @@ -195,6 +202,47 @@ 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 (!params_->allowed())
|
| + return;
|
| +
|
| + AddDefaultProxyBypassRules();
|
| + net::NetworkChangeNotifier::AddIPAddressObserver(this);
|
| +}
|
| +
|
| +void DataReductionProxyConfig::SetProxyConfigs(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
|
| + // is enabled.
|
| + if (enabled & !params()->holdback()) {
|
| + if (alternative_enabled) {
|
| + configurator_->Enable(restricted,
|
| + !params()->alternative_fallback_allowed(),
|
| + params()->alt_origin().spec(), std::string(),
|
| + params()->ssl_origin().spec());
|
| + } else {
|
| + configurator_->Enable(restricted,
|
| + !params()->fallback_allowed(),
|
| + params()->origin().spec(),
|
| + params()->fallback_origin().spec(), std::string());
|
| + }
|
| + } else {
|
| + configurator_->Disable();
|
| + }
|
| +}
|
| +
|
| void DataReductionProxyConfig::AddDefaultProxyBypassRules() {
|
| // localhost
|
| DCHECK(configurator_);
|
|
|