| 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 InputStub* input_stub) | 26 : loop_(message_loop), |
| 27 : client_authenticated_(false), | |
| 28 loop_(message_loop), | |
| 29 handler_(handler), | 27 handler_(handler), |
| 30 host_stub_(NULL), | 28 host_stub_(NULL), |
| 31 input_stub_(input_stub) { | 29 input_stub_(NULL) { |
| 32 DCHECK(loop_); | 30 DCHECK(loop_); |
| 33 DCHECK(handler_); | 31 DCHECK(handler_); |
| 34 } | 32 } |
| 35 | 33 |
| 36 ConnectionToClient::~ConnectionToClient() { | 34 ConnectionToClient::~ConnectionToClient() { |
| 37 // TODO(hclam): When we shut down the viewer we may have to close the | 35 // TODO(hclam): When we shut down the viewer we may have to close the |
| 38 // connection. | 36 // connection. |
| 39 } | 37 } |
| 40 | 38 |
| 41 void ConnectionToClient::Init(protocol::Session* session) { | 39 void ConnectionToClient::Init(protocol::Session* session) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 | 66 |
| 69 VideoStub* ConnectionToClient::video_stub() { | 67 VideoStub* ConnectionToClient::video_stub() { |
| 70 return video_writer_.get(); | 68 return video_writer_.get(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 // Return pointer to ClientStub. | 71 // Return pointer to ClientStub. |
| 74 ClientStub* ConnectionToClient::client_stub() { | 72 ClientStub* ConnectionToClient::client_stub() { |
| 75 return client_stub_.get(); | 73 return client_stub_.get(); |
| 76 } | 74 } |
| 77 | 75 |
| 78 protocol::HostStub* ConnectionToClient::host_stub() { | |
| 79 return host_stub_; | |
| 80 } | |
| 81 | |
| 82 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { | 76 void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { |
| 83 host_stub_ = host_stub; | 77 host_stub_ = host_stub; |
| 84 } | 78 } |
| 85 | 79 |
| 80 void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { |
| 81 input_stub_ = input_stub; |
| 82 } |
| 83 |
| 86 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { | 84 void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { |
| 87 if (state == protocol::Session::CONNECTED) { | 85 if (state == protocol::Session::CONNECTED) { |
| 88 client_stub_.reset(new ClientControlSender(session_->control_channel())); | 86 client_stub_.reset(new ClientControlSender(session_->control_channel())); |
| 89 video_writer_.reset(VideoWriter::Create(session_->config())); | 87 video_writer_.reset(VideoWriter::Create(session_->config())); |
| 90 video_writer_->Init(session_); | 88 video_writer_->Init(session_); |
| 91 | 89 |
| 92 dispatcher_.reset(new HostMessageDispatcher()); | 90 dispatcher_.reset(new HostMessageDispatcher()); |
| 93 dispatcher_->Initialize(session_.get(), host_stub_, input_stub_); | 91 dispatcher_->Initialize(session_.get(), host_stub_, input_stub_); |
| 94 } | 92 } |
| 95 | 93 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 handler_->OnConnectionFailed(this); | 119 handler_->OnConnectionFailed(this); |
| 122 break; | 120 break; |
| 123 default: | 121 default: |
| 124 // We shouldn't receive other states. | 122 // We shouldn't receive other states. |
| 125 NOTREACHED(); | 123 NOTREACHED(); |
| 126 } | 124 } |
| 127 } | 125 } |
| 128 | 126 |
| 129 // OnClosed() is used as a callback for protocol::Session::Close(). | 127 // OnClosed() is used as a callback for protocol::Session::Close(). |
| 130 void ConnectionToClient::OnClosed() { | 128 void ConnectionToClient::OnClosed() { |
| 131 client_authenticated_ = false; | |
| 132 | |
| 133 // TODO(lambroslambrou): Remove these when stubs are refactored not to | |
| 134 // store authentication state. | |
| 135 if (input_stub_) | |
| 136 input_stub_->OnClosed(); | |
| 137 if (host_stub_) | |
| 138 host_stub_->OnClosed(); | |
| 139 if (client_stub_.get()) | |
| 140 client_stub_->OnClosed(); | |
| 141 } | |
| 142 | |
| 143 void ConnectionToClient::OnClientAuthenticated() { | |
| 144 client_authenticated_ = true; | |
| 145 | |
| 146 // Enable/disable each of the channels. | |
| 147 if (input_stub_) | |
| 148 input_stub_->OnAuthenticated(); | |
| 149 if (host_stub_) | |
| 150 host_stub_->OnAuthenticated(); | |
| 151 if (client_stub_.get()) | |
| 152 client_stub_->OnAuthenticated(); | |
| 153 } | |
| 154 | |
| 155 bool ConnectionToClient::client_authenticated() { | |
| 156 return client_authenticated_; | |
| 157 } | 129 } |
| 158 | 130 |
| 159 } // namespace protocol | 131 } // namespace protocol |
| 160 } // namespace remoting | 132 } // namespace remoting |
| OLD | NEW |