Commit ed8d98f2 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert ProxyLookupClient to new Mojo types

This CL converts ProxyLookupClient from proxy_lookup_client.mojom
to new Mojo types using PendingRemote, Receiver, and Remote.

Bug: 955171
Change-Id: I1765ac683cc567bb2a5d7d31dc3b983ec2a18741
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852527Reviewed-by: default avatarBill Budge <bbudge@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#705510}
parent 07f13c73
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "dbus/bus.h" #include "dbus/bus.h"
#include "dbus/message.h" #include "dbus/message.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -45,10 +46,10 @@ class ProxyLookupRequest : public network::mojom::ProxyLookupClient { ...@@ -45,10 +46,10 @@ class ProxyLookupRequest : public network::mojom::ProxyLookupClient {
network::mojom::NetworkContext* network_context, network::mojom::NetworkContext* network_context,
const GURL& source_url, const GURL& source_url,
ProxyResolutionServiceProvider::NotifyCallback notify_callback) ProxyResolutionServiceProvider::NotifyCallback notify_callback)
: binding_(this), notify_callback_(std::move(notify_callback)) { : notify_callback_(std::move(notify_callback)) {
network::mojom::ProxyLookupClientPtr proxy_lookup_client; mojo::PendingRemote<network::mojom::ProxyLookupClient> proxy_lookup_client =
binding_.Bind(mojo::MakeRequest(&proxy_lookup_client)); receiver_.BindNewPipeAndPassRemote();
binding_.set_connection_error_handler(base::BindOnce( receiver_.set_disconnect_handler(base::BindOnce(
&ProxyLookupRequest::OnProxyLookupComplete, base::Unretained(this), &ProxyLookupRequest::OnProxyLookupComplete, base::Unretained(this),
net::ERR_ABORTED, base::nullopt)); net::ERR_ABORTED, base::nullopt));
...@@ -73,13 +74,13 @@ class ProxyLookupRequest : public network::mojom::ProxyLookupClient { ...@@ -73,13 +74,13 @@ class ProxyLookupRequest : public network::mojom::ProxyLookupClient {
result = proxy_info->ToPacString(); result = proxy_info->ToPacString();
} }
binding_.Close(); receiver_.reset();
std::move(notify_callback_).Run(error, result); std::move(notify_callback_).Run(error, result);
delete this; delete this;
} }
private: private:
mojo::Binding<network::mojom::ProxyLookupClient> binding_; mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
ProxyResolutionServiceProvider::NotifyCallback notify_callback_; ProxyResolutionServiceProvider::NotifyCallback notify_callback_;
DISALLOW_COPY_AND_ASSIGN(ProxyLookupRequest); DISALLOW_COPY_AND_ASSIGN(ProxyLookupRequest);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "chromeos/dbus/services/service_provider_test_helper.h" #include "chromeos/dbus/services/service_provider_test_helper.h"
#include "dbus/message.h" #include "dbus/message.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
...@@ -43,14 +45,17 @@ class MockNetworkContext : public network::TestNetworkContext { ...@@ -43,14 +45,17 @@ class MockNetworkContext : public network::TestNetworkContext {
// network::mojom::NetworkContext implementation: // network::mojom::NetworkContext implementation:
void LookUpProxyForURL( void LookUpProxyForURL(
const GURL& url, const GURL& url,
::network::mojom::ProxyLookupClientPtr proxy_lookup_client) override { mojo::PendingRemote<::network::mojom::ProxyLookupClient>
proxy_lookup_client) override {
mojo::Remote<::network::mojom::ProxyLookupClient>
proxy_lookup_client_remote(std::move(proxy_lookup_client));
if (lookup_proxy_result_.error == net::OK) { if (lookup_proxy_result_.error == net::OK) {
net::ProxyInfo proxy_info; net::ProxyInfo proxy_info;
proxy_info.UsePacString(lookup_proxy_result_.proxy_info_pac_string); proxy_info.UsePacString(lookup_proxy_result_.proxy_info_pac_string);
proxy_lookup_client->OnProxyLookupComplete(net::OK, proxy_info); proxy_lookup_client_remote->OnProxyLookupComplete(net::OK, proxy_info);
} else { } else {
proxy_lookup_client->OnProxyLookupComplete(lookup_proxy_result_.error, proxy_lookup_client_remote->OnProxyLookupComplete(
base::nullopt); lookup_proxy_result_.error, base::nullopt);
} }
} }
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "chrome/browser/predictors/resolve_host_client_impl.h" #include "chrome/browser/predictors/resolve_host_client_impl.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/base/network_isolation_key.h" #include "net/base/network_isolation_key.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
...@@ -79,9 +81,9 @@ class MockNetworkContext : public network::TestNetworkContext { ...@@ -79,9 +81,9 @@ class MockNetworkContext : public network::TestNetworkContext {
ResolveHostProxy(host); ResolveHostProxy(host);
} }
void LookUpProxyForURL( void LookUpProxyForURL(const GURL& url,
const GURL& url, mojo::PendingRemote<network::mojom::ProxyLookupClient>
network::mojom::ProxyLookupClientPtr proxy_lookup_client) override { proxy_lookup_client) override {
EXPECT_TRUE( EXPECT_TRUE(
proxy_lookup_clients_.emplace(url, std::move(proxy_lookup_client)) proxy_lookup_clients_.emplace(url, std::move(proxy_lookup_client))
.second); .second);
...@@ -146,7 +148,8 @@ class MockNetworkContext : public network::TestNetworkContext { ...@@ -146,7 +148,8 @@ class MockNetworkContext : public network::TestNetworkContext {
std::map<std::string, network::mojom::ResolveHostClientPtr> std::map<std::string, network::mojom::ResolveHostClientPtr>
resolve_host_clients_; resolve_host_clients_;
std::map<GURL, network::mojom::ProxyLookupClientPtr> proxy_lookup_clients_; std::map<GURL, mojo::Remote<network::mojom::ProxyLookupClient>>
proxy_lookup_clients_;
bool enabled_proxy_testing_ = false; bool enabled_proxy_testing_ = false;
std::vector<std::string> hanging_hosts_; std::vector<std::string> hanging_hosts_;
}; };
......
...@@ -21,15 +21,14 @@ ProxyLookupClientImpl::ProxyLookupClientImpl( ...@@ -21,15 +21,14 @@ ProxyLookupClientImpl::ProxyLookupClientImpl(
const GURL& url, const GURL& url,
ProxyLookupCallback callback, ProxyLookupCallback callback,
network::mojom::NetworkContext* network_context) network::mojom::NetworkContext* network_context)
: binding_(this), callback_(std::move(callback)) { : callback_(std::move(callback)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
network::mojom::ProxyLookupClientPtr proxy_lookup_client_ptr; network_context->LookUpProxyForURL(
binding_.Bind( url,
mojo::MakeRequest(&proxy_lookup_client_ptr), receiver_.BindNewPipeAndPassRemote(base::CreateSingleThreadTaskRunner(
base::CreateSingleThreadTaskRunner( {content::BrowserThread::UI,
{content::BrowserThread::UI, content::BrowserTaskType::kPreconnect})); content::BrowserTaskType::kPreconnect})));
network_context->LookUpProxyForURL(url, std::move(proxy_lookup_client_ptr)); receiver_.set_disconnect_handler(
binding_.set_connection_error_handler(
base::BindOnce(&ProxyLookupClientImpl::OnProxyLookupComplete, base::BindOnce(&ProxyLookupClientImpl::OnProxyLookupComplete,
base::Unretained(this), net::ERR_ABORTED, base::nullopt)); base::Unretained(this), net::ERR_ABORTED, base::nullopt));
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h" #include "services/network/public/mojom/proxy_lookup_client.mojom.h"
class GURL; class GURL;
...@@ -41,7 +41,7 @@ class ProxyLookupClientImpl : public network::mojom::ProxyLookupClient { ...@@ -41,7 +41,7 @@ class ProxyLookupClientImpl : public network::mojom::ProxyLookupClient {
const base::Optional<net::ProxyInfo>& proxy_info) override; const base::Optional<net::ProxyInfo>& proxy_info) override;
private: private:
mojo::Binding<network::mojom::ProxyLookupClient> binding_; mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
ProxyLookupCallback callback_; ProxyLookupCallback callback_;
DISALLOW_COPY_AND_ASSIGN(ProxyLookupClientImpl); DISALLOW_COPY_AND_ASSIGN(ProxyLookupClientImpl);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/common/socket_permission_request.h" #include "content/public/common/socket_permission_request.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/host/dispatch_host_message.h" #include "ppapi/host/dispatch_host_message.h"
...@@ -33,7 +34,8 @@ bool LookUpProxyForURLCallback( ...@@ -33,7 +34,8 @@ bool LookUpProxyForURLCallback(
int render_process_host_id, int render_process_host_id,
int render_frame_host_id, int render_frame_host_id,
const GURL& url, const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client) { mojo::PendingRemote<network::mojom::ProxyLookupClient>
proxy_lookup_client) {
RenderFrameHost* render_frame_host = RenderFrameHost* render_frame_host =
RenderFrameHost::FromID(render_process_host_id, render_frame_host_id); RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
if (!render_frame_host) if (!render_frame_host)
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -29,8 +28,7 @@ class PepperProxyLookupHelper::UIThreadHelper ...@@ -29,8 +28,7 @@ class PepperProxyLookupHelper::UIThreadHelper
UIThreadHelper(const GURL& url, UIThreadHelper(const GURL& url,
LookUpProxyForURLCallback look_up_proxy_for_url_callback, LookUpProxyForURLCallback look_up_proxy_for_url_callback,
LookUpCompleteCallback look_up_complete_callback) LookUpCompleteCallback look_up_complete_callback)
: binding_(this), : look_up_complete_callback_(std::move(look_up_complete_callback)),
look_up_complete_callback_(std::move(look_up_complete_callback)),
callback_task_runner_(base::SequencedTaskRunnerHandle::Get()) { callback_task_runner_(base::SequencedTaskRunnerHandle::Get()) {
base::PostTask( base::PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, {BrowserThread::UI},
...@@ -45,9 +43,9 @@ class PepperProxyLookupHelper::UIThreadHelper ...@@ -45,9 +43,9 @@ class PepperProxyLookupHelper::UIThreadHelper
LookUpProxyForURLCallback look_up_proxy_for_url_callback) { LookUpProxyForURLCallback look_up_proxy_for_url_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
network::mojom::ProxyLookupClientPtr proxy_lookup_client; mojo::PendingRemote<network::mojom::ProxyLookupClient> proxy_lookup_client =
binding_.Bind(mojo::MakeRequest(&proxy_lookup_client)); receiver_.BindNewPipeAndPassRemote();
binding_.set_connection_error_handler(base::BindOnce( receiver_.set_disconnect_handler(base::BindOnce(
&UIThreadHelper::OnProxyLookupComplete, base::Unretained(this), &UIThreadHelper::OnProxyLookupComplete, base::Unretained(this),
net::ERR_ABORTED, base::nullopt)); net::ERR_ABORTED, base::nullopt));
if (!std::move(look_up_proxy_for_url_callback) if (!std::move(look_up_proxy_for_url_callback)
...@@ -61,13 +59,13 @@ class PepperProxyLookupHelper::UIThreadHelper ...@@ -61,13 +59,13 @@ class PepperProxyLookupHelper::UIThreadHelper
const base::Optional<net::ProxyInfo>& proxy_info) override { const base::Optional<net::ProxyInfo>& proxy_info) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
binding_.Close(); receiver_.reset();
callback_task_runner_->PostTask( callback_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(look_up_complete_callback_), proxy_info)); base::BindOnce(std::move(look_up_complete_callback_), proxy_info));
} }
mojo::Binding<network::mojom::ProxyLookupClient> binding_; mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
LookUpCompleteCallback look_up_complete_callback_; LookUpCompleteCallback look_up_complete_callback_;
scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; scoped_refptr<base::SequencedTaskRunner> callback_task_runner_;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h" #include "services/network/public/mojom/proxy_lookup_client.mojom.h"
class GURL; class GURL;
...@@ -32,7 +33,8 @@ class CONTENT_EXPORT PepperProxyLookupHelper { ...@@ -32,7 +33,8 @@ class CONTENT_EXPORT PepperProxyLookupHelper {
// testing. Returns false if unable to make the call, for whatever reason. // testing. Returns false if unable to make the call, for whatever reason.
using LookUpProxyForURLCallback = base::OnceCallback<bool( using LookUpProxyForURLCallback = base::OnceCallback<bool(
const GURL& url, const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client)>; mojo::PendingRemote<network::mojom::ProxyLookupClient>
proxy_lookup_client)>;
// Callback to invoke when complete. Invoked on thread the // Callback to invoke when complete. Invoked on thread the
// PepperProxyLookupHelper was created on. // PepperProxyLookupHelper was created on.
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h" #include "services/network/public/mojom/proxy_lookup_client.mojom.h"
...@@ -51,10 +52,10 @@ class PepperProxyLookupHelperTest : public testing::Test { ...@@ -51,10 +52,10 @@ class PepperProxyLookupHelperTest : public testing::Test {
EXPECT_TRUE(proxy_lookup_client_); EXPECT_TRUE(proxy_lookup_client_);
} }
// Takes the |ProxyLookupClientPtr| passed by |lookup_helper_| to // Takes the |mojo::Remote<ProxyLookupClient>| passed by |lookup_helper_| to
// LookUpProxyForURLOnUIThread(). May only be called after |lookup_helper_| // LookUpProxyForURLOnUIThread(). May only be called after |lookup_helper_|
// has successfully called into LookUpProxyForURLOnUIThread(). // has successfully called into LookUpProxyForURLOnUIThread().
network::mojom::ProxyLookupClientPtr ClaimProxyLookupClient() { mojo::Remote<network::mojom::ProxyLookupClient> ClaimProxyLookupClient() {
EXPECT_TRUE(proxy_lookup_client_); EXPECT_TRUE(proxy_lookup_client_);
return std::move(proxy_lookup_client_); return std::move(proxy_lookup_client_);
} }
...@@ -112,7 +113,8 @@ class PepperProxyLookupHelperTest : public testing::Test { ...@@ -112,7 +113,8 @@ class PepperProxyLookupHelperTest : public testing::Test {
bool LookUpProxyForURLOnUIThread( bool LookUpProxyForURLOnUIThread(
base::OnceClosure closure, base::OnceClosure closure,
const GURL& url, const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client) { mojo::PendingRemote<network::mojom::ProxyLookupClient>
proxy_lookup_client) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::move(closure).Run(); std::move(closure).Run();
...@@ -121,7 +123,7 @@ class PepperProxyLookupHelperTest : public testing::Test { ...@@ -121,7 +123,7 @@ class PepperProxyLookupHelperTest : public testing::Test {
return false; return false;
EXPECT_EQ(GURL(kTestURL), url); EXPECT_EQ(GURL(kTestURL), url);
proxy_lookup_client_ = std::move(proxy_lookup_client); proxy_lookup_client_.Bind(std::move(proxy_lookup_client));
return true; return true;
} }
...@@ -147,7 +149,7 @@ class PepperProxyLookupHelperTest : public testing::Test { ...@@ -147,7 +149,7 @@ class PepperProxyLookupHelperTest : public testing::Test {
std::unique_ptr<PepperProxyLookupHelper> lookup_helper_; std::unique_ptr<PepperProxyLookupHelper> lookup_helper_;
base::Optional<net::ProxyInfo> proxy_info_; base::Optional<net::ProxyInfo> proxy_info_;
network::mojom::ProxyLookupClientPtr proxy_lookup_client_; mojo::Remote<network::mojom::ProxyLookupClient> proxy_lookup_client_;
base::RunLoop lookup_complete_run_loop_; base::RunLoop lookup_complete_run_loop_;
}; };
...@@ -196,9 +198,9 @@ TEST_F(PepperProxyLookupHelperTest, FailToStartRequest) { ...@@ -196,9 +198,9 @@ TEST_F(PepperProxyLookupHelperTest, FailToStartRequest) {
TEST_F(PepperProxyLookupHelperTest, DestroyBeforeComplete) { TEST_F(PepperProxyLookupHelperTest, DestroyBeforeComplete) {
StartLookup(); StartLookup();
base::RunLoop run_loop; base::RunLoop run_loop;
network::mojom::ProxyLookupClientPtr proxy_lookup_client = mojo::Remote<network::mojom::ProxyLookupClient> proxy_lookup_client =
ClaimProxyLookupClient(); ClaimProxyLookupClient();
proxy_lookup_client.set_connection_error_handler(run_loop.QuitClosure()); proxy_lookup_client.set_disconnect_handler(run_loop.QuitClosure());
DestroyLookupHelper(); DestroyLookupHelper();
run_loop.Run(); run_loop.Run();
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
...@@ -18,8 +17,7 @@ namespace content { ...@@ -18,8 +17,7 @@ namespace content {
ResolveProxyMsgHelper::ResolveProxyMsgHelper(int render_process_host_id) ResolveProxyMsgHelper::ResolveProxyMsgHelper(int render_process_host_id)
: BrowserMessageFilter(ViewMsgStart), : BrowserMessageFilter(ViewMsgStart),
render_process_host_id_(render_process_host_id), render_process_host_id_(render_process_host_id) {}
binding_(this) {}
void ResolveProxyMsgHelper::OverrideThreadForMessage( void ResolveProxyMsgHelper::OverrideThreadForMessage(
const IPC::Message& message, const IPC::Message& message,
...@@ -45,7 +43,7 @@ void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url, ...@@ -45,7 +43,7 @@ void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url,
pending_requests_.push_back(PendingRequest(url, reply_msg)); pending_requests_.push_back(PendingRequest(url, reply_msg));
// If nothing is in progress, start. // If nothing is in progress, start.
if (!binding_.is_bound()) { if (!receiver_.is_bound()) {
DCHECK_EQ(1u, pending_requests_.size()); DCHECK_EQ(1u, pending_requests_.size());
StartPendingRequest(); StartPendingRequest();
} }
...@@ -53,18 +51,18 @@ void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url, ...@@ -53,18 +51,18 @@ void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url,
ResolveProxyMsgHelper::~ResolveProxyMsgHelper() { ResolveProxyMsgHelper::~ResolveProxyMsgHelper() {
DCHECK(!owned_self_); DCHECK(!owned_self_);
DCHECK(!binding_.is_bound()); DCHECK(!receiver_.is_bound());
} }
void ResolveProxyMsgHelper::StartPendingRequest() { void ResolveProxyMsgHelper::StartPendingRequest() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!binding_.is_bound()); DCHECK(!receiver_.is_bound());
DCHECK(!pending_requests_.empty()); DCHECK(!pending_requests_.empty());
// Start the request. // Start the request.
network::mojom::ProxyLookupClientPtr proxy_lookup_client; mojo::PendingRemote<network::mojom::ProxyLookupClient> proxy_lookup_client =
binding_.Bind(mojo::MakeRequest(&proxy_lookup_client)); receiver_.BindNewPipeAndPassRemote();
binding_.set_connection_error_handler( receiver_.set_disconnect_handler(
base::BindOnce(&ResolveProxyMsgHelper::OnProxyLookupComplete, base::BindOnce(&ResolveProxyMsgHelper::OnProxyLookupComplete,
base::Unretained(this), net::ERR_ABORTED, base::nullopt)); base::Unretained(this), net::ERR_ABORTED, base::nullopt));
owned_self_ = this; owned_self_ = this;
...@@ -76,7 +74,8 @@ void ResolveProxyMsgHelper::StartPendingRequest() { ...@@ -76,7 +74,8 @@ void ResolveProxyMsgHelper::StartPendingRequest() {
bool ResolveProxyMsgHelper::SendRequestToNetworkService( bool ResolveProxyMsgHelper::SendRequestToNetworkService(
const GURL& url, const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client) { mojo::PendingRemote<network::mojom::ProxyLookupClient>
proxy_lookup_client) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderProcessHost* render_process_host = RenderProcessHost* render_process_host =
...@@ -96,7 +95,7 @@ void ResolveProxyMsgHelper::OnProxyLookupComplete( ...@@ -96,7 +95,7 @@ void ResolveProxyMsgHelper::OnProxyLookupComplete(
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!pending_requests_.empty()); DCHECK(!pending_requests_.empty());
binding_.Close(); receiver_.reset();
// Need to keep |this| alive until the end of this method, and then release // Need to keep |this| alive until the end of this method, and then release
// this reference. StartPendingRequest(), if called, will grab other // this reference. StartPendingRequest(), if called, will grab other
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
#include "base/sequenced_task_runner_helpers.h" #include "base/sequenced_task_runner_helpers.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/browser_message_filter.h" #include "content/public/browser/browser_message_filter.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h" #include "services/network/public/mojom/proxy_lookup_client.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -65,7 +66,8 @@ class CONTENT_EXPORT ResolveProxyMsgHelper : public BrowserMessageFilter, ...@@ -65,7 +66,8 @@ class CONTENT_EXPORT ResolveProxyMsgHelper : public BrowserMessageFilter,
// to the RenderProcessHost no longer existing. // to the RenderProcessHost no longer existing.
virtual bool SendRequestToNetworkService( virtual bool SendRequestToNetworkService(
const GURL& url, const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client); mojo::PendingRemote<network::mojom::ProxyLookupClient>
proxy_lookup_client);
// network::mojom::ProxyLookupClient implementation. // network::mojom::ProxyLookupClient implementation.
void OnProxyLookupComplete( void OnProxyLookupComplete(
...@@ -99,12 +101,12 @@ class CONTENT_EXPORT ResolveProxyMsgHelper : public BrowserMessageFilter, ...@@ -99,12 +101,12 @@ class CONTENT_EXPORT ResolveProxyMsgHelper : public BrowserMessageFilter,
// Self-reference. Owned as long as there's an outstanding proxy lookup. // Self-reference. Owned as long as there's an outstanding proxy lookup.
// Needed to shut down safely, since this class is refcounted, with some // Needed to shut down safely, since this class is refcounted, with some
// references owned on multiple threads, while |binding_| lives on the UI // references owned on multiple threads, while |receiver_| lives on the UI
// thread, and may receive callbacks there whenever there's a pending request. // thread, and may receive callbacks there whenever there's a pending request.
scoped_refptr<ResolveProxyMsgHelper> owned_self_; scoped_refptr<ResolveProxyMsgHelper> owned_self_;
// Binding for the currently in-progress request, if any. // Receiver for the currently in-progress request, if any.
mojo::Binding<network::mojom::ProxyLookupClient> binding_; mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
DISALLOW_COPY_AND_ASSIGN(ResolveProxyMsgHelper); DISALLOW_COPY_AND_ASSIGN(ResolveProxyMsgHelper);
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "ipc/ipc_test_sink.h" #include "ipc/ipc_test_sink.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
...@@ -21,10 +22,11 @@ namespace content { ...@@ -21,10 +22,11 @@ namespace content {
class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper { class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper {
public: public:
// Incoming ProxyLookupClientPtrs are written to |proxy_lookup_client|. // Incoming mojo::Remote<ProxyLookupClient>s are written to
// |proxy_lookup_client|.
explicit TestResolveProxyMsgHelper( explicit TestResolveProxyMsgHelper(
IPC::Listener* listener, IPC::Listener* listener,
network::mojom::ProxyLookupClientPtr* proxy_lookup_client) mojo::Remote<network::mojom::ProxyLookupClient>* proxy_lookup_client)
: ResolveProxyMsgHelper(0 /* renderer_process_host_id */), : ResolveProxyMsgHelper(0 /* renderer_process_host_id */),
listener_(listener), listener_(listener),
proxy_lookup_client_(proxy_lookup_client) {} proxy_lookup_client_(proxy_lookup_client) {}
...@@ -40,7 +42,8 @@ class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper { ...@@ -40,7 +42,8 @@ class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper {
bool SendRequestToNetworkService( bool SendRequestToNetworkService(
const GURL& url, const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client) override { mojo::PendingRemote<network::mojom::ProxyLookupClient>
proxy_lookup_client) override {
// Only one request should be send at a time. // Only one request should be send at a time.
EXPECT_FALSE(*proxy_lookup_client_); EXPECT_FALSE(*proxy_lookup_client_);
...@@ -48,7 +51,7 @@ class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper { ...@@ -48,7 +51,7 @@ class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper {
return false; return false;
pending_url_ = url; pending_url_ = url;
*proxy_lookup_client_ = std::move(proxy_lookup_client); proxy_lookup_client_->Bind(std::move(proxy_lookup_client));
return true; return true;
} }
...@@ -65,7 +68,7 @@ class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper { ...@@ -65,7 +68,7 @@ class TestResolveProxyMsgHelper : public ResolveProxyMsgHelper {
bool fail_to_send_request_ = false; bool fail_to_send_request_ = false;
network::mojom::ProxyLookupClientPtr* proxy_lookup_client_; mojo::Remote<network::mojom::ProxyLookupClient>* proxy_lookup_client_;
GURL pending_url_; GURL pending_url_;
DISALLOW_COPY_AND_ASSIGN(TestResolveProxyMsgHelper); DISALLOW_COPY_AND_ASSIGN(TestResolveProxyMsgHelper);
...@@ -119,7 +122,7 @@ class ResolveProxyMsgHelperTest : public testing::Test, public IPC::Listener { ...@@ -119,7 +122,7 @@ class ResolveProxyMsgHelperTest : public testing::Test, public IPC::Listener {
scoped_refptr<TestResolveProxyMsgHelper> helper_; scoped_refptr<TestResolveProxyMsgHelper> helper_;
std::unique_ptr<PendingResult> pending_result_; std::unique_ptr<PendingResult> pending_result_;
network::mojom::ProxyLookupClientPtr proxy_lookup_client_; mojo::Remote<network::mojom::ProxyLookupClient> proxy_lookup_client_;
IPC::TestSink test_sink_; IPC::TestSink test_sink_;
}; };
...@@ -265,7 +268,7 @@ TEST_F(ResolveProxyMsgHelperTest, CancelPendingRequests) { ...@@ -265,7 +268,7 @@ TEST_F(ResolveProxyMsgHelperTest, CancelPendingRequests) {
helper_ = nullptr; helper_ = nullptr;
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(proxy_lookup_client_.is_bound()); EXPECT_TRUE(proxy_lookup_client_.is_bound());
EXPECT_FALSE(proxy_lookup_client_.encountered_error()); EXPECT_FALSE(!proxy_lookup_client_.is_connected());
// Send Mojo message on the pipe. // Send Mojo message on the pipe.
net::ProxyInfo proxy_info; net::ProxyInfo proxy_info;
...@@ -276,7 +279,7 @@ TEST_F(ResolveProxyMsgHelperTest, CancelPendingRequests) { ...@@ -276,7 +279,7 @@ TEST_F(ResolveProxyMsgHelperTest, CancelPendingRequests) {
// the pipe. // the pipe.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(!proxy_lookup_client_.is_bound() || EXPECT_TRUE(!proxy_lookup_client_.is_bound() ||
proxy_lookup_client_.encountered_error()); !proxy_lookup_client_.is_connected());
// The result should not have been sent. // The result should not have been sent.
EXPECT_FALSE(pending_result()); EXPECT_FALSE(pending_result());
...@@ -366,7 +369,7 @@ TEST_F(ResolveProxyMsgHelperTest, Lifetime) { ...@@ -366,7 +369,7 @@ TEST_F(ResolveProxyMsgHelperTest, Lifetime) {
helper_ = nullptr; helper_ = nullptr;
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(proxy_lookup_client_.is_bound()); EXPECT_TRUE(proxy_lookup_client_.is_bound());
EXPECT_FALSE(proxy_lookup_client_.encountered_error()); EXPECT_FALSE(!proxy_lookup_client_.is_connected());
// Send Mojo message on the pipe. // Send Mojo message on the pipe.
net::ProxyInfo proxy_info; net::ProxyInfo proxy_info;
...@@ -377,7 +380,7 @@ TEST_F(ResolveProxyMsgHelperTest, Lifetime) { ...@@ -377,7 +380,7 @@ TEST_F(ResolveProxyMsgHelperTest, Lifetime) {
// the pipe. // the pipe.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(!proxy_lookup_client_.is_bound() || EXPECT_TRUE(!proxy_lookup_client_.is_bound() ||
proxy_lookup_client_.encountered_error()); !proxy_lookup_client_.is_connected());
// The result should not have been sent. // The result should not have been sent.
EXPECT_FALSE(pending_result()); EXPECT_FALSE(pending_result());
} }
......
...@@ -1053,7 +1053,7 @@ void NetworkContext::CreateProxyResolvingSocketFactory( ...@@ -1053,7 +1053,7 @@ void NetworkContext::CreateProxyResolvingSocketFactory(
void NetworkContext::LookUpProxyForURL( void NetworkContext::LookUpProxyForURL(
const GURL& url, const GURL& url,
mojom::ProxyLookupClientPtr proxy_lookup_client) { mojo::PendingRemote<mojom::ProxyLookupClient> proxy_lookup_client) {
DCHECK(proxy_lookup_client); DCHECK(proxy_lookup_client);
std::unique_ptr<ProxyLookupRequest> proxy_lookup_request( std::unique_ptr<ProxyLookupRequest> proxy_lookup_request(
std::make_unique<ProxyLookupRequest>(std::move(proxy_lookup_client), std::make_unique<ProxyLookupRequest>(std::move(proxy_lookup_client),
......
...@@ -268,9 +268,9 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext ...@@ -268,9 +268,9 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkContext
CreateTCPBoundSocketCallback callback) override; CreateTCPBoundSocketCallback callback) override;
void CreateProxyResolvingSocketFactory( void CreateProxyResolvingSocketFactory(
mojom::ProxyResolvingSocketFactoryRequest request) override; mojom::ProxyResolvingSocketFactoryRequest request) override;
void LookUpProxyForURL( void LookUpProxyForURL(const GURL& url,
const GURL& url, mojo::PendingRemote<mojom::ProxyLookupClient>
mojom::ProxyLookupClientPtr proxy_lookup_client) override; proxy_lookup_client) override;
void ForceReloadProxyConfig(ForceReloadProxyConfigCallback callback) override; void ForceReloadProxyConfig(ForceReloadProxyConfigCallback callback) override;
void ClearBadProxiesCache(ClearBadProxiesCacheCallback callback) override; void ClearBadProxiesCache(ClearBadProxiesCacheCallback callback) override;
void CreateWebSocket( void CreateWebSocket(
......
...@@ -306,17 +306,16 @@ std::unique_ptr<net::test_server::HttpResponse> CustomProxyResponse( ...@@ -306,17 +306,16 @@ std::unique_ptr<net::test_server::HttpResponse> CustomProxyResponse(
// be received. // be received.
class TestProxyLookupClient : public mojom::ProxyLookupClient { class TestProxyLookupClient : public mojom::ProxyLookupClient {
public: public:
TestProxyLookupClient() : binding_(this) {} TestProxyLookupClient() = default;
~TestProxyLookupClient() override = default; ~TestProxyLookupClient() override = default;
void StartLookUpProxyForURL(const GURL& url, void StartLookUpProxyForURL(const GURL& url,
mojom::NetworkContext* network_context) { mojom::NetworkContext* network_context) {
// Make sure this method is called at most once. // Make sure this method is called at most once.
EXPECT_FALSE(binding_.is_bound()); EXPECT_FALSE(receiver_.is_bound());
mojom::ProxyLookupClientPtr proxy_lookup_client; network_context->LookUpProxyForURL(url,
binding_.Bind(mojo::MakeRequest(&proxy_lookup_client)); receiver_.BindNewPipeAndPassRemote());
network_context->LookUpProxyForURL(url, std::move(proxy_lookup_client));
} }
void WaitForResult() { run_loop_.Run(); } void WaitForResult() { run_loop_.Run(); }
...@@ -333,7 +332,7 @@ class TestProxyLookupClient : public mojom::ProxyLookupClient { ...@@ -333,7 +332,7 @@ class TestProxyLookupClient : public mojom::ProxyLookupClient {
is_done_ = true; is_done_ = true;
proxy_info_ = proxy_info; proxy_info_ = proxy_info;
net_error_ = net_error; net_error_ = net_error;
binding_.Close(); receiver_.reset();
run_loop_.Quit(); run_loop_.Quit();
} }
...@@ -345,7 +344,7 @@ class TestProxyLookupClient : public mojom::ProxyLookupClient { ...@@ -345,7 +344,7 @@ class TestProxyLookupClient : public mojom::ProxyLookupClient {
bool is_done() const { return is_done_; } bool is_done() const { return is_done_; }
private: private:
mojo::Binding<mojom::ProxyLookupClient> binding_; mojo::Receiver<mojom::ProxyLookupClient> receiver_{this};
bool is_done_ = false; bool is_done_ = false;
base::Optional<net::ProxyInfo> proxy_info_; base::Optional<net::ProxyInfo> proxy_info_;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
namespace network { namespace network {
ProxyLookupRequest::ProxyLookupRequest( ProxyLookupRequest::ProxyLookupRequest(
mojom::ProxyLookupClientPtr proxy_lookup_client, mojo::PendingRemote<mojom::ProxyLookupClient> proxy_lookup_client,
NetworkContext* network_context) NetworkContext* network_context)
: network_context_(network_context), : network_context_(network_context),
proxy_lookup_client_(std::move(proxy_lookup_client)) { proxy_lookup_client_(std::move(proxy_lookup_client)) {
...@@ -36,7 +36,7 @@ ProxyLookupRequest::~ProxyLookupRequest() { ...@@ -36,7 +36,7 @@ ProxyLookupRequest::~ProxyLookupRequest() {
} }
void ProxyLookupRequest::Start(const GURL& url) { void ProxyLookupRequest::Start(const GURL& url) {
proxy_lookup_client_.set_connection_error_handler( proxy_lookup_client_.set_disconnect_handler(
base::BindOnce(&ProxyLookupRequest::DestroySelf, base::Unretained(this))); base::BindOnce(&ProxyLookupRequest::DestroySelf, base::Unretained(this)));
// TODO(mmenke): The NetLogWithSource() means nothing is logged. Fix that. // TODO(mmenke): The NetLogWithSource() means nothing is logged. Fix that.
int result = int result =
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_info.h"
#include "net/proxy_resolution/proxy_resolution_service.h" #include "net/proxy_resolution/proxy_resolution_service.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h" #include "services/network/public/mojom/proxy_lookup_client.mojom.h"
...@@ -23,8 +25,9 @@ class NetworkContext; ...@@ -23,8 +25,9 @@ class NetworkContext;
// Single-use object to manage a proxy lookup. // Single-use object to manage a proxy lookup.
class COMPONENT_EXPORT(NETWORK_SERVICE) ProxyLookupRequest { class COMPONENT_EXPORT(NETWORK_SERVICE) ProxyLookupRequest {
public: public:
ProxyLookupRequest(mojom::ProxyLookupClientPtr proxy_lookup_client, ProxyLookupRequest(
NetworkContext* network_context); mojo::PendingRemote<mojom::ProxyLookupClient> proxy_lookup_client,
NetworkContext* network_context);
~ProxyLookupRequest(); ~ProxyLookupRequest();
// Starts looking up what proxy to use for |url|. On completion, will inform // Starts looking up what proxy to use for |url|. On completion, will inform
...@@ -41,7 +44,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) ProxyLookupRequest { ...@@ -41,7 +44,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) ProxyLookupRequest {
void DestroySelf(); void DestroySelf();
NetworkContext* const network_context_; NetworkContext* const network_context_;
mojom::ProxyLookupClientPtr proxy_lookup_client_; mojo::Remote<mojom::ProxyLookupClient> proxy_lookup_client_;
net::ProxyInfo proxy_info_; net::ProxyInfo proxy_info_;
std::unique_ptr<net::ProxyResolutionService::Request> request_; std::unique_ptr<net::ProxyResolutionService::Request> request_;
......
...@@ -1012,7 +1012,7 @@ interface NetworkContext { ...@@ -1012,7 +1012,7 @@ interface NetworkContext {
// Looks up what proxy to use for a particular URL. // Looks up what proxy to use for a particular URL.
LookUpProxyForURL(url.mojom.Url url, LookUpProxyForURL(url.mojom.Url url,
ProxyLookupClient proxy_lookup_client); pending_remote<ProxyLookupClient> proxy_lookup_client);
// Forces refetching the proxy configuration, and applying it. // Forces refetching the proxy configuration, and applying it.
ForceReloadProxyConfig() => (); ForceReloadProxyConfig() => ();
......
...@@ -159,7 +159,8 @@ class TestNetworkContext : public mojom::NetworkContext { ...@@ -159,7 +159,8 @@ class TestNetworkContext : public mojom::NetworkContext {
mojo::PendingRemote<mojom::TrustedHeaderClient> header_client) override {} mojo::PendingRemote<mojom::TrustedHeaderClient> header_client) override {}
void LookUpProxyForURL( void LookUpProxyForURL(
const GURL& url, const GURL& url,
::network::mojom::ProxyLookupClientPtr proxy_lookup_client) override {} mojo::PendingRemote<::network::mojom::ProxyLookupClient>
proxy_lookup_client) override {}
void CreateNetLogExporter( void CreateNetLogExporter(
mojo::PendingReceiver<mojom::NetLogExporter> receiver) override {} mojo::PendingReceiver<mojom::NetLogExporter> receiver) override {}
void ResolveHost(const net::HostPortPair& host, void ResolveHost(const net::HostPortPair& host,
......
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