Chromium Code Reviews| Index: remoting/protocol/data_channel_handler.h |
| diff --git a/remoting/protocol/data_channel_handler.h b/remoting/protocol/data_channel_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d4d6ae0b3d9530f4d2aa80bfe2f87e35826fec93 |
| --- /dev/null |
| +++ b/remoting/protocol/data_channel_handler.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ |
| +#define REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/sequenced_task_runner_helpers.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "remoting/protocol/message_pipe.h" |
| + |
| +namespace google { |
| +namespace protobuf { |
| +class MessageLite; |
| +} // namespace protobuf |
| +} // namespace google |
| + |
| +namespace remoting { |
| + |
| +class CompoundBuffer; |
| + |
| +namespace protocol { |
| + |
| +// A base class to handle data from a named data channel. |
| +class DataChannelHandler : public MessagePipe::EventHandler { |
| + public: |
| + // Creates a DataChannelHandler to handle data from |pipe|. |
| + DataChannelHandler(const std::string& name, |
| + std::unique_ptr<MessagePipe> pipe); |
| + |
| + // Closes the channel and eventually destructs this instance. Any operations |
| + // 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.
|
| + void Close(); |
| + |
| + const std::string& pipe_name() const { return name_; } |
| + |
| + bool closed() const { return pipe_ == nullptr; } |
| + |
| + 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().
|
| + |
| + // 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
|
| + 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.
|
| + |
| + protected: |
| + ~DataChannelHandler() override; |
| + |
| + // Derived classes can override these functions to receive data from the |
| + // 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
|
| + virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message); |
| + virtual void OnConnected(); |
| + virtual void OnDisconnected(); |
| + |
| + private: |
| + friend class base::DeleteHelper<DataChannelHandler>; |
| + |
| + // MessagePipe::EventHandler implementation. |
| + void OnMessagePipeOpen() override; |
| + void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override; |
| + void OnMessagePipeClosed() override; |
| + |
| + const std::string name_; |
| + std::unique_ptr<MessagePipe> pipe_; |
| + base::ThreadChecker thread_checker_; |
| + bool is_connected_ = false; |
| +}; |
| + |
| +} // namespace protocol |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_PROTOCOL_DATA_CHANNEL_HANDLER_H_ |