Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_NACL_NACL_IPC_MANAGER_H_ | 5 #ifndef CHROME_NACL_NACL_IPC_MANAGER_H_ |
| 6 #define CHROME_NACL_NACL_IPC_MANAGER_H_ | 6 #define CHROME_NACL_NACL_IPC_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/thread.h" | |
|
dmichael (off chromium)
2012/05/07 20:30:19
Should you instead be adding base/message_loop_pro
bbudge
2012/05/07 21:39:18
Done.
| |
| 13 #include "ipc/ipc_channel_handle.h" | 14 #include "ipc/ipc_channel_handle.h" |
| 14 | 15 |
| 15 class NaClIPCAdapter; | 16 class NaClIPCAdapter; |
| 16 | 17 |
| 17 // This class manages all IPC channels exposed to NaCl. We give NaCl void* | 18 // This class manages all IPC channels exposed to NaCl. We give NaCl void* |
| 18 // "handles" to identify channels. When the untrusted nacl code does operations | 19 // "handles" to identify channels. When the untrusted nacl code does operations |
| 19 // on these handles, this class maps them to the corresponding adapter object. | 20 // on these handles, this class maps them to the corresponding adapter object. |
| 20 // | 21 // |
| 21 // This class must be threadsafe since nacl send/recvmsg functions can be | 22 // This class must be threadsafe since nacl send/recvmsg functions can be |
| 22 // called on any thread. | 23 // called on any thread. |
| 23 class NaClIPCManager { | 24 class NaClIPCManager { |
| 24 public: | 25 public: |
| 25 NaClIPCManager(); | 26 NaClIPCManager(); |
| 26 ~NaClIPCManager(); | 27 ~NaClIPCManager(); |
| 27 | 28 |
| 29 void Init(scoped_refptr<base::MessageLoopProxy> message_loop_proxy); | |
| 30 | |
| 28 // Creates a nacl channel associated with the given channel handle (normally | 31 // Creates a nacl channel associated with the given channel handle (normally |
| 29 // this will come from the browser process). Returns the handle that should | 32 // this will come from the browser process). Returns the handle that should |
| 30 // be given to nacl to associated with this IPC channel. | 33 // be given to nacl to associated with this IPC channel. |
| 31 void* CreateChannel(const IPC::ChannelHandle& handle); | 34 void* CreateChannel(const IPC::ChannelHandle& handle); |
| 32 | 35 |
| 33 // Destroys the channel with the given handle. | 36 // Destroys the channel with the given handle. |
| 34 void DestroyChannel(void* handle); | 37 void DestroyChannel(void* handle); |
| 35 | 38 |
| 36 // Implementation of sendmsg on the given channel. The return value is the | 39 // Implementation of sendmsg on the given channel. The return value is the |
| 37 // number of bytes written or -1 on failure. | 40 // number of bytes written or -1 on failure. |
| 38 int SendMessage(void* handle, const char* data, int data_length); | 41 int SendMessage(void* handle, const char* data, int data_length); |
| 39 | 42 |
| 40 // Implementation of recvmsg on the given channel. The return value is the | 43 // Implementation of recvmsg on the given channel. The return value is the |
| 41 // number of bytes received or -1 on failure. | 44 // number of bytes received or -1 on failure. |
| 42 int ReceiveMessage(void* handle, char* buffer, int buffer_length); | 45 int ReceiveMessage(void* handle, char* buffer, int buffer_length); |
| 43 | 46 |
| 44 private: | 47 private: |
| 45 // Looks up the adapter if given a handle. The pointer wil be null on | 48 // Looks up the adapter if given a handle. The pointer wil be null on |
| 46 // failures. | 49 // failures. |
| 47 scoped_refptr<NaClIPCAdapter> GetAdapter(void* handle); | 50 scoped_refptr<NaClIPCAdapter> GetAdapter(void* handle); |
| 48 | 51 |
| 52 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 53 | |
| 49 // Lock around all data below. | 54 // Lock around all data below. |
| 50 base::Lock lock_; | 55 base::Lock lock_; |
| 51 | 56 |
| 52 // All active IPC channels. Locked by lock_ above. | 57 // All active IPC channels. Locked by lock_ above. |
| 53 typedef std::map<void*, scoped_refptr<NaClIPCAdapter> > AdapterMap; | 58 typedef std::map<void*, scoped_refptr<NaClIPCAdapter> > AdapterMap; |
| 54 AdapterMap adapters_; | 59 AdapterMap adapters_; |
| 55 | 60 |
| 56 DISALLOW_COPY_AND_ASSIGN(NaClIPCManager); | 61 DISALLOW_COPY_AND_ASSIGN(NaClIPCManager); |
| 57 }; | 62 }; |
| 58 | 63 |
| 59 #endif // CHROME_NACL_NACL_IPC_MANAGER_H_ | 64 #endif // CHROME_NACL_NACL_IPC_MANAGER_H_ |
| OLD | NEW |