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/synchronization/waitable_event.h"
12 #include "base/threading/thread.h"
13 #include "components/nacl/common/nacl_types.h"
14 #include "components/nacl/loader/nacl_trusted_listener.h"
15 #include "ipc/ipc_listener.h"
18 class MessageLoopProxy
;
23 class SyncMessageFilter
;
26 // The NaClListener is an IPC channel listener that waits for a
27 // request to start a NaCl module.
28 class NaClListener
: public IPC::Listener
{
31 virtual ~NaClListener();
32 // Listen for a request to launch a NaCl module.
35 bool Send(IPC::Message
* msg
);
37 void set_uses_nonsfi_mode(bool uses_nonsfi_mode
) {
38 uses_nonsfi_mode_
= uses_nonsfi_mode
;
41 void set_prereserved_sandbox_size(size_t prereserved_sandbox_size
) {
42 prereserved_sandbox_size_
= prereserved_sandbox_size
;
46 void set_number_of_cores(int number_of_cores
) {
47 number_of_cores_
= number_of_cores
;
52 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
54 void OnStart(const nacl::NaClStartParams
& params
);
56 // Non-SFI version of OnStart().
57 void StartNonSfi(const nacl::NaClStartParams
& params
);
59 IPC::ChannelHandle
CreateTrustedListener(
60 base::MessageLoopProxy
* message_loop_proxy
,
61 base::WaitableEvent
* shutdown_event
);
63 // A channel back to the browser.
64 scoped_ptr
<IPC::SyncChannel
> channel_
;
66 // A filter that allows other threads to use the channel.
67 scoped_refptr
<IPC::SyncMessageFilter
> filter_
;
69 base::WaitableEvent shutdown_event_
;
70 base::Thread io_thread_
;
72 bool uses_nonsfi_mode_
;
74 size_t prereserved_sandbox_size_
;
77 // The outer sandbox on Linux and OSX prevents
78 // sysconf(_SC_NPROCESSORS) from working; in Windows, there are no
79 // problems with invoking GetSystemInfo. Therefore, only in
80 // OS_POSIX do we need to supply the number of cores into the
81 // NaClChromeMainArgs object.
85 scoped_refptr
<NaClTrustedListener
> trusted_listener_
;
87 // Used to identify what thread we're on.
88 base::MessageLoop
* main_loop_
;
90 DISALLOW_COPY_AND_ASSIGN(NaClListener
);
93 #endif // CHROME_NACL_NACL_LISTENER_H_