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 #include "remoting/protocol/data_channel_manager.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/location.h" | |
11 #include "remoting/protocol/data_channel_handler.h" | |
joedow
2017/06/06 23:33:25
Remove this header since it isn't used here.
Hzj_jie
2017/06/07 17:31:25
Done.
| |
12 | |
13 namespace remoting { | |
14 namespace protocol { | |
15 | |
16 DataChannelManager::DataChannelManager() = default; | |
17 DataChannelManager::~DataChannelManager() = default; | |
18 | |
19 bool DataChannelManager::RegisterCreateHandlerCallback( | |
20 const std::string& regex, | |
joedow
2017/06/06 23:33:25
replace 'regex' with 'prefix'
Hzj_jie
2017/06/07 17:31:24
Done.
| |
21 CreateHandlerCallback constructor) { | |
22 if (regex.empty() || !constructor) { | |
joedow
2017/06/06 23:33:25
Just curious, shouldn't calling this method with a
Hzj_jie
2017/06/07 17:31:24
Done.
| |
23 return false; | |
24 } | |
25 | |
26 constructors_.push_back(std::make_pair(regex, constructor)); | |
27 return true; | |
28 } | |
29 | |
30 bool DataChannelManager::OnIncomingDataChannel( | |
31 const std::string& name, | |
32 std::unique_ptr<MessagePipe> pipe) { | |
33 #if DCHECK_IS_ON() | |
joedow
2017/06/06 23:33:25
I think you can remove this block now that you are
Hzj_jie
2017/06/07 17:31:25
Done.
| |
34 // Ensures the name matches only one regex. | |
35 bool matched = false; | |
36 for (auto& constructor : constructors_) { | |
37 if (name.find(constructor.first) == 0) { | |
38 CHECK(!matched); | |
39 matched = true; | |
40 } | |
41 } | |
42 if (!matched) { | |
43 return false; | |
44 } | |
45 #endif | |
46 for (auto& constructor : constructors_) { | |
47 if (name.find(constructor.first) == 0) { | |
48 constructor.second.Run(name, std::move(pipe)); | |
49 return true; | |
50 } | |
51 } | |
52 return false; | |
53 } | |
54 | |
55 } // namespace protocol | |
56 } // namespace remoting | |
OLD | NEW |