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

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

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
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 #ifndef REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ 5 #ifndef REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
6 #define REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ 6 #define REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/ref_counted.h" 9 #include "base/ref_counted.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/task.h"
11 12
12 namespace remoting { 13 namespace remoting {
13 14
14 class ChromotocolConnection; 15 class ChromotocolConnection;
15 class ClientControlMessage; 16 class EventMessage;
16 class ClientEventMessage;
17 class HostControlMessageHandler;
18 class HostEventMessageHandler;
19 class MessageReader; 17 class MessageReader;
20 18
19 namespace protocol {
20
21 class ControlMessage;
22 class HostStub;
23 class InputStub;
24
21 // A message dispatcher used to listen for messages received in 25 // A message dispatcher used to listen for messages received in
22 // ChromotocolConnection. It dispatches messages to the corresponding 26 // ChromotocolConnection. It dispatches messages to the corresponding
23 // handler. 27 // handler.
24 // 28 //
25 // Internally it contains an EventStreamReader that decodes data on 29 // Internally it contains an EventStreamReader that decodes data on
26 // communications channels into protocol buffer messages. 30 // communications channels into protocol buffer messages.
27 // EventStreamReader is registered with ChromotocolConnection given to it. 31 // EventStreamReader is registered with ChromotocolConnection given to it.
28 // 32 //
29 // Object of this class is owned by ChromotingHost to dispatch messages 33 // Object of this class is owned by ChromotingHost to dispatch messages
30 // to itself. 34 // to itself.
31 class HostMessageDispatcher : 35 class HostMessageDispatcher :
32 public base::RefCountedThreadSafe<HostMessageDispatcher> { 36 public base::RefCountedThreadSafe<HostMessageDispatcher> {
33 public: 37 public:
34 // Construct a message dispatcher. 38 // Construct a message dispatcher.
35 HostMessageDispatcher(); 39 HostMessageDispatcher();
36 virtual ~HostMessageDispatcher(); 40 virtual ~HostMessageDispatcher();
37 41
38 // Initialize the message dispatcher with the given connection and 42 // Initialize the message dispatcher with the given connection and
39 // message handlers. 43 // message handlers.
40 // Return true if initalization was successful. 44 // Return true if initalization was successful.
41 bool Initialize(ChromotocolConnection* connection, 45 bool Initialize(ChromotocolConnection* connection,
42 HostControlMessageHandler* control_message_handler, 46 HostStub* host_stub, InputStub* input_stub);
43 HostEventMessageHandler* event_message_handler);
44 47
45 private: 48 private:
46 // A single protobuf can contain multiple messages that will be handled by
47 // different message handlers. We use this wrapper to ensure that the
48 // protobuf is only deleted after all the handlers have finished executing.
49 template <typename T>
50 class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > {
51 public:
52 RefCountedMessage(T* message) : message_(message) { }
53
54 T* message() { return message_.get(); }
55
56 private:
57 scoped_ptr<T> message_;
58 };
59
60 // This method is called by |control_channel_reader_| when a control 49 // This method is called by |control_channel_reader_| when a control
61 // message is received. 50 // message is received.
62 void OnControlMessageReceived(ClientControlMessage* message); 51 void OnControlMessageReceived(ControlMessage* message);
63 52
64 // This method is called by |event_channel_reader_| when a event 53 // This method is called by |event_channel_reader_| when a event
65 // message is received. 54 // message is received.
66 void OnEventMessageReceived(ClientEventMessage* message); 55 void OnEventMessageReceived(EventMessage* message);
67
68 // Dummy methods to destroy messages.
69 template <class T>
70 static void DeleteMessage(scoped_refptr<T> message) { }
71 56
72 // MessageReader that runs on the control channel. It runs a loop 57 // MessageReader that runs on the control channel. It runs a loop
73 // that parses data on the channel and then delegates the message to this 58 // that parses data on the channel and then delegates the message to this
74 // class. 59 // class.
75 scoped_ptr<MessageReader> control_message_reader_; 60 scoped_ptr<MessageReader> control_message_reader_;
76 61
77 // MessageReader that runs on the event channel. 62 // MessageReader that runs on the event channel.
78 scoped_ptr<MessageReader> event_message_reader_; 63 scoped_ptr<MessageReader> event_message_reader_;
79 64
80 // Event handlers for control channel and event channel respectively. 65 // Stubs for host and input. These objects are not owned.
81 // Method calls to these objects are made on the message loop given. 66 // They are called on the thread there data is received, i.e. jingle thread.
82 scoped_ptr<HostControlMessageHandler> control_message_handler_; 67 HostStub* host_stub_;
83 scoped_ptr<HostEventMessageHandler> event_message_handler_; 68 InputStub* input_stub_;
84 }; 69 };
85 70
71 } // namespace protocol
86 } // namespace remoting 72 } // namespace remoting
87 73
88 #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ 74 #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_
OLDNEW
« no previous file with comments | « remoting/protocol/host_event_message_handler.h ('k') | remoting/protocol/host_message_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698