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

Unified 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, 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..0fb3036d9f28afef9d556242eec6b00c1cca33a1
--- /dev/null
+++ b/remoting/protocol/data_channel_manager.cc
@@ -0,0 +1,57 @@
+// 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,
+ HandlerFactory constructor) {
+ if (regex.empty() || !constructor) {
+ return false;
+ }
+
+ constructors_.push_back(std::make_pair(regex, constructor));
+ return true;
+}
+
+bool DataChannelManager::OnIncomingDataChannel(
+ const std::string& name,
+ std::unique_ptr<MessagePipe> pipe) {
+#if DCHECK_IS_ON()
+ // Ensures the name matches only one regex.
+ bool matched = false;
+ for (auto& constructor : constructors_) {
+ if (re2::RE2::FullMatch(name, constructor.first)) {
+ DCHECK(!matched);
+ matched = true;
+ }
+ }
+ if (!matched) {
+ return false;
+ }
+#endif
+ for (auto& constructor : constructors_) {
+ 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