Index: content/public/renderer/socket_client.h |
diff --git a/content/public/renderer/socket_client.h b/content/public/renderer/socket_client.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2202e28b84e9e1cfa24cf12bf18182e16cb96c24 |
--- /dev/null |
+++ b/content/public/renderer/socket_client.h |
@@ -0,0 +1,78 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Alpha Left Google
2013/10/25 20:07:51
The file name should better reflect the class defi
hubbe
2013/10/25 21:26:57
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_PUBLIC_RENDERER_SOCKET_CLIENT_H_ |
+#define CONTENT_PUBLIC_RENDERER_SOCKET_CLIENT_H_ |
+ |
+#include <vector> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "content/public/common/p2p_sockets.h" |
+#include "net/base/ip_endpoint.h" |
+ |
+namespace content { |
+ |
+// P2P socket that routes all calls over IPC. |
+// |
+// The object runs on two threads: IPC thread and delegate thread. The |
+// IPC thread is used to interact with P2PSocketDispatcher. All |
+// callbacks to the user of this class are called on the delegate |
+// thread which is specified in Init(). |
+class P2PSocketClientInterface : |
Alpha Left Google
2013/10/25 20:07:51
Suggestion: maybe rename this to P2PSocketClient.
hubbe
2013/10/25 21:26:57
Done.
|
+ public base::RefCountedThreadSafe<P2PSocketClientInterface> { |
+ public: |
+ P2PSocketClientInterface() {} |
+ |
+ // Delegate is called on the the same thread on which P2PSocketCLient is |
+ // created. |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() { } |
+ |
+ virtual void OnOpen(const net::IPEndPoint& address) = 0; |
+ virtual void OnIncomingTcpConnection(const net::IPEndPoint& address, |
+ P2PSocketClientInterface* client) = 0; |
+ virtual void OnSendComplete() = 0; |
+ virtual void OnError() = 0; |
+ virtual void OnDataReceived(const net::IPEndPoint& address, |
+ const std::vector<char>& data) = 0; |
+ }; |
+ |
+ // Initialize socket of the specified |type| and connected to the |
+ // specified |address|. |address| matters only when |type| is set to |
+ // P2P_SOCKET_TCP_CLIENT. |
+ virtual void Init(P2PSocketType type, |
+ const net::IPEndPoint& local_address, |
+ const net::IPEndPoint& remote_address, |
+ Delegate* delegate) = 0; |
+ |
+ // Send the |data| to the |address|. |
+ virtual void Send(const net::IPEndPoint& address, |
+ const std::vector<char>& data) = 0; |
+ |
+ // Send the |data| to the |address| using Differentiated Services Code Point |
+ // |dscp|. |
+ virtual void SendWithDscp(const net::IPEndPoint& address, |
+ const std::vector<char>& data, |
+ net::DiffServCodePoint dscp) = 0; |
+ |
+ // Must be called before the socket is destroyed. |
+ virtual void Close() = 0; |
+ |
+ virtual int socket_id() const = 0; |
+ virtual void set_delegate(Delegate* delegate) = 0; |
+ |
+ protected: |
+ virtual ~P2PSocketClientInterface() {} |
+ |
+ private: |
+ // Calls destructor. |
+ friend class base::RefCountedThreadSafe<P2PSocketClientInterface>; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(P2PSocketClientInterface); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_PUBLIC_RENDERER_SOCKET_CLIENT_H_ |