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 #include "remoting/protocol/data_channel_manager.h"
6 
7 #include <utility>
8 
9 #include "base/check.h"
10 #include "remoting/protocol/message_pipe.h"
11 
12 namespace remoting {
13 namespace protocol {
14 
15 DataChannelManager::DataChannelManager() = default;
16 DataChannelManager::~DataChannelManager() = default;
17 
RegisterCreateHandlerCallback(const std::string & prefix,CreateHandlerCallback constructor)18 void DataChannelManager::RegisterCreateHandlerCallback(
19     const std::string& prefix,
20     CreateHandlerCallback constructor) {
21   DCHECK(!prefix.empty());
22   DCHECK(constructor);
23   constructors_.push_back(std::make_pair(prefix, std::move(constructor)));
24 }
25 
OnIncomingDataChannel(const std::string & name,std::unique_ptr<MessagePipe> pipe)26 bool DataChannelManager::OnIncomingDataChannel(
27     const std::string& name,
28     std::unique_ptr<MessagePipe> pipe) {
29   for (auto& constructor : constructors_) {
30     if (name.find(constructor.first) == 0) {
31       constructor.second.Run(name, std::move(pipe));
32       return true;
33     }
34   }
35   return false;
36 }
37 
38 }  // namespace protocol
39 }  // namespace remoting
40