OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 REMOTING_PROTOCOL_FAKE_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_FAKE_SESSION_H_ |
6 #define REMOTING_PROTOCOL_FAKE_SESSION_H_ | 6 #define REMOTING_PROTOCOL_FAKE_SESSION_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "net/socket/socket.h" | 13 #include "net/socket/socket.h" |
| 14 #include "net/socket/stream_socket.h" |
13 #include "remoting/protocol/session.h" | 15 #include "remoting/protocol/session.h" |
14 | 16 |
15 namespace remoting { | 17 namespace remoting { |
16 namespace protocol { | 18 namespace protocol { |
17 | 19 |
18 extern const char kTestJid[]; | 20 extern const char kTestJid[]; |
19 | 21 |
20 // FakeSocket implement net::Socket interface for FakeConnection. All data | 22 // FakeSocket implement net::Socket interface for FakeConnection. All data |
21 // written to FakeSocket is stored in a buffer returned by written_data(). | 23 // written to FakeSocket is stored in a buffer returned by written_data(). |
22 // Read() reads data from another buffer that can be set with AppendInputData(). | 24 // Read() reads data from another buffer that can be set with AppendInputData(). |
23 // Pending reads are supported, so if there is a pending read AppendInputData() | 25 // Pending reads are supported, so if there is a pending read AppendInputData() |
24 // calls the read callback. | 26 // calls the read callback. |
25 class FakeSocket : public net::Socket { | 27 class FakeSocket : public net::StreamSocket { |
26 public: | 28 public: |
27 FakeSocket(); | 29 FakeSocket(); |
28 virtual ~FakeSocket(); | 30 virtual ~FakeSocket(); |
29 | 31 |
30 const std::string& written_data() const { return written_data_; } | 32 const std::string& written_data() const { return written_data_; } |
31 | 33 |
32 void AppendInputData(const char* data, int data_size); | 34 void AppendInputData(const char* data, int data_size); |
33 int input_pos() const { return input_pos_; } | 35 int input_pos() const { return input_pos_; } |
34 bool read_pending() const { return read_pending_; } | 36 bool read_pending() const { return read_pending_; } |
35 | 37 |
36 // net::Socket interface. | 38 // net::Socket interface. |
37 virtual int Read(net::IOBuffer* buf, int buf_len, | 39 virtual int Read(net::IOBuffer* buf, int buf_len, |
38 net::CompletionCallback* callback); | 40 net::CompletionCallback* callback); |
39 virtual int Write(net::IOBuffer* buf, int buf_len, | 41 virtual int Write(net::IOBuffer* buf, int buf_len, |
40 net::CompletionCallback* callback); | 42 net::CompletionCallback* callback); |
41 | 43 |
42 virtual bool SetReceiveBufferSize(int32 size); | 44 virtual bool SetReceiveBufferSize(int32 size); |
43 virtual bool SetSendBufferSize(int32 size); | 45 virtual bool SetSendBufferSize(int32 size); |
44 | 46 |
| 47 // net::StreamSocket interface. |
| 48 virtual int Connect(net::CompletionCallback* callback) OVERRIDE; |
| 49 virtual void Disconnect() OVERRIDE; |
| 50 virtual bool IsConnected() const OVERRIDE; |
| 51 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 52 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; |
| 53 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; |
| 54 virtual const net::BoundNetLog& NetLog() const OVERRIDE; |
| 55 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 56 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 57 virtual bool WasEverUsed() const OVERRIDE; |
| 58 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 59 virtual int64 NumBytesRead() const OVERRIDE; |
| 60 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 61 |
45 private: | 62 private: |
46 bool read_pending_; | 63 bool read_pending_; |
47 scoped_refptr<net::IOBuffer> read_buffer_; | 64 scoped_refptr<net::IOBuffer> read_buffer_; |
48 int read_buffer_size_; | 65 int read_buffer_size_; |
49 net::CompletionCallback* read_callback_; | 66 net::CompletionCallback* read_callback_; |
50 | 67 |
51 std::string written_data_; | 68 std::string written_data_; |
52 std::string input_data_; | 69 std::string input_data_; |
53 int input_pos_; | 70 int input_pos_; |
| 71 |
| 72 net::BoundNetLog net_log_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(FakeSocket); |
54 }; | 75 }; |
55 | 76 |
56 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written | 77 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written |
57 // packets are stored separetely in written_packets(). AppendInputPacket() adds | 78 // packets are stored separetely in written_packets(). AppendInputPacket() adds |
58 // one packet that will be returned by Read(). | 79 // one packet that will be returned by Read(). |
59 class FakeUdpSocket : public net::Socket { | 80 class FakeUdpSocket : public net::Socket { |
60 public: | 81 public: |
61 FakeUdpSocket(); | 82 FakeUdpSocket(); |
62 virtual ~FakeUdpSocket(); | 83 virtual ~FakeUdpSocket(); |
63 | 84 |
(...skipping 15 matching lines...) Expand all Loading... |
79 | 100 |
80 private: | 101 private: |
81 bool read_pending_; | 102 bool read_pending_; |
82 scoped_refptr<net::IOBuffer> read_buffer_; | 103 scoped_refptr<net::IOBuffer> read_buffer_; |
83 int read_buffer_size_; | 104 int read_buffer_size_; |
84 net::CompletionCallback* read_callback_; | 105 net::CompletionCallback* read_callback_; |
85 | 106 |
86 std::vector<std::string> written_packets_; | 107 std::vector<std::string> written_packets_; |
87 std::vector<std::string> input_packets_; | 108 std::vector<std::string> input_packets_; |
88 int input_pos_; | 109 int input_pos_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(FakeUdpSocket); |
89 }; | 112 }; |
90 | 113 |
91 // FakeSession is a dummy protocol::Session that uses FakeSocket for all | 114 // FakeSession is a dummy protocol::Session that uses FakeSocket for all |
92 // channels. | 115 // channels. |
93 class FakeSession : public Session { | 116 class FakeSession : public Session { |
94 public: | 117 public: |
95 FakeSession(); | 118 FakeSession(); |
96 virtual ~FakeSession(); | 119 virtual ~FakeSession(); |
97 | 120 |
98 StateChangeCallback* state_change_callback() { return callback_.get(); } | 121 StateChangeCallback* state_change_callback() { return callback_.get(); } |
99 | 122 |
100 void set_message_loop(MessageLoop* message_loop) { | 123 void set_message_loop(MessageLoop* message_loop) { |
101 message_loop_ = message_loop; | 124 message_loop_ = message_loop; |
102 } | 125 } |
103 | 126 |
104 bool is_closed() const { return closed_; } | 127 bool is_closed() const { return closed_; } |
105 | 128 |
| 129 FakeSocket* GetStreamChannel(const std::string& name); |
| 130 FakeUdpSocket* GetDatagramChannel(const std::string& name); |
| 131 |
| 132 // Session interface. |
106 virtual void SetStateChangeCallback(StateChangeCallback* callback); | 133 virtual void SetStateChangeCallback(StateChangeCallback* callback); |
107 | 134 |
108 virtual void CreateStreamChannel( | 135 virtual void CreateStreamChannel( |
109 const std::string& name, const StreamChannelCallback& callback); | 136 const std::string& name, const StreamChannelCallback& callback); |
110 virtual void CreateDatagramChannel( | 137 virtual void CreateDatagramChannel( |
111 const std::string& name, const DatagramChannelCallback& callback); | 138 const std::string& name, const DatagramChannelCallback& callback); |
112 | 139 |
113 virtual FakeSocket* control_channel(); | 140 virtual FakeSocket* control_channel(); |
114 virtual FakeSocket* event_channel(); | 141 virtual FakeSocket* event_channel(); |
115 virtual FakeSocket* video_channel(); | |
116 | |
117 virtual FakeUdpSocket* video_rtp_channel(); | |
118 virtual FakeUdpSocket* video_rtcp_channel(); | |
119 | 142 |
120 virtual const std::string& jid(); | 143 virtual const std::string& jid(); |
121 | 144 |
122 virtual const CandidateSessionConfig* candidate_config(); | 145 virtual const CandidateSessionConfig* candidate_config(); |
123 virtual const SessionConfig* config(); | 146 virtual const SessionConfig* config(); |
124 virtual void set_config(const SessionConfig* config); | 147 virtual void set_config(const SessionConfig* config); |
125 | 148 |
126 virtual const std::string& initiator_token(); | 149 virtual const std::string& initiator_token(); |
127 virtual void set_initiator_token(const std::string& initiator_token); | 150 virtual void set_initiator_token(const std::string& initiator_token); |
128 virtual const std::string& receiver_token(); | 151 virtual const std::string& receiver_token(); |
129 virtual void set_receiver_token(const std::string& receiver_token); | 152 virtual void set_receiver_token(const std::string& receiver_token); |
130 | 153 |
131 virtual void set_shared_secret(const std::string& secret); | 154 virtual void set_shared_secret(const std::string& secret); |
132 virtual const std::string& shared_secret(); | 155 virtual const std::string& shared_secret(); |
133 | 156 |
134 virtual void Close(); | 157 virtual void Close(); |
135 | 158 |
136 public: | 159 public: |
137 scoped_ptr<StateChangeCallback> callback_; | 160 scoped_ptr<StateChangeCallback> callback_; |
138 scoped_ptr<const CandidateSessionConfig> candidate_config_; | 161 scoped_ptr<const CandidateSessionConfig> candidate_config_; |
139 scoped_ptr<const SessionConfig> config_; | 162 scoped_ptr<const SessionConfig> config_; |
140 MessageLoop* message_loop_; | 163 MessageLoop* message_loop_; |
141 FakeSocket control_channel_; | 164 FakeSocket control_channel_; |
142 FakeSocket event_channel_; | 165 FakeSocket event_channel_; |
143 FakeSocket video_channel_; | 166 |
144 FakeUdpSocket video_rtp_channel_; | 167 std::map<std::string, FakeSocket*> stream_channels_; |
145 FakeUdpSocket video_rtcp_channel_; | 168 std::map<std::string, FakeUdpSocket*> datagram_channels_; |
146 | 169 |
147 std::string initiator_token_; | 170 std::string initiator_token_; |
148 std::string receiver_token_; | 171 std::string receiver_token_; |
149 | 172 |
150 std::string shared_secret_; | 173 std::string shared_secret_; |
151 | 174 |
152 std::string jid_; | 175 std::string jid_; |
153 bool closed_; | 176 bool closed_; |
| 177 |
| 178 DISALLOW_COPY_AND_ASSIGN(FakeSession); |
154 }; | 179 }; |
155 | 180 |
156 } // namespace protocol | 181 } // namespace protocol |
157 } // namespace remoting | 182 } // namespace remoting |
158 | 183 |
159 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ | 184 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ |
OLD | NEW |