Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 23 matching lines...) Expand all Loading... | |
| 34 control_connected_(false), | 34 control_connected_(false), |
| 35 input_connected_(false), | 35 input_connected_(false), |
| 36 video_connected_(false) { | 36 video_connected_(false) { |
| 37 DCHECK(message_loop_); | 37 DCHECK(message_loop_); |
| 38 session_->SetStateChangeCallback( | 38 session_->SetStateChangeCallback( |
| 39 base::Bind(&ConnectionToClient::OnSessionStateChange, | 39 base::Bind(&ConnectionToClient::OnSessionStateChange, |
| 40 base::Unretained(this))); | 40 base::Unretained(this))); |
| 41 } | 41 } |
| 42 | 42 |
| 43 ConnectionToClient::~ConnectionToClient() { | 43 ConnectionToClient::~ConnectionToClient() { |
| 44 // TODO(hclam): When we shut down the viewer we may have to close the | |
| 45 // connection. | |
| 46 } | 44 } |
| 47 | 45 |
| 48 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { | 46 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { |
| 49 DCHECK(message_loop_->BelongsToCurrentThread()); | 47 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 50 handler_ = event_handler; | 48 handler_ = event_handler; |
| 51 } | 49 } |
| 52 | 50 |
| 53 protocol::Session* ConnectionToClient::session() { | 51 protocol::Session* ConnectionToClient::session() { |
| 54 return session_.get(); | 52 return session_.get(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void ConnectionToClient::Disconnect() { | 55 void ConnectionToClient::Disconnect() { |
| 58 // This method can be called from main thread so perform threading switching. | 56 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 59 if (!message_loop_->BelongsToCurrentThread()) { | |
| 60 message_loop_->PostTask( | |
| 61 FROM_HERE, | |
| 62 NewRunnableMethod(this, &ConnectionToClient::Disconnect)); | |
| 63 return; | |
| 64 } | |
| 65 | 57 |
| 66 CloseChannels(); | 58 CloseChannels(); |
| 67 | 59 |
| 68 // If there is a session then release it, causing it to close. | 60 // If there is a session then release it, causing it to close. |
| 69 if (session_.get()) | 61 if (session_.get()) { |
| 70 session_.reset(); | 62 session_->Close(); |
| 63 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 64 &DeletePointer<protocol::Session>, session_.release())); | |
|
Wez
2011/11/09 02:32:22
Like DeleteSoon()?
Sergey Ulanov
2011/11/09 21:24:00
Done.
| |
| 65 } | |
| 71 } | 66 } |
| 72 | 67 |
| 73 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { | 68 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
| 74 if (handler_) | 69 if (handler_) |
| 75 handler_->OnSequenceNumberUpdated(this, sequence_number); | 70 handler_->OnSequenceNumberUpdated(this, sequence_number); |
| 76 } | 71 } |
| 77 | 72 |
| 78 VideoStub* ConnectionToClient::video_stub() { | 73 VideoStub* ConnectionToClient::video_stub() { |
| 79 return video_writer_.get(); | 74 return video_writer_.get(); |
| 80 } | 75 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 156 |
| 162 void ConnectionToClient::CloseChannels() { | 157 void ConnectionToClient::CloseChannels() { |
| 163 if (video_writer_.get()) | 158 if (video_writer_.get()) |
| 164 video_writer_->Close(); | 159 video_writer_->Close(); |
| 165 if (client_control_sender_.get()) | 160 if (client_control_sender_.get()) |
| 166 client_control_sender_->Close(); | 161 client_control_sender_->Close(); |
| 167 } | 162 } |
| 168 | 163 |
| 169 } // namespace protocol | 164 } // namespace protocol |
| 170 } // namespace remoting | 165 } // namespace remoting |
| OLD | NEW |