Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: content/browser/renderer_host/p2p/socket_dispatcher_host.cc

Issue 2963733002: Use TaskScheduler instead of PostTask in P2PSocketDispatcherHost. (Closed)
Patch Set: Move TaskRunner creation to .cc file. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/p2p/socket_dispatcher_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" 5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/task_scheduler/post_task.h"
13 #include "content/browser/bad_message.h" 14 #include "content/browser/bad_message.h"
14 #include "content/browser/renderer_host/p2p/socket_host.h" 15 #include "content/browser/renderer_host/p2p/socket_host.h"
15 #include "content/common/p2p_messages.h" 16 #include "content/common/p2p_messages.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/resource_context.h" 18 #include "content/public/browser/resource_context.h"
18 #include "net/base/address_list.h" 19 #include "net/base/address_list.h"
19 #include "net/base/completion_callback.h" 20 #include "net/base/completion_callback.h"
20 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
21 #include "net/base/network_interfaces.h" 22 #include "net/base/network_interfaces.h"
22 #include "net/base/sys_addrinfo.h" 23 #include "net/base/sys_addrinfo.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 }; 113 };
113 114
114 P2PSocketDispatcherHost::P2PSocketDispatcherHost( 115 P2PSocketDispatcherHost::P2PSocketDispatcherHost(
115 content::ResourceContext* resource_context, 116 content::ResourceContext* resource_context,
116 net::URLRequestContextGetter* url_context) 117 net::URLRequestContextGetter* url_context)
117 : BrowserMessageFilter(P2PMsgStart), 118 : BrowserMessageFilter(P2PMsgStart),
118 resource_context_(resource_context), 119 resource_context_(resource_context),
119 url_context_(url_context), 120 url_context_(url_context),
120 monitoring_networks_(false), 121 monitoring_networks_(false),
121 dump_incoming_rtp_packet_(false), 122 dump_incoming_rtp_packet_(false),
122 dump_outgoing_rtp_packet_(false) { 123 dump_outgoing_rtp_packet_(false),
123 } 124 network_list_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
125 {base::MayBlock(), base::TaskPriority::USER_VISIBLE})) {}
124 126
125 void P2PSocketDispatcherHost::OnChannelClosing() { 127 void P2PSocketDispatcherHost::OnChannelClosing() {
126 // Since the IPC sender is gone, close pending connections. 128 // Since the IPC sender is gone, close pending connections.
127 sockets_.clear(); 129 sockets_.clear();
128 130
129 dns_requests_.clear(); 131 dns_requests_.clear();
130 132
131 if (monitoring_networks_) { 133 if (monitoring_networks_) {
132 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 134 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
133 monitoring_networks_ = false; 135 monitoring_networks_ = false;
(...skipping 18 matching lines...) Expand all
152 IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend) 154 IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend)
153 IPC_MESSAGE_HANDLER(P2PHostMsg_SetOption, OnSetOption) 155 IPC_MESSAGE_HANDLER(P2PHostMsg_SetOption, OnSetOption)
154 IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket) 156 IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket)
155 IPC_MESSAGE_UNHANDLED(handled = false) 157 IPC_MESSAGE_UNHANDLED(handled = false)
156 IPC_END_MESSAGE_MAP() 158 IPC_END_MESSAGE_MAP()
157 return handled; 159 return handled;
158 } 160 }
159 161
160 void P2PSocketDispatcherHost::OnIPAddressChanged() { 162 void P2PSocketDispatcherHost::OnIPAddressChanged() {
161 // Notify the renderer about changes to list of network interfaces. 163 // Notify the renderer about changes to list of network interfaces.
162 BrowserThread::PostTask( 164 network_list_task_runner_->PostTask(
163 BrowserThread::FILE, FROM_HERE, base::Bind( 165 FROM_HERE, base::Bind(&P2PSocketDispatcherHost::DoGetNetworkList, this));
164 &P2PSocketDispatcherHost::DoGetNetworkList, this));
165 } 166 }
166 167
167 void P2PSocketDispatcherHost::StartRtpDump( 168 void P2PSocketDispatcherHost::StartRtpDump(
168 bool incoming, 169 bool incoming,
169 bool outgoing, 170 bool outgoing,
170 const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback) { 171 const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback) {
171 DCHECK_CURRENTLY_ON(BrowserThread::IO); 172 DCHECK_CURRENTLY_ON(BrowserThread::IO);
172 173
173 if ((!dump_incoming_rtp_packet_ && incoming) || 174 if ((!dump_incoming_rtp_packet_ && incoming) ||
174 (!dump_outgoing_rtp_packet_ && outgoing)) { 175 (!dump_outgoing_rtp_packet_ && outgoing)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 SocketsMap::iterator it = sockets_.find(socket_id); 209 SocketsMap::iterator it = sockets_.find(socket_id);
209 return (it == sockets_.end()) ? nullptr : it->second.get(); 210 return (it == sockets_.end()) ? nullptr : it->second.get();
210 } 211 }
211 212
212 void P2PSocketDispatcherHost::OnStartNetworkNotifications() { 213 void P2PSocketDispatcherHost::OnStartNetworkNotifications() {
213 if (!monitoring_networks_) { 214 if (!monitoring_networks_) {
214 net::NetworkChangeNotifier::AddIPAddressObserver(this); 215 net::NetworkChangeNotifier::AddIPAddressObserver(this);
215 monitoring_networks_ = true; 216 monitoring_networks_ = true;
216 } 217 }
217 218
218 BrowserThread::PostTask( 219 network_list_task_runner_->PostTask(
219 BrowserThread::FILE, FROM_HERE, base::Bind( 220 FROM_HERE, base::Bind(&P2PSocketDispatcherHost::DoGetNetworkList, this));
220 &P2PSocketDispatcherHost::DoGetNetworkList, this));
221 } 221 }
222 222
223 void P2PSocketDispatcherHost::OnStopNetworkNotifications() { 223 void P2PSocketDispatcherHost::OnStopNetworkNotifications() {
224 if (monitoring_networks_) { 224 if (monitoring_networks_) {
225 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 225 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
226 monitoring_networks_ = false; 226 monitoring_networks_ = false;
227 } 227 }
228 } 228 }
229 229
230 void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name, 230 void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 const net::IPAddress& default_ipv4_local_address, 360 const net::IPAddress& default_ipv4_local_address,
361 const net::IPAddress& default_ipv6_local_address) { 361 const net::IPAddress& default_ipv6_local_address) {
362 Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address, 362 Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address,
363 default_ipv6_local_address)); 363 default_ipv6_local_address));
364 } 364 }
365 365
366 net::IPAddress P2PSocketDispatcherHost::GetDefaultLocalAddress(int family) { 366 net::IPAddress P2PSocketDispatcherHost::GetDefaultLocalAddress(int family) {
367 DCHECK(family == AF_INET || family == AF_INET6); 367 DCHECK(family == AF_INET || family == AF_INET6);
368 368
369 // Creation and connection of a UDP socket might be janky. 369 // Creation and connection of a UDP socket might be janky.
370 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 370 DCHECK(network_list_task_runner_->RunsTasksInCurrentSequence());
371 371
372 std::unique_ptr<net::DatagramClientSocket> socket( 372 std::unique_ptr<net::DatagramClientSocket> socket(
373 net::ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( 373 net::ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket(
374 net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), nullptr, 374 net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), nullptr,
375 net::NetLogSource())); 375 net::NetLogSource()));
376 376
377 net::IPAddress ip_address; 377 net::IPAddress ip_address;
378 if (family == AF_INET) { 378 if (family == AF_INET) {
379 ip_address = net::IPAddress(kPublicIPv4Host); 379 ip_address = net::IPAddress(kPublicIPv4Host);
380 } else { 380 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 416
417 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) 417 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_)
418 packet_callback_.Reset(); 418 packet_callback_.Reset();
419 419
420 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) 420 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it)
421 it->second->StopRtpDump(incoming, outgoing); 421 it->second->StopRtpDump(incoming, outgoing);
422 } 422 }
423 } 423 }
424 424
425 } // namespace content 425 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_dispatcher_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698