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. | |
| 29 class DataChannelHandler : public MessagePipe::EventHandler { | |
| 30 public: | |
| 31 // Creates a DataChannelHandler to handle data from |pipe|. | |
| 32 DataChannelHandler(const std::string& name, | |
| 33 std::unique_ptr<MessagePipe> pipe); | |
| 34 | |
| 35 // Closes the channel and eventually destructs this instance. Any operations | |
| 36 // should not be performed after executing this function. | |
|
joedow
2017/05/30 16:24:18
The last sentence could be more clear:
"No operati
Hzj_jie
2017/05/31 00:11:52
Done.
| |
| 37 void Close(); | |
| 38 | |
| 39 const std::string& pipe_name() const { return name_; } | |
| 40 | |
| 41 bool closed() const { return pipe_ == nullptr; } | |
| 42 | |
| 43 bool connected() const { return is_connected_; } | |
|
joedow
2017/05/30 16:24:17
How are 'connected()' and 'closed()' different? T
Hzj_jie
2017/05/31 00:11:51
I may rename "closed()" to "finialized()" to avoid
joedow
2017/06/01 17:25:25
I think this is more confusing as finalized() is a
Hzj_jie
2017/06/01 19:32:08
I have changed the function name into closing().
| |
| 44 | |
| 45 // Returns false before the channel is connected. | |
|
joedow
2017/05/30 16:24:17
I'd make this comment more generic, "Returns false
Hzj_jie
2017/05/31 00:11:52
Updated, but I still prefer to explicitly mention
joedow
2017/06/01 17:25:26
I think it is better to avoid impl details in the
Hzj_jie
2017/06/01 19:32:08
DCHECK() the state does not match the design of "a
| |
| 46 bool Send(google::protobuf::MessageLite* message, const base::Closure& done); | |
|
joedow
2017/05/30 16:24:17
Why is message a pointer and not a const ref, are
Hzj_jie
2017/05/31 00:11:52
Because MessagePipe::Send() receives a pointer. It
Sergey Ulanov
2017/05/31 19:49:02
Potentially MessagePipe::Send() can be changed to
Hzj_jie
2017/06/01 15:43:34
MessageLite is not copyable anyway, so using const
joedow
2017/06/01 17:25:25
I didn't realize MessageLite was an interface, tha
Hzj_jie
2017/06/01 19:32:08
Done.
| |
| 47 | |
| 48 protected: | |
| 49 ~DataChannelHandler() override; | |
| 50 | |
| 51 // Derived classes can override these functions to receive data from the | |
| 52 // connection or observe the connection state. | |
|
joedow
2017/05/30 16:24:17
Why use inheritance here instead of an observer pa
Hzj_jie
2017/05/31 00:11:52
A derived class of DataChannelHandler handles data
joedow
2017/06/01 17:25:25
I missed that the first time around. A better app
Hzj_jie
2017/06/01 19:32:08
I still do not see the difference,
1. who will con
| |
| 53 virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message); | |
| 54 virtual void OnConnected(); | |
| 55 virtual void OnDisconnected(); | |
| 56 | |
| 57 private: | |
| 58 friend class base::DeleteHelper<DataChannelHandler>; | |
| 59 | |
| 60 // MessagePipe::EventHandler implementation. | |
| 61 void OnMessagePipeOpen() override; | |
| 62 void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override; | |
| 63 void OnMessagePipeClosed() override; | |
| 64 | |
| 65 const std::string name_; | |
| 66 std::unique_ptr<MessagePipe> pipe_; | |
| 67 base::ThreadChecker thread_checker_; | |
| 68 bool is_connected_ = false; | |
| 69 }; | |
| 70 | |
| 71 } // namespace protocol | |
| 72 } // namespace remoting | |
| 73 | |
| 74 #endif // REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ | |
| OLD | NEW |