OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/socket/socket.h" | 15 #include "net/socket/socket.h" |
16 #include "net/socket/stream_socket.h" | 16 #include "net/socket/stream_socket.h" |
17 #include "remoting/protocol/channel_factory.h" | 17 #include "remoting/protocol/channel_factory.h" |
18 #include "remoting/protocol/session.h" | 18 #include "remoting/protocol/session.h" |
19 | 19 |
| 20 namespace base { |
20 class MessageLoop; | 21 class MessageLoop; |
| 22 } |
21 | 23 |
22 namespace remoting { | 24 namespace remoting { |
23 namespace protocol { | 25 namespace protocol { |
24 | 26 |
25 extern const char kTestJid[]; | 27 extern const char kTestJid[]; |
26 | 28 |
27 // FakeSocket implement net::Socket interface for FakeConnection. All data | 29 // FakeSocket implement net::Socket interface for FakeConnection. All data |
28 // written to FakeSocket is stored in a buffer returned by written_data(). | 30 // written to FakeSocket is stored in a buffer returned by written_data(). |
29 // Read() reads data from another buffer that can be set with AppendInputData(). | 31 // Read() reads data from another buffer that can be set with AppendInputData(). |
30 // Pending reads are supported, so if there is a pending read AppendInputData() | 32 // Pending reads are supported, so if there is a pending read AppendInputData() |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 int read_buffer_size_; | 95 int read_buffer_size_; |
94 net::CompletionCallback read_callback_; | 96 net::CompletionCallback read_callback_; |
95 base::WeakPtr<FakeSocket> peer_socket_; | 97 base::WeakPtr<FakeSocket> peer_socket_; |
96 | 98 |
97 std::string written_data_; | 99 std::string written_data_; |
98 std::string input_data_; | 100 std::string input_data_; |
99 int input_pos_; | 101 int input_pos_; |
100 | 102 |
101 net::BoundNetLog net_log_; | 103 net::BoundNetLog net_log_; |
102 | 104 |
103 MessageLoop* message_loop_; | 105 base::MessageLoop* message_loop_; |
104 base::WeakPtrFactory<FakeSocket> weak_factory_; | 106 base::WeakPtrFactory<FakeSocket> weak_factory_; |
105 | 107 |
106 DISALLOW_COPY_AND_ASSIGN(FakeSocket); | 108 DISALLOW_COPY_AND_ASSIGN(FakeSocket); |
107 }; | 109 }; |
108 | 110 |
109 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written | 111 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written |
110 // packets are stored separetely in written_packets(). AppendInputPacket() adds | 112 // packets are stored separetely in written_packets(). AppendInputPacket() adds |
111 // one packet that will be returned by Read(). | 113 // one packet that will be returned by Read(). |
112 class FakeUdpSocket : public net::Socket { | 114 class FakeUdpSocket : public net::Socket { |
113 public: | 115 public: |
(...skipping 19 matching lines...) Expand all Loading... |
133 private: | 135 private: |
134 bool read_pending_; | 136 bool read_pending_; |
135 scoped_refptr<net::IOBuffer> read_buffer_; | 137 scoped_refptr<net::IOBuffer> read_buffer_; |
136 int read_buffer_size_; | 138 int read_buffer_size_; |
137 net::CompletionCallback read_callback_; | 139 net::CompletionCallback read_callback_; |
138 | 140 |
139 std::vector<std::string> written_packets_; | 141 std::vector<std::string> written_packets_; |
140 std::vector<std::string> input_packets_; | 142 std::vector<std::string> input_packets_; |
141 int input_pos_; | 143 int input_pos_; |
142 | 144 |
143 MessageLoop* message_loop_; | 145 base::MessageLoop* message_loop_; |
144 | 146 |
145 DISALLOW_COPY_AND_ASSIGN(FakeUdpSocket); | 147 DISALLOW_COPY_AND_ASSIGN(FakeUdpSocket); |
146 }; | 148 }; |
147 | 149 |
148 // FakeSession is a dummy protocol::Session that uses FakeSocket for all | 150 // FakeSession is a dummy protocol::Session that uses FakeSocket for all |
149 // channels. | 151 // channels. |
150 class FakeSession : public Session, | 152 class FakeSession : public Session, |
151 public ChannelFactory { | 153 public ChannelFactory { |
152 public: | 154 public: |
153 FakeSession(); | 155 FakeSession(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void NotifyStreamChannelCallback( | 192 void NotifyStreamChannelCallback( |
191 const std::string& name, | 193 const std::string& name, |
192 const StreamChannelCallback& callback); | 194 const StreamChannelCallback& callback); |
193 void NotifyDatagramChannelCallback( | 195 void NotifyDatagramChannelCallback( |
194 const std::string& name, | 196 const std::string& name, |
195 const DatagramChannelCallback& callback); | 197 const DatagramChannelCallback& callback); |
196 | 198 |
197 EventHandler* event_handler_; | 199 EventHandler* event_handler_; |
198 scoped_ptr<const CandidateSessionConfig> candidate_config_; | 200 scoped_ptr<const CandidateSessionConfig> candidate_config_; |
199 SessionConfig config_; | 201 SessionConfig config_; |
200 MessageLoop* message_loop_; | 202 base::MessageLoop* message_loop_; |
201 | 203 |
202 bool async_creation_; | 204 bool async_creation_; |
203 | 205 |
204 std::map<std::string, FakeSocket*> stream_channels_; | 206 std::map<std::string, FakeSocket*> stream_channels_; |
205 std::map<std::string, FakeUdpSocket*> datagram_channels_; | 207 std::map<std::string, FakeUdpSocket*> datagram_channels_; |
206 | 208 |
207 std::string jid_; | 209 std::string jid_; |
208 | 210 |
209 ErrorCode error_; | 211 ErrorCode error_; |
210 bool closed_; | 212 bool closed_; |
211 | 213 |
212 base::WeakPtrFactory<FakeSession> weak_factory_; | 214 base::WeakPtrFactory<FakeSession> weak_factory_; |
213 | 215 |
214 DISALLOW_COPY_AND_ASSIGN(FakeSession); | 216 DISALLOW_COPY_AND_ASSIGN(FakeSession); |
215 }; | 217 }; |
216 | 218 |
217 } // namespace protocol | 219 } // namespace protocol |
218 } // namespace remoting | 220 } // namespace remoting |
219 | 221 |
220 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ | 222 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ |
OLD | NEW |