Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CHANNEL_DISPATCHER_BASE_H_ | 5 #ifndef REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
| 6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "remoting/base/buffered_socket_writer.h" | 13 #include "remoting/base/buffered_socket_writer.h" |
| 14 #include "remoting/protocol/errors.h" | 14 #include "remoting/protocol/errors.h" |
| 15 #include "remoting/protocol/message_reader.h" | 15 #include "remoting/protocol/stream_message_pipe_adapter.h" |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 namespace protocol { | 18 namespace protocol { |
| 19 | 19 |
| 20 class StreamChannelFactory; | 20 class StreamChannelFactory; |
| 21 | 21 |
| 22 // Base class for channel message dispatchers. It's responsible for | 22 // Base class for channel message dispatchers. It's responsible for |
| 23 // creating the named channel. Derived dispatchers then dispatch | 23 // creating the named channel. Derived dispatchers then dispatch |
| 24 // incoming messages on this channel as well as send outgoing | 24 // incoming messages on this channel as well as send outgoing |
| 25 // messages. | 25 // messages. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 42 | 42 |
| 43 virtual ~ChannelDispatcherBase(); | 43 virtual ~ChannelDispatcherBase(); |
| 44 | 44 |
| 45 // Creates and connects the channel in the specified | 45 // Creates and connects the channel in the specified |
| 46 // |session|. Caller retains ownership of the Session. | 46 // |session|. Caller retains ownership of the Session. |
| 47 void Init(StreamChannelFactory* channel_factory, EventHandler* event_handler); | 47 void Init(StreamChannelFactory* channel_factory, EventHandler* event_handler); |
| 48 | 48 |
| 49 const std::string& channel_name() { return channel_name_; } | 49 const std::string& channel_name() { return channel_name_; } |
| 50 | 50 |
| 51 // Returns true if the channel is currently connected. | 51 // Returns true if the channel is currently connected. |
| 52 bool is_connected() { return channel_ != nullptr; } | 52 bool is_connected() { return message_pipe() != nullptr; } |
|
Jamie
2016/02/01 22:48:20
message_pipe() can never return null with this imp
Sergey Ulanov
2016/02/02 21:16:42
Replaced message_pipe_ with a scoped_ptr.
| |
| 53 | 53 |
| 54 protected: | 54 protected: |
| 55 explicit ChannelDispatcherBase(const char* channel_name); | 55 explicit ChannelDispatcherBase(const char* channel_name); |
| 56 | 56 |
| 57 BufferedSocketWriter* writer() { return &writer_; } | 57 MessagePipe* message_pipe() { return &message_pipe_; } |
| 58 | 58 |
| 59 // Should be overridden in child classes to handle incoming messages. | |
| 60 virtual void OnIncomingMessage(scoped_ptr<CompoundBuffer> message); | 59 virtual void OnIncomingMessage(scoped_ptr<CompoundBuffer> message); |
| 61 | 60 |
| 62 private: | 61 private: |
| 63 void OnChannelReady(scoped_ptr<P2PStreamSocket> socket); | 62 void OnChannelReady(scoped_ptr<P2PStreamSocket> socket); |
| 64 void OnReadWriteFailed(int error); | 63 void OnPipeError(int error); |
| 65 | 64 |
| 66 std::string channel_name_; | 65 std::string channel_name_; |
| 67 StreamChannelFactory* channel_factory_; | 66 StreamChannelFactory* channel_factory_; |
| 68 EventHandler* event_handler_; | 67 EventHandler* event_handler_; |
| 69 scoped_ptr<P2PStreamSocket> channel_; | |
| 70 | 68 |
| 71 BufferedSocketWriter writer_; | 69 StreamMessagePipeAdapter message_pipe_; |
| 72 MessageReader reader_; | |
| 73 | 70 |
| 74 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); | 71 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); |
| 75 }; | 72 }; |
| 76 | 73 |
| 77 } // namespace protocol | 74 } // namespace protocol |
| 78 } // namespace remoting | 75 } // namespace remoting |
| 79 | 76 |
| 80 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 77 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
| OLD | NEW |