diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 18:43:37 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 18:43:37 +0000 |
commit | 4d10edeb5f3db4366b4521c2346bfb4741c21e6f (patch) | |
tree | 98a0a1d7d295cc31c0840977dc15134c1271de31 /remoting/protocol/host_message_dispatcher.h | |
parent | 45b10f0917d6449aa53f66a6ea7fa6e8a4aea079 (diff) | |
download | chromium_src-4d10edeb5f3db4366b4521c2346bfb4741c21e6f.zip chromium_src-4d10edeb5f3db4366b4521c2346bfb4741c21e6f.tar.gz chromium_src-4d10edeb5f3db4366b4521c2346bfb4741c21e6f.tar.bz2 |
HostMessageDispatcher to parse control messages
Changed MessageReader and MessageDecoder to support parsing in
HostMessageDispatcher.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/4017002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/host_message_dispatcher.h')
-rw-r--r-- | remoting/protocol/host_message_dispatcher.h | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/remoting/protocol/host_message_dispatcher.h b/remoting/protocol/host_message_dispatcher.h index aab7fbf..23dc55a 100644 --- a/remoting/protocol/host_message_dispatcher.h +++ b/remoting/protocol/host_message_dispatcher.h @@ -9,58 +9,73 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" -namespace base { -class MessageLoopProxy; -} // namespace base - namespace remoting { -class ChromotingClientMessage; -class ChromotingConnection; -class EventStreamReader; +class ChromotocolConnection; +class ClientControlMessage; +class ClientEventMessage; class HostControlMessageHandler; class HostEventMessageHandler; +class MessageReader; // A message dispatcher used to listen for messages received in -// ChromotingConnection. It dispatches messages to the corresponding +// ChromotocolConnection. It dispatches messages to the corresponding // handler. // // Internally it contains an EventStreamReader that decodes data on // communications channels into protocol buffer messages. -// EventStreamReader is registered with ChromotingConnection given to it. +// EventStreamReader is registered with ChromotocolConnection given to it. // // Object of this class is owned by ChromotingHost to dispatch messages // to itself. -class HostMessageDispatcher { +class HostMessageDispatcher : + public base::RefCountedThreadSafe<HostMessageDispatcher> { public: - // Construct a message dispatcher that dispatches messages received - // in ChromotingConnection. - HostMessageDispatcher(base::MessageLoopProxy* message_loop_proxy, - ChromotingConnection* connection, - HostControlMessageHandler* control_message_handler, - HostEventMessageHandler* event_message_handler); - + // Construct a message dispatcher. + HostMessageDispatcher(); virtual ~HostMessageDispatcher(); + // Initialize the message dispatcher with the given connection and + // message handlers. + // Return true if initalization was successful. + bool Initialize(ChromotocolConnection* connection, + HostControlMessageHandler* control_message_handler, + HostEventMessageHandler* event_message_handler); + private: + // A single protobuf can contain multiple messages that will be handled by + // different message handlers. We use this wrapper to ensure that the + // protobuf is only deleted after all the handlers have finished executing. + template <typename T> + class RefCountedMessage : public base::RefCounted<RefCountedMessage<T> > { + public: + RefCountedMessage(T* message) : message_(message) { } + + T* message() { return message_.get(); } + + private: + scoped_ptr<T> message_; + }; + // This method is called by |control_channel_reader_| when a control // message is received. - void OnControlMessageReceived(ChromotingClientMessage* message); + void OnControlMessageReceived(ClientControlMessage* message); // This method is called by |event_channel_reader_| when a event // message is received. - void OnEventMessageReceived(ChromotingClientMessage* message); + void OnEventMessageReceived(ClientEventMessage* message); - // Message loop to dispatch the messages. - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; + // Dummy methods to destroy messages. + template <class T> + static void DeleteMessage(scoped_refptr<T> message) { } - // EventStreamReader that runs on the control channel. It runs a loop - // that parses data on the channel and then delegate the message to this + // MessageReader that runs on the control channel. It runs a loop + // that parses data on the channel and then delegates the message to this // class. - scoped_ptr<EventStreamReader> control_channel_reader_; + scoped_ptr<MessageReader> control_message_reader_; - // EventStreamReader that runs on the event channel. - scoped_ptr<EventStreamReader> event_channel_reader_; + // MessageReader that runs on the event channel. + scoped_ptr<MessageReader> event_message_reader_; // Event handlers for control channel and event channel respectively. // Method calls to these objects are made on the message loop given. |