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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/nacl/nacl_ipc_manager.h ('k') | ipc/ipc_message.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "chrome/nacl/nacl_ipc_manager.h"
6
7 #include "chrome/nacl/nacl_ipc_adapter.h"
8 #include "content/common/child_process.h"
9
10 NaClIPCManager::NaClIPCManager() {
11 }
12
13 NaClIPCManager::~NaClIPCManager() {
14 }
15
16 void* NaClIPCManager::CreateChannel(const IPC::ChannelHandle& handle) {
17 scoped_refptr<NaClIPCAdapter> adapter(
18 new NaClIPCAdapter(handle,
19 ChildProcess::current()->io_message_loop_proxy()));
20
21 // Use the object's address as the handle given to nacl. We just need a
22 // unique void* to give to nacl for us to look it up when we get calls on
23 // this handle in the future.
24 void* nacl_handle = adapter.get();
25 adapters_.insert(std::make_pair(nacl_handle, adapter));
26 return nacl_handle;
27 }
28
29 void NaClIPCManager::DestroyChannel(void* handle) {
30 scoped_refptr<NaClIPCAdapter> adapter = GetAdapter(handle);
31 if (!adapter.get())
32 return;
33 adapter->CloseChannel();
34 }
35
36 int NaClIPCManager::SendMessage(void* handle,
37 const char* data,
38 int data_length) {
39 scoped_refptr<NaClIPCAdapter> adapter = GetAdapter(handle);
40 if (!adapter.get())
41 return -1;
42 return adapter->Send(data, data_length);
43 }
44
45 int NaClIPCManager::ReceiveMessage(void* handle,
46 char* buffer,
47 int buffer_length) {
48 scoped_refptr<NaClIPCAdapter> adapter = GetAdapter(handle);
49 if (!adapter.get())
50 return -1;
51 return adapter->BlockingReceive(buffer, buffer_length);
52 }
53
54 scoped_refptr<NaClIPCAdapter> NaClIPCManager::GetAdapter(void* handle) {
55 base::AutoLock lock(lock_);
56 AdapterMap::iterator found = adapters_.find(handle);
57 if (found == adapters_.end())
58 return scoped_refptr<NaClIPCAdapter>();
59 return found->second;
60 }
OLDNEW
« 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