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

Unified Diff: content/browser/renderer_host/p2p_sockets_host.cc

Issue 6598053: P2P Sockets host implementation. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: - Created 9 years, 10 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
« no previous file with comments | « content/browser/renderer_host/p2p_sockets_host.h ('k') | content/common/p2p_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/p2p_sockets_host.cc
diff --git a/content/browser/renderer_host/p2p_sockets_host.cc b/content/browser/renderer_host/p2p_sockets_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..310bd1dcfa9b19c39ea5722f8469f4ef67f5368e
--- /dev/null
+++ b/content/browser/renderer_host/p2p_sockets_host.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/p2p_sockets_host.h"
+
+#include "content/browser/renderer_host/p2p_socket_host.h"
+#include "content/common/p2p_messages.h"
+
+P2PSocketsHost::P2PSocketsHost() {
+}
+
+P2PSocketsHost::~P2PSocketsHost() {
+}
+
+void P2PSocketsHost::OnChannelClosing() {
+ BrowserMessageFilter::OnChannelClosing();
+
+ // Since the IPC channel is gone, close pending connections.
+ for (IDMap<P2PSocketHost>::iterator i(&sockets_); !i.IsAtEnd(); i.Advance()) {
+ sockets_.Remove(i.GetCurrentKey());
+ }
+}
+
+void P2PSocketsHost::OnDestruct() const {
+ BrowserThread::DeleteOnIOThread::Destruct(this);
+}
+
+bool P2PSocketsHost::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(P2PSocketsHost, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(P2PHostMsg_CreateSocket, OnCreateSocket)
+ IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend)
+ IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ return handled;
+}
+
+void P2PSocketsHost::OnCreateSocket(
+ const IPC::Message& msg, P2PSocketType type, int socket_id,
+ P2PSocketAddress remote_address) {
+ if (sockets_.Lookup(socket_id)) {
+ LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket "
+ "that already exists.";
+ return;
+ }
+
+ if (type != P2P_SOCKET_UDP) {
+ Send(new P2PMsg_OnError(msg.routing_id(), socket_id));
+ return;
+ }
+
+ scoped_ptr<P2PSocketHost> socket(
+ P2PSocketHost::Create(this, msg.routing_id(), socket_id, type));
+
+ if (!socket.get()) {
+ Send(new P2PMsg_OnError(msg.routing_id(), socket_id));
+ return;
+ }
+
+ if (socket->Init()) {
+ sockets_.AddWithID(socket.release(), socket_id);
+ }
+}
+
+void P2PSocketsHost::OnSend(const IPC::Message& msg, int socket_id,
+ P2PSocketAddress socket_address,
+ const std::vector<char>& data) {
+ P2PSocketHost* socket = sockets_.Lookup(socket_id);
+ if (!socket) {
+ LOG(ERROR) << "Received P2PHostMsg_Send for invalid socket_id.";
+ return;
+ }
+ socket->Send(socket_address, data);
+}
+
+void P2PSocketsHost::OnDestroySocket(const IPC::Message& msg, int socket_id) {
+ sockets_.Remove(socket_id);
+}
« no previous file with comments | « content/browser/renderer_host/p2p_sockets_host.h ('k') | content/common/p2p_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698