Commit 7d757688 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Make PrivetTrafficDetector::CreateUDPSocketOnUIThread() standalone.

Split CreateUDPSocketOnUIThread() into a standalone function so less of
PrivetTrafficDetector lives on the UI thread.

Change-Id: Ide58478bb235d9c1da72fccd6b86da35cd3997af
Reviewed-on: https://chromium-review.googlesource.com/1177443
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarRobbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583740}
parent f6c2880c
...@@ -55,6 +55,17 @@ void GetNetworkListInBackground( ...@@ -55,6 +55,17 @@ void GetNetworkListInBackground(
base::BindOnce(std::move(callback), std::move(ip4_networks))); base::BindOnce(std::move(callback), std::move(ip4_networks)));
} }
void CreateUDPSocketOnUIThread(
content::BrowserContext* profile,
network::mojom::UDPSocketRequest request,
network::mojom::UDPSocketReceiverPtr receiver_ptr) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
network::mojom::NetworkContext* network_context =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetNetworkContext();
network_context->CreateUDPSocket(std::move(request), std::move(receiver_ptr));
}
} // namespace } // namespace
namespace cloud_print { namespace cloud_print {
...@@ -129,7 +140,7 @@ void PrivetTrafficDetector::Bind() { ...@@ -129,7 +140,7 @@ void PrivetTrafficDetector::Bind() {
receiver_binding_.Bind(std::move(receiver_request)); receiver_binding_.Bind(std::move(receiver_request));
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&PrivetTrafficDetector::CreateUDPSocketOnUIThread, this, base::BindOnce(&CreateUDPSocketOnUIThread, profile_,
mojo::MakeRequest(&socket_), std::move(receiver_ptr))); mojo::MakeRequest(&socket_), std::move(receiver_ptr)));
net::IPEndPoint multicast_addr = net::IPEndPoint multicast_addr =
...@@ -148,16 +159,6 @@ void PrivetTrafficDetector::Bind() { ...@@ -148,16 +159,6 @@ void PrivetTrafficDetector::Bind() {
multicast_addr)); multicast_addr));
} }
void PrivetTrafficDetector::CreateUDPSocketOnUIThread(
network::mojom::UDPSocketRequest request,
network::mojom::UDPSocketReceiverPtr receiver_ptr) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
network::mojom::NetworkContext* network_context =
content::BrowserContext::GetDefaultStoragePartition(profile_)
->GetNetworkContext();
network_context->CreateUDPSocket(std::move(request), std::move(receiver_ptr));
}
void PrivetTrafficDetector::OnBindComplete( void PrivetTrafficDetector::OnBindComplete(
net::IPEndPoint multicast_addr, net::IPEndPoint multicast_addr,
int rv, int rv,
......
...@@ -55,12 +55,6 @@ class PrivetTrafficDetector ...@@ -55,12 +55,6 @@ class PrivetTrafficDetector
void ScheduleRestart(); void ScheduleRestart();
void Restart(net::NetworkInterfaceList networks); void Restart(net::NetworkInterfaceList networks);
void Bind(); void Bind();
// Called on the UI thread.
void CreateUDPSocketOnUIThread(
network::mojom::UDPSocketRequest request,
network::mojom::UDPSocketReceiverPtr receiver_ptr);
void OnBindComplete(net::IPEndPoint multicast_addr, void OnBindComplete(net::IPEndPoint multicast_addr,
int rv, int rv,
const base::Optional<net::IPEndPoint>& ip_address); const base::Optional<net::IPEndPoint>& ip_address);
...@@ -92,7 +86,8 @@ class PrivetTrafficDetector ...@@ -92,7 +86,8 @@ class PrivetTrafficDetector
// Initialized on the UI thread, but only accessed on the IO thread. // Initialized on the UI thread, but only accessed on the IO thread.
mojo::Binding<network::mojom::UDPSocketReceiver> receiver_binding_; mojo::Binding<network::mojom::UDPSocketReceiver> receiver_binding_;
// Only accessed on the UI thread // Initialized on the UI thread, but only accessed on the IO thread for the
// purpose of passing it back to the UI thread. Safe because it is const.
content::BrowserContext* const profile_; content::BrowserContext* const profile_;
base::WeakPtrFactory<PrivetTrafficDetector> weak_ptr_factory_; base::WeakPtrFactory<PrivetTrafficDetector> weak_ptr_factory_;
......
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