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/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "remoting/protocol/fake_stream_socket.h" | 15 #include "remoting/protocol/fake_stream_socket.h" |
16 #include "remoting/protocol/session.h" | 16 #include "remoting/protocol/session.h" |
17 #include "remoting/protocol/transport.h" | 17 #include "remoting/protocol/transport.h" |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 namespace protocol { | 20 namespace protocol { |
21 | 21 |
22 extern const char kTestJid[]; | 22 extern const char kTestJid[]; |
23 | 23 |
24 class FakeTransport : public Transport { | 24 class FakeAuthenticator; |
25 public: | |
26 FakeTransport(); | |
27 ~FakeTransport() override; | |
28 | 25 |
29 // Transport interface. | |
30 void Start(EventHandler* event_handler, | |
31 Authenticator* authenticator) override; | |
32 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; | |
33 FakeStreamChannelFactory* GetStreamChannelFactory() override; | |
34 FakeStreamChannelFactory* GetMultiplexedChannelFactory() override; | |
35 | |
36 private: | |
37 FakeStreamChannelFactory channel_factory_; | |
38 }; | |
39 | |
40 // FakeSession is a dummy protocol::Session that uses FakeStreamSocket for all | |
41 // channels. | |
42 class FakeSession : public Session { | 26 class FakeSession : public Session { |
43 public: | 27 public: |
44 FakeSession(); | 28 FakeSession(); |
45 ~FakeSession() override; | 29 ~FakeSession() override; |
46 | 30 |
47 void SimulateConnection(FakeSession* peer); | 31 void SimulateConnection(FakeSession* peer); |
48 | 32 |
49 EventHandler* event_handler() { return event_handler_; } | 33 EventHandler* event_handler() { return event_handler_; } |
50 void set_error(ErrorCode error) { error_ = error; } | 34 void set_error(ErrorCode error) { error_ = error; } |
51 bool is_closed() const { return closed_; } | 35 bool is_closed() const { return closed_; } |
52 | 36 |
53 // Session interface. | 37 // Session interface. |
54 void SetEventHandler(EventHandler* event_handler) override; | 38 void SetEventHandler(EventHandler* event_handler) override; |
55 ErrorCode error() override; | 39 ErrorCode error() override; |
56 const std::string& jid() override; | 40 const std::string& jid() override; |
57 const SessionConfig& config() override; | 41 const SessionConfig& config() override; |
58 FakeTransport* GetTransport() override; | 42 void SetTransport(Transport* transport) override; |
59 void Close(ErrorCode error) override; | 43 void Close(ErrorCode error) override; |
60 | 44 |
61 private: | 45 private: |
| 46 // Callback provided to the |transport_|. |
| 47 void SendTransportInfo(scoped_ptr<buzz::XmlElement> transport_info); |
| 48 |
62 EventHandler* event_handler_ = nullptr; | 49 EventHandler* event_handler_ = nullptr; |
63 scoped_ptr<SessionConfig> config_; | 50 scoped_ptr<SessionConfig> config_; |
64 | 51 |
65 std::string jid_; | 52 std::string jid_; |
66 | 53 |
67 FakeTransport transport_; | 54 scoped_ptr<FakeAuthenticator> authenticator_; |
| 55 Transport* transport_; |
68 | 56 |
69 ErrorCode error_ = OK; | 57 ErrorCode error_ = OK; |
70 bool closed_ = false; | 58 bool closed_ = false; |
71 | 59 |
72 base::WeakPtr<FakeSession> peer_; | 60 base::WeakPtr<FakeSession> peer_; |
73 | 61 |
74 base::WeakPtrFactory<FakeSession> weak_factory_; | 62 base::WeakPtrFactory<FakeSession> weak_factory_; |
75 | 63 |
76 DISALLOW_COPY_AND_ASSIGN(FakeSession); | 64 DISALLOW_COPY_AND_ASSIGN(FakeSession); |
77 }; | 65 }; |
78 | 66 |
79 } // namespace protocol | 67 } // namespace protocol |
80 } // namespace remoting | 68 } // namespace remoting |
81 | 69 |
82 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ | 70 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ |
OLD | NEW |