blob: 32b0198b936347d9014800024b132bc59cce7a89 [file] [log] [blame]
zijiehef81a3b572017-06-11 23:03:371// 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
14namespace remoting {
15namespace protocol {
16
17class MessagePipe;
18
19// DataChannelManager helps to manage optional data channels. Consumers can
20// register a function to handle data from a named data channel.
21class 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:
zijieheb7da62422017-07-11 01:17:1541 std::vector<std::pair<std::string, CreateHandlerCallback>> constructors_;
zijiehef81a3b572017-06-11 23:03:3742};
43
44} // namespace protocol
45} // namespace remoting
46
47#endif // REMOTING_PROTOCOL_DATA_CHANNEL_MANAGER_H_