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

Unified Diff: remoting/protocol/data_channel_handler.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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/data_channel_handler.cc
diff --git a/remoting/protocol/data_channel_handler.cc b/remoting/protocol/data_channel_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dfc5d32a72fa93d3ddcc3005610534c316ab140e
--- /dev/null
+++ b/remoting/protocol/data_channel_handler.cc
@@ -0,0 +1,75 @@
+// 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_handler.h"
+
+#include <utility>
+
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "remoting/base/compound_buffer.h"
+
+namespace remoting {
+namespace protocol {
+
+DataChannelHandler::DataChannelHandler(const std::string& name,
+ std::unique_ptr<MessagePipe> pipe)
+ : name_(name),
+ pipe_(std::move(pipe)) {
+ DCHECK(pipe_);
+ pipe_->Start(this);
+}
+
+DataChannelHandler::~DataChannelHandler() = default;
+
+void DataChannelHandler::Close() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (connected()) {
+ OnDisconnecting();
+ is_connected_ = false;
+ }
+ if (!closing()) {
+ pipe_.reset();
+ base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
joedow 2017/06/06 23:33:25 Why not just delete now instead of doing it async?
Hzj_jie 2017/06/07 17:31:24 If the DataChannelHandler works with a timer and t
+ }
+}
+
+bool DataChannelHandler::Send(google::protobuf::MessageLite* message,
+ const base::Closure& done) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (connected()) {
+ pipe_->Send(message, done);
+ return true;
+ }
+
+ return false;
joedow 2017/06/06 23:33:25 Why don't you want to DCHECK if someone tries to s
Hzj_jie 2017/06/07 17:31:24 It also relates to the potential usage of timer: t
+}
+
+void DataChannelHandler::OnIncomingMessage(
+ std::unique_ptr<CompoundBuffer> message) {}
+
+void DataChannelHandler::OnConnected() {}
+
+void DataChannelHandler::OnDisconnecting() {}
+
+void DataChannelHandler::OnMessagePipeOpen() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!is_connected_);
+ is_connected_ = true;
+ OnConnected();
+}
+
+void DataChannelHandler::OnMessageReceived(
+ std::unique_ptr<CompoundBuffer> message) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ OnIncomingMessage(std::move(message));
+}
+
+void DataChannelHandler::OnMessagePipeClosed() {
+ Close();
+}
+
+} // namespace protocol
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698