Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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 #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/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "remoting/protocol/message_reader.h" | 11 #include "remoting/protocol/message_reader.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 class ConnectionToClient; | |
| 16 class ControlMessage; | 17 class ControlMessage; |
| 17 class EventMessage; | 18 class EventMessage; |
| 18 class HostStub; | 19 class HostStub; |
| 19 class InputStub; | 20 class InputStub; |
| 20 class Session; | 21 class Session; |
| 21 | 22 |
| 22 // A message dispatcher used to listen for messages received in | 23 // A message dispatcher used to listen for messages received in |
| 23 // protocol::Session. It dispatches messages to the corresponding | 24 // protocol::Session. It dispatches messages to the corresponding |
| 24 // handler. | 25 // handler. |
| 25 // | 26 // |
| 26 // Internally it contains an EventStreamReader that decodes data on | 27 // Internally it contains an EventStreamReader that decodes data on |
| 27 // communications channels into protocol buffer messages. | 28 // communications channels into protocol buffer messages. |
| 28 // EventStreamReader is registered with protocol::Session given to it. | 29 // EventStreamReader is registered with protocol::Session given to it. |
| 29 // | 30 // |
| 30 // Object of this class is owned by ConnectionToClient to dispatch messages | 31 // Object of this class is owned by ConnectionToClient to dispatch messages |
| 31 // to itself. | 32 // to itself. |
| 32 class HostMessageDispatcher { | 33 class HostMessageDispatcher { |
| 33 public: | 34 public: |
| 34 // Construct a message dispatcher. | 35 // Construct a message dispatcher. |
| 35 HostMessageDispatcher(); | 36 HostMessageDispatcher(); |
| 36 virtual ~HostMessageDispatcher(); | 37 virtual ~HostMessageDispatcher(); |
| 37 | 38 |
| 38 // Initialize the message dispatcher with the given connection and | 39 // Initialize the message dispatcher with the given connection and |
| 39 // message handlers. | 40 // message handlers. |
| 40 void Initialize(protocol::Session* session, | 41 void Initialize(ConnectionToClient* connection, |
| 41 HostStub* host_stub, InputStub* input_stub); | 42 HostStub* host_stub, InputStub* input_stub); |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 // This method is called by |control_channel_reader_| when a control | 45 // This method is called by |control_channel_reader_| when a control |
| 45 // message is received. | 46 // message is received. |
| 46 void OnControlMessageReceived(ControlMessage* message, Task* done_task); | 47 void OnControlMessageReceived(ControlMessage* message, Task* done_task); |
| 47 | 48 |
| 48 // This method is called by |event_channel_reader_| when a event | 49 // This method is called by |event_channel_reader_| when a event |
| 49 // message is received. | 50 // message is received. |
| 50 void OnEventMessageReceived(EventMessage* message, Task* done_task); | 51 void OnEventMessageReceived(EventMessage* message, Task* done_task); |
| 51 | 52 |
| 52 // MessageReader that runs on the control channel. It runs a loop | 53 // MessageReader that runs on the control channel. It runs a loop |
| 53 // that parses data on the channel and then delegates the message to this | 54 // that parses data on the channel and then delegates the message to this |
| 54 // class. | 55 // class. |
| 55 scoped_ptr<ProtobufMessageReader<ControlMessage> > control_message_reader_; | 56 scoped_ptr<ProtobufMessageReader<ControlMessage> > control_message_reader_; |
| 56 | 57 |
| 57 // MessageReader that runs on the event channel. | 58 // MessageReader that runs on the event channel. |
| 58 scoped_ptr<ProtobufMessageReader<EventMessage> > event_message_reader_; | 59 scoped_ptr<ProtobufMessageReader<EventMessage> > event_message_reader_; |
| 59 | 60 |
| 60 // Stubs for host and input. These objects are not owned. | 61 // Stubs for host and input. These objects are not owned. |
| 61 // They are called on the thread there data is received, i.e. jingle thread. | 62 // They are called on the thread there data is received, i.e. jingle thread. |
| 62 HostStub* host_stub_; | 63 HostStub* host_stub_; |
| 63 InputStub* input_stub_; | 64 InputStub* input_stub_; |
| 65 | |
| 66 ConnectionToClient* connection_; | |
|
Sergey Ulanov
2011/03/18 18:12:21
With this change, HostMessageDispatcher hold refer
simonmorris
2011/03/22 13:09:10
Done.
| |
| 64 }; | 67 }; |
| 65 | 68 |
| 66 } // namespace protocol | 69 } // namespace protocol |
| 67 } // namespace remoting | 70 } // namespace remoting |
| 68 | 71 |
| 69 #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ | 72 #endif // REMOTING_PROTOCOL_HOST_MESSAGE_DISPATCHER_H_ |
| OLD | NEW |