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

Unified Diff: chrome/nacl/nacl_ipc_manager.h

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_adapter_unittest.cc ('k') | chrome/nacl/nacl_ipc_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/nacl/nacl_ipc_manager.h
diff --git a/chrome/nacl/nacl_ipc_manager.h b/chrome/nacl/nacl_ipc_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..603b8dc613104a39031670beffa5ce84ea5addcb
--- /dev/null
+++ b/chrome/nacl/nacl_ipc_manager.h
@@ -0,0 +1,59 @@
+// 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.
+
+#ifndef CHROME_NACL_NACL_IPC_MANAGER_H_
+#define CHROME_NACL_NACL_IPC_MANAGER_H_
+#pragma once
+
+#include <map>
+
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
+#include "ipc/ipc_channel_handle.h"
+
+class NaClIPCAdapter;
+
+// This class manages all IPC channels exposed to NaCl. We give NaCl void*
+// "handles" to identify channels. When the untrusted nacl code does operations
+// on these handles, this class maps them to the corresponding adapter object.
+//
+// This class must be threadsafe since nacl send/recvmsg functions can be
+// called on any thread.
+class NaClIPCManager {
+ public:
+ NaClIPCManager();
+ ~NaClIPCManager();
+
+ // Creates a nacl channel associated with the given channel handle (normally
+ // this will come from the browser process). Returns the handle that should
+ // be given to nacl to associated with this IPC channel.
+ void* CreateChannel(const IPC::ChannelHandle& handle);
+
+ // Destroys the channel with the given handle.
+ void DestroyChannel(void* handle);
+
+ // Implementation of sendmsg on the given channel. The return value is the
+ // number of bytes written or -1 on failure.
+ int SendMessage(void* handle, const char* data, int data_length);
+
+ // Implementation of recvmsg on the given channel. The return value is the
+ // number of bytes received or -1 on failure.
+ int ReceiveMessage(void* handle, char* buffer, int buffer_length);
+
+ private:
+ // Looks up the adapter if given a handle. The pointer wil be null on
+ // failures.
+ scoped_refptr<NaClIPCAdapter> GetAdapter(void* handle);
+
+ // Lock around all data below.
+ base::Lock lock_;
+
+ // All active IPC channels. Locked by lock_ above.
+ typedef std::map<void*, scoped_refptr<NaClIPCAdapter> > AdapterMap;
+ AdapterMap adapters_;
+
+ DISALLOW_COPY_AND_ASSIGN(NaClIPCManager);
+};
+
+#endif // CHROME_NACL_NACL_IPC_MANAGER_H_
« no previous file with comments | « chrome/nacl/nacl_ipc_adapter_unittest.cc ('k') | chrome/nacl/nacl_ipc_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698