Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Side by Side Diff: remoting/protocol/connection_to_client.cc

Issue 4726003: Implement InputStub in the host side for chromoting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 11
11 // TODO(hclam): Remove this header once MessageDispatcher is used. 12 // TODO(hclam): Remove this header once MessageDispatcher is used.
12 #include "remoting/base/multiple_array_input_stream.h" 13 #include "remoting/base/multiple_array_input_stream.h"
13 14
14 namespace remoting { 15 namespace remoting {
15 namespace protocol { 16 namespace protocol {
16 17
17 // Determine how many update streams we should count to find the size of 18 // Determine how many update streams we should count to find the size of
18 // average update stream. 19 // average update stream.
19 static const size_t kAverageUpdateStream = 10; 20 static const size_t kAverageUpdateStream = 10;
20 21
21 ConnectionToClient::ConnectionToClient(MessageLoop* message_loop, 22 ConnectionToClient::ConnectionToClient(MessageLoop* message_loop,
22 EventHandler* handler) 23 EventHandler* handler,
24 HostStub* host_stub,
25 InputStub* input_stub)
23 : loop_(message_loop), 26 : loop_(message_loop),
24 handler_(handler) { 27 handler_(handler),
28 host_stub_(host_stub),
29 input_stub_(input_stub) {
25 DCHECK(loop_); 30 DCHECK(loop_);
26 DCHECK(handler_); 31 DCHECK(handler_);
27 } 32 }
28 33
29 ConnectionToClient::~ConnectionToClient() { 34 ConnectionToClient::~ConnectionToClient() {
30 // 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
31 // connection. 36 // connection.
32 } 37 }
33 38
34 void ConnectionToClient::Init(protocol::Session* session) { 39 void ConnectionToClient::Init(protocol::Session* session) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 session_ = NULL; 72 session_ = NULL;
68 } 73 }
69 } 74 }
70 75
71 ConnectionToClient::ConnectionToClient() {} 76 ConnectionToClient::ConnectionToClient() {}
72 77
73 void ConnectionToClient::OnSessionStateChange( 78 void ConnectionToClient::OnSessionStateChange(
74 protocol::Session::State state) { 79 protocol::Session::State state) {
75 if (state == protocol::Session::CONNECTED) { 80 if (state == protocol::Session::CONNECTED) {
76 client_stub_.reset(new ClientControlSender(session_->control_channel())); 81 client_stub_.reset(new ClientControlSender(session_->control_channel()));
77 event_reader_.Init<ChromotingClientMessage>(
78 session_->event_channel(),
79 NewCallback(this, &ConnectionToClient::OnMessageReceived));
80 video_writer_.reset(VideoWriter::Create(session_->config())); 82 video_writer_.reset(VideoWriter::Create(session_->config()));
81 video_writer_->Init(session_); 83 video_writer_->Init(session_);
84
85 dispatcher_.reset(new HostMessageDispatcher());
86 dispatcher_->Initialize(session_.get(), host_stub_, input_stub_);
82 } 87 }
83 88
84 loop_->PostTask(FROM_HERE, 89 loop_->PostTask(FROM_HERE,
85 NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state)); 90 NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state));
86 } 91 }
87 92
88 void ConnectionToClient::OnMessageReceived(ChromotingClientMessage* message) {
89 loop_->PostTask(FROM_HERE,
90 NewRunnableMethod(this, &ConnectionToClient::MessageReceivedTask,
91 message));
92 }
93
94 void ConnectionToClient::StateChangeTask(protocol::Session::State state) { 93 void ConnectionToClient::StateChangeTask(protocol::Session::State state) {
95 DCHECK_EQ(loop_, MessageLoop::current()); 94 DCHECK_EQ(loop_, MessageLoop::current());
96 95
97 DCHECK(handler_); 96 DCHECK(handler_);
98 switch(state) { 97 switch(state) {
99 case protocol::Session::CONNECTING: 98 case protocol::Session::CONNECTING:
100 break; 99 break;
101 // Don't care about this message. 100 // Don't care about this message.
102 case protocol::Session::CONNECTED: 101 case protocol::Session::CONNECTED:
103 handler_->OnConnectionOpened(this); 102 handler_->OnConnectionOpened(this);
104 break; 103 break;
105 case protocol::Session::CLOSED: 104 case protocol::Session::CLOSED:
106 handler_->OnConnectionClosed(this); 105 handler_->OnConnectionClosed(this);
107 break; 106 break;
108 case protocol::Session::FAILED: 107 case protocol::Session::FAILED:
109 handler_->OnConnectionFailed(this); 108 handler_->OnConnectionFailed(this);
110 break; 109 break;
111 default: 110 default:
112 // We shouldn't receive other states. 111 // We shouldn't receive other states.
113 NOTREACHED(); 112 NOTREACHED();
114 } 113 }
115 } 114 }
116 115
117 void ConnectionToClient::MessageReceivedTask(ChromotingClientMessage* message) {
118 DCHECK_EQ(loop_, MessageLoop::current());
119 DCHECK(handler_);
120 handler_->HandleMessage(this, message);
121 }
122
123 // OnClosed() is used as a callback for protocol::Session::Close(). 116 // OnClosed() is used as a callback for protocol::Session::Close().
124 void ConnectionToClient::OnClosed() { 117 void ConnectionToClient::OnClosed() {
125 } 118 }
126 119
127 } // namespace protocol 120 } // namespace protocol
128 } // namespace remoting 121 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698