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_MANAGER_H_ | |
| 6 #define REMOTING_PROTOCOL_DATA_CHANNEL_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
|
Sergey Ulanov
2017/06/05 18:48:29
not used in this header
Hzj_jie
2017/06/06 03:21:52
Done.
| |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 | |
| 15 namespace remoting { | |
| 16 namespace protocol { | |
| 17 | |
| 18 class DataChannelHandler; | |
| 19 class MessagePipe; | |
| 20 | |
| 21 // DataChannelManager helps to manage optional data channels. Each | |
| 22 // DataChannelHandler implementation registers a factory function to create an | |
| 23 // instance of itself to handle data from a named data channel. All handles are | |
| 24 // closed when the associated MessagePipe is closed. Clients can also close a | |
| 25 // data channel manually by calling DataChannelHandler::Close() function. | |
| 26 class DataChannelManager final { | |
| 27 public: | |
| 28 using HandlerFactory = base::Callback<void( | |
|
Sergey Ulanov
2017/06/05 18:48:29
"Factory" is usually an interface. Call it CreateH
Hzj_jie
2017/06/06 03:21:51
Done.
| |
| 29 const std::string& name, | |
| 30 std::unique_ptr<MessagePipe> pipe)>; | |
| 31 | |
| 32 DataChannelManager(); | |
| 33 ~DataChannelManager(); | |
| 34 | |
| 35 // Registers a factory function to create a DataChannelHandler to handle a new | |
| 36 // incoming data channel with a name matching |regex|. Returns false if the | |
| 37 // registration fails, usually it happens when |regex| or |constructor| are | |
| 38 // empty. | |
| 39 bool RegisterHandlerFactory(const std::string& regex, | |
|
Sergey Ulanov
2017/06/05 18:48:29
Is it really worth to pull re2 dependency for this
Hzj_jie
2017/06/06 03:21:51
Done.
| |
| 40 HandlerFactory constructor); | |
| 41 | |
| 42 // Creates a DataChannelHandler to handle the new incoming data channel. | |
| 43 // Returns true if a handler exists for the new data channel. | |
| 44 bool OnIncomingDataChannel(const std::string& name, | |
| 45 std::unique_ptr<MessagePipe> pipe); | |
| 46 | |
| 47 private: | |
| 48 std::vector<std::pair<std::string, HandlerFactory>> constructors_; | |
| 49 }; | |
| 50 | |
| 51 } // namespace protocol | |
| 52 } // namespace remoting | |
| 53 | |
| 54 #endif // REMOTING_PROTOCOL_DATA_CHANNEL_MANAGER_H_ | |
| OLD | NEW |