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 <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 |
| 14 namespace remoting { |
| 15 namespace protocol { |
| 16 |
| 17 class MessagePipe; |
| 18 |
| 19 // DataChannelManager helps to manage optional data channels. Consumers can |
| 20 // register a function to handle data from a named data channel. |
| 21 class DataChannelManager final { |
| 22 public: |
| 23 using CreateHandlerCallback = base::Callback<void( |
| 24 const std::string& name, |
| 25 std::unique_ptr<MessagePipe> pipe)>; |
| 26 |
| 27 DataChannelManager(); |
| 28 ~DataChannelManager(); |
| 29 |
| 30 // Registers a factory function to handle a new incoming data channel with a |
| 31 // name matching |prefix|. Both |constructor| and |prefix| cannot be empty. |
| 32 void RegisterCreateHandlerCallback(const std::string& prefix, |
| 33 CreateHandlerCallback constructor); |
| 34 |
| 35 // Executes the registered callback to handle the new incoming data channel. |
| 36 // Returns true if a handler of the new data channel has been executed. |
| 37 bool OnIncomingDataChannel(const std::string& name, |
| 38 std::unique_ptr<MessagePipe> pipe); |
| 39 |
| 40 private: |
| 41 std::vector<std::pair<std::string, CreateHandlerCallback>> constructors_; |
| 42 }; |
| 43 |
| 44 } // namespace protocol |
| 45 } // namespace remoting |
| 46 |
| 47 #endif // REMOTING_PROTOCOL_DATA_CHANNEL_MANAGER_H_ |
OLD | NEW |