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" | |
12 #include "third_party/re2/src/re2/re2.h" | |
13 | |
14 namespace remoting { | |
15 namespace protocol { | |
16 | |
17 DataChannelManager::DataChannelManager() = default; | |
18 DataChannelManager::~DataChannelManager() = default; | |
19 | |
20 bool DataChannelManager::RegisterHandlerFactory( | |
21 const std::string& regex, | |
22 HandlerConstructor constructor) { | |
joedow
2017/05/30 16:24:18
I think factory is a better term than constructor
Hzj_jie
2017/05/31 00:11:52
Done.
| |
23 if (regex.empty() || !constructor) { | |
24 return false; | |
25 } | |
26 | |
27 constructors_.push_back(std::make_pair(regex, constructor)); | |
joedow
2017/05/30 16:24:18
Do you want to check for double-registration (i.e.
Hzj_jie
2017/05/31 00:11:52
Yes, I considered this issue before, but since reg
joedow
2017/06/01 17:25:26
Flexibility doesn't necessarily lead to a good API
Hzj_jie
2017/06/01 19:32:08
As I have mentioned in another comment, using rege
| |
28 return true; | |
29 } | |
30 | |
31 bool DataChannelManager::OnIncomingDataChannel( | |
32 const std::string& name, | |
33 std::unique_ptr<MessagePipe> pipe) { | |
34 for (auto& constructor : constructors_) { | |
joedow
2017/05/30 16:24:18
Using a dictionary would be cleaner here. You cou
Hzj_jie
2017/05/31 00:11:52
A dictionary cannot handle prefix matches.
joedow
2017/06/01 17:25:26
Sure it can. The prefix is the name of the channe
Hzj_jie
2017/06/01 19:32:08
Then it will introduce another magic character or
| |
35 if (re2::RE2::FullMatch(name, constructor.first)) { | |
36 constructor.second.Run(name, std::move(pipe)); | |
37 return true; | |
38 } | |
39 } | |
40 return false; | |
41 } | |
42 | |
43 } // namespace protocol | |
44 } // namespace remoting | |
OLD | NEW |