Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: remoting/host/native_messaging/native_messaging_pipe.cc

Issue 591463003: Remote Assistance on Chrome OS Part III - NativeMessageHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging
Patch Set: Address Sergey's feedback Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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::Init(
21 scoped_ptr<extensions::NativeMessageHost> host,
22 scoped_ptr<extensions::NativeMessagingChannel> channel) {
23 host_ = host.Pass();
24 channel_ = channel.Pass();
25 }
26
27 void NativeMessagingPipe::Start(const base::Closure& quit_closure) {
28 quit_closure_ = quit_closure;
29 channel_->Start(this);
30 }
31
32 void NativeMessagingPipe::OnMessage(scoped_ptr<base::Value> message) {
33 std::string message_json;
34 base::JSONWriter::Write(message.get(), &message_json);
35 host_->Send(message_json);
36 }
37
38 void NativeMessagingPipe::OnDisconnect() {
39 if (!quit_closure_.is_null())
40 base::ResetAndReturn(&quit_closure_).Run();
41 }
42
43 void NativeMessagingPipe::PostMessageFromNativeHost(
44 int port_id,
45 const std::string& message) {
46 scoped_ptr<base::Value> json(base::JSONReader::Read(message));
47 channel_->SendMessage(json.Pass());
48 }
49
50 void NativeMessagingPipe::CloseChannel(int port_id,
51 const std::string& error_message) {
52 if (!quit_closure_.is_null())
53 base::ResetAndReturn(&quit_closure_).Run();
54 }
55
56 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698