| 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);
|
| + }
|
| +}
|
| +
|
| +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;
|
| +}
|
| +
|
| +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
|
|
|