| 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 "google/protobuf/message.h" | 7 #include "google/protobuf/message.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "remoting/protocol/client_control_sender.h" | 9 #include "remoting/protocol/client_control_sender.h" |
| 10 #include "remoting/protocol/host_message_dispatcher.h" | 10 #include "remoting/protocol/host_message_dispatcher.h" |
| 11 #include "remoting/protocol/host_stub.h" | 11 #include "remoting/protocol/host_stub.h" |
| 12 #include "remoting/protocol/input_stub.h" | 12 #include "remoting/protocol/input_stub.h" |
| 13 | 13 |
| 14 // TODO(hclam): Remove this header once MessageDispatcher is used. | 14 // TODO(hclam): Remove this header once MessageDispatcher is used. |
| 15 #include "remoting/base/compound_buffer.h" | 15 #include "remoting/base/compound_buffer.h" |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 namespace protocol { | 18 namespace protocol { |
| 19 | 19 |
| 20 // Determine how many update streams we should count to find the size of | 20 // Determine how many update streams we should count to find the size of |
| 21 // average update stream. | 21 // average update stream. |
| 22 static const size_t kAverageUpdateStream = 10; | 22 static const size_t kAverageUpdateStream = 10; |
| 23 | 23 |
| 24 ConnectionToClient::ConnectionToClient(MessageLoop* message_loop, | 24 ConnectionToClient::ConnectionToClient(MessageLoop* message_loop, |
| 25 EventHandler* handler) | 25 EventHandler* handler) |
| 26 : loop_(message_loop), | 26 : loop_(message_loop), |
| 27 handler_(handler), | 27 handler_(handler), |
| 28 host_stub_(NULL), | 28 host_stub_(NULL), |
| 29 input_stub_(NULL) { | 29 input_stub_(NULL), |
| 30 sequence_number_(0) { |
| 30 DCHECK(loop_); | 31 DCHECK(loop_); |
| 31 DCHECK(handler_); | 32 DCHECK(handler_); |
| 32 } | 33 } |
| 33 | 34 |
| 34 ConnectionToClient::~ConnectionToClient() { | 35 ConnectionToClient::~ConnectionToClient() { |
| 35 // TODO(hclam): When we shut down the viewer we may have to close the | 36 // TODO(hclam): When we shut down the viewer we may have to close the |
| 36 // connection. | 37 // connection. |
| 37 } | 38 } |
| 38 | 39 |
| 39 void ConnectionToClient::Init(protocol::Session* session) { | 40 void ConnectionToClient::Init(protocol::Session* session) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 return; | 58 return; |
| 58 } | 59 } |
| 59 | 60 |
| 60 // If there is a channel then close it and release the reference. | 61 // If there is a channel then close it and release the reference. |
| 61 if (session_) { | 62 if (session_) { |
| 62 session_->Close(NewRunnableMethod(this, &ConnectionToClient::OnClosed)); | 63 session_->Close(NewRunnableMethod(this, &ConnectionToClient::OnClosed)); |
| 63 session_ = NULL; | 64 session_ = NULL; |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 68 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
| 69 handler_->OnSequenceNumberUpdated(this, sequence_number); |
| 70 } |
| 71 |
| 67 VideoStub* ConnectionToClient::video_stub() { | 72 VideoStub* ConnectionToClient::video_stub() { |
| 68 return video_writer_.get(); | 73 return video_writer_.get(); |
| 69 } | 74 } |
| 70 | 75 |
| 71 // Return pointer to ClientStub. | 76 // Return pointer to ClientStub. |
| 72 ClientStub* ConnectionToClient::client_stub() { | 77 ClientStub* ConnectionToClient::client_stub() { |
| 73 return client_stub_.get(); | 78 return client_stub_.get(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { | 81 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { |
| 77 host_stub_ = host_stub; | 82 host_stub_ = host_stub; |
| 78 } | 83 } |
| 79 | 84 |
| 80 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { | 85 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { |
| 81 input_stub_ = input_stub; | 86 input_stub_ = input_stub; |
| 82 } | 87 } |
| 83 | 88 |
| 84 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { | 89 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { |
| 85 if (state == protocol::Session::CONNECTED) { | 90 if (state == protocol::Session::CONNECTED) { |
| 86 client_stub_.reset(new ClientControlSender(session_->control_channel())); | 91 client_stub_.reset(new ClientControlSender(session_->control_channel())); |
| 87 video_writer_.reset(VideoWriter::Create(session_->config())); | 92 video_writer_.reset(VideoWriter::Create(session_->config())); |
| 88 video_writer_->Init(session_); | 93 video_writer_->Init(session_); |
| 89 | 94 |
| 90 dispatcher_.reset(new HostMessageDispatcher()); | 95 dispatcher_.reset(new HostMessageDispatcher()); |
| 91 dispatcher_->Initialize(session_.get(), host_stub_, input_stub_); | 96 dispatcher_->Initialize(this, host_stub_, input_stub_); |
| 92 } | 97 } |
| 93 | 98 |
| 94 // This method can be called from main thread so perform threading switching. | 99 // This method can be called from main thread so perform threading switching. |
| 95 if (MessageLoop::current() != loop_) { | 100 if (MessageLoop::current() != loop_) { |
| 96 loop_->PostTask( | 101 loop_->PostTask( |
| 97 FROM_HERE, | 102 FROM_HERE, |
| 98 NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state)); | 103 NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state)); |
| 99 } else { | 104 } else { |
| 100 StateChangeTask(state); | 105 StateChangeTask(state); |
| 101 } | 106 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 123 NOTREACHED(); | 128 NOTREACHED(); |
| 124 } | 129 } |
| 125 } | 130 } |
| 126 | 131 |
| 127 // OnClosed() is used as a callback for protocol::Session::Close(). | 132 // OnClosed() is used as a callback for protocol::Session::Close(). |
| 128 void ConnectionToClient::OnClosed() { | 133 void ConnectionToClient::OnClosed() { |
| 129 } | 134 } |
| 130 | 135 |
| 131 } // namespace protocol | 136 } // namespace protocol |
| 132 } // namespace remoting | 137 } // namespace remoting |
| OLD | NEW |