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

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

Issue 4336001: Stub classes for Chromoting and use them in HostMessageDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « remoting/protocol/host_message_dispatcher.h ('k') | remoting/protocol/host_stub.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/base/io_buffer.h" 5 #include "net/base/io_buffer.h"
6 #include "remoting/base/multiple_array_input_stream.h" 6 #include "remoting/base/multiple_array_input_stream.h"
7 #include "remoting/proto/control.pb.h" 7 #include "remoting/proto/control.pb.h"
8 #include "remoting/proto/event.pb.h" 8 #include "remoting/proto/event.pb.h"
9 #include "remoting/proto/video.pb.h" 9 #include "remoting/proto/video.pb.h"
10 #include "remoting/protocol/chromotocol_connection.h" 10 #include "remoting/protocol/chromotocol_connection.h"
11 #include "remoting/protocol/host_message_dispatcher.h" 11 #include "remoting/protocol/host_message_dispatcher.h"
12 #include "remoting/protocol/host_control_message_handler.h" 12 #include "remoting/protocol/host_stub.h"
13 #include "remoting/protocol/host_event_message_handler.h" 13 #include "remoting/protocol/input_stub.h"
14 #include "remoting/protocol/message_reader.h" 14 #include "remoting/protocol/message_reader.h"
15 15
16 namespace {
17
18 // A single protobuf can contain multiple messages that will be handled by
19 // different message handlers. We use this wrapper to ensure that the
20 // protobuf is only deleted after all the handlers have finished executing.
21 template <typename T>
22 class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > {
23 public:
24 RefCountedMessage(T* message) : message_(message) { }
25
26 T* message() { return message_.get(); }
27
28 private:
29 scoped_ptr<T> message_;
30 };
31
32 // Dummy methods to destroy messages.
33 template <class T>
34 static void DeleteMessage(scoped_refptr<T> message) { }
35
36 template <class T>
37 static Task* NewDeleteTask(scoped_refptr<T> message) {
38 return NewRunnableFunction(&DeleteMessage<T>, message);
39 }
40
41 } // namespace
42
16 namespace remoting { 43 namespace remoting {
44 namespace protocol {
17 45
18 HostMessageDispatcher::HostMessageDispatcher() { 46 HostMessageDispatcher::HostMessageDispatcher() :
47 host_stub_(NULL),
48 input_stub_(NULL) {
19 } 49 }
20 50
21 HostMessageDispatcher::~HostMessageDispatcher() { 51 HostMessageDispatcher::~HostMessageDispatcher() {
22 } 52 }
23 53
24 bool HostMessageDispatcher::Initialize( 54 bool HostMessageDispatcher::Initialize(
25 ChromotocolConnection* connection, 55 ChromotocolConnection* connection,
26 HostControlMessageHandler* control_message_handler, 56 HostStub* host_stub, InputStub* input_stub) {
27 HostEventMessageHandler* event_message_handler) { 57 if (!connection || !host_stub || !input_stub ||
28 if (!connection || !control_message_handler || !event_message_handler ||
29 !connection->event_channel() || !connection->control_channel()) { 58 !connection->event_channel() || !connection->control_channel()) {
30 return false; 59 return false;
31 } 60 }
32 61
33 control_message_reader_.reset(new MessageReader()); 62 control_message_reader_.reset(new MessageReader());
34 event_message_reader_.reset(new MessageReader()); 63 event_message_reader_.reset(new MessageReader());
35 control_message_handler_.reset(control_message_handler); 64 host_stub_ = host_stub;
36 event_message_handler_.reset(event_message_handler); 65 input_stub_ = input_stub;
37 66
38 // Initialize the readers on the sockets provided by channels. 67 // Initialize the readers on the sockets provided by channels.
39 event_message_reader_->Init<ClientEventMessage>( 68 event_message_reader_->Init<EventMessage>(
40 connection->event_channel(), 69 connection->event_channel(),
41 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived)); 70 NewCallback(this, &HostMessageDispatcher::OnEventMessageReceived));
42 control_message_reader_->Init<ClientControlMessage>( 71 control_message_reader_->Init<ControlMessage>(
43 connection->control_channel(), 72 connection->control_channel(),
44 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived)); 73 NewCallback(this, &HostMessageDispatcher::OnControlMessageReceived));
45 return true; 74 return true;
46 } 75 }
47 76
48 void HostMessageDispatcher::OnControlMessageReceived( 77 void HostMessageDispatcher::OnControlMessageReceived(ControlMessage* message) {
49 ClientControlMessage* message) { 78 scoped_refptr<RefCountedMessage<ControlMessage> > ref_msg =
50 scoped_refptr<RefCountedMessage<ClientControlMessage> > ref_msg( 79 new RefCountedMessage<ControlMessage>(message);
51 new RefCountedMessage<ClientControlMessage>(message)); 80 if (message->has_suggest_resolution()) {
52 if (message->has_suggest_screen_resolution_request()) { 81 host_stub_->SuggestResolution(
53 control_message_handler_->OnSuggestScreenResolutionRequest( 82 message->suggest_resolution(), NewDeleteTask(ref_msg));
54 message->suggest_screen_resolution_request(),
55 NewRunnableFunction(
56 &DeleteMessage<RefCountedMessage<ClientControlMessage> >,
57 ref_msg));
58 } 83 }
59 } 84 }
60 85
61 void HostMessageDispatcher::OnEventMessageReceived( 86 void HostMessageDispatcher::OnEventMessageReceived(
62 ClientEventMessage* message) { 87 EventMessage* message) {
63 // TODO(hclam): Implement. 88 // TODO(hclam): Implement.
64 } 89 }
65 90
91 } // namespace protocol
66 } // namespace remoting 92 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/host_message_dispatcher.h ('k') | remoting/protocol/host_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698