Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 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_SOCKET_CLIENT_H_ | |
| 6 #define CONTENT_PUBLIC_RENDERER_SOCKET_CLIENT_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "content/public/common/p2p_sockets.h" | |
| 12 #include "net/base/ip_endpoint.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 // P2P socket that routes all calls over IPC. | |
| 17 // | |
| 18 // The object runs on two threads: IPC thread and delegate thread. The | |
| 19 // IPC thread is used to interact with P2PSocketDispatcher. All | |
| 20 // callbacks to the user of this class are called on the delegate | |
| 21 // thread which is specified in Init(). | |
| 22 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.
| |
| 23 public base::RefCountedThreadSafe<P2PSocketClientInterface> { | |
| 24 public: | |
| 25 P2PSocketClientInterface() {} | |
| 26 | |
| 27 // Delegate is called on the the same thread on which P2PSocketCLient is | |
| 28 // created. | |
| 29 class Delegate { | |
| 30 public: | |
| 31 virtual ~Delegate() { } | |
| 32 | |
| 33 virtual void OnOpen(const net::IPEndPoint& address) = 0; | |
| 34 virtual void OnIncomingTcpConnection(const net::IPEndPoint& address, | |
| 35 P2PSocketClientInterface* client) = 0; | |
| 36 virtual void OnSendComplete() = 0; | |
| 37 virtual void OnError() = 0; | |
| 38 virtual void OnDataReceived(const net::IPEndPoint& address, | |
| 39 const std::vector<char>& data) = 0; | |
| 40 }; | |
| 41 | |
| 42 // Initialize socket of the specified |type| and connected to the | |
| 43 // specified |address|. |address| matters only when |type| is set to | |
| 44 // P2P_SOCKET_TCP_CLIENT. | |
| 45 virtual void Init(P2PSocketType type, | |
| 46 const net::IPEndPoint& local_address, | |
| 47 const net::IPEndPoint& remote_address, | |
| 48 Delegate* delegate) = 0; | |
| 49 | |
| 50 // Send the |data| to the |address|. | |
| 51 virtual void Send(const net::IPEndPoint& address, | |
| 52 const std::vector<char>& data) = 0; | |
| 53 | |
| 54 // Send the |data| to the |address| using Differentiated Services Code Point | |
| 55 // |dscp|. | |
| 56 virtual void SendWithDscp(const net::IPEndPoint& address, | |
| 57 const std::vector<char>& data, | |
| 58 net::DiffServCodePoint dscp) = 0; | |
| 59 | |
| 60 // Must be called before the socket is destroyed. | |
| 61 virtual void Close() = 0; | |
| 62 | |
| 63 virtual int socket_id() const = 0; | |
| 64 virtual void set_delegate(Delegate* delegate) = 0; | |
| 65 | |
| 66 protected: | |
| 67 virtual ~P2PSocketClientInterface() {} | |
| 68 | |
| 69 private: | |
| 70 // Calls destructor. | |
| 71 friend class base::RefCountedThreadSafe<P2PSocketClientInterface>; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(P2PSocketClientInterface); | |
| 74 }; | |
| 75 | |
| 76 } // namespace content | |
| 77 | |
| 78 #endif // CONTENT_PUBLIC_RENDERER_SOCKET_CLIENT_H_ | |
| OLD | NEW |