OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_NACL_NACL_IPC_MANAGER_H_ | |
6 #define CHROME_NACL_NACL_IPC_MANAGER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/synchronization/lock.h" | |
13 #include "ipc/ipc_channel_handle.h" | |
14 | |
15 class NaClIPCAdapter; | |
16 | |
17 // This class manages all IPC channels exposed to NaCl. It mostly just provides | |
18 // a threadsafe (since nacl send/recvmsg functions can be called on any thread) | |
19 // 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
| |
20 class NaClIPCManager { | |
21 public: | |
22 NaClIPCManager(); | |
23 ~NaClIPCManager(); | |
24 | |
25 // Creates a nacl channel associated with the given channel handle (normally | |
26 // this will come from the browser process). Returns the handle that should | |
27 // be given to nacl to associated with this IPC channel. | |
28 void* CreateChannel(const IPC::ChannelHandle& handle); | |
29 | |
30 // Destroys the channel with the given handle. | |
31 void DestroyChannel(void* handle); | |
32 | |
33 // Implementation of sendmsg on the given channel. The return value is the | |
34 // number of bytes written or -1 on failure. | |
35 int SendMessage(void* handle, const char* data, int data_length); | |
36 | |
37 // Implementation of recvmsg on the given channel. The return value is the | |
38 // number of bytes received or -1 on failure. | |
39 int ReceiveMessage(void* handle, char* buffer, int buffer_length); | |
40 | |
41 private: | |
42 // Looks up the adapter if given a handle. The pointer wil be null on | |
43 // failures. | |
44 scoped_refptr<NaClIPCAdapter> GetAdapter(void* handle); | |
45 | |
46 // Lock around all data below. | |
47 base::Lock lock_; | |
48 | |
49 // All active IPC channels. Locked by lock_ above. | |
50 typedef std::map<void*, scoped_refptr<NaClIPCAdapter> > AdapterMap; | |
51 AdapterMap adapters_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(NaClIPCManager); | |
54 }; | |
55 | |
56 #endif // CHROME_NACL_NACL_IPC_MANAGER_H_ | |
OLD | NEW |