Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: remoting/protocol/data_channel_manager.cc

Issue 2907073003: [Chromoting] Add DataChannelManager to manage optional incoming data channels (Closed)
Patch Set: Resolve review comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 HandlerFactory constructor) {
23 if (regex.empty() || !constructor) {
24 return false;
25 }
26
27 constructors_.push_back(std::make_pair(regex, constructor));
28 return true;
29 }
30
31 bool DataChannelManager::OnIncomingDataChannel(
32 const std::string& name,
33 std::unique_ptr<MessagePipe> pipe) {
34 #if DCHECK_IS_ON()
35 // Ensures the name matches only one regex.
36 bool matched = false;
37 for (auto& constructor : constructors_) {
38 if (re2::RE2::FullMatch(name, constructor.first)) {
39 DCHECK(!matched);
40 matched = true;
41 }
42 }
43 if (!matched) {
44 return false;
45 }
46 #endif
47 for (auto& constructor : constructors_) {
48 if (re2::RE2::FullMatch(name, constructor.first)) {
49 constructor.second.Run(name, std::move(pipe));
50 return true;
51 }
52 }
53 return false;
54 }
55
56 } // namespace protocol
57 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698