OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_PUBLIC_RENDERER_P2P_SOCKET_CLIENT_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_P2P_SOCKET_CLIENT_H_ |
6 #define CONTENT_PUBLIC_RENDERER_P2P_SOCKET_CLIENT_H_ | 6 #define CONTENT_PUBLIC_RENDERER_P2P_SOCKET_CLIENT_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "content/public/common/p2p_socket_type.h" | 12 #include "content/public/common/p2p_socket_type.h" |
13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
14 | 14 |
15 namespace talk_base { | |
16 struct PacketOptions; | |
17 }; | |
18 | |
19 namespace content { | 15 namespace content { |
20 | 16 |
21 class P2PSocketClientDelegate; | 17 class P2PSocketClientDelegate; |
22 | 18 |
23 // P2P socket that routes all calls over IPC. | 19 // P2P socket that routes all calls over IPC. |
24 // Note that while ref-counting is thread-safe, all methods must be | 20 // Note that while ref-counting is thread-safe, all methods must be |
25 // called on the same thread. | 21 // called on the same thread. |
26 class CONTENT_EXPORT P2PSocketClient : | 22 class CONTENT_EXPORT P2PSocketClient : |
27 public base::RefCountedThreadSafe<P2PSocketClient> { | 23 public base::RefCountedThreadSafe<P2PSocketClient> { |
28 public: | 24 public: |
29 // Create a new P2PSocketClient() of the specified |type| and connected to | 25 // Create a new P2PSocketClient() of the specified |type| and connected to |
30 // the specified |address|. |address| matters only when |type| is set to | 26 // the specified |address|. |address| matters only when |type| is set to |
31 // P2P_SOCKET_TCP_CLIENT. The methods on the returned socket may only be | 27 // P2P_SOCKET_TCP_CLIENT. The methods on the returned socket may only be |
32 // called on the same thread that created it. | 28 // called on the same thread that created it. |
33 static scoped_refptr<P2PSocketClient> Create( | 29 static scoped_refptr<P2PSocketClient> Create( |
34 P2PSocketType type, | 30 P2PSocketType type, |
35 const net::IPEndPoint& local_address, | 31 const net::IPEndPoint& local_address, |
36 const net::IPEndPoint& remote_address, | 32 const net::IPEndPoint& remote_address, |
37 P2PSocketClientDelegate* delegate); | 33 P2PSocketClientDelegate* delegate); |
38 | 34 |
39 P2PSocketClient() {} | 35 P2PSocketClient() {} |
40 | 36 |
41 // Send the |data| to the |address|. | 37 // Send the |data| to the |address|. |
42 virtual void Send(const net::IPEndPoint& address, | 38 virtual void Send(const net::IPEndPoint& address, |
43 const std::vector<char>& data) = 0; | 39 const std::vector<char>& data) = 0; |
44 | 40 |
45 // Send the |data| to the |address| using Differentiated Services Code Point | 41 // Send the |data| to the |address| using Differentiated Services Code Point |
46 // |dscp|. | 42 // |dscp|. |
47 virtual void SendWithOptions(const net::IPEndPoint& address, | 43 virtual void SendWithDscp(const net::IPEndPoint& address, |
48 const std::vector<char>& data, | 44 const std::vector<char>& data, |
49 const talk_base::PacketOptions& options) = 0; | 45 net::DiffServCodePoint dscp) = 0; |
50 | 46 |
51 virtual void SetOption(P2PSocketOption option, int value) = 0; | 47 virtual void SetOption(P2PSocketOption option, int value) = 0; |
52 | 48 |
53 // Must be called before the socket is destroyed. | 49 // Must be called before the socket is destroyed. |
54 virtual void Close() = 0; | 50 virtual void Close() = 0; |
55 | 51 |
56 virtual int GetSocketID() const = 0; | 52 virtual int GetSocketID() const = 0; |
57 virtual void SetDelegate(P2PSocketClientDelegate* delegate) = 0; | 53 virtual void SetDelegate(P2PSocketClientDelegate* delegate) = 0; |
58 | 54 |
59 protected: | 55 protected: |
60 virtual ~P2PSocketClient() {} | 56 virtual ~P2PSocketClient() {} |
61 | 57 |
62 private: | 58 private: |
63 // Calls destructor. | 59 // Calls destructor. |
64 friend class base::RefCountedThreadSafe<P2PSocketClient>; | 60 friend class base::RefCountedThreadSafe<P2PSocketClient>; |
65 }; | 61 }; |
66 } // namespace content | 62 } // namespace content |
67 | 63 |
68 #endif // CONTENT_PUBLIC_RENDERER_P2P_SOCKET_CLIENT_H_ | 64 #endif // CONTENT_PUBLIC_RENDERER_P2P_SOCKET_CLIENT_H_ |
OLD | NEW |