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

Unified Diff: chrome/browser/extensions/api/messaging/native_message_process_host_posix.cc

Issue 10818013: Native Messaging! (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: MultiPlatform and UnitTest! Created 8 years, 4 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
Index: chrome/browser/extensions/api/messaging/native_message_process_host_posix.cc
diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host_posix.cc b/chrome/browser/extensions/api/messaging/native_message_process_host_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf129a628ab0ca7861634f4b4929ca3df7c6422a
--- /dev/null
+++ b/chrome/browser/extensions/api/messaging/native_message_process_host_posix.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 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 "chrome/browser/extensions/api/messaging/native_message_process_host.h"
+
+#include <unistd.h>
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/pickle.h"
+#include "base/process_util.h"
+#include "base/values.h"
+#include "chrome/common/chrome_paths.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/result_codes.h"
+
+namespace extensions {
+
+void NativeMessageProcessHost::ReadNowForTesting() {
+ OnFileCanReadWithoutBlocking(read_file_);
+}
+
+void NativeMessageProcessHost::InitIO() {
+ // Always watch the read end.
+ MessageLoopForIO::current()->WatchFileDescriptor(read_file_,
+ true, /* persistent */
+ MessageLoopForIO::WATCH_READ,
+ &read_watcher_,
+ this);
+}
+
+void NativeMessageProcessHost::OnFileCanReadWithoutBlocking(int fd) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+
+ // Make sure that the fd given to us is the same one we started with.
+ CHECK_EQ(fd, read_file_);
+
+ // If this is a sendMessage request, stop trying to read after the first
+ // message.
+ if (is_send_message_)
+ read_watcher_.StopWatchingFileDescriptor();
+
+ MessageType type;
+ std::string message;
+ if (!ReadMessage(&type, &message)) {
+ LOG(ERROR) << "Bad Read";
Matt Perry 2012/08/22 00:02:42 ReadMessage already spits out a LOG message on fai
eaugusti 2012/08/31 23:47:13 Done.
+ return;
+ }
+
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&Client::PostMessageFromNativeProcess, weak_client_,
+ destination_port_, message));
+}
+
+bool NativeMessageProcessHost::WriteData(FileHandle file, const char* data,
+ size_t bytes_to_write) {
+ return file_util::WriteFileDescriptor(file, data, bytes_to_write);
+}
+
+bool NativeMessageProcessHost::ReadData(FileHandle file, char* data,
+ size_t bytes_to_read) {
+ return file_util::ReadFromFD(file, data, bytes_to_read);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698