Index: remoting/protocol/data_channel_manager.h |
diff --git a/remoting/protocol/data_channel_manager.h b/remoting/protocol/data_channel_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2d39ede6b3b30a07cdadf7d909a86ada0484416d |
--- /dev/null |
+++ b/remoting/protocol/data_channel_manager.h |
@@ -0,0 +1,55 @@ |
+// 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_MANAGER_H_ |
+#define REMOTING_PROTOCOL_DATA_CHANNEL_MANAGER_H_ |
+ |
+#include <map> |
+#include <memory> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+ |
+namespace remoting { |
+namespace protocol { |
+ |
+class DataChannelHandler; |
+class MessagePipe; |
+ |
+// DataChannelManager helps to manage optional data channels. Each |
+// DataChannelHandler implementation register a factory function to create an |
joedow
2017/05/30 16:24:18
s/register/registers
Hzj_jie
2017/05/31 00:11:53
Done.
Also the comment does not reflect the lates
|
+// instance of itself to handle data from a named data channel. Lifetime of all |
+// DataChannelHandler instances are mananged by DataChannelManager instance. |
joedow
2017/05/30 16:24:18
s/mananged/managed
Hzj_jie
2017/05/31 00:11:52
Done.
|
+// Besides releasing when session closing, clients can also actively close the |
+// channel by calling DataChannelHandler::Close() function. |
joedow
2017/05/30 16:24:18
re-write lines 25/26 -> All handlers are closed wh
Hzj_jie
2017/05/31 00:11:53
Done.
|
+class DataChannelManager final { |
+ public: |
+ using HandlerConstructor = base::Callback<void( |
joedow
2017/05/30 16:24:18
maybe rename HandlerConstructor to DataChannelHand
Hzj_jie
2017/05/31 00:11:53
Term "DataChannel" seems a little bit redundant, I
|
+ const std::string& name, |
+ std::unique_ptr<MessagePipe> pipe)>; |
+ |
+ DataChannelManager(); |
+ ~DataChannelManager(); |
+ |
+ // Registers a factory function to create a DataChannelHandler to handle a new |
+ // incoming data channel with a name matching |regex|. This function fails and |
+ // returns false when |regex| or |constructor| are empty. |
joedow
2017/05/30 16:24:18
fix the last sentence:
Returns true if the registr
Hzj_jie
2017/05/31 00:11:53
Same as DataChannelHandler::Send(), I still prefer
|
+ bool RegisterHandlerFactory(const std::string& regex, |
joedow
2017/05/30 16:24:18
A regex isn't needed is it? Data channels have a
Hzj_jie
2017/05/31 00:11:52
I do not think there is any restriction of the nam
joedow
2017/06/01 17:25:26
Can you think of a scenario where a regex is requi
Hzj_jie
2017/06/01 19:32:08
By using regex, you can still use "channel-name" w
|
+ HandlerConstructor constructor); |
+ |
+ // Creates a DataChannelHandler to handle the new incoming data channel. This |
+ // function fails and returns false if no registered factory function matches |
+ // |name|. |
joedow
2017/05/30 16:24:18
The last sentence is a bit awkward. It is totally
Hzj_jie
2017/05/31 00:11:52
Done.
|
+ bool OnIncomingDataChannel(const std::string& name, |
+ std::unique_ptr<MessagePipe> pipe); |
+ |
+ private: |
+ std::vector<std::pair<std::string, HandlerConstructor>> constructors_; |
+}; |
+ |
+} // namespace protocol |
+} // namespace remoting |
+ |
+#endif // REMOTING_PROTOCOL_DATA_CHANNEL_MANAGER_H_ |