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