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

Unified Diff: chrome/renderer/p2p/socket_client.h

Issue 6602039: P2P sockets IPC dispatcher for the renderer side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | « chrome/chrome_renderer.gypi ('k') | chrome/renderer/p2p/socket_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/p2p/socket_client.h
diff --git a/chrome/renderer/p2p/socket_client.h b/chrome/renderer/p2p/socket_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..d7bb638256279a66e7486cdc91b623d9b3679322
--- /dev/null
+++ b/chrome/renderer/p2p/socket_client.h
@@ -0,0 +1,84 @@
+// 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.
+
+#ifndef CHROME_RENDERER_P2P_SOCKET_CLIENT_H_
+#define CHROME_RENDERER_P2P_SOCKET_CLIENT_H_
+
+#include <vector>
+
+#include "base/ref_counted.h"
+#include "content/common/p2p_sockets.h"
+
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
+class P2PSocketDispatcher;
+class Task;
+
+// P2P socket that rountes all calls over IPC. It can be created and
+// used from any thread.
+class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> {
+ public:
+ // Delegate is called on the IPC thread.
+ class Delegate {
+ public:
+ virtual ~Delegate() { }
+
+ virtual void OnOpen(P2PSocketAddress address) = 0;
+ virtual void OnError() = 0;
+ virtual void OnDataReceived(P2PSocketAddress address,
+ const std::vector<char>& data) = 0;
+ };
+
+ explicit P2PSocketClient(P2PSocketDispatcher* dispatcher);
+
+ // Initialize socket of the specified |type| and connected to the
+ // specified |address|. |address| matters only when |type| is set to
+ // P2P_SOCKET_TCP_CLIENT.
+ void Init(P2PSocketType type, P2PSocketAddress address, Delegate* delegate);
+
+ // Send the |data| to the |address|.
+ void Send(P2PSocketAddress address, const std::vector<char>& data);
+
+ // Must be called before the socket is destroyed. The delegate may
+ // not be called after |closed_task| is executed.
+ void Close(Task* closed_task);
+
+ int socket_id() const { return socket_id_; }
+
+ private:
+ enum State {
+ STATE_UNINITIALIZED,
+ STATE_OPENING,
+ STATE_OPEN,
+ STATE_CLOSED,
+ STATE_ERROR,
+ };
+
+ friend class P2PSocketDispatcher;
+
+ // Calls destructor.
+ friend class base::RefCountedThreadSafe<P2PSocketClient>;
+
+ virtual ~P2PSocketClient();
+
+ void OnSocketCreated(P2PSocketAddress address);
+ void OnError();
+ void OnDataReceived(P2PSocketAddress address,
+ const std::vector<char>& data);
+
+ // Called by the dispatcher when it is destroyed.
+ void Detach();
+
+ P2PSocketDispatcher* dispatcher_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ int socket_id_;
+ Delegate* delegate_;
+ State state_;
+
+ DISALLOW_COPY_AND_ASSIGN(P2PSocketClient);
+};
+
+#endif // CHROME_RENDERER_P2P_SOCKET_CLIENT_H_
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | chrome/renderer/p2p/socket_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698