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/connection_to_host.h" | 5 #include "remoting/protocol/connection_to_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 if (session_.get()) | 44 if (session_.get()) |
45 session_.reset(); | 45 session_.reset(); |
46 | 46 |
47 if (session_manager_.get()) | 47 if (session_manager_.get()) |
48 session_manager_.reset(); | 48 session_manager_.reset(); |
49 | 49 |
50 if (signal_strategy_) | 50 if (signal_strategy_) |
51 signal_strategy_->RemoveListener(this); | 51 signal_strategy_->RemoveListener(this); |
52 } | 52 } |
53 | 53 |
54 ClipboardStub* ConnectionToHost::clipboard_stub() { | |
55 return &clipboard_forwarder_; | |
56 } | |
57 | |
58 HostStub* ConnectionToHost::host_stub() { | |
59 // TODO(wez): Add a HostFilter class, equivalent to input filter. | |
60 return control_dispatcher_.get(); | |
61 } | |
62 | |
63 InputStub* ConnectionToHost::input_stub() { | |
64 return &event_forwarder_; | |
65 } | |
66 | |
67 void ConnectionToHost::Connect(SignalStrategy* signal_strategy, | 54 void ConnectionToHost::Connect(SignalStrategy* signal_strategy, |
| 55 scoped_ptr<TransportFactory> transport_factory, |
| 56 scoped_ptr<Authenticator> authenticator, |
68 const std::string& host_jid, | 57 const std::string& host_jid, |
69 const std::string& host_public_key, | 58 const std::string& host_public_key, |
70 scoped_ptr<TransportFactory> transport_factory, | 59 HostEventCallback* event_callback) { |
71 scoped_ptr<Authenticator> authenticator, | 60 DCHECK(client_stub_); |
72 HostEventCallback* event_callback, | 61 DCHECK(clipboard_stub_); |
73 ClientStub* client_stub, | 62 DCHECK(monitored_video_stub_); |
74 ClipboardStub* clipboard_stub, | 63 |
75 VideoStub* video_stub, | |
76 AudioStub* audio_stub) { | |
77 signal_strategy_ = signal_strategy; | 64 signal_strategy_ = signal_strategy; |
78 event_callback_ = event_callback; | 65 event_callback_ = event_callback; |
79 client_stub_ = client_stub; | |
80 clipboard_stub_ = clipboard_stub; | |
81 monitored_video_stub_.reset(new MonitoredVideoStub( | |
82 video_stub, | |
83 base::TimeDelta::FromSeconds( | |
84 MonitoredVideoStub::kConnectivityCheckDelaySeconds), | |
85 base::Bind(&ConnectionToHost::OnVideoChannelStatus, | |
86 base::Unretained(this)))); | |
87 audio_stub_ = audio_stub; | |
88 authenticator_ = authenticator.Pass(); | 66 authenticator_ = authenticator.Pass(); |
89 | 67 |
90 // Save jid of the host. The actual connection is created later after | 68 // Save jid of the host. The actual connection is created later after |
91 // |signal_strategy_| is connected. | 69 // |signal_strategy_| is connected. |
92 host_jid_ = host_jid; | 70 host_jid_ = host_jid; |
93 host_public_key_ = host_public_key; | 71 host_public_key_ = host_public_key; |
94 | 72 |
95 signal_strategy_->AddListener(this); | 73 signal_strategy_->AddListener(this); |
96 signal_strategy_->Connect(); | 74 signal_strategy_->Connect(); |
97 | 75 |
98 session_manager_.reset(new JingleSessionManager(transport_factory.Pass())); | 76 session_manager_.reset(new JingleSessionManager(transport_factory.Pass())); |
99 session_manager_->Init(signal_strategy_, this); | 77 session_manager_->Init(signal_strategy_, this); |
100 | 78 |
101 SetState(CONNECTING, OK); | 79 SetState(CONNECTING, OK); |
102 } | 80 } |
103 | 81 |
104 const SessionConfig& ConnectionToHost::config() { | 82 const SessionConfig& ConnectionToHost::config() { |
105 return session_->config(); | 83 return session_->config(); |
106 } | 84 } |
107 | 85 |
| 86 ClipboardStub* ConnectionToHost::clipboard_forwarder() { |
| 87 return &clipboard_forwarder_; |
| 88 } |
| 89 |
| 90 HostStub* ConnectionToHost::host_stub() { |
| 91 // TODO(wez): Add a HostFilter class, equivalent to input filter. |
| 92 return control_dispatcher_.get(); |
| 93 } |
| 94 |
| 95 InputStub* ConnectionToHost::input_stub() { |
| 96 return &event_forwarder_; |
| 97 } |
| 98 |
| 99 void ConnectionToHost::set_client_stub(ClientStub* client_stub) { |
| 100 client_stub_ = client_stub; |
| 101 } |
| 102 |
| 103 void ConnectionToHost::set_clipboard_stub(ClipboardStub* clipboard_stub) { |
| 104 clipboard_stub_ = clipboard_stub; |
| 105 } |
| 106 |
| 107 void ConnectionToHost::set_video_stub(VideoStub* video_stub) { |
| 108 DCHECK(video_stub); |
| 109 monitored_video_stub_.reset(new MonitoredVideoStub( |
| 110 video_stub, |
| 111 base::TimeDelta::FromSeconds( |
| 112 MonitoredVideoStub::kConnectivityCheckDelaySeconds), |
| 113 base::Bind(&ConnectionToHost::OnVideoChannelStatus, |
| 114 base::Unretained(this)))); |
| 115 } |
| 116 |
| 117 void ConnectionToHost::set_audio_stub(AudioStub* audio_stub) { |
| 118 audio_stub_ = audio_stub; |
| 119 } |
| 120 |
108 void ConnectionToHost::OnSignalStrategyStateChange( | 121 void ConnectionToHost::OnSignalStrategyStateChange( |
109 SignalStrategy::State state) { | 122 SignalStrategy::State state) { |
110 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
111 DCHECK(event_callback_); | 124 DCHECK(event_callback_); |
112 | 125 |
113 if (state == SignalStrategy::CONNECTED) { | 126 if (state == SignalStrategy::CONNECTED) { |
114 VLOG(1) << "Connected as: " << signal_strategy_->GetLocalJid(); | 127 VLOG(1) << "Connected as: " << signal_strategy_->GetLocalJid(); |
115 } else if (state == SignalStrategy::DISCONNECTED) { | 128 } else if (state == SignalStrategy::DISCONNECTED) { |
116 VLOG(1) << "Connection closed."; | 129 VLOG(1) << "Connection closed."; |
117 CloseOnError(SIGNALING_ERROR); | 130 CloseOnError(SIGNALING_ERROR); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 291 |
279 if (state != state_) { | 292 if (state != state_) { |
280 state_ = state; | 293 state_ = state; |
281 error_ = error; | 294 error_ = error; |
282 event_callback_->OnConnectionState(state_, error_); | 295 event_callback_->OnConnectionState(state_, error_); |
283 } | 296 } |
284 } | 297 } |
285 | 298 |
286 } // namespace protocol | 299 } // namespace protocol |
287 } // namespace remoting | 300 } // namespace remoting |
OLD | NEW |