| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/native_messaging/native_messaging_pipe.h" | 5 #include "remoting/host/native_messaging/native_messaging_pipe.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 8 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 | 13 |
| 12 namespace remoting { | 14 namespace remoting { |
| 13 | 15 |
| 14 NativeMessagingPipe::NativeMessagingPipe() { | 16 NativeMessagingPipe::NativeMessagingPipe() {} |
| 15 } | 17 NativeMessagingPipe::~NativeMessagingPipe() {} |
| 16 | |
| 17 NativeMessagingPipe::~NativeMessagingPipe() { | |
| 18 } | |
| 19 | 18 |
| 20 void NativeMessagingPipe::Start( | 19 void NativeMessagingPipe::Start( |
| 21 scoped_ptr<extensions::NativeMessageHost> host, | 20 scoped_ptr<extensions::NativeMessageHost> host, |
| 22 scoped_ptr<extensions::NativeMessagingChannel> channel) { | 21 scoped_ptr<extensions::NativeMessagingChannel> channel) { |
| 23 host_ = host.Pass(); | 22 host_ = std::move(host); |
| 24 channel_ = channel.Pass(); | 23 channel_ = std::move(channel); |
| 25 channel_->Start(this); | 24 channel_->Start(this); |
| 26 } | 25 } |
| 27 | 26 |
| 28 void NativeMessagingPipe::OnMessage(scoped_ptr<base::Value> message) { | 27 void NativeMessagingPipe::OnMessage(scoped_ptr<base::Value> message) { |
| 29 std::string message_json; | 28 std::string message_json; |
| 30 base::JSONWriter::Write(*message, &message_json); | 29 base::JSONWriter::Write(*message, &message_json); |
| 31 host_->OnMessage(message_json); | 30 host_->OnMessage(message_json); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void NativeMessagingPipe::OnDisconnect() { | 33 void NativeMessagingPipe::OnDisconnect() { |
| 35 host_.reset(); | 34 host_.reset(); |
| 36 channel_.reset(); | 35 channel_.reset(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 void NativeMessagingPipe::PostMessageFromNativeHost( | 38 void NativeMessagingPipe::PostMessageFromNativeHost( |
| 40 const std::string& message) { | 39 const std::string& message) { |
| 41 scoped_ptr<base::Value> json = base::JSONReader::Read(message); | 40 scoped_ptr<base::Value> json = base::JSONReader::Read(message); |
| 42 channel_->SendMessage(json.Pass()); | 41 channel_->SendMessage(std::move(json)); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void NativeMessagingPipe::CloseChannel(const std::string& error_message) { | 44 void NativeMessagingPipe::CloseChannel(const std::string& error_message) { |
| 46 host_.reset(); | 45 host_.reset(); |
| 47 channel_.reset(); | 46 channel_.reset(); |
| 48 } | 47 } |
| 49 | 48 |
| 50 } // namespace remoting | 49 } // namespace remoting |
| OLD | NEW |