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

Unified Diff: remoting/protocol/data_channel_manager.cc

Issue 2907073003: [Chromoting] Add DataChannelManager to manage optional incoming data channels (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/data_channel_manager.cc
diff --git a/remoting/protocol/data_channel_manager.cc b/remoting/protocol/data_channel_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0a1145fc4b1433421a3455863b176d6da96694a5
--- /dev/null
+++ b/remoting/protocol/data_channel_manager.cc
@@ -0,0 +1,44 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/protocol/data_channel_manager.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "remoting/protocol/data_channel_handler.h"
+#include "third_party/re2/src/re2/re2.h"
+
+namespace remoting {
+namespace protocol {
+
+DataChannelManager::DataChannelManager() = default;
+DataChannelManager::~DataChannelManager() = default;
+
+bool DataChannelManager::RegisterHandlerFactory(
+ const std::string& regex,
+ 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.
+ if (regex.empty() || !constructor) {
+ return false;
+ }
+
+ 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
+ return true;
+}
+
+bool DataChannelManager::OnIncomingDataChannel(
+ const std::string& name,
+ std::unique_ptr<MessagePipe> pipe) {
+ 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
+ if (re2::RE2::FullMatch(name, constructor.first)) {
+ constructor.second.Run(name, std::move(pipe));
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace protocol
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698