OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/host/native_messaging/native_messaging_pipe.h" |
| 6 |
| 7 #include "base/callback_helpers.h" |
| 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" |
| 10 #include "base/values.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 NativeMessagingPipe::NativeMessagingPipe() { |
| 15 } |
| 16 |
| 17 NativeMessagingPipe::~NativeMessagingPipe() { |
| 18 } |
| 19 |
| 20 void NativeMessagingPipe::Start( |
| 21 scoped_ptr<extensions::NativeMessageHost> host, |
| 22 scoped_ptr<extensions::NativeMessagingChannel> channel, |
| 23 const base::Closure& quit_closure) { |
| 24 host_ = host.Pass(); |
| 25 channel_ = channel.Pass(); |
| 26 quit_closure_ = quit_closure; |
| 27 channel_->Start(this); |
| 28 } |
| 29 |
| 30 void NativeMessagingPipe::OnMessage(scoped_ptr<base::Value> message) { |
| 31 std::string message_json; |
| 32 base::JSONWriter::Write(message.get(), &message_json); |
| 33 host_->OnMessage(message_json); |
| 34 } |
| 35 |
| 36 void NativeMessagingPipe::OnDisconnect() { |
| 37 if (!quit_closure_.is_null()) |
| 38 base::ResetAndReturn(&quit_closure_).Run(); |
| 39 } |
| 40 |
| 41 void NativeMessagingPipe::PostMessageFromNativeHost( |
| 42 const std::string& message) { |
| 43 scoped_ptr<base::Value> json(base::JSONReader::Read(message)); |
| 44 channel_->SendMessage(json.Pass()); |
| 45 } |
| 46 |
| 47 void NativeMessagingPipe::CloseChannel(const std::string& error_message) { |
| 48 if (!quit_closure_.is_null()) |
| 49 base::ResetAndReturn(&quit_closure_).Run(); |
| 50 } |
| 51 |
| 52 } // namespace remoting |
OLD | NEW |