Commit 4b395568 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Fix DRP syncing config client to multiple NetworkContexts

When multiple network contexts are created for a profile (e.g. from
storage partitions for extensions), DRP stopped syncing the config to
the first network context. This probably didn't show up before
http://crrev.com/c/1746682 because of timing issues with the thread
hops.

Also cleans up the mojo types to use the new versions.

Bug: 996334
Change-Id: I1c92e7da6fd9a1df7f46cfc5f8e435fb1fc11d72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764897Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689723}
parent ee36e433
...@@ -559,10 +559,10 @@ ProfileNetworkContextService::CreateNetworkContextParams( ...@@ -559,10 +559,10 @@ ProfileNetworkContextService::CreateNetworkContextParams(
auto* drp_settings = auto* drp_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_); DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_);
if (drp_settings) { if (drp_settings) {
network::mojom::CustomProxyConfigClientPtrInfo config_client_info; mojo::Remote<network::mojom::CustomProxyConfigClient> config_client;
network_context_params->custom_proxy_config_client_request = network_context_params->custom_proxy_config_client_request =
mojo::MakeRequest(&config_client_info); config_client.BindNewPipeAndPassReceiver();
drp_settings->SetCustomProxyConfigClient(std::move(config_client_info)); drp_settings->AddCustomProxyConfigClient(std::move(config_client));
} }
} }
......
...@@ -265,8 +265,8 @@ void DataReductionProxyService::SetProxyPrefs(bool enabled, bool at_startup) { ...@@ -265,8 +265,8 @@ void DataReductionProxyService::SetProxyPrefs(bool enabled, bool at_startup) {
// If Data Saver is disabled, reset data reduction proxy state. // If Data Saver is disabled, reset data reduction proxy state.
if (!enabled) { if (!enabled) {
if (proxy_config_client_) for (auto& client : proxy_config_clients_)
proxy_config_client_->ClearBadProxiesCache(); client->ClearBadProxiesCache();
} }
} }
...@@ -319,9 +319,9 @@ void DataReductionProxyService::SetIgnoreLongTermBlackListRules( ...@@ -319,9 +319,9 @@ void DataReductionProxyService::SetIgnoreLongTermBlackListRules(
settings_->SetIgnoreLongTermBlackListRules(ignore_long_term_black_list_rules); settings_->SetIgnoreLongTermBlackListRules(ignore_long_term_black_list_rules);
} }
void DataReductionProxyService::SetCustomProxyConfigClient( void DataReductionProxyService::AddCustomProxyConfigClient(
network::mojom::CustomProxyConfigClientPtrInfo config_client_info) { mojo::Remote<network::mojom::CustomProxyConfigClient> config_client) {
proxy_config_client_.Bind(std::move(config_client_info)); proxy_config_clients_.Add(std::move(config_client));
UpdateCustomProxyConfig(); UpdateCustomProxyConfig();
} }
...@@ -430,8 +430,8 @@ void DataReductionProxyService::MarkProxiesAsBad( ...@@ -430,8 +430,8 @@ void DataReductionProxyService::MarkProxiesAsBad(
} }
} }
proxy_config_client_->MarkProxiesAsBad(bypass_duration, bad_proxies, for (auto& client : proxy_config_clients_)
std::move(callback)); client->MarkProxiesAsBad(bypass_duration, bad_proxies, std::move(callback));
} }
void DataReductionProxyService::AddThrottleConfigObserver( void DataReductionProxyService::AddThrottleConfigObserver(
...@@ -446,13 +446,12 @@ void DataReductionProxyService::Clone( ...@@ -446,13 +446,12 @@ void DataReductionProxyService::Clone(
} }
void DataReductionProxyService::UpdateCustomProxyConfig() { void DataReductionProxyService::UpdateCustomProxyConfig() {
if (!proxy_config_client_) network::mojom::CustomProxyConfigPtr config = CreateCustomProxyConfig(
return;
proxy_config_client_->OnCustomProxyConfigUpdated(CreateCustomProxyConfig(
!base::FeatureList::IsEnabled( !base::FeatureList::IsEnabled(
features::kDataReductionProxyDisableProxyFailedWarmup), features::kDataReductionProxyDisableProxyFailedWarmup),
config_->GetProxiesForHttp())); config_->GetProxiesForHttp());
for (auto& client : proxy_config_clients_)
client->OnCustomProxyConfigUpdated(config->Clone());
} }
void DataReductionProxyService::UpdateThrottleConfig() { void DataReductionProxyService::UpdateThrottleConfig() {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy.mojom.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy.mojom.h"
#include "components/data_use_measurement/core/data_use_measurement.h" #include "components/data_use_measurement/core/data_use_measurement.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h" #include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/nqe/effective_connection_type.h" #include "net/nqe/effective_connection_type.h"
#include "services/network/public/cpp/network_connection_tracker.h" #include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/public/cpp/network_quality_tracker.h" #include "services/network/public/cpp/network_quality_tracker.h"
...@@ -157,10 +158,10 @@ class DataReductionProxyService ...@@ -157,10 +158,10 @@ class DataReductionProxyService
// Sends the given |headers| to |DataReductionProxySettings|. // Sends the given |headers| to |DataReductionProxySettings|.
void UpdateProxyRequestHeaders(const net::HttpRequestHeaders& headers); void UpdateProxyRequestHeaders(const net::HttpRequestHeaders& headers);
// Sets a config client that can be used to update Data Reduction Proxy // Adds a config client that can be used to update Data Reduction Proxy
// settings when the network service is enabled. // settings.
void SetCustomProxyConfigClient( void AddCustomProxyConfigClient(
network::mojom::CustomProxyConfigClientPtrInfo config_client_info); mojo::Remote<network::mojom::CustomProxyConfigClient> config_client);
// mojom::DataReductionProxy implementation: // mojom::DataReductionProxy implementation:
void MarkProxiesAsBad(base::TimeDelta bypass_duration, void MarkProxiesAsBad(base::TimeDelta bypass_duration,
...@@ -321,7 +322,9 @@ class DataReductionProxyService ...@@ -321,7 +322,9 @@ class DataReductionProxyService
// is unavailable, then the destruction will happen on the UI thread. // is unavailable, then the destruction will happen on the UI thread.
std::unique_ptr<NetworkPropertiesManager> network_properties_manager_; std::unique_ptr<NetworkPropertiesManager> network_properties_manager_;
network::mojom::CustomProxyConfigClientPtr proxy_config_client_; // The set of clients that will get updates about changes to the proxy config.
mojo::RemoteSet<network::mojom::CustomProxyConfigClient>
proxy_config_clients_;
mojo::BindingSet<mojom::DataReductionProxy> drp_bindings_; mojo::BindingSet<mojom::DataReductionProxy> drp_bindings_;
......
...@@ -82,8 +82,9 @@ class TestCustomProxyConfigClient ...@@ -82,8 +82,9 @@ class TestCustomProxyConfigClient
: public network::mojom::CustomProxyConfigClient { : public network::mojom::CustomProxyConfigClient {
public: public:
TestCustomProxyConfigClient( TestCustomProxyConfigClient(
network::mojom::CustomProxyConfigClientRequest request) mojo::PendingReceiver<network::mojom::CustomProxyConfigClient>
: binding_(this, std::move(request)) {} pending_receiver)
: receiver_(this, std::move(pending_receiver)) {}
// network::mojom::CustomProxyConfigClient implementation: // network::mojom::CustomProxyConfigClient implementation:
void OnCustomProxyConfigUpdated( void OnCustomProxyConfigUpdated(
...@@ -101,7 +102,7 @@ class TestCustomProxyConfigClient ...@@ -101,7 +102,7 @@ class TestCustomProxyConfigClient
int num_clear_cache_calls = 0; int num_clear_cache_calls = 0;
private: private:
mojo::Binding<network::mojom::CustomProxyConfigClient> binding_; mojo::Receiver<network::mojom::CustomProxyConfigClient> receiver_;
}; };
TEST_F(DataReductionProxyServiceTest, TestResetBadProxyListOnDisableDataSaver) { TEST_F(DataReductionProxyServiceTest, TestResetBadProxyListOnDisableDataSaver) {
...@@ -113,10 +114,11 @@ TEST_F(DataReductionProxyServiceTest, TestResetBadProxyListOnDisableDataSaver) { ...@@ -113,10 +114,11 @@ TEST_F(DataReductionProxyServiceTest, TestResetBadProxyListOnDisableDataSaver) {
drp_test_context->SetDataReductionProxyEnabled(true); drp_test_context->SetDataReductionProxyEnabled(true);
drp_test_context->InitSettings(); drp_test_context->InitSettings();
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
drp_test_context->data_reduction_proxy_service()->SetCustomProxyConfigClient( client_remote.BindNewPipeAndPassReceiver());
std::move(client_ptr_info)); drp_test_context->data_reduction_proxy_service()->AddCustomProxyConfigClient(
std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Turn Data Saver off. // Turn Data Saver off.
...@@ -158,9 +160,10 @@ TEST_F(DataReductionProxyServiceTest, TestCustomProxyConfigClient) { ...@@ -158,9 +160,10 @@ TEST_F(DataReductionProxyServiceTest, TestCustomProxyConfigClient) {
service->config_client()->ApplySerializedConfig( service->config_client()->ApplySerializedConfig(
CreateEncodedConfig({DataReductionProxyServer(proxy_server)})); CreateEncodedConfig({DataReductionProxyServer(proxy_server)}));
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
service->SetCustomProxyConfigClient(std::move(client_ptr_info)); client_remote.BindNewPipeAndPassReceiver());
service->AddCustomProxyConfigClient(std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(client.config->rules.proxies_for_http.Get(), proxy_server); EXPECT_EQ(client.config->rules.proxies_for_http.Get(), proxy_server);
...@@ -178,10 +181,11 @@ TEST_F(DataReductionProxyServiceTest, TestCustomProxyConfigUpdatedOnECTChange) { ...@@ -178,10 +181,11 @@ TEST_F(DataReductionProxyServiceTest, TestCustomProxyConfigUpdatedOnECTChange) {
->ReportEffectiveConnectionTypeForTesting( ->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_4G); net::EFFECTIVE_CONNECTION_TYPE_4G);
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
drp_test_context->data_reduction_proxy_service()->SetCustomProxyConfigClient( client_remote.BindNewPipeAndPassReceiver());
std::move(client_ptr_info)); drp_test_context->data_reduction_proxy_service()->AddCustomProxyConfigClient(
std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::string value; std::string value;
...@@ -206,9 +210,10 @@ TEST_F(DataReductionProxyServiceTest, ...@@ -206,9 +210,10 @@ TEST_F(DataReductionProxyServiceTest,
DataReductionProxyService* service = DataReductionProxyService* service =
drp_test_context->data_reduction_proxy_service(); drp_test_context->data_reduction_proxy_service();
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
service->SetCustomProxyConfigClient(std::move(client_ptr_info)); client_remote.BindNewPipeAndPassReceiver());
service->AddCustomProxyConfigClient(std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
std::string value; std::string value;
...@@ -241,9 +246,10 @@ TEST_F(DataReductionProxyServiceTest, ...@@ -241,9 +246,10 @@ TEST_F(DataReductionProxyServiceTest,
service->config_client()->ApplySerializedConfig( service->config_client()->ApplySerializedConfig(
CreateEncodedConfig({DataReductionProxyServer(proxy_server1)})); CreateEncodedConfig({DataReductionProxyServer(proxy_server1)}));
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
service->SetCustomProxyConfigClient(std::move(client_ptr_info)); client_remote.BindNewPipeAndPassReceiver());
service->AddCustomProxyConfigClient(std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(client.config->rules.proxies_for_http.Get(), proxy_server1); EXPECT_EQ(client.config->rules.proxies_for_http.Get(), proxy_server1);
...@@ -276,9 +282,10 @@ TEST_F(DataReductionProxyServiceTest, ...@@ -276,9 +282,10 @@ TEST_F(DataReductionProxyServiceTest,
CreateEncodedConfig({DataReductionProxyServer(core_proxy_server), CreateEncodedConfig({DataReductionProxyServer(core_proxy_server),
DataReductionProxyServer(second_proxy_server)})); DataReductionProxyServer(second_proxy_server)}));
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
service->SetCustomProxyConfigClient(std::move(client_ptr_info)); client_remote.BindNewPipeAndPassReceiver());
service->AddCustomProxyConfigClient(std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
net::ProxyConfig::ProxyRules expected_rules; net::ProxyConfig::ProxyRules expected_rules;
...@@ -302,9 +309,10 @@ TEST_F(DataReductionProxyServiceTest, TestCustomProxyConfigProperties) { ...@@ -302,9 +309,10 @@ TEST_F(DataReductionProxyServiceTest, TestCustomProxyConfigProperties) {
&network_properties_manager); &network_properties_manager);
service->config()->UpdateConfigForTesting(true, true, true); service->config()->UpdateConfigForTesting(true, true, true);
network::mojom::CustomProxyConfigClientPtrInfo client_ptr_info; mojo::Remote<network::mojom::CustomProxyConfigClient> client_remote;
TestCustomProxyConfigClient client(mojo::MakeRequest(&client_ptr_info)); TestCustomProxyConfigClient client(
service->SetCustomProxyConfigClient(std::move(client_ptr_info)); client_remote.BindNewPipeAndPassReceiver());
service->AddCustomProxyConfigClient(std::move(client_remote));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(client.config->assume_https_proxies_support_quic); EXPECT_TRUE(client.config->assume_https_proxies_support_quic);
......
...@@ -84,9 +84,10 @@ void DataReductionProxySettings::InitDataReductionProxySettings( ...@@ -84,9 +84,10 @@ void DataReductionProxySettings::InitDataReductionProxySettings(
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnSettingsInitialized(); observer.OnSettingsInitialized();
if (proxy_config_client_) { while (!proxy_config_clients_.empty()) {
data_reduction_proxy_service_->SetCustomProxyConfigClient( data_reduction_proxy_service_->AddCustomProxyConfigClient(
std::move(proxy_config_client_)); std::move(proxy_config_clients_.back()));
proxy_config_clients_.pop_back();
} }
} }
...@@ -325,15 +326,15 @@ void DataReductionProxySettings::RemoveDataReductionProxySettingsObserver( ...@@ -325,15 +326,15 @@ void DataReductionProxySettings::RemoveDataReductionProxySettingsObserver(
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
void DataReductionProxySettings::SetCustomProxyConfigClient( void DataReductionProxySettings::AddCustomProxyConfigClient(
network::mojom::CustomProxyConfigClientPtrInfo proxy_config_client) { mojo::Remote<network::mojom::CustomProxyConfigClient> proxy_config_client) {
if (data_reduction_proxy_service_) { if (data_reduction_proxy_service_) {
data_reduction_proxy_service_->SetCustomProxyConfigClient( data_reduction_proxy_service_->AddCustomProxyConfigClient(
std::move(proxy_config_client)); std::move(proxy_config_client));
return; return;
} }
proxy_config_client_ = std::move(proxy_config_client); proxy_config_clients_.push_back(std::move(proxy_config_client));
} }
// Metrics methods // Metrics methods
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_server.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/http/http_request_headers.h" #include "net/http/http_request_headers.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -178,10 +179,11 @@ class DataReductionProxySettings { ...@@ -178,10 +179,11 @@ class DataReductionProxySettings {
void RemoveDataReductionProxySettingsObserver( void RemoveDataReductionProxySettingsObserver(
DataReductionProxySettingsObserver* observer); DataReductionProxySettingsObserver* observer);
// Sets a config client that can be used to update Data Reduction Proxy // Addds a config client that can be used to update Data Reduction Proxy
// settings when the network service is enabled. // settings.
void SetCustomProxyConfigClient( void AddCustomProxyConfigClient(
network::mojom::CustomProxyConfigClientPtrInfo proxy_config_client); mojo::Remote<network::mojom::CustomProxyConfigClient>
proxy_config_client);
DataReductionProxyService* data_reduction_proxy_service() { DataReductionProxyService* data_reduction_proxy_service() {
return data_reduction_proxy_service_.get(); return data_reduction_proxy_service_.get();
...@@ -297,7 +299,10 @@ class DataReductionProxySettings { ...@@ -297,7 +299,10 @@ class DataReductionProxySettings {
// The headers to use for requests to the proxy server. // The headers to use for requests to the proxy server.
net::HttpRequestHeaders proxy_request_headers_; net::HttpRequestHeaders proxy_request_headers_;
network::mojom::CustomProxyConfigClientPtrInfo proxy_config_client_; // A list of CustomProxyConfigClients that may have been added before
// the DataReductionProxyService was available.
std::vector<mojo::Remote<network::mojom::CustomProxyConfigClient>>
proxy_config_clients_;
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment