Chromium Code Reviews| 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_client.h" | 5 #include "remoting/protocol/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 "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "google/protobuf/message.h" | 10 #include "google/protobuf/message.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { | 61 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
| 62 DCHECK(CalledOnValidThread()); | 62 DCHECK(CalledOnValidThread()); |
| 63 handler_->OnSequenceNumberUpdated(this, sequence_number); | 63 handler_->OnSequenceNumberUpdated(this, sequence_number); |
| 64 } | 64 } |
| 65 | 65 |
| 66 VideoStub* ConnectionToClient::video_stub() { | 66 VideoStub* ConnectionToClient::video_stub() { |
| 67 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
| 68 return video_writer_.get(); | 68 return video_writer_.get(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 AudioStub* ConnectionToClient::audio_stub() { | |
| 72 DCHECK(CalledOnValidThread()); | |
| 73 return audio_writer_.get(); | |
| 74 } | |
| 75 | |
| 71 // Return pointer to ClientStub. | 76 // Return pointer to ClientStub. |
| 72 ClientStub* ConnectionToClient::client_stub() { | 77 ClientStub* ConnectionToClient::client_stub() { |
| 73 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
| 74 return control_dispatcher_.get(); | 79 return control_dispatcher_.get(); |
| 75 } | 80 } |
| 76 | 81 |
| 77 void ConnectionToClient::set_clipboard_stub( | 82 void ConnectionToClient::set_clipboard_stub( |
| 78 protocol::ClipboardStub* clipboard_stub) { | 83 protocol::ClipboardStub* clipboard_stub) { |
| 79 DCHECK(CalledOnValidThread()); | 84 DCHECK(CalledOnValidThread()); |
| 80 clipboard_stub_ = clipboard_stub; | 85 clipboard_stub_ = clipboard_stub; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 event_dispatcher_->Init(session_.get(), base::Bind( | 118 event_dispatcher_->Init(session_.get(), base::Bind( |
| 114 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); | 119 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); |
| 115 event_dispatcher_->set_input_stub(input_stub_); | 120 event_dispatcher_->set_input_stub(input_stub_); |
| 116 event_dispatcher_->set_sequence_number_callback(base::Bind( | 121 event_dispatcher_->set_sequence_number_callback(base::Bind( |
| 117 &ConnectionToClient::UpdateSequenceNumber, base::Unretained(this))); | 122 &ConnectionToClient::UpdateSequenceNumber, base::Unretained(this))); |
| 118 | 123 |
| 119 video_writer_ = VideoWriter::Create(session_->config()); | 124 video_writer_ = VideoWriter::Create(session_->config()); |
| 120 video_writer_->Init(session_.get(), base::Bind( | 125 video_writer_->Init(session_.get(), base::Bind( |
| 121 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); | 126 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); |
| 122 | 127 |
| 128 use_audio_ = (session_->config().audio_config().transport != | |
| 129 ChannelConfig::TRANSPORT_NONE); | |
| 130 if (use_audio_) { | |
| 131 audio_writer_ = AudioWriter::Create(session_->config()); | |
|
Sergey Ulanov
2012/06/21 17:24:56
Change AudioWriter::Create() to return NULL when a
kxing
2012/06/21 18:09:22
Even if AudioWriter::Create() returns NULL, wouldn
Sergey Ulanov
2012/06/21 18:20:45
Yes, you will need to check NULL before calling In
| |
| 132 audio_writer_->Init(session_.get(), base::Bind( | |
| 133 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); | |
| 134 } | |
| 135 | |
| 123 // Notify the handler after initializing the channels, so that | 136 // Notify the handler after initializing the channels, so that |
| 124 // ClientSession can get a client clipboard stub. | 137 // ClientSession can get a client clipboard stub. |
| 125 handler_->OnConnectionAuthenticated(this); | 138 handler_->OnConnectionAuthenticated(this); |
| 126 break; | 139 break; |
| 127 | 140 |
| 128 case Session::CLOSED: | 141 case Session::CLOSED: |
| 129 Close(OK); | 142 Close(OK); |
| 130 break; | 143 break; |
| 131 | 144 |
| 132 case Session::FAILED: | 145 case Session::FAILED: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 151 } | 164 } |
| 152 | 165 |
| 153 NotifyIfChannelsReady(); | 166 NotifyIfChannelsReady(); |
| 154 } | 167 } |
| 155 | 168 |
| 156 void ConnectionToClient::NotifyIfChannelsReady() { | 169 void ConnectionToClient::NotifyIfChannelsReady() { |
| 157 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
| 158 | 171 |
| 159 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && | 172 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && |
| 160 event_dispatcher_.get() && event_dispatcher_->is_connected() && | 173 event_dispatcher_.get() && event_dispatcher_->is_connected() && |
| 161 video_writer_.get() && video_writer_->is_connected()) { | 174 video_writer_.get() && video_writer_->is_connected() && |
| 175 (!use_audio_ || (audio_writer_.get() && audio_writer_->is_connected()))) { | |
|
Sergey Ulanov
2012/06/21 17:24:56
This code potentially may be called even before yo
kxing
2012/06/21 18:09:22
Done.
| |
| 162 handler_->OnConnectionChannelsConnected(this); | 176 handler_->OnConnectionChannelsConnected(this); |
| 163 } | 177 } |
| 164 } | 178 } |
| 165 | 179 |
| 166 void ConnectionToClient::Close(ErrorCode error) { | 180 void ConnectionToClient::Close(ErrorCode error) { |
| 167 CloseChannels(); | 181 CloseChannels(); |
| 168 handler_->OnConnectionClosed(this, error); | 182 handler_->OnConnectionClosed(this, error); |
| 169 } | 183 } |
| 170 | 184 |
| 171 void ConnectionToClient::CloseChannels() { | 185 void ConnectionToClient::CloseChannels() { |
| 172 control_dispatcher_.reset(); | 186 control_dispatcher_.reset(); |
| 173 event_dispatcher_.reset(); | 187 event_dispatcher_.reset(); |
| 174 video_writer_.reset(); | 188 video_writer_.reset(); |
| 189 audio_writer_.reset(); | |
| 175 } | 190 } |
| 176 | 191 |
| 177 } // namespace protocol | 192 } // namespace protocol |
| 178 } // namespace remoting | 193 } // namespace remoting |
| OLD | NEW |