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

Unified Diff: content/browser/renderer_host/p2p/socket_dispatcher_host.cc

Issue 10917167: Refactor the P2PSocketDispatcher to be created on the RenderThread instead of the RenderView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unnecessary destruction callback. Removed remaining routing_id. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/p2p/socket_dispatcher_host.cc
diff --git a/content/browser/renderer_host/p2p/socket_dispatcher_host.cc b/content/browser/renderer_host/p2p/socket_dispatcher_host.cc
index eaf7beb1293b08b65a45e619d51dc47eaf5e6793..49463c0f2591e264ea1cdf7ae49cf3c067357302 100644
--- a/content/browser/renderer_host/p2p/socket_dispatcher_host.cc
+++ b/content/browser/renderer_host/p2p/socket_dispatcher_host.cc
@@ -25,10 +25,9 @@ class P2PSocketDispatcherHost::DnsRequest {
public:
typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback;
- DnsRequest(int32 routing_id, int32 request_id,
+ DnsRequest(int32 request_id,
net::HostResolver* host_resolver)
- : routing_id_(routing_id),
- request_id_(request_id),
+ : request_id_(request_id),
resolver_(host_resolver) {
}
@@ -60,7 +59,6 @@ class P2PSocketDispatcherHost::DnsRequest {
OnDone(result);
}
- int32 routing_id() { return routing_id_; }
int32 request_id() { return request_id_; }
private:
@@ -83,7 +81,6 @@ class P2PSocketDispatcherHost::DnsRequest {
done_callback_.Run(addresses_.front().address());
}
- int32 routing_id_;
int32 request_id_;
net::AddressList addresses_;
@@ -148,10 +145,8 @@ P2PSocketDispatcherHost::~P2PSocketDispatcherHost() {
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
-P2PSocketHost* P2PSocketDispatcherHost::LookupSocket(
- int32 routing_id, int socket_id) {
- SocketsMap::iterator it = sockets_.find(
- ExtendedSocketId(routing_id, socket_id));
+P2PSocketHost* P2PSocketDispatcherHost::LookupSocket(int socket_id) {
+ SocketsMap::iterator it = sockets_.find(socket_id);
if (it == sockets_.end())
tommi (sloooow) - chröme 2012/09/11 12:09:09 change this to: return (it == sockets_.end()) ? N
perkj_chrome 2012/09/11 14:27:30 Done.
return NULL;
else
@@ -165,8 +160,6 @@ void P2PSocketDispatcherHost::OnStartNetworkNotifications(
monitoring_networks_ = true;
}
- notifications_routing_ids_.insert(msg.routing_id());
-
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE, base::Bind(
&P2PSocketDispatcherHost::DoGetNetworkList, this));
@@ -174,14 +167,16 @@ void P2PSocketDispatcherHost::OnStartNetworkNotifications(
void P2PSocketDispatcherHost::OnStopNetworkNotifications(
const IPC::Message& msg) {
- notifications_routing_ids_.erase(msg.routing_id());
+ if (monitoring_networks_) {
+ net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
+ monitoring_networks_ = false;
+ }
}
-void P2PSocketDispatcherHost::OnGetHostAddress(const IPC::Message& msg,
- const std::string& host_name,
+void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name,
int32 request_id) {
- DnsRequest* request = new DnsRequest(
- msg.routing_id(), request_id, resource_context_->GetHostResolver());
+ DnsRequest* request = new DnsRequest(request_id,
+ resource_context_->GetHostResolver());
dns_requests_.insert(request);
request->Resolve(host_name, base::Bind(
&P2PSocketDispatcherHost::OnAddressResolved,
@@ -189,33 +184,32 @@ void P2PSocketDispatcherHost::OnGetHostAddress(const IPC::Message& msg,
}
void P2PSocketDispatcherHost::OnCreateSocket(
- const IPC::Message& msg, P2PSocketType type, int socket_id,
+ P2PSocketType type, int socket_id,
const net::IPEndPoint& local_address,
const net::IPEndPoint& remote_address) {
- if (LookupSocket(msg.routing_id(), socket_id)) {
+ if (LookupSocket(socket_id)) {
LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket "
"that already exists.";
return;
}
scoped_ptr<P2PSocketHost> socket(
- P2PSocketHost::Create(this, msg.routing_id(), socket_id, type));
+ P2PSocketHost::Create(this, socket_id, type));
if (!socket.get()) {
- Send(new P2PMsg_OnError(msg.routing_id(), socket_id));
+ Send(new P2PMsg_OnError(socket_id));
return;
}
if (socket->Init(local_address, remote_address)) {
- sockets_.insert(std::pair<ExtendedSocketId, P2PSocketHost*>(
- ExtendedSocketId(msg.routing_id(), socket_id), socket.release()));
+ sockets_.insert(SocketPair(socket_id, socket.release()));
tommi (sloooow) - chröme 2012/09/11 12:09:09 without using SocketPair, this should just be: soc
perkj_chrome 2012/09/11 14:27:30 Done.
}
}
void P2PSocketDispatcherHost::OnAcceptIncomingTcpConnection(
- const IPC::Message& msg, int listen_socket_id,
- const net::IPEndPoint& remote_address, int connected_socket_id) {
- P2PSocketHost* socket = LookupSocket(msg.routing_id(), listen_socket_id);
+ int listen_socket_id, const net::IPEndPoint& remote_address,
+ int connected_socket_id) {
+ P2PSocketHost* socket = LookupSocket(listen_socket_id);
if (!socket) {
LOG(ERROR) << "Received P2PHostMsg_AcceptIncomingTcpConnection "
"for invalid socket_id.";
@@ -224,16 +218,14 @@ void P2PSocketDispatcherHost::OnAcceptIncomingTcpConnection(
P2PSocketHost* accepted_connection =
socket->AcceptIncomingTcpConnection(remote_address, connected_socket_id);
if (accepted_connection) {
- sockets_.insert(std::pair<ExtendedSocketId, P2PSocketHost*>(
- ExtendedSocketId(msg.routing_id(), connected_socket_id),
- accepted_connection));
+ sockets_.insert(SocketPair(connected_socket_id, accepted_connection));
tommi (sloooow) - chröme 2012/09/11 12:09:09 sockets_[connected_socket_id] = accepted_connectio
perkj_chrome 2012/09/11 14:27:30 Done.
}
}
-void P2PSocketDispatcherHost::OnSend(const IPC::Message& msg, int socket_id,
+void P2PSocketDispatcherHost::OnSend(int socket_id,
const net::IPEndPoint& socket_address,
const std::vector<char>& data) {
- P2PSocketHost* socket = LookupSocket(msg.routing_id(), socket_id);
+ P2PSocketHost* socket = LookupSocket(socket_id);
if (!socket) {
LOG(ERROR) << "Received P2PHostMsg_Send for invalid socket_id.";
return;
@@ -241,10 +233,8 @@ void P2PSocketDispatcherHost::OnSend(const IPC::Message& msg, int socket_id,
socket->Send(socket_address, data);
}
-void P2PSocketDispatcherHost::OnDestroySocket(const IPC::Message& msg,
- int socket_id) {
- SocketsMap::iterator it = sockets_.find(
- ExtendedSocketId(msg.routing_id(), socket_id));
+void P2PSocketDispatcherHost::OnDestroySocket(int socket_id) {
+ SocketsMap::iterator it = sockets_.find(socket_id);
if (it != sockets_.end()) {
delete it->second;
sockets_.erase(it);
@@ -263,17 +253,13 @@ void P2PSocketDispatcherHost::DoGetNetworkList() {
void P2PSocketDispatcherHost::SendNetworkList(
const net::NetworkInterfaceList& list) {
- for (std::set<int>::iterator it = notifications_routing_ids_.begin();
- it != notifications_routing_ids_.end(); ++it) {
- Send(new P2PMsg_NetworkListChanged(*it, list));
- }
+ Send(new P2PMsg_NetworkListChanged(list));
}
void P2PSocketDispatcherHost::OnAddressResolved(
DnsRequest* request,
const net::IPAddressNumber& result) {
- Send(new P2PMsg_GetHostAddressResult(
- request->routing_id(), request->request_id(), result));
+ Send(new P2PMsg_GetHostAddressResult(request->request_id(), result));
dns_requests_.erase(request);
delete request;

Powered by Google App Engine
This is Rietveld 408576698