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" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "remoting/protocol/client_control_sender.h" | 12 #include "remoting/protocol/client_control_sender.h" |
13 #include "remoting/protocol/host_message_dispatcher.h" | 13 #include "remoting/protocol/host_message_dispatcher.h" |
14 #include "remoting/protocol/host_stub.h" | 14 #include "remoting/protocol/host_stub.h" |
15 #include "remoting/protocol/input_stub.h" | 15 #include "remoting/protocol/input_stub.h" |
16 | 16 |
17 // TODO(hclam): Remove this header once MessageDispatcher is used. | |
18 #include "remoting/base/compound_buffer.h" | |
19 | |
20 namespace remoting { | 17 namespace remoting { |
21 namespace protocol { | 18 namespace protocol { |
22 | 19 |
23 // Determine how many update streams we should count to find the size of | |
24 // average update stream. | |
25 static const size_t kAverageUpdateStream = 10; | |
26 | |
27 ConnectionToClient::ConnectionToClient(base::MessageLoopProxy* message_loop, | 20 ConnectionToClient::ConnectionToClient(base::MessageLoopProxy* message_loop, |
28 EventHandler* handler) | 21 protocol::Session* session) |
29 : message_loop_(message_loop), | 22 : message_loop_(message_loop), |
30 handler_(handler), | 23 handler_(NULL), |
31 host_stub_(NULL), | 24 host_stub_(NULL), |
32 input_stub_(NULL), | 25 input_stub_(NULL), |
| 26 session_(session), |
33 control_connected_(false), | 27 control_connected_(false), |
34 input_connected_(false), | 28 input_connected_(false), |
35 video_connected_(false) { | 29 video_connected_(false) { |
36 DCHECK(message_loop_); | 30 DCHECK(message_loop_); |
37 DCHECK(handler_); | 31 session_->SetStateChangeCallback( |
| 32 base::Bind(&ConnectionToClient::OnSessionStateChange, |
| 33 base::Unretained(this))); |
38 } | 34 } |
39 | 35 |
40 ConnectionToClient::~ConnectionToClient() { | 36 ConnectionToClient::~ConnectionToClient() { |
41 // TODO(hclam): When we shut down the viewer we may have to close the | 37 // TODO(hclam): When we shut down the viewer we may have to close the |
42 // connection. | 38 // connection. |
43 } | 39 } |
44 | 40 |
45 void ConnectionToClient::Init(protocol::Session* session) { | 41 void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { |
46 DCHECK(message_loop_->BelongsToCurrentThread()); | 42 DCHECK(message_loop_->BelongsToCurrentThread()); |
47 session_.reset(session); | 43 handler_ = event_handler; |
48 session_->SetStateChangeCallback( | |
49 base::Bind(&ConnectionToClient::OnSessionStateChange, | |
50 base::Unretained(this))); | |
51 } | 44 } |
52 | 45 |
53 protocol::Session* ConnectionToClient::session() { | 46 protocol::Session* ConnectionToClient::session() { |
54 return session_.get(); | 47 return session_.get(); |
55 } | 48 } |
56 | 49 |
57 void ConnectionToClient::Disconnect() { | 50 void ConnectionToClient::Disconnect() { |
58 // This method can be called from main thread so perform threading switching. | 51 // This method can be called from main thread so perform threading switching. |
59 if (!message_loop_->BelongsToCurrentThread()) { | 52 if (!message_loop_->BelongsToCurrentThread()) { |
60 message_loop_->PostTask( | 53 message_loop_->PostTask( |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 149 |
157 void ConnectionToClient::CloseChannels() { | 150 void ConnectionToClient::CloseChannels() { |
158 if (video_writer_.get()) | 151 if (video_writer_.get()) |
159 video_writer_->Close(); | 152 video_writer_->Close(); |
160 if (client_control_sender_.get()) | 153 if (client_control_sender_.get()) |
161 client_control_sender_->Close(); | 154 client_control_sender_->Close(); |
162 } | 155 } |
163 | 156 |
164 } // namespace protocol | 157 } // namespace protocol |
165 } // namespace remoting | 158 } // namespace remoting |
OLD | NEW |