| 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/named_message_pipe_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 NamedMessagePipeHandler::NamedMessagePipeHandler( | |
| 18 const std::string& name, | |
| 19 std::unique_ptr<MessagePipe> pipe) | |
| 20 : name_(name), | |
| 21 pipe_(std::move(pipe)) { | |
| 22 DCHECK(pipe_); | |
| 23 pipe_->Start(this); | |
| 24 } | |
| 25 | |
| 26 NamedMessagePipeHandler::~NamedMessagePipeHandler() = default; | |
| 27 | |
| 28 void NamedMessagePipeHandler::Close() { | |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 30 if (connected()) { | |
| 31 OnDisconnecting(); | |
| 32 is_connected_ = false; | |
| 33 } | |
| 34 delete this; | |
| 35 } | |
| 36 | |
| 37 void NamedMessagePipeHandler::Send(google::protobuf::MessageLite* message, | |
| 38 const base::Closure& done) { | |
| 39 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 40 DCHECK(connected()); | |
| 41 pipe_->Send(message, done); | |
| 42 } | |
| 43 | |
| 44 void NamedMessagePipeHandler::OnIncomingMessage( | |
| 45 std::unique_ptr<CompoundBuffer> message) {} | |
| 46 | |
| 47 void NamedMessagePipeHandler::OnConnected() {} | |
| 48 | |
| 49 void NamedMessagePipeHandler::OnDisconnecting() {} | |
| 50 | |
| 51 void NamedMessagePipeHandler::OnMessagePipeOpen() { | |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 53 DCHECK(!is_connected_); | |
| 54 is_connected_ = true; | |
| 55 OnConnected(); | |
| 56 } | |
| 57 | |
| 58 void NamedMessagePipeHandler::OnMessageReceived( | |
| 59 std::unique_ptr<CompoundBuffer> message) { | |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 61 OnIncomingMessage(std::move(message)); | |
| 62 } | |
| 63 | |
| 64 void NamedMessagePipeHandler::OnMessagePipeClosed() { | |
| 65 Close(); | |
| 66 } | |
| 67 | |
| 68 } // namespace protocol | |
| 69 } // namespace remoting | |
| OLD | NEW |