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" |
| 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 26 matching lines...) Expand all Loading... | |
| 87 host_stub_ = host_stub; | 80 host_stub_ = host_stub; |
| 88 } | 81 } |
| 89 | 82 |
| 90 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { | 83 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { |
| 91 input_stub_ = input_stub; | 84 input_stub_ = input_stub; |
| 92 } | 85 } |
| 93 | 86 |
| 94 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { | 87 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { |
| 95 DCHECK(message_loop_->BelongsToCurrentThread()); | 88 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 96 | 89 |
| 97 DCHECK(handler_); | 90 DCHECK(handler_); |
|
Wez
2011/11/09 23:34:50
Doesn't this mean we can't handle state change eve
Sergey Ulanov
2011/11/10 00:55:57
SetEventHandler() is required to be called after C
| |
| 98 switch(state) { | 91 switch(state) { |
| 99 case protocol::Session::CONNECTING: | 92 case protocol::Session::CONNECTING: |
| 100 // Don't care about this message. | 93 // Don't care about this message. |
| 101 break; | 94 break; |
| 102 | 95 |
| 103 case protocol::Session::CONNECTED: | 96 case protocol::Session::CONNECTED: |
| 104 video_writer_.reset( | 97 video_writer_.reset( |
| 105 VideoWriter::Create(message_loop_, session_->config())); | 98 VideoWriter::Create(message_loop_, session_->config())); |
| 106 video_writer_->Init( | 99 video_writer_->Init( |
| 107 session_.get(), base::Bind(&ConnectionToClient::OnVideoInitialized, | 100 session_.get(), base::Bind(&ConnectionToClient::OnVideoInitialized, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 150 |
| 158 void ConnectionToClient::CloseChannels() { | 151 void ConnectionToClient::CloseChannels() { |
| 159 if (video_writer_.get()) | 152 if (video_writer_.get()) |
| 160 video_writer_->Close(); | 153 video_writer_->Close(); |
| 161 if (client_control_sender_.get()) | 154 if (client_control_sender_.get()) |
| 162 client_control_sender_->Close(); | 155 client_control_sender_->Close(); |
| 163 } | 156 } |
| 164 | 157 |
| 165 } // namespace protocol | 158 } // namespace protocol |
| 166 } // namespace remoting | 159 } // namespace remoting |
| OLD | NEW |