Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: remoting/protocol/ice_connection_to_host.cc

Issue 1545743002: Move ownership of Transport out of Session. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass_client
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/ice_connection_to_host.h ('k') | remoting/protocol/ice_transport.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ice_connection_to_host.h" 5 #include "remoting/protocol/ice_connection_to_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
13 #include "remoting/protocol/audio_reader.h" 13 #include "remoting/protocol/audio_reader.h"
14 #include "remoting/protocol/audio_stub.h" 14 #include "remoting/protocol/audio_stub.h"
15 #include "remoting/protocol/auth_util.h" 15 #include "remoting/protocol/auth_util.h"
16 #include "remoting/protocol/client_control_dispatcher.h" 16 #include "remoting/protocol/client_control_dispatcher.h"
17 #include "remoting/protocol/client_event_dispatcher.h" 17 #include "remoting/protocol/client_event_dispatcher.h"
18 #include "remoting/protocol/client_stub.h" 18 #include "remoting/protocol/client_stub.h"
19 #include "remoting/protocol/client_video_dispatcher.h" 19 #include "remoting/protocol/client_video_dispatcher.h"
20 #include "remoting/protocol/clipboard_stub.h" 20 #include "remoting/protocol/clipboard_stub.h"
21 #include "remoting/protocol/errors.h" 21 #include "remoting/protocol/errors.h"
22 #include "remoting/protocol/ice_transport.h" 22 #include "remoting/protocol/ice_transport.h"
23 #include "remoting/protocol/transport.h" 23 #include "remoting/protocol/transport_context.h"
24 #include "remoting/protocol/video_stub.h" 24 #include "remoting/protocol/video_stub.h"
25 25
26 namespace remoting { 26 namespace remoting {
27 namespace protocol { 27 namespace protocol {
28 28
29 IceConnectionToHost::IceConnectionToHost() {} 29 IceConnectionToHost::IceConnectionToHost() {}
30 IceConnectionToHost::~IceConnectionToHost() {} 30 IceConnectionToHost::~IceConnectionToHost() {}
31 31
32 void IceConnectionToHost::Connect(scoped_ptr<Session> session, 32 void IceConnectionToHost::Connect(
33 HostEventCallback* event_callback) { 33 scoped_ptr<Session> session,
34 scoped_refptr<TransportContext> transport_context,
35 HostEventCallback* event_callback) {
34 DCHECK(client_stub_); 36 DCHECK(client_stub_);
35 DCHECK(clipboard_stub_); 37 DCHECK(clipboard_stub_);
36 DCHECK(monitored_video_stub_); 38 DCHECK(monitored_video_stub_);
37 39
40 transport_.reset(new IceTransport(transport_context, this));
41
38 session_ = std::move(session); 42 session_ = std::move(session);
39 session_->SetEventHandler(this); 43 session_->SetEventHandler(this);
44 session_->SetTransport(transport_.get());
40 45
41 event_callback_ = event_callback; 46 event_callback_ = event_callback;
42 47
43 SetState(CONNECTING, OK); 48 SetState(CONNECTING, OK);
44 } 49 }
45 50
46 const SessionConfig& IceConnectionToHost::config() { 51 const SessionConfig& IceConnectionToHost::config() {
47 return session_->config(); 52 return session_->config();
48 } 53 }
49 54
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 void IceConnectionToHost::OnSessionStateChange(Session::State state) { 89 void IceConnectionToHost::OnSessionStateChange(Session::State state) {
85 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
86 DCHECK(event_callback_); 91 DCHECK(event_callback_);
87 92
88 switch (state) { 93 switch (state) {
89 case Session::INITIALIZING: 94 case Session::INITIALIZING:
90 case Session::CONNECTING: 95 case Session::CONNECTING:
91 case Session::ACCEPTING: 96 case Session::ACCEPTING:
92 case Session::ACCEPTED: 97 case Session::ACCEPTED:
93 case Session::AUTHENTICATING: 98 case Session::AUTHENTICATING:
94 case Session::CONNECTED:
95 // Don't care about these events. 99 // Don't care about these events.
96 break; 100 break;
97 101
98 case Session::AUTHENTICATED: 102 case Session::AUTHENTICATED:
99 SetState(AUTHENTICATED, OK); 103 SetState(AUTHENTICATED, OK);
100
101 control_dispatcher_.reset(new ClientControlDispatcher()); 104 control_dispatcher_.reset(new ClientControlDispatcher());
102 control_dispatcher_->Init( 105 control_dispatcher_->Init(transport_->GetMultiplexedChannelFactory(),
103 session_->GetTransport()->GetMultiplexedChannelFactory(), this); 106 this);
104 control_dispatcher_->set_client_stub(client_stub_); 107 control_dispatcher_->set_client_stub(client_stub_);
105 control_dispatcher_->set_clipboard_stub(clipboard_stub_); 108 control_dispatcher_->set_clipboard_stub(clipboard_stub_);
106 109
107 event_dispatcher_.reset(new ClientEventDispatcher()); 110 event_dispatcher_.reset(new ClientEventDispatcher());
108 event_dispatcher_->Init( 111 event_dispatcher_->Init(transport_->GetMultiplexedChannelFactory(), this);
109 session_->GetTransport()->GetMultiplexedChannelFactory(), this);
110 112
111 video_dispatcher_.reset( 113 video_dispatcher_.reset(
112 new ClientVideoDispatcher(monitored_video_stub_.get())); 114 new ClientVideoDispatcher(monitored_video_stub_.get()));
113 video_dispatcher_->Init( 115 video_dispatcher_->Init(transport_->GetStreamChannelFactory(), this);
114 session_->GetTransport()->GetStreamChannelFactory(), this);
115 116
116 if (session_->config().is_audio_enabled()) { 117 if (session_->config().is_audio_enabled()) {
117 audio_reader_.reset(new AudioReader(audio_stub_)); 118 audio_reader_.reset(new AudioReader(audio_stub_));
118 audio_reader_->Init( 119 audio_reader_->Init(transport_->GetMultiplexedChannelFactory(), this);
119 session_->GetTransport()->GetMultiplexedChannelFactory(), this);
120 } 120 }
121 break; 121 break;
122 122
123 case Session::CLOSED: 123 case Session::CLOSED:
124 CloseChannels(); 124 CloseChannels();
125 SetState(CLOSED, OK); 125 SetState(CLOSED, OK);
126 break; 126 break;
127 127
128 case Session::FAILED: 128 case Session::FAILED:
129 // If we were connected then treat signaling timeout error as if 129 // If we were connected then treat signaling timeout error as if
130 // the connection was closed by the peer. 130 // the connection was closed by the peer.
131 // 131 //
132 // TODO(sergeyu): This logic belongs to the webapp, but we 132 // TODO(sergeyu): This logic belongs to the webapp, but we
133 // currently don't expose this error code to the webapp, and it 133 // currently don't expose this error code to the webapp, and it
134 // would be hard to add it because client plugin and webapp 134 // would be hard to add it because client plugin and webapp
135 // versions may not be in sync. It should be easy to do after we 135 // versions may not be in sync. It should be easy to do after we
136 // are finished moving the client plugin to NaCl. 136 // are finished moving the client plugin to NaCl.
137 if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) { 137 if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) {
138 CloseChannels(); 138 CloseChannels();
139 SetState(CLOSED, OK); 139 SetState(CLOSED, OK);
140 } else { 140 } else {
141 CloseOnError(session_->error()); 141 CloseOnError(session_->error());
142 } 142 }
143 break; 143 break;
144 } 144 }
145 } 145 }
146 146
147 void IceConnectionToHost::OnSessionRouteChange(const std::string& channel_name, 147 void IceConnectionToHost::OnIceTransportRouteChange(
148 const TransportRoute& route) { 148 const std::string& channel_name,
149 const TransportRoute& route) {
149 event_callback_->OnRouteChanged(channel_name, route); 150 event_callback_->OnRouteChanged(channel_name, route);
150 } 151 }
151 152
153 void IceConnectionToHost::OnIceTransportError(ErrorCode error) {
154 session_->Close(error);
155 }
156
152 void IceConnectionToHost::OnChannelInitialized( 157 void IceConnectionToHost::OnChannelInitialized(
153 ChannelDispatcherBase* channel_dispatcher) { 158 ChannelDispatcherBase* channel_dispatcher) {
154 NotifyIfChannelsReady(); 159 NotifyIfChannelsReady();
155 } 160 }
156 161
157 void IceConnectionToHost::OnChannelError( 162 void IceConnectionToHost::OnChannelError(
158 ChannelDispatcherBase* channel_dispatcher, 163 ChannelDispatcherBase* channel_dispatcher,
159 ErrorCode error) { 164 ErrorCode error) {
160 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; 165 LOG(ERROR) << "Failed to connect channel "
166 << channel_dispatcher->channel_name();
161 CloseOnError(CHANNEL_CONNECTION_ERROR); 167 CloseOnError(CHANNEL_CONNECTION_ERROR);
162 return;
163 } 168 }
164 169
165 void IceConnectionToHost::OnVideoChannelStatus(bool active) { 170 void IceConnectionToHost::OnVideoChannelStatus(bool active) {
166 event_callback_->OnConnectionReady(active); 171 event_callback_->OnConnectionReady(active);
167 } 172 }
168 173
169 ConnectionToHost::State IceConnectionToHost::state() const { 174 ConnectionToHost::State IceConnectionToHost::state() const {
170 return state_; 175 return state_;
171 } 176 }
172 177
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 216
212 if (state != state_) { 217 if (state != state_) {
213 state_ = state; 218 state_ = state;
214 error_ = error; 219 error_ = error;
215 event_callback_->OnConnectionState(state_, error_); 220 event_callback_->OnConnectionState(state_, error_);
216 } 221 }
217 } 222 }
218 223
219 } // namespace protocol 224 } // namespace protocol
220 } // namespace remoting 225 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/ice_connection_to_host.h ('k') | remoting/protocol/ice_transport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698