1 // Copyright 2013 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.
5 #ifndef CHROME_NACL_NACL_LISTENER_H_
6 #define CHROME_NACL_NACL_LISTENER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/shared_memory.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h"
14 #include "components/nacl/common/nacl_types.h"
15 #include "components/nacl/loader/nacl_trusted_listener.h"
16 #include "ipc/ipc_listener.h"
19 class MessageLoopProxy
;
24 class SyncMessageFilter
;
27 // The NaClListener is an IPC channel listener that waits for a
28 // request to start a NaCl module.
29 class NaClListener
: public IPC::Listener
{
32 ~NaClListener() override
;
33 // Listen for a request to launch a NaCl module.
36 bool Send(IPC::Message
* msg
);
39 void set_prereserved_sandbox_size(size_t prereserved_sandbox_size
) {
40 prereserved_sandbox_size_
= prereserved_sandbox_size
;
44 void set_number_of_cores(int number_of_cores
) {
45 number_of_cores_
= number_of_cores
;
49 void* crash_info_shmem_memory() const { return crash_info_shmem_
->memory(); }
51 typedef base::Callback
<void(IPC::PlatformFileForTransit
, base::FilePath
)>
52 ResolveFileTokenCallback
;
53 void ResolveFileToken(uint64_t token_lo
,
55 ResolveFileTokenCallback cb
);
56 void OnFileTokenResolved(uint64_t token_lo
,
58 IPC::PlatformFileForTransit ipc_fd
,
59 base::FilePath file_path
);
62 bool OnMessageReceived(const IPC::Message
& msg
) override
;
64 void OnStart(const nacl::NaClStartParams
& params
);
66 // A channel back to the browser.
67 scoped_ptr
<IPC::SyncChannel
> channel_
;
69 // A filter that allows other threads to use the channel.
70 scoped_refptr
<IPC::SyncMessageFilter
> filter_
;
72 base::WaitableEvent shutdown_event_
;
73 base::Thread io_thread_
;
76 size_t prereserved_sandbox_size_
;
79 // The outer sandbox on Linux and OSX prevents
80 // sysconf(_SC_NPROCESSORS) from working; in Windows, there are no
81 // problems with invoking GetSystemInfo. Therefore, only in
82 // OS_POSIX do we need to supply the number of cores into the
83 // NaClChromeMainArgs object.
87 scoped_ptr
<base::SharedMemory
> crash_info_shmem_
;
89 scoped_refptr
<NaClTrustedListener
> trusted_listener_
;
91 ResolveFileTokenCallback resolved_cb_
;
93 // Used to identify what thread we're on.
94 base::MessageLoop
* main_loop_
;
96 DISALLOW_COPY_AND_ASSIGN(NaClListener
);
99 #endif // CHROME_NACL_NACL_LISTENER_H_