Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ | |
| 6 #define REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/sequenced_task_runner_helpers.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 #include "remoting/protocol/message_pipe.h" | |
| 15 | |
| 16 namespace google { | |
| 17 namespace protobuf { | |
| 18 class MessageLite; | |
| 19 } // namespace protobuf | |
| 20 } // namespace google | |
| 21 | |
| 22 namespace remoting { | |
| 23 | |
| 24 class CompoundBuffer; | |
| 25 | |
| 26 namespace protocol { | |
| 27 | |
| 28 // A base class to handle data from a named data channel. This class manages the | |
|
joedow
2017/06/06 23:33:25
nit: Replace 'data channel' with 'MessagePipe'. O
Hzj_jie
2017/06/07 17:31:24
Done.
| |
| 29 // lifetime itself: it deletes itself once the data channel is closed or the | |
| 30 // derived instance actively calls Close() function. | |
| 31 class DataChannelHandler : public MessagePipe::EventHandler { | |
|
joedow
2017/06/06 23:33:25
Consider renaming to something like MessagePipeHan
Hzj_jie
2017/06/07 17:31:24
I think NamedMessagePipeHandler would be better, a
| |
| 32 protected: | |
| 33 // Creates a DataChannelHandler to handle data from |pipe|. | |
| 34 // This class is not virtual, but it is an no-op instance. So hide the | |
|
joedow
2017/06/06 23:33:25
This class isn't a no-op instance though, it does
Hzj_jie
2017/06/07 17:31:24
Done.
| |
| 35 // constructor. | |
| 36 DataChannelHandler(const std::string& name, | |
| 37 std::unique_ptr<MessagePipe> pipe); | |
|
joedow
2017/06/06 23:33:25
Would it makes sense to use a zero-param c'tor and
Hzj_jie
2017/06/07 17:31:24
Keeping a copy of |name| in derived classes is not
| |
| 38 | |
| 39 ~DataChannelHandler() override; | |
| 40 | |
| 41 // Closes the channel and eventually destructs this instance. No operations | |
| 42 // should be performed after executing this function. | |
| 43 void Close(); | |
| 44 | |
| 45 const std::string& pipe_name() const { return name_; } | |
| 46 | |
| 47 // Returns true if |this| object has been scheduled to be deleted. This | |
| 48 // function always indicates the lifetime of |this| even the |pipe_| has never | |
| 49 // been opened. | |
| 50 bool closing() const { return pipe_ == nullptr; } | |
| 51 | |
| 52 // Whether |pipe_| has been connected. | |
| 53 bool connected() const { return is_connected_; } | |
| 54 | |
| 55 // Returns false if the message is not sent, usually it happens before the | |
| 56 // |pipe_| is opened. | |
| 57 bool Send(google::protobuf::MessageLite* message, const base::Closure& done); | |
| 58 | |
| 59 // Derived classes can override these functions to receive data from the | |
| 60 // connection or observe the connection state. These functions will not be | |
| 61 // called unless |pipe_| has been opened. | |
| 62 | |
|
joedow
2017/06/06 23:33:25
nit: remove newline
Hzj_jie
2017/06/07 17:31:24
Done.
| |
| 63 virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message); | |
| 64 virtual void OnConnected(); | |
| 65 virtual void OnDisconnecting(); | |
|
joedow
2017/06/06 23:33:25
Can these be pure virtual? Is the only benefit th
Hzj_jie
2017/06/07 17:31:24
I believe in most the case, only one or two of the
| |
| 66 | |
| 67 private: | |
| 68 friend class base::DeleteHelper<DataChannelHandler>; | |
|
joedow
2017/06/06 23:33:25
Why is DeleteHelper needed here? I haven't used i
Hzj_jie
2017/06/07 17:31:24
Because the destructor is protected (to avoid unex
| |
| 69 | |
| 70 // MessagePipe::EventHandler implementation. | |
| 71 void OnMessagePipeOpen() override; | |
| 72 void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override; | |
| 73 void OnMessagePipeClosed() override; | |
| 74 | |
| 75 const std::string name_; | |
| 76 std::unique_ptr<MessagePipe> pipe_; | |
| 77 base::ThreadChecker thread_checker_; | |
| 78 bool is_connected_ = false; | |
| 79 }; | |
| 80 | |
| 81 } // namespace protocol | |
| 82 } // namespace remoting | |
| 83 | |
| 84 #endif // REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ | |
| OLD | NEW |