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 16 matching lines...) Expand all Loading... |
27 control_connected_(false), | 27 control_connected_(false), |
28 input_connected_(false), | 28 input_connected_(false), |
29 video_connected_(false) { | 29 video_connected_(false) { |
30 DCHECK(message_loop_); | 30 DCHECK(message_loop_); |
31 session_->SetStateChangeCallback( | 31 session_->SetStateChangeCallback( |
32 base::Bind(&ConnectionToClient::OnSessionStateChange, | 32 base::Bind(&ConnectionToClient::OnSessionStateChange, |
33 base::Unretained(this))); | 33 base::Unretained(this))); |
34 } | 34 } |
35 | 35 |
36 ConnectionToClient::~ConnectionToClient() { | 36 ConnectionToClient::~ConnectionToClient() { |
37 // TODO(hclam): When we shut down the viewer we may have to close the | |
38 // connection. | |
39 } | 37 } |
40 | 38 |
41 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { | 39 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { |
42 DCHECK(message_loop_->BelongsToCurrentThread()); | 40 DCHECK(message_loop_->BelongsToCurrentThread()); |
43 handler_ = event_handler; | 41 handler_ = event_handler; |
44 } | 42 } |
45 | 43 |
46 protocol::Session* ConnectionToClient::session() { | 44 protocol::Session* ConnectionToClient::session() { |
47 return session_.get(); | 45 return session_.get(); |
48 } | 46 } |
49 | 47 |
50 void ConnectionToClient::Disconnect() { | 48 void ConnectionToClient::Disconnect() { |
51 // This method can be called from main thread so perform threading switching. | 49 DCHECK(message_loop_->BelongsToCurrentThread()); |
52 if (!message_loop_->BelongsToCurrentThread()) { | |
53 message_loop_->PostTask( | |
54 FROM_HERE, | |
55 NewRunnableMethod(this, &ConnectionToClient::Disconnect)); | |
56 return; | |
57 } | |
58 | 50 |
59 CloseChannels(); | 51 CloseChannels(); |
60 | 52 |
61 // If there is a session then release it, causing it to close. | 53 // If there is a session then release it, causing it to close. |
62 if (session_.get()) | 54 if (session_.get()) { |
63 session_.reset(); | 55 session_->Close(); |
| 56 // It may not be safe to delete |session_| here becase this method |
| 57 // may be invoked in resonse to a libjingle event and libjingle's |
| 58 // sigslot doesn't handle it properly, so postpone the deletion. |
| 59 message_loop_->DeleteSoon(FROM_HERE, session_.release()); |
| 60 } |
64 } | 61 } |
65 | 62 |
66 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { | 63 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
67 handler_->OnSequenceNumberUpdated(this, sequence_number); | 64 handler_->OnSequenceNumberUpdated(this, sequence_number); |
68 } | 65 } |
69 | 66 |
70 VideoStub* ConnectionToClient::video_stub() { | 67 VideoStub* ConnectionToClient::video_stub() { |
71 return video_writer_.get(); | 68 return video_writer_.get(); |
72 } | 69 } |
73 | 70 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 147 |
151 void ConnectionToClient::CloseChannels() { | 148 void ConnectionToClient::CloseChannels() { |
152 if (video_writer_.get()) | 149 if (video_writer_.get()) |
153 video_writer_->Close(); | 150 video_writer_->Close(); |
154 if (client_control_sender_.get()) | 151 if (client_control_sender_.get()) |
155 client_control_sender_->Close(); | 152 client_control_sender_->Close(); |
156 } | 153 } |
157 | 154 |
158 } // namespace protocol | 155 } // namespace protocol |
159 } // namespace remoting | 156 } // namespace remoting |
OLD | NEW |