diff options
Diffstat (limited to 'components/data_reduction_proxy')
14 files changed, 225 insertions, 49 deletions
diff --git a/components/data_reduction_proxy/core/browser/BUILD.gn b/components/data_reduction_proxy/core/browser/BUILD.gn index 0f0489e..a292f6b 100644 --- a/components/data_reduction_proxy/core/browser/BUILD.gn +++ b/components/data_reduction_proxy/core/browser/BUILD.gn @@ -35,6 +35,7 @@ static_library("browser") { "data_reduction_proxy_request_options.h", "data_reduction_proxy_service.cc", "data_reduction_proxy_service.h", + "data_reduction_proxy_service_observer.h", "data_reduction_proxy_settings.cc", "data_reduction_proxy_settings.h", "data_reduction_proxy_tamper_detection.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 a6f47c1..75ee7c3 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 @@ -80,16 +80,6 @@ void DataReductionProxyConfig::SetDataReductionProxyService( data_reduction_proxy_service_ = data_reduction_proxy_service; } -void DataReductionProxyConfig::SetProxyPrefs(bool enabled, - bool alternative_enabled, - bool at_startup) { - DCHECK(thread_checker_.CalledOnValidThread()); - io_task_runner_->PostTask( - FROM_HERE, base::Bind(&DataReductionProxyConfig::SetProxyConfigOnIOThread, - base::Unretained(this), enabled, - alternative_enabled, at_startup)); -} - void DataReductionProxyConfig::ReloadConfig() { DCHECK(io_task_runner_->BelongsToCurrentThread()); UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_, @@ -244,7 +234,7 @@ bool DataReductionProxyConfig::promo_allowed() const { return config_values_->promo_allowed(); } -void DataReductionProxyConfig::SetProxyConfigOnIOThread( +void DataReductionProxyConfig::SetProxyConfig( bool enabled, bool alternative_enabled, bool at_startup) { enabled_by_user_ = enabled; alternative_enabled_by_user_ = alternative_enabled; 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 61305e5..7692f6b 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 @@ -84,11 +84,17 @@ class DataReductionProxyConfig void SetDataReductionProxyService( base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service); - // This method expects to run on the UI thread. It permits the Data Reduction - // Proxy configuration to change based on changes initiated by the user. - virtual void SetProxyPrefs(bool enabled, - bool alternative_enabled, - bool at_startup); + // 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 + // |restricted| is true, only enable the fallback proxy. |at_startup| is true + // when this method is called from InitDataReductionProxySettings. + // TODO(jeremyim): Change enabled/alternative_enabled to be a single enum, + // since there are only 3 valid states - also update in + // DataReductionProxyIOData. + void SetProxyConfig(bool enabled, + bool alternative_enabled, + bool at_startup); // Provides a mechanism for an external object to force |this| to refresh // the Data Reduction Proxy configuration from |config_values_| and apply to @@ -166,15 +172,6 @@ class DataReductionProxyConfig bool promo_allowed() const; protected: - // 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 - // |restricted| is true, only enable the fallback proxy. |at_startup| is true - // when this method is called from InitDataReductionProxySettings. - void SetProxyConfigOnIOThread(bool enabled, - bool alternative_enabled, - bool at_startup); - // Writes a warning to the log that is used in backend processing of // customer feedback. Virtual so tests can mock it for verification. virtual void LogProxyState(bool enabled, bool restricted, bool at_startup); 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 3c9ebef..a4ee0ab 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 @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/command_line.h" +#include "base/memory/weak_ptr.h" #include "base/prefs/pref_member.h" #include "base/single_thread_task_runner.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.h" @@ -38,10 +39,11 @@ DataReductionProxyIOData::DataReductionProxyIOData( net_log_(net_log), io_task_runner_(io_task_runner), ui_task_runner_(ui_task_runner), - shutdown_on_ui_(false) { + shutdown_on_ui_(false), + weak_factory_(this) { DCHECK(net_log); - DCHECK(io_task_runner_.get()); - DCHECK(ui_task_runner_.get()); + DCHECK(io_task_runner_); + DCHECK(ui_task_runner_); scoped_ptr<DataReductionProxyParams> params( new DataReductionProxyParams(param_flags)); params->EnableQuic(enable_quic); @@ -83,7 +85,9 @@ DataReductionProxyIOData::DataReductionProxyIOData( new DataReductionProxyDelegate(request_options_.get(), config_.get())); } -DataReductionProxyIOData::DataReductionProxyIOData() : shutdown_on_ui_(false) { +DataReductionProxyIOData::DataReductionProxyIOData() + : shutdown_on_ui_(false), + weak_factory_(this) { } DataReductionProxyIOData::~DataReductionProxyIOData() { @@ -107,6 +111,21 @@ void DataReductionProxyIOData::SetDataReductionProxyService( base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service) { service_ = data_reduction_proxy_service; 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 + // part of class initialization. + io_task_runner_->PostTask( + FROM_HERE, + base::Bind(&DataReductionProxyIOData::InitializeOnIOThread, + base::Unretained(this))); +} + +void DataReductionProxyIOData::InitializeOnIOThread() { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + ui_task_runner_->PostTask( + FROM_HERE, + base::Bind(&DataReductionProxyService::SetIOData, + service_, weak_factory_.GetWeakPtr())); } bool DataReductionProxyIOData::IsEnabled() const { @@ -137,6 +156,13 @@ DataReductionProxyIOData::CreateNetworkDelegate( return network_delegate.Pass(); } +void DataReductionProxyIOData::SetProxyPrefs(bool enabled, + bool alternative_enabled, + bool at_startup) { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + config_->SetProxyConfig(enabled, alternative_enabled, at_startup); +} + void DataReductionProxyIOData::UpdateContentLengths( int received_content_length, int original_content_length, 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 e258ec4..d55dbcb 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 @@ -68,6 +68,14 @@ class DataReductionProxyIOData { scoped_ptr<net::NetworkDelegate> wrapped_network_delegate, bool track_proxy_bypass_statistics); + // Sets user defined preferences for how the Data Reduction Proxy + // configuration should be set. Use the alternative configuration only if + // |enabled| and |alternative_enabled| are true. |at_startup| is true only + // when DataReductionProxySettings is initialized. + void SetProxyPrefs(bool enabled, + bool alternative_enabled, + bool at_startup); + // Bridge methods to safely call to the UI thread objects. void UpdateContentLengths(int received_content_length, int original_content_length, @@ -102,8 +110,8 @@ class DataReductionProxyIOData { return net_log_; } - base::WeakPtr<DataReductionProxyService> service() const { - return service_; + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner() const { + return io_task_runner_; } // Used for testing. @@ -126,6 +134,11 @@ class DataReductionProxyIOData { // Used for testing. DataReductionProxyIOData(); + // Initializes the weak pointer to |this| on the IO thread. It must be done + // on the IO thread, since it is used for posting tasks from the UI thread + // to IO thread objects in a thread safe manner. + void InitializeOnIOThread(); + // Records that the data reduction proxy is unreachable or not. void SetUnreachable(bool unreachable); @@ -175,6 +188,8 @@ class DataReductionProxyIOData { // by the user. In practice, this can be overridden by the command line. BooleanPrefMember enabled_; + base::WeakPtrFactory<DataReductionProxyIOData> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(DataReductionProxyIOData); }; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc index 326d92a..632e4e2 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc @@ -4,8 +4,12 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" +#include "base/bind.h" +#include "base/location.h" #include "base/sequenced_task_runner.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h" #include "net/base/load_flags.h" #include "net/url_request/url_fetcher.h" @@ -16,9 +20,12 @@ namespace data_reduction_proxy { DataReductionProxyService::DataReductionProxyService( scoped_ptr<DataReductionProxyCompressionStats> compression_stats, DataReductionProxySettings* settings, - net::URLRequestContextGetter* request_context_getter) + net::URLRequestContextGetter* request_context_getter, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) : url_request_context_getter_(request_context_getter), settings_(settings), + io_task_runner_(io_task_runner), + initialized_(false), weak_factory_(this) { DCHECK(settings); compression_stats_ = compression_stats.Pass(); @@ -27,6 +34,15 @@ DataReductionProxyService::DataReductionProxyService( DataReductionProxyService::~DataReductionProxyService() { } +void DataReductionProxyService::SetIOData( + base::WeakPtr<DataReductionProxyIOData> io_data) { + DCHECK(CalledOnValidThread()); + io_data_ = io_data; + initialized_ = true; + FOR_EACH_OBSERVER(DataReductionProxyServiceObserver, + observer_list_, OnServiceInitialized()); +} + void DataReductionProxyService::Shutdown() { DCHECK(CalledOnValidThread()); weak_factory_.InvalidateWeakPtrs(); @@ -60,6 +76,33 @@ void DataReductionProxyService::SetUnreachable(bool unreachable) { settings_->SetUnreachable(unreachable); } +void DataReductionProxyService::SetProxyPrefs(bool enabled, + bool alternative_enabled, + bool at_startup) { + DCHECK(CalledOnValidThread()); + io_task_runner_->PostTask( + FROM_HERE, + base::Bind(&DataReductionProxyIOData::SetProxyPrefs, + io_data_, enabled, alternative_enabled, at_startup)); +} + +void DataReductionProxyService::AddObserver( + DataReductionProxyServiceObserver* observer) { + DCHECK(CalledOnValidThread()); + observer_list_.AddObserver(observer); +} + +void DataReductionProxyService::RemoveObserver( + DataReductionProxyServiceObserver* observer) { + DCHECK(CalledOnValidThread()); + observer_list_.RemoveObserver(observer); +} + +bool DataReductionProxyService::Initialized() const { + DCHECK(CalledOnValidThread()); + return initialized_; +} + base::WeakPtr<DataReductionProxyService> DataReductionProxyService::GetWeakPtr() { DCHECK(CalledOnValidThread()); 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 bf44a45..7a1a5c8 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 @@ -7,8 +7,11 @@ #include "base/callback.h" #include "base/macros.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "base/observer_list.h" +#include "base/single_thread_task_runner.h" #include "base/threading/non_thread_safe.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h" #include "net/url_request/url_fetcher_delegate.h" @@ -32,8 +35,10 @@ namespace data_reduction_proxy { typedef base::Callback<void(const std::string&, const net::URLRequestStatus&)> FetcherResponseCallback; -class DataReductionProxySettings; class DataReductionProxyCompressionStats; +class DataReductionProxyIOData; +class DataReductionProxyServiceObserver; +class DataReductionProxySettings; // Contains and initializes all Data Reduction Proxy objects that have a // lifetime based on the UI thread. @@ -48,12 +53,20 @@ class DataReductionProxyService : public base::NonThreadSafe, DataReductionProxyService( scoped_ptr<DataReductionProxyCompressionStats> compression_stats, DataReductionProxySettings* settings, - net::URLRequestContextGetter* request_context_getter); + net::URLRequestContextGetter* request_context_getter, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); ~DataReductionProxyService() override; + // Sets the DataReductionProxyIOData weak pointer. + void SetIOData(base::WeakPtr<DataReductionProxyIOData> io_data); + void Shutdown(); + // Indicates whether |this| has been fully initialized. |SetIOData| is the + // final step in initialization. + bool Initialized() const; + // Requests the given |secure_proxy_check_url|. Upon completion, returns the // results to the caller via the |fetcher_callback|. Virtualized for unit // testing. @@ -76,6 +89,16 @@ class DataReductionProxyService : public base::NonThreadSafe, // Records whether the Data Reduction Proxy is unreachable or not. void SetUnreachable(bool unreachable); + // Bridge methods to safely call to the UI thread objects. + // Virtual for testing. + virtual void SetProxyPrefs(bool enabled, + bool alternative_enabled, + bool at_startup); + + // Methods for adding/removing observers on |this|. + void AddObserver(DataReductionProxyServiceObserver* observer); + void RemoveObserver(DataReductionProxyServiceObserver* observer); + // Accessor methods. DataReductionProxyCompressionStats* compression_stats() const { return compression_stats_.get(); @@ -108,6 +131,17 @@ class DataReductionProxyService : public base::NonThreadSafe, DataReductionProxySettings* settings_; + // Used to post tasks to |io_data_|. + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; + + // A weak pointer to DataReductionProxyIOData so that UI based objects can + // make calls to IO based objects. + base::WeakPtr<DataReductionProxyIOData> io_data_; + + ObserverList<DataReductionProxyServiceObserver> observer_list_; + + bool initialized_; + base::WeakPtrFactory<DataReductionProxyService> weak_factory_; DISALLOW_COPY_AND_ASSIGN(DataReductionProxyService); diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h new file mode 100644 index 0000000..2654afa --- /dev/null +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h @@ -0,0 +1,17 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_OBSERVER_H_ +#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_OBSERVER_H_ + +namespace data_reduction_proxy { + +class DataReductionProxyServiceObserver { + public: + virtual void OnServiceInitialized() = 0; +}; + +} // namespace data_reduction_proxy + +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_OBSERVER_H_ diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc index c9b2555..408ad45 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc @@ -44,6 +44,7 @@ const char kDataReductionPassThroughHeader[] = DataReductionProxySettings::DataReductionProxySettings() : unreachable_(false), + deferred_initialization_(false), allowed_(false), alternative_allowed_(false), promo_allowed_(false), @@ -93,11 +94,22 @@ void DataReductionProxySettings::InitDataReductionProxySettings( config_ = io_data->config(); event_store_ = io_data->event_store(); data_reduction_proxy_service_ = data_reduction_proxy_service.Pass(); + data_reduction_proxy_service_->AddObserver(this); InitPrefMembers(); UpdateConfigValues(); RecordDataReductionInit(); } +void DataReductionProxySettings::OnServiceInitialized() { + DCHECK(thread_checker_.CalledOnValidThread()); + if (!deferred_initialization_) + return; + deferred_initialization_ = false; + // Technically, this is not "at startup", but this is the first chance that + // IO data objects can be called. + UpdateIOData(true); +} + void DataReductionProxySettings::SetCallbackToRegisterSyntheticFieldTrial( const SyntheticFieldTrialRegistrationCallback& on_data_reduction_proxy_enabled) { @@ -210,6 +222,12 @@ void DataReductionProxySettings::ResetDataReductionStatistics() { data_reduction_proxy_service_->compression_stats()->ResetStatistics(); } +void DataReductionProxySettings::UpdateIOData(bool at_startup) { + data_reduction_proxy_service_->SetProxyPrefs( + IsDataReductionProxyEnabled(), IsDataReductionProxyAlternativeEnabled(), + at_startup); +} + void DataReductionProxySettings::MaybeActivateDataReductionProxy( bool at_startup) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -227,8 +245,10 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy( ResetDataReductionStatistics(); } // Configure use of the data reduction proxy if it is enabled. - config_->SetProxyPrefs(IsDataReductionProxyEnabled(), - IsDataReductionProxyAlternativeEnabled(), at_startup); + if (at_startup && !data_reduction_proxy_service_->Initialized()) + deferred_initialization_ = true; + else + UpdateIOData(at_startup); } // Metrics methods diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h index 4b87b3c..c7f3685 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h @@ -16,6 +16,7 @@ #include "base/prefs/pref_member.h" #include "base/threading/thread_checker.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h" +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h" #include "url/gurl.h" class PrefService; @@ -48,7 +49,7 @@ enum ProxyStartupState { // be called from there. // TODO(marq): Convert this to be a KeyedService with an // associated factory class, and refactor the Java call sites accordingly. -class DataReductionProxySettings { +class DataReductionProxySettings : public DataReductionProxyServiceObserver { public: typedef base::Callback<bool(const std::string&, const std::string&)> SyntheticFieldTrialRegistrationCallback; @@ -203,6 +204,9 @@ class DataReductionProxySettings { FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed); + // Override of DataReductionProxyService::Observer. + void OnServiceInitialized() override; + // Returns true if both LoFi and the proxy are enabled. bool IsLoFiEnabled() const; @@ -223,8 +227,19 @@ class DataReductionProxySettings { void ResetDataReductionStatistics(); + // Update IO thread objects in response to UI thread changes. + void UpdateIOData(bool at_startup); + bool unreachable_; + // A call to MaybeActivateDataReductionProxy may take place before the + // |data_reduction_proxy_service_| has received a DataReductionProxyIOData + // pointer. In that case, the operation against the IO objects will not + // succeed and |deferred_initialization_| will be set to true. When + // OnServiceInitialized is called, if |deferred_initialization_| is true, + // IO object calls will be performed at that time. + bool deferred_initialization_; + // The following values are cached in order to access the values on the // correct thread. bool allowed_; 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 3ff88cd..91a71cb 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 @@ -102,6 +102,8 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed, settings->prefs_ = test_context_->pref_service(); settings->data_reduction_proxy_service_ = test_context_->CreateDataReductionProxyService(); + settings->data_reduction_proxy_service_->SetIOData( + test_context_->io_data()->GetWeakPtr()); test_context_->config()->ResetParamFlagsForTest(flags); settings->UpdateConfigValues(); EXPECT_CALL(*settings, GetOriginalProfilePrefs()) @@ -126,9 +128,10 @@ void DataReductionProxySettingsTestBase::ExpectSetProxyPrefs( bool expected_enabled, bool expected_alternate_enabled, bool expected_at_startup) { - MockDataReductionProxyConfig* config = - static_cast<MockDataReductionProxyConfig*>(test_context_->config()); - EXPECT_CALL(*config, + MockDataReductionProxyService* mock_service = + static_cast<MockDataReductionProxyService*>( + settings_->data_reduction_proxy_service()); + EXPECT_CALL(*mock_service, SetProxyPrefs(expected_enabled, expected_alternate_enabled, expected_at_startup)); } @@ -154,6 +157,8 @@ void DataReductionProxySettingsTestBase::InitDataReductionProxy( settings_->InitDataReductionProxySettings( test_context_->pref_service(), test_context_->io_data(), test_context_->CreateDataReductionProxyService()); + settings_->data_reduction_proxy_service()->SetIOData( + test_context_->io_data()->GetWeakPtr()); settings_->SetCallbackToRegisterSyntheticFieldTrial( base::Bind(&DataReductionProxySettingsTestBase:: SyntheticFieldTrialRegistrationCallback, diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc index 90b873b..0b404ad 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc @@ -243,14 +243,18 @@ TEST(DataReductionProxySettingsStandaloneTest, TestOnProxyEnabledPrefChange) { drp_test_context->config()->SetStateForTest(true, false, false); drp_test_context->InitSettings(); + MockDataReductionProxyService* mock_service = + static_cast<MockDataReductionProxyService*>( + drp_test_context->data_reduction_proxy_service()); + // The pref is disabled, so correspondingly should be the proxy. - EXPECT_CALL(*drp_test_context->mock_config(), + EXPECT_CALL(*mock_service, SetProxyPrefs(false, false, false)); drp_test_context->pref_service()->SetBoolean( prefs::kDataReductionProxyEnabled, false); // The pref is enabled, so correspondingly should be the proxy. - EXPECT_CALL(*drp_test_context->mock_config(), + EXPECT_CALL(*mock_service, SetProxyPrefs(true, false, false)); drp_test_context->pref_service()->SetBoolean( prefs::kDataReductionProxyEnabled, true); 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 7333914..f479053 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 @@ -162,9 +162,10 @@ TestDataReductionProxyConfigServiceClient::TestBackoffEntry::ImplGetTimeNow() MockDataReductionProxyService::MockDataReductionProxyService( scoped_ptr<DataReductionProxyCompressionStats> compression_stats, DataReductionProxySettings* settings, - net::URLRequestContextGetter* request_context) + net::URLRequestContextGetter* request_context, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) : DataReductionProxyService( - compression_stats.Pass(), settings, request_context) { + compression_stats.Pass(), settings, request_context, io_task_runner) { } MockDataReductionProxyService::~MockDataReductionProxyService() { @@ -442,6 +443,7 @@ void DataReductionProxyTestContext::InitSettingsWithoutCheck() { CreateDataReductionProxyServiceInternal()); io_data_->SetDataReductionProxyService( settings_->data_reduction_proxy_service()->GetWeakPtr()); + settings_->data_reduction_proxy_service()->SetIOData(io_data_->GetWeakPtr()); } scoped_ptr<DataReductionProxyService> @@ -460,11 +462,11 @@ DataReductionProxyTestContext::CreateDataReductionProxyServiceInternal() { if (test_context_flags_ & DataReductionProxyTestContext::USE_MOCK_SERVICE) { return make_scoped_ptr(new MockDataReductionProxyService( compression_stats.Pass(), settings_.get(), - request_context_getter_.get())); + request_context_getter_.get(), task_runner_)); } else { - return make_scoped_ptr( - new DataReductionProxyService(compression_stats.Pass(), settings_.get(), - request_context_getter_.get())); + return make_scoped_ptr(new DataReductionProxyService( + compression_stats.Pass(), settings_.get(), + request_context_getter_.get(), task_runner_)); } } 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 105ac2a..5cc6dfb 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 @@ -157,12 +157,15 @@ class MockDataReductionProxyService : public DataReductionProxyService { MockDataReductionProxyService( scoped_ptr<DataReductionProxyCompressionStats> compression_stats, DataReductionProxySettings* settings, - net::URLRequestContextGetter* request_context); + net::URLRequestContextGetter* request_context, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); ~MockDataReductionProxyService() override; MOCK_METHOD2(SecureProxyCheck, void(const GURL& secure_proxy_check_url, FetcherResponseCallback fetcher_callback)); + MOCK_METHOD3(SetProxyPrefs, + void(bool enabled, bool alternative_enabled, bool at_startup)); }; // Test version of |DataReductionProxyIOData|, which bypasses initialization in @@ -186,6 +189,10 @@ class TestDataReductionProxyIOData : public DataReductionProxyIOData { DataReductionProxyConfigServiceClient* config_client() const { return config_client_.get(); } + + base::WeakPtr<DataReductionProxyIOData> GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } }; // Builds a test version of the Data Reduction Proxy stack for use in tests. |