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 | 37 if (session_.get()) |
38 // connection. | 38 message_loop_->DeleteSoon(FROM_HERE, session_.release()); |
39 } | 39 } |
40 | 40 |
41 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { | 41 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { |
42 DCHECK(message_loop_->BelongsToCurrentThread()); | 42 DCHECK(message_loop_->BelongsToCurrentThread()); |
43 handler_ = event_handler; | 43 handler_ = event_handler; |
44 } | 44 } |
45 | 45 |
46 protocol::Session* ConnectionToClient::session() { | 46 protocol::Session* ConnectionToClient::session() { |
47 return session_.get(); | 47 return session_.get(); |
48 } | 48 } |
49 | 49 |
50 void ConnectionToClient::Disconnect() { | 50 void ConnectionToClient::Disconnect() { |
51 // This method can be called from main thread so perform threading switching. | 51 DCHECK(message_loop_->BelongsToCurrentThread()); |
52 if (!message_loop_->BelongsToCurrentThread()) { | |
53 message_loop_->PostTask( | |
54 FROM_HERE, base::Bind(&ConnectionToClient::Disconnect, this)); | |
55 return; | |
56 } | |
57 | 52 |
58 CloseChannels(); | 53 CloseChannels(); |
59 | 54 |
60 // If there is a session then release it, causing it to close. | 55 DCHECK(session_.get()); |
61 if (session_.get()) | 56 Session* session = session_.release(); |
62 session_.reset(); | 57 |
| 58 // It may not be safe to delete |session_| here becase this method |
| 59 // may be invoked in resonse to a libjingle event and libjingle's |
| 60 // sigslot doesn't handle it properly, so postpone the deletion. |
| 61 message_loop_->DeleteSoon(FROM_HERE, session); |
| 62 |
| 63 // This should trigger OnConnectionClosed() event and this object |
| 64 // may be destroyed as the result. |
| 65 session->Close(); |
63 } | 66 } |
64 | 67 |
65 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { | 68 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
66 handler_->OnSequenceNumberUpdated(this, sequence_number); | 69 handler_->OnSequenceNumberUpdated(this, sequence_number); |
67 } | 70 } |
68 | 71 |
69 VideoStub* ConnectionToClient::video_stub() { | 72 VideoStub* ConnectionToClient::video_stub() { |
70 return video_writer_.get(); | 73 return video_writer_.get(); |
71 } | 74 } |
72 | 75 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 152 |
150 void ConnectionToClient::CloseChannels() { | 153 void ConnectionToClient::CloseChannels() { |
151 if (video_writer_.get()) | 154 if (video_writer_.get()) |
152 video_writer_->Close(); | 155 video_writer_->Close(); |
153 if (client_control_sender_.get()) | 156 if (client_control_sender_.get()) |
154 client_control_sender_->Close(); | 157 client_control_sender_->Close(); |
155 } | 158 } |
156 | 159 |
157 } // namespace protocol | 160 } // namespace protocol |
158 } // namespace remoting | 161 } // namespace remoting |
OLD | NEW |