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