Chromium Code Reviews| 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..c2da2b35ddb35428afbd10e1d8a6ecabd0d2fffc |
| --- /dev/null |
| +++ b/chrome/nacl/nacl_ipc_manager.h |
| @@ -0,0 +1,56 @@ |
| +// 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. It mostly just provides |
| +// a threadsafe (since nacl send/recvmsg functions can be called on any thread) |
| +// map from handle to our IPC adapters. |
|
bbudge
2012/03/27 18:38:37
It seems like it would be better if this comment e
|
| +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_ |