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

Unified 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: Fix NativeMessagingBasic test on Release builds 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/native_messaging/native_messaging_pipe.h ('k') | remoting/remoting_host.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/native_messaging/native_messaging_pipe.cc
diff --git a/remoting/host/native_messaging/native_messaging_pipe.cc b/remoting/host/native_messaging/native_messaging_pipe.cc
new file mode 100644
index 0000000000000000000000000000000000000000..13abc35d4ddc821e7d99a3bb04193dbbb5be63a4
--- /dev/null
+++ b/remoting/host/native_messaging/native_messaging_pipe.cc
@@ -0,0 +1,52 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/native_messaging/native_messaging_pipe.h"
+
+#include "base/callback_helpers.h"
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
+#include "base/values.h"
+
+namespace remoting {
+
+NativeMessagingPipe::NativeMessagingPipe() {
+}
+
+NativeMessagingPipe::~NativeMessagingPipe() {
+}
+
+void NativeMessagingPipe::Start(
+ scoped_ptr<extensions::NativeMessageHost> host,
+ scoped_ptr<extensions::NativeMessagingChannel> channel,
+ const base::Closure& quit_closure) {
+ host_ = host.Pass();
+ channel_ = channel.Pass();
+ quit_closure_ = quit_closure;
+ channel_->Start(this);
+}
+
+void NativeMessagingPipe::OnMessage(scoped_ptr<base::Value> message) {
+ std::string message_json;
+ base::JSONWriter::Write(message.get(), &message_json);
+ host_->OnMessage(message_json);
+}
+
+void NativeMessagingPipe::OnDisconnect() {
+ if (!quit_closure_.is_null())
+ base::ResetAndReturn(&quit_closure_).Run();
+}
+
+void NativeMessagingPipe::PostMessageFromNativeHost(
+ const std::string& message) {
+ scoped_ptr<base::Value> json(base::JSONReader::Read(message));
+ channel_->SendMessage(json.Pass());
+}
+
+void NativeMessagingPipe::CloseChannel(const std::string& error_message) {
+ if (!quit_closure_.is_null())
+ base::ResetAndReturn(&quit_closure_).Run();
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/host/native_messaging/native_messaging_pipe.h ('k') | remoting/remoting_host.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698