Chromium Code Reviews| 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_RENDERER_P2P_SOCKET_CLIENT_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_P2P_SOCKET_CLIENT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_P2P_SOCKET_CLIENT_IMPL_H_ | 6 #define CONTENT_RENDERER_P2P_SOCKET_CLIENT_IMPL_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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 // Initialize socket of the specified |type| and connected to the | 34 // Initialize socket of the specified |type| and connected to the |
| 35 // specified |address|. |address| matters only when |type| is set to | 35 // specified |address|. |address| matters only when |type| is set to |
| 36 // P2P_SOCKET_TCP_CLIENT. | 36 // P2P_SOCKET_TCP_CLIENT. |
| 37 virtual void Init(P2PSocketType type, | 37 virtual void Init(P2PSocketType type, |
| 38 const net::IPEndPoint& local_address, | 38 const net::IPEndPoint& local_address, |
| 39 const P2PHostAndIPEndPoint& remote_address, | 39 const P2PHostAndIPEndPoint& remote_address, |
| 40 P2PSocketClientDelegate* delegate); | 40 P2PSocketClientDelegate* delegate); |
| 41 | 41 |
| 42 // Send the |data| to the |address|. | 42 // Send the |data| to the |address|. |
| 43 void Send(const net::IPEndPoint& address, | 43 void Send(const net::IPEndPoint& address, |
|
Sergey Ulanov
2014/12/23 01:11:02
Remove this? It no longer overrides anything, so i
guoweis_left_chromium
2014/12/23 19:08:32
Done.
| |
| 44 const std::vector<char>& data) override; | 44 const std::vector<char>& data) override; |
| 45 | 45 |
| 46 // Send the |data| to the |address| using Differentiated Services Code Point | 46 // Send the |data| to the |address| using Differentiated Services Code Point |
| 47 // |dscp|. | 47 // |dscp|. Return value is the unique packet_id for this packet. |
| 48 void SendWithDscp(const net::IPEndPoint& address, | 48 uint64_t SendWithDscp(const net::IPEndPoint& address, |
| 49 const std::vector<char>& data, | 49 const std::vector<char>& data, |
| 50 const rtc::PacketOptions& options) override; | 50 const rtc::PacketOptions& options) override; |
| 51 | 51 |
| 52 // Setting socket options. | 52 // Setting socket options. |
| 53 void SetOption(P2PSocketOption option, int value) override; | 53 void SetOption(P2PSocketOption option, int value) override; |
| 54 | 54 |
| 55 // Must be called before the socket is destroyed. The delegate may | 55 // Must be called before the socket is destroyed. The delegate may |
| 56 // not be called after |closed_task| is executed. | 56 // not be called after |closed_task| is executed. |
| 57 void Close() override; | 57 void Close() override; |
| 58 | 58 |
| 59 int GetSocketID() const override; | 59 int GetSocketID() const override; |
| 60 | 60 |
| 61 void SetDelegate(P2PSocketClientDelegate* delegate) override; | 61 void SetDelegate(P2PSocketClientDelegate* delegate) override; |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 enum State { | 64 enum State { |
| 65 STATE_UNINITIALIZED, | 65 STATE_UNINITIALIZED, |
| 66 STATE_OPENING, | 66 STATE_OPENING, |
| 67 STATE_OPEN, | 67 STATE_OPEN, |
| 68 STATE_CLOSED, | 68 STATE_CLOSED, |
| 69 STATE_ERROR, | 69 STATE_ERROR, |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 friend class P2PSocketDispatcher; | 72 friend class P2PSocketDispatcher; |
| 73 | 73 |
| 74 ~P2PSocketClientImpl() override; | 74 ~P2PSocketClientImpl() override; |
| 75 | 75 |
| 76 // Message handlers that run on IPC thread. | 76 // Message handlers that run on IPC thread. |
| 77 void OnSocketCreated(const net::IPEndPoint& local_address, | 77 void OnSocketCreated(const net::IPEndPoint& local_address, |
| 78 const net::IPEndPoint& remote_address); | 78 const net::IPEndPoint& remote_address); |
| 79 void OnIncomingTcpConnection(const net::IPEndPoint& address); | 79 void OnIncomingTcpConnection(const net::IPEndPoint& address); |
| 80 void OnSendComplete(int packet_id); | 80 void OnSendComplete(const P2PSendPacketMetrics& send_metrics); |
| 81 void OnSendComplete(); | |
| 82 void OnError(); | 81 void OnError(); |
| 83 void OnDataReceived(const net::IPEndPoint& address, | 82 void OnDataReceived(const net::IPEndPoint& address, |
| 84 const std::vector<char>& data, | 83 const std::vector<char>& data, |
| 85 const base::TimeTicks& timestamp); | 84 const base::TimeTicks& timestamp); |
| 86 | 85 |
| 87 // Proxy methods that deliver messages to the delegate thread. | 86 // Proxy methods that deliver messages to the delegate thread. |
| 88 void DeliverOnSocketCreated(const net::IPEndPoint& local_address, | 87 void DeliverOnSocketCreated(const net::IPEndPoint& local_address, |
| 89 const net::IPEndPoint& remote_address); | 88 const net::IPEndPoint& remote_address); |
| 90 void DeliverOnIncomingTcpConnection( | 89 void DeliverOnIncomingTcpConnection( |
| 91 const net::IPEndPoint& address, | 90 const net::IPEndPoint& address, |
| 92 scoped_refptr<P2PSocketClient> new_client); | 91 scoped_refptr<P2PSocketClient> new_client); |
| 93 void DeliverOnSendComplete(); | 92 void DeliverOnSendComplete(const P2PSendPacketMetrics& send_metrics); |
| 94 void DeliverOnError(); | 93 void DeliverOnError(); |
| 95 void DeliverOnDataReceived(const net::IPEndPoint& address, | 94 void DeliverOnDataReceived(const net::IPEndPoint& address, |
| 96 const std::vector<char>& data, | 95 const std::vector<char>& data, |
| 97 const base::TimeTicks& timestamp); | 96 const base::TimeTicks& timestamp); |
| 98 | 97 |
| 98 // Helper function to be called by SendWithDscp to handle different threading | |
| 99 // condition. | |
| 100 void SendWithDscpAndPacketId(const net::IPEndPoint& address, | |
| 101 const std::vector<char>& data, | |
| 102 const rtc::PacketOptions& options, | |
| 103 uint64_t packet_id); | |
| 104 | |
| 99 // Scheduled on the IPC thread to finish initialization. | 105 // Scheduled on the IPC thread to finish initialization. |
| 100 void DoInit(P2PSocketType type, | 106 void DoInit(P2PSocketType type, |
| 101 const net::IPEndPoint& local_address, | 107 const net::IPEndPoint& local_address, |
| 102 const P2PHostAndIPEndPoint& remote_address); | 108 const P2PHostAndIPEndPoint& remote_address); |
| 103 | 109 |
| 104 // Scheduled on the IPC thread to finish closing the connection. | 110 // Scheduled on the IPC thread to finish closing the connection. |
| 105 void DoClose(); | 111 void DoClose(); |
| 106 | 112 |
| 107 // Called by the dispatcher when it is destroyed. | 113 // Called by the dispatcher when it is destroyed. |
| 108 void Detach(); | 114 void Detach(); |
| 109 | 115 |
| 110 P2PSocketDispatcher* dispatcher_; | 116 P2PSocketDispatcher* dispatcher_; |
| 111 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; | 117 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; |
| 112 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; | 118 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; |
| 113 int socket_id_; | 119 int socket_id_; |
| 114 P2PSocketClientDelegate* delegate_; | 120 P2PSocketClientDelegate* delegate_; |
| 115 State state_; | 121 State state_; |
| 116 | 122 |
| 117 // These two fields are used to identify packets for tracing. | 123 // These two fields are used to identify packets for tracing. |
| 118 uint32 random_socket_id_; | 124 uint32 random_socket_id_; |
| 119 uint32 next_packet_id_; | 125 uint32 next_packet_id_; |
| 120 | 126 |
| 121 DISALLOW_COPY_AND_ASSIGN(P2PSocketClientImpl); | 127 DISALLOW_COPY_AND_ASSIGN(P2PSocketClientImpl); |
| 122 }; | 128 }; |
| 123 | 129 |
| 124 } // namespace content | 130 } // namespace content |
| 125 | 131 |
| 126 #endif // CONTENT_RENDERER_P2P_SOCKET_CLIENT_IMPL_H_ | 132 #endif // CONTENT_RENDERER_P2P_SOCKET_CLIENT_IMPL_H_ |
| OLD | NEW |