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

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

Issue 1460593005: Make protocol::ConnectionToClient an abstract interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2012 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/connection_to_client.h" 5 #include "remoting/protocol/ice_connection_to_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "remoting/protocol/audio_writer.h"
10 #include "remoting/protocol/clipboard_stub.h" 11 #include "remoting/protocol/clipboard_stub.h"
11 #include "remoting/protocol/host_control_dispatcher.h" 12 #include "remoting/protocol/host_control_dispatcher.h"
12 #include "remoting/protocol/host_event_dispatcher.h" 13 #include "remoting/protocol/host_event_dispatcher.h"
13 #include "remoting/protocol/host_stub.h" 14 #include "remoting/protocol/host_stub.h"
14 #include "remoting/protocol/host_video_dispatcher.h" 15 #include "remoting/protocol/host_video_dispatcher.h"
15 #include "remoting/protocol/input_stub.h" 16 #include "remoting/protocol/input_stub.h"
16 17
17 namespace remoting { 18 namespace remoting {
18 namespace protocol { 19 namespace protocol {
19 20
20 ConnectionToClient::ConnectionToClient(protocol::Session* session) 21 IceConnectionToClient::IceConnectionToClient(
21 : handler_(nullptr), 22 scoped_ptr<protocol::Session> session)
22 session_(session) { 23 : handler_(nullptr), session_(session.Pass()) {
23 session_->SetEventHandler(this); 24 session_->SetEventHandler(this);
24 } 25 }
25 26
26 ConnectionToClient::~ConnectionToClient() { 27 IceConnectionToClient::~IceConnectionToClient() {
27 } 28 }
28 29
29 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { 30 void IceConnectionToClient::SetEventHandler(
30 DCHECK(CalledOnValidThread()); 31 ConnectionToClient::EventHandler* event_handler) {
32 DCHECK(thread_checker_.CalledOnValidThread());
31 handler_ = event_handler; 33 handler_ = event_handler;
32 } 34 }
33 35
34 protocol::Session* ConnectionToClient::session() { 36 protocol::Session* IceConnectionToClient::session() {
35 DCHECK(CalledOnValidThread()); 37 DCHECK(thread_checker_.CalledOnValidThread());
36 return session_.get(); 38 return session_.get();
37 } 39 }
38 40
39 void ConnectionToClient::Disconnect(ErrorCode error) { 41 void IceConnectionToClient::Disconnect(ErrorCode error) {
40 DCHECK(CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
41 43
42 CloseChannels(); 44 CloseChannels();
43 45
44 // This should trigger OnConnectionClosed() event and this object 46 // This should trigger OnConnectionClosed() event and this object
45 // may be destroyed as the result. 47 // may be destroyed as the result.
46 session_->Close(error); 48 session_->Close(error);
47 } 49 }
48 50
49 void ConnectionToClient::OnInputEventReceived(int64_t timestamp) { 51 void IceConnectionToClient::OnInputEventReceived(int64_t timestamp) {
50 DCHECK(CalledOnValidThread()); 52 DCHECK(thread_checker_.CalledOnValidThread());
51 handler_->OnInputEventReceived(this, timestamp); 53 handler_->OnInputEventReceived(this, timestamp);
52 } 54 }
53 55
54 VideoStub* ConnectionToClient::video_stub() { 56 VideoStub* IceConnectionToClient::video_stub() {
55 DCHECK(CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
56 return video_dispatcher_.get(); 58 return video_dispatcher_.get();
57 } 59 }
58 60
59 AudioStub* ConnectionToClient::audio_stub() { 61 AudioStub* IceConnectionToClient::audio_stub() {
60 DCHECK(CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
61 return audio_writer_.get(); 63 return audio_writer_.get();
62 } 64 }
63 65
64 // Return pointer to ClientStub. 66 // Return pointer to ClientStub.
65 ClientStub* ConnectionToClient::client_stub() { 67 ClientStub* IceConnectionToClient::client_stub() {
66 DCHECK(CalledOnValidThread()); 68 DCHECK(thread_checker_.CalledOnValidThread());
67 return control_dispatcher_.get(); 69 return control_dispatcher_.get();
68 } 70 }
69 71
70 void ConnectionToClient::set_clipboard_stub( 72 void IceConnectionToClient::set_clipboard_stub(
71 protocol::ClipboardStub* clipboard_stub) { 73 protocol::ClipboardStub* clipboard_stub) {
72 DCHECK(CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
73 control_dispatcher_->set_clipboard_stub(clipboard_stub); 75 control_dispatcher_->set_clipboard_stub(clipboard_stub);
74 } 76 }
75 77
76 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { 78 void IceConnectionToClient::set_host_stub(protocol::HostStub* host_stub) {
77 DCHECK(CalledOnValidThread()); 79 DCHECK(thread_checker_.CalledOnValidThread());
78 control_dispatcher_->set_host_stub(host_stub); 80 control_dispatcher_->set_host_stub(host_stub);
79 } 81 }
80 82
81 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { 83 void IceConnectionToClient::set_input_stub(protocol::InputStub* input_stub) {
82 DCHECK(CalledOnValidThread()); 84 DCHECK(thread_checker_.CalledOnValidThread());
83 event_dispatcher_->set_input_stub(input_stub); 85 event_dispatcher_->set_input_stub(input_stub);
84 } 86 }
85 87
86 void ConnectionToClient::set_video_feedback_stub( 88 void IceConnectionToClient::set_video_feedback_stub(
87 VideoFeedbackStub* video_feedback_stub) { 89 VideoFeedbackStub* video_feedback_stub) {
88 DCHECK(CalledOnValidThread()); 90 DCHECK(thread_checker_.CalledOnValidThread());
89 video_dispatcher_->set_video_feedback_stub(video_feedback_stub); 91 video_dispatcher_->set_video_feedback_stub(video_feedback_stub);
90 } 92 }
91 93
92 void ConnectionToClient::OnSessionStateChange(Session::State state) { 94 void IceConnectionToClient::OnSessionStateChange(Session::State state) {
93 DCHECK(CalledOnValidThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
94 96
95 DCHECK(handler_); 97 DCHECK(handler_);
96 switch(state) { 98 switch(state) {
97 case Session::INITIALIZING: 99 case Session::INITIALIZING:
98 case Session::CONNECTING: 100 case Session::CONNECTING:
99 case Session::ACCEPTING: 101 case Session::ACCEPTING:
100 case Session::CONNECTED: 102 case Session::CONNECTED:
101 // Don't care about these events. 103 // Don't care about these events.
102 break; 104 break;
103 case Session::AUTHENTICATING: 105 case Session::AUTHENTICATING:
104 handler_->OnConnectionAuthenticating(this); 106 handler_->OnConnectionAuthenticating(this);
105 break; 107 break;
106 case Session::AUTHENTICATED: 108 case Session::AUTHENTICATED:
107 // Initialize channels. 109 // Initialize channels.
108 control_dispatcher_.reset(new HostControlDispatcher()); 110 control_dispatcher_.reset(new HostControlDispatcher());
109 control_dispatcher_->Init(session_.get(), 111 control_dispatcher_->Init(session_.get(),
110 session_->config().control_config(), this); 112 session_->config().control_config(), this);
111 113
112 event_dispatcher_.reset(new HostEventDispatcher()); 114 event_dispatcher_.reset(new HostEventDispatcher());
113 event_dispatcher_->Init(session_.get(), session_->config().event_config(), 115 event_dispatcher_->Init(session_.get(), session_->config().event_config(),
114 this); 116 this);
115 event_dispatcher_->set_on_input_event_callback(base::Bind( 117 event_dispatcher_->set_on_input_event_callback(
116 &ConnectionToClient::OnInputEventReceived, base::Unretained(this))); 118 base::Bind(&IceConnectionToClient::OnInputEventReceived,
119 base::Unretained(this)));
117 120
118 video_dispatcher_.reset(new HostVideoDispatcher()); 121 video_dispatcher_.reset(new HostVideoDispatcher());
119 video_dispatcher_->Init(session_.get(), session_->config().video_config(), 122 video_dispatcher_->Init(session_.get(), session_->config().video_config(),
120 this); 123 this);
121 124
122 audio_writer_ = AudioWriter::Create(session_->config()); 125 audio_writer_ = AudioWriter::Create(session_->config());
123 if (audio_writer_.get()) { 126 if (audio_writer_.get()) {
124 audio_writer_->Init(session_.get(), session_->config().audio_config(), 127 audio_writer_->Init(session_.get(), session_->config().audio_config(),
125 this); 128 this);
126 } 129 }
127 130
128 // Notify the handler after initializing the channels, so that 131 // Notify the handler after initializing the channels, so that
129 // ClientSession can get a client clipboard stub. 132 // ClientSession can get a client clipboard stub.
130 handler_->OnConnectionAuthenticated(this); 133 handler_->OnConnectionAuthenticated(this);
131 break; 134 break;
132 135
133 case Session::CLOSED: 136 case Session::CLOSED:
134 Close(OK); 137 Close(OK);
135 break; 138 break;
136 139
137 case Session::FAILED: 140 case Session::FAILED:
138 Close(session_->error()); 141 Close(session_->error());
139 break; 142 break;
140 } 143 }
141 } 144 }
142 145
143 void ConnectionToClient::OnSessionRouteChange( 146 void IceConnectionToClient::OnSessionRouteChange(
144 const std::string& channel_name, 147 const std::string& channel_name,
145 const TransportRoute& route) { 148 const TransportRoute& route) {
146 handler_->OnRouteChange(this, channel_name, route); 149 handler_->OnRouteChange(this, channel_name, route);
147 } 150 }
148 151
149 void ConnectionToClient::OnChannelInitialized( 152 void IceConnectionToClient::OnChannelInitialized(
150 ChannelDispatcherBase* channel_dispatcher) { 153 ChannelDispatcherBase* channel_dispatcher) {
151 DCHECK(CalledOnValidThread()); 154 DCHECK(thread_checker_.CalledOnValidThread());
152 155
153 NotifyIfChannelsReady(); 156 NotifyIfChannelsReady();
154 } 157 }
155 158
156 void ConnectionToClient::OnChannelError( 159 void IceConnectionToClient::OnChannelError(
157 ChannelDispatcherBase* channel_dispatcher, 160 ChannelDispatcherBase* channel_dispatcher,
158 ErrorCode error) { 161 ErrorCode error) {
159 DCHECK(CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
160 163
161 LOG(ERROR) << "Failed to connect channel " 164 LOG(ERROR) << "Failed to connect channel "
162 << channel_dispatcher->channel_name(); 165 << channel_dispatcher->channel_name();
163 Close(CHANNEL_CONNECTION_ERROR); 166 Close(CHANNEL_CONNECTION_ERROR);
164 } 167 }
165 168
166 void ConnectionToClient::NotifyIfChannelsReady() { 169 void IceConnectionToClient::NotifyIfChannelsReady() {
167 DCHECK(CalledOnValidThread()); 170 DCHECK(thread_checker_.CalledOnValidThread());
168 171
169 if (!control_dispatcher_ || !control_dispatcher_->is_connected()) 172 if (!control_dispatcher_ || !control_dispatcher_->is_connected())
170 return; 173 return;
171 if (!event_dispatcher_ || !event_dispatcher_->is_connected()) 174 if (!event_dispatcher_ || !event_dispatcher_->is_connected())
172 return; 175 return;
173 if (!video_dispatcher_ || !video_dispatcher_->is_connected()) 176 if (!video_dispatcher_ || !video_dispatcher_->is_connected())
174 return; 177 return;
175 if ((!audio_writer_ || !audio_writer_->is_connected()) && 178 if ((!audio_writer_ || !audio_writer_->is_connected()) &&
176 session_->config().is_audio_enabled()) { 179 session_->config().is_audio_enabled()) {
177 return; 180 return;
178 } 181 }
179 handler_->OnConnectionChannelsConnected(this); 182 handler_->OnConnectionChannelsConnected(this);
180 } 183 }
181 184
182 void ConnectionToClient::Close(ErrorCode error) { 185 void IceConnectionToClient::Close(ErrorCode error) {
183 CloseChannels(); 186 CloseChannels();
184 handler_->OnConnectionClosed(this, error); 187 handler_->OnConnectionClosed(this, error);
185 } 188 }
186 189
187 void ConnectionToClient::CloseChannels() { 190 void IceConnectionToClient::CloseChannels() {
188 control_dispatcher_.reset(); 191 control_dispatcher_.reset();
189 event_dispatcher_.reset(); 192 event_dispatcher_.reset();
190 video_dispatcher_.reset(); 193 video_dispatcher_.reset();
191 audio_writer_.reset(); 194 audio_writer_.reset();
192 } 195 }
193 196
194 } // namespace protocol 197 } // namespace protocol
195 } // namespace remoting 198 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698