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

Unified Diff: chrome/nacl/nacl_ipc_manager.cc

Issue 9863005: Initial implementation of an IPC adapter to expose Chrome IPC to Native Client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | « chrome/nacl/nacl_ipc_manager.h ('k') | ipc/ipc_message.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/nacl/nacl_ipc_manager.cc
diff --git a/chrome/nacl/nacl_ipc_manager.cc b/chrome/nacl/nacl_ipc_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..00e132a0ac768ac5b6870236bad98e760f80a07a
--- /dev/null
+++ b/chrome/nacl/nacl_ipc_manager.cc
@@ -0,0 +1,60 @@
+// 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/nacl/nacl_ipc_manager.h"
+
+#include "chrome/nacl/nacl_ipc_adapter.h"
+#include "content/common/child_process.h"
+
+NaClIPCManager::NaClIPCManager() {
+}
+
+NaClIPCManager::~NaClIPCManager() {
+}
+
+void* NaClIPCManager::CreateChannel(const IPC::ChannelHandle& handle) {
+ scoped_refptr<NaClIPCAdapter> adapter(
+ new NaClIPCAdapter(handle,
+ ChildProcess::current()->io_message_loop_proxy()));
+
+ // Use the object's address as the handle given to nacl. We just need a
+ // unique void* to give to nacl for us to look it up when we get calls on
+ // this handle in the future.
+ void* nacl_handle = adapter.get();
+ adapters_.insert(std::make_pair(nacl_handle, adapter));
+ return nacl_handle;
+}
+
+void NaClIPCManager::DestroyChannel(void* handle) {
+ scoped_refptr<NaClIPCAdapter> adapter = GetAdapter(handle);
+ if (!adapter.get())
+ return;
+ adapter->CloseChannel();
+}
+
+int NaClIPCManager::SendMessage(void* handle,
+ const char* data,
+ int data_length) {
+ scoped_refptr<NaClIPCAdapter> adapter = GetAdapter(handle);
+ if (!adapter.get())
+ return -1;
+ return adapter->Send(data, data_length);
+}
+
+int NaClIPCManager::ReceiveMessage(void* handle,
+ char* buffer,
+ int buffer_length) {
+ scoped_refptr<NaClIPCAdapter> adapter = GetAdapter(handle);
+ if (!adapter.get())
+ return -1;
+ return adapter->BlockingReceive(buffer, buffer_length);
+}
+
+scoped_refptr<NaClIPCAdapter> NaClIPCManager::GetAdapter(void* handle) {
+ base::AutoLock lock(lock_);
+ AdapterMap::iterator found = adapters_.find(handle);
+ if (found == adapters_.end())
+ return scoped_refptr<NaClIPCAdapter>();
+ return found->second;
+}
« no previous file with comments | « chrome/nacl/nacl_ipc_manager.h ('k') | ipc/ipc_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698