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