Commit 5807c24f authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert DnsConfigChangeManagerClient to new Mojo types

This CL converts DnsConfigChangeManagerClient{Ptr, Request} in
chrome and services to the new Mojo type, and uses
pending_remote<DnsConfigChangeManagerClient> in host_resolver.mojom.

Bug: 955171
Change-Id: If8038bf601d99eb11c6f62f250872919fa6338f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1859655
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705871}
parent e0b63762
......@@ -222,21 +222,19 @@ void IntranetRedirectDetector::OnSystemDnsConfigChanged() {
}
void IntranetRedirectDetector::SetupDnsConfigClient() {
DCHECK(!dns_config_client_binding_.is_bound());
network::mojom::DnsConfigChangeManagerClientPtr client_ptr;
dns_config_client_binding_.Bind(mojo::MakeRequest(&client_ptr));
dns_config_client_binding_.set_connection_error_handler(base::BindRepeating(
&IntranetRedirectDetector::OnDnsConfigClientConnectionError,
base::Unretained(this)));
DCHECK(!dns_config_client_receiver_.is_bound());
network::mojom::DnsConfigChangeManagerPtr manager_ptr;
content::GetNetworkService()->GetDnsConfigChangeManager(
mojo::MakeRequest(&manager_ptr));
manager_ptr->RequestNotifications(std::move(client_ptr));
manager_ptr->RequestNotifications(
dns_config_client_receiver_.BindNewPipeAndPassRemote());
dns_config_client_receiver_.set_disconnect_handler(base::BindRepeating(
&IntranetRedirectDetector::OnDnsConfigClientConnectionError,
base::Unretained(this)));
}
void IntranetRedirectDetector::OnDnsConfigClientConnectionError() {
dns_config_client_binding_.Close();
dns_config_client_receiver_.reset();
SetupDnsConfigClient();
}
......@@ -14,7 +14,7 @@
#include "base/memory/weak_ptr.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "url/gurl.h"
......@@ -90,8 +90,8 @@ class IntranetRedirectDetector
// period that begins at browser start, or the
// one-second "no fetching" period that begins after
// network switches.
mojo::Binding<network::mojom::DnsConfigChangeManagerClient>
dns_config_client_binding_{this};
mojo::Receiver<network::mojom::DnsConfigChangeManagerClient>
dns_config_client_receiver_{this};
base::WeakPtrFactory<IntranetRedirectDetector> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector);
......
......@@ -22,7 +22,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/dns/public/dns_protocol.h"
......@@ -169,7 +169,7 @@ class DnsProbeServiceImpl
NetworkContextGetter network_context_getter_;
DnsConfigChangeManagerGetter dns_config_change_manager_getter_;
mojo::Binding<network::mojom::DnsConfigChangeManagerClient> binding_;
mojo::Receiver<network::mojom::DnsConfigChangeManagerClient> receiver_{this};
// DnsProbeRunners for the system DNS configuration and a public DNS server.
DnsProbeRunner system_runner_;
DnsProbeRunner public_runner_;
......@@ -195,7 +195,6 @@ DnsProbeServiceImpl::DnsProbeServiceImpl(
: state_(STATE_NO_RESULT),
network_context_getter_(network_context_getter),
dns_config_change_manager_getter_(dns_config_change_manager_getter),
binding_(this),
system_runner_(SystemOverrides(), network_context_getter),
public_runner_(PublicOverrides(), network_context_getter),
tick_clock_(tick_clock) {
......@@ -315,13 +314,11 @@ bool DnsProbeServiceImpl::CachedResultIsExpired() const {
void DnsProbeServiceImpl::SetupDnsConfigChangeNotifications() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
network::mojom::DnsConfigChangeManagerClientPtr client_ptr;
binding_.Bind(mojo::MakeRequest(&client_ptr));
binding_.set_connection_error_handler(base::BindRepeating(
dns_config_change_manager_getter_.Run()->RequestNotifications(
receiver_.BindNewPipeAndPassRemote());
receiver_.set_disconnect_handler(base::BindRepeating(
&DnsProbeServiceImpl::OnDnsConfigChangeManagerConnectionError,
base::Unretained(this)));
dns_config_change_manager_getter_.Run()->RequestNotifications(
std::move(client_ptr));
}
void DnsProbeServiceImpl::OnDnsConfigChangeManagerConnectionError() {
......@@ -330,7 +327,7 @@ void DnsProbeServiceImpl::OnDnsConfigChangeManagerConnectionError() {
// getting notifications.
ClearCachedResult();
binding_.Close();
receiver_.reset();
SetupDnsConfigChangeNotifications();
}
......
......@@ -126,9 +126,9 @@ FakeDnsConfigChangeManager::FakeDnsConfigChangeManager(
FakeDnsConfigChangeManager::~FakeDnsConfigChangeManager() = default;
void FakeDnsConfigChangeManager::RequestNotifications(
network::mojom::DnsConfigChangeManagerClientPtr client) {
mojo::PendingRemote<network::mojom::DnsConfigChangeManagerClient> client) {
ASSERT_FALSE(client_);
client_ = std::move(client);
client_.Bind(std::move(client));
}
void FakeDnsConfigChangeManager::SimulateDnsConfigChange() {
......
......@@ -109,13 +109,14 @@ class FakeDnsConfigChangeManager
// mojom::DnsConfigChangeManager implementation:
void RequestNotifications(
network::mojom::DnsConfigChangeManagerClientPtr client) override;
mojo::PendingRemote<network::mojom::DnsConfigChangeManagerClient> client)
override;
void SimulateDnsConfigChange();
private:
mojo::Binding<network::mojom::DnsConfigChangeManager> binding_;
network::mojom::DnsConfigChangeManagerClientPtr client_;
mojo::Remote<network::mojom::DnsConfigChangeManagerClient> client_;
};
} // namespace chrome_browser_net
......
......@@ -22,14 +22,13 @@ void DnsConfigChangeManager::AddReceiver(
}
void DnsConfigChangeManager::RequestNotifications(
mojom::DnsConfigChangeManagerClientPtr client) {
clients_.AddPtr(std::move(client));
mojo::PendingRemote<mojom::DnsConfigChangeManagerClient> client) {
clients_.Add(std::move(client));
}
void DnsConfigChangeManager::OnDNSChanged() {
clients_.ForAllPtrs([](mojom::DnsConfigChangeManagerClient* client) {
for (const auto& client : clients_)
client->OnSystemDnsConfigChanged();
});
}
void DnsConfigChangeManager::OnInitialDNSConfigRead() {
......
......@@ -10,8 +10,9 @@
#include "base/component_export.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/base/network_change_notifier.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
......@@ -29,7 +30,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) DnsConfigChangeManager
// mojom::DnsConfigChangeManager implementation:
void RequestNotifications(
mojom::DnsConfigChangeManagerClientPtr client) override;
mojo::PendingRemote<mojom::DnsConfigChangeManagerClient> client) override;
private:
// net::NetworkChangeNotifier::DNSObserver implementation:
......@@ -37,7 +38,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) DnsConfigChangeManager
void OnInitialDNSConfigRead() override;
mojo::ReceiverSet<mojom::DnsConfigChangeManager> receivers_;
mojo::InterfacePtrSet<mojom::DnsConfigChangeManagerClient> clients_;
mojo::RemoteSet<mojom::DnsConfigChangeManagerClient> clients_;
DISALLOW_COPY_AND_ASSIGN(DnsConfigChangeManager);
};
......
......@@ -9,7 +9,7 @@
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace network {
......@@ -21,13 +21,7 @@ class TestDnsConfigChangeManagerClient
explicit TestDnsConfigChangeManagerClient(DnsConfigChangeManager* manager) {
mojo::Remote<mojom::DnsConfigChangeManager> manager_remote;
manager->AddReceiver(manager_remote.BindNewPipeAndPassReceiver());
mojom::DnsConfigChangeManagerClientPtr client_ptr;
mojom::DnsConfigChangeManagerClientRequest client_request(
mojo::MakeRequest(&client_ptr));
binding_.Bind(std::move(client_request));
manager_remote->RequestNotifications(std::move(client_ptr));
manager_remote->RequestNotifications(receiver_.BindNewPipeAndPassRemote());
}
void OnSystemDnsConfigChanged() override {
......@@ -48,7 +42,7 @@ class TestDnsConfigChangeManagerClient
int num_notifications_ = 0;
int num_notifications_expected_ = INT_MAX;
base::RunLoop run_loop_;
mojo::Binding<mojom::DnsConfigChangeManagerClient> binding_{this};
mojo::Receiver<mojom::DnsConfigChangeManagerClient> receiver_{this};
DISALLOW_COPY_AND_ASSIGN(TestDnsConfigChangeManagerClient);
};
......
......@@ -301,5 +301,5 @@ interface DnsConfigChangeManagerClient {
// An interface that broadcasts DNS config change events.
interface DnsConfigChangeManager {
// Requests to receive notification when there is a DNS config change.
RequestNotifications(DnsConfigChangeManagerClient client_ptr);
RequestNotifications(pending_remote<DnsConfigChangeManagerClient> client);
};
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