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 #include "remoting/protocol/fake_session.h" | 5 #include "remoting/protocol/fake_session.h" |
6 | 6 |
| 7 #include "base/location.h" |
| 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "remoting/protocol/fake_authenticator.h" |
| 10 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 11 |
7 namespace remoting { | 12 namespace remoting { |
8 namespace protocol { | 13 namespace protocol { |
9 | 14 |
10 const char kTestJid[] = "host1@gmail.com/chromoting123"; | 15 const char kTestJid[] = "host1@gmail.com/chromoting123"; |
11 | 16 |
12 FakeTransport::FakeTransport() {} | |
13 FakeTransport::~FakeTransport() {} | |
14 | |
15 void FakeTransport::Start(EventHandler* event_handler, | |
16 Authenticator* authenticator) { | |
17 NOTREACHED(); | |
18 } | |
19 | |
20 bool FakeTransport::ProcessTransportInfo( | |
21 buzz::XmlElement* transport_info) { | |
22 NOTREACHED(); | |
23 return true; | |
24 } | |
25 | |
26 FakeStreamChannelFactory* FakeTransport::GetStreamChannelFactory() { | |
27 return &channel_factory_; | |
28 } | |
29 | |
30 FakeStreamChannelFactory* FakeTransport::GetMultiplexedChannelFactory() { | |
31 return &channel_factory_; | |
32 } | |
33 | |
34 FakeSession::FakeSession() | 17 FakeSession::FakeSession() |
35 : config_(SessionConfig::ForTest()), jid_(kTestJid), weak_factory_(this) {} | 18 : config_(SessionConfig::ForTest()), jid_(kTestJid), weak_factory_(this) {} |
36 | |
37 FakeSession::~FakeSession() {} | 19 FakeSession::~FakeSession() {} |
38 | 20 |
39 void FakeSession::SimulateConnection(FakeSession* peer) { | 21 void FakeSession::SimulateConnection(FakeSession* peer) { |
40 peer_ = peer->weak_factory_.GetWeakPtr(); | 22 peer_ = peer->weak_factory_.GetWeakPtr(); |
41 peer->peer_ = weak_factory_.GetWeakPtr(); | 23 peer->peer_ = weak_factory_.GetWeakPtr(); |
42 | 24 |
43 transport_.GetStreamChannelFactory()->PairWith( | |
44 peer->transport_.GetStreamChannelFactory()); | |
45 transport_.GetMultiplexedChannelFactory()->PairWith( | |
46 peer->transport_.GetMultiplexedChannelFactory()); | |
47 | |
48 event_handler_->OnSessionStateChange(CONNECTING); | 25 event_handler_->OnSessionStateChange(CONNECTING); |
49 peer->event_handler_->OnSessionStateChange(ACCEPTING); | 26 peer->event_handler_->OnSessionStateChange(ACCEPTING); |
50 peer->event_handler_->OnSessionStateChange(ACCEPTED); | 27 peer->event_handler_->OnSessionStateChange(ACCEPTED); |
51 event_handler_->OnSessionStateChange(ACCEPTED); | 28 event_handler_->OnSessionStateChange(ACCEPTED); |
52 event_handler_->OnSessionStateChange(AUTHENTICATING); | 29 event_handler_->OnSessionStateChange(AUTHENTICATING); |
53 peer->event_handler_->OnSessionStateChange(AUTHENTICATING); | 30 peer->event_handler_->OnSessionStateChange(AUTHENTICATING); |
| 31 |
| 32 // Initialize transport and authenticator on the client. |
| 33 authenticator_.reset(new FakeAuthenticator(FakeAuthenticator::CLIENT, 0, |
| 34 FakeAuthenticator::ACCEPT, false)); |
| 35 transport_->Start(authenticator_.get(), |
| 36 base::Bind(&FakeSession::SendTransportInfo, |
| 37 weak_factory_.GetWeakPtr())); |
| 38 |
| 39 // Initialize transport and authenticator on the host. |
| 40 peer->authenticator_.reset(new FakeAuthenticator( |
| 41 FakeAuthenticator::HOST, 0, FakeAuthenticator::ACCEPT, false)); |
| 42 peer->transport_->Start(peer->authenticator_.get(), |
| 43 base::Bind(&FakeSession::SendTransportInfo, peer_)); |
| 44 |
| 45 peer->event_handler_->OnSessionStateChange(AUTHENTICATED); |
54 event_handler_->OnSessionStateChange(AUTHENTICATED); | 46 event_handler_->OnSessionStateChange(AUTHENTICATED); |
55 peer->event_handler_->OnSessionStateChange(AUTHENTICATED); | |
56 event_handler_->OnSessionStateChange(CONNECTED); | |
57 peer->event_handler_->OnSessionStateChange(CONNECTED); | |
58 } | 47 } |
59 | 48 |
60 void FakeSession::SetEventHandler(EventHandler* event_handler) { | 49 void FakeSession::SetEventHandler(EventHandler* event_handler) { |
61 event_handler_ = event_handler; | 50 event_handler_ = event_handler; |
62 } | 51 } |
63 | 52 |
64 ErrorCode FakeSession::error() { | 53 ErrorCode FakeSession::error() { |
65 return error_; | 54 return error_; |
66 } | 55 } |
67 | 56 |
68 const std::string& FakeSession::jid() { | 57 const std::string& FakeSession::jid() { |
69 return jid_; | 58 return jid_; |
70 } | 59 } |
71 | 60 |
72 const SessionConfig& FakeSession::config() { | 61 const SessionConfig& FakeSession::config() { |
73 return *config_; | 62 return *config_; |
74 } | 63 } |
75 | 64 |
76 FakeTransport* FakeSession::GetTransport() { | 65 void FakeSession::SetTransport(Transport* transport) { |
77 return &transport_; | 66 transport_ = transport; |
78 } | 67 } |
79 | 68 |
80 void FakeSession::Close(ErrorCode error) { | 69 void FakeSession::Close(ErrorCode error) { |
81 closed_ = true; | 70 closed_ = true; |
82 error_ = error; | 71 error_ = error; |
83 event_handler_->OnSessionStateChange(CLOSED); | 72 event_handler_->OnSessionStateChange(CLOSED); |
84 | 73 |
85 FakeSession* peer = peer_.get(); | 74 FakeSession* peer = peer_.get(); |
86 if (peer) { | 75 if (peer) { |
87 peer->peer_.reset(); | 76 peer->peer_.reset(); |
88 peer_.reset(); | 77 peer_.reset(); |
89 peer->Close(error); | 78 peer->Close(error); |
90 } | 79 } |
91 } | 80 } |
92 | 81 |
| 82 void FakeSession::SendTransportInfo( |
| 83 scoped_ptr<buzz::XmlElement> transport_info) { |
| 84 if (!peer_) |
| 85 return; |
| 86 peer_->transport_->ProcessTransportInfo(transport_info.get()); |
| 87 } |
| 88 |
93 } // namespace protocol | 89 } // namespace protocol |
94 } // namespace remoting | 90 } // namespace remoting |
OLD | NEW |