| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 void Init(MessageChannelFactory* channel_factory, | 50 void Init(MessageChannelFactory* channel_factory, |
| 51 EventHandler* event_handler); | 51 EventHandler* event_handler); |
| 52 | 52 |
| 53 // Initializes the channel using |message_pipe| that's already connected. | 53 // Initializes the channel using |message_pipe| that's already connected. |
| 54 void Init(std::unique_ptr<MessagePipe> message_pipe, | 54 void Init(std::unique_ptr<MessagePipe> message_pipe, |
| 55 EventHandler* event_handler); | 55 EventHandler* event_handler); |
| 56 | 56 |
| 57 const std::string& channel_name() { return channel_name_; } | 57 const std::string& channel_name() { return channel_name_; } |
| 58 | 58 |
| 59 // Returns true if the channel is currently connected. | 59 // Returns true if the channel is currently connected. |
| 60 bool is_connected() { return message_pipe() != nullptr; } | 60 bool is_connected() { return is_connected_; } |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 explicit ChannelDispatcherBase(const char* channel_name); | 63 explicit ChannelDispatcherBase(const char* channel_name); |
| 64 | 64 |
| 65 MessagePipe* message_pipe() { return message_pipe_.get(); } | 65 MessagePipe* message_pipe() { return message_pipe_.get(); } |
| 66 | 66 |
| 67 // Child classes must override this method to handle incoming messages. | 67 // Child classes must override this method to handle incoming messages. |
| 68 virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message) = 0; | 68 virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message) = 0; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 void OnChannelReady(std::unique_ptr<MessagePipe> message_pipe); | 71 void OnChannelReady(std::unique_ptr<MessagePipe> message_pipe); |
| 72 | 72 |
| 73 // MessagePipe::EventHandler interface. | 73 // MessagePipe::EventHandler interface. |
| 74 void OnMessagePipeOpen() override; |
| 74 void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override; | 75 void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override; |
| 75 void OnMessagePipeClosed() override; | 76 void OnMessagePipeClosed() override; |
| 76 | 77 |
| 77 std::string channel_name_; | 78 std::string channel_name_; |
| 78 MessageChannelFactory* channel_factory_ = nullptr; | 79 MessageChannelFactory* channel_factory_ = nullptr; |
| 79 EventHandler* event_handler_ = nullptr; | 80 EventHandler* event_handler_ = nullptr; |
| 81 bool is_connected_ = false; |
| 80 | 82 |
| 81 std::unique_ptr<MessagePipe> message_pipe_; | 83 std::unique_ptr<MessagePipe> message_pipe_; |
| 82 | 84 |
| 83 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); | 85 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 } // namespace protocol | 88 } // namespace protocol |
| 87 } // namespace remoting | 89 } // namespace remoting |
| 88 | 90 |
| 89 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ | 91 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ |
| OLD | NEW |