OLD | NEW |
(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_handler.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/location.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "remoting/base/compound_buffer.h" |
| 13 |
| 14 namespace remoting { |
| 15 namespace protocol { |
| 16 |
| 17 DataChannelHandler::DataChannelHandler(const std::string& name, |
| 18 std::unique_ptr<MessagePipe> pipe) |
| 19 : name_(name), |
| 20 pipe_(std::move(pipe)) { |
| 21 DCHECK(pipe_); |
| 22 pipe_->Start(this); |
| 23 } |
| 24 |
| 25 DataChannelHandler::~DataChannelHandler() = default; |
| 26 |
| 27 void DataChannelHandler::Close() { |
| 28 DCHECK(thread_checker_.CalledOnValidThread()); |
| 29 if (connected()) { |
| 30 OnDisconnecting(); |
| 31 is_connected_ = false; |
| 32 } |
| 33 if (!closing()) { |
| 34 pipe_.reset(); |
| 35 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 36 } |
| 37 } |
| 38 |
| 39 bool DataChannelHandler::Send(google::protobuf::MessageLite* message, |
| 40 const base::Closure& done) { |
| 41 DCHECK(thread_checker_.CalledOnValidThread()); |
| 42 if (connected()) { |
| 43 pipe_->Send(message, done); |
| 44 return true; |
| 45 } |
| 46 |
| 47 return false; |
| 48 } |
| 49 |
| 50 void DataChannelHandler::OnIncomingMessage( |
| 51 std::unique_ptr<CompoundBuffer> message) {} |
| 52 |
| 53 void DataChannelHandler::OnConnected() {} |
| 54 |
| 55 void DataChannelHandler::OnDisconnecting() {} |
| 56 |
| 57 void DataChannelHandler::OnMessagePipeOpen() { |
| 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 DCHECK(!is_connected_); |
| 60 is_connected_ = true; |
| 61 OnConnected(); |
| 62 } |
| 63 |
| 64 void DataChannelHandler::OnMessageReceived( |
| 65 std::unique_ptr<CompoundBuffer> message) { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 OnIncomingMessage(std::move(message)); |
| 68 } |
| 69 |
| 70 void DataChannelHandler::OnMessagePipeClosed() { |
| 71 Close(); |
| 72 } |
| 73 |
| 74 } // namespace protocol |
| 75 } // namespace remoting |
OLD | NEW |