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_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h"
15 #include "components/nacl/common/nacl_types.h"
16 #include "components/nacl/loader/nacl_trusted_listener.h"
17 #include "ipc/ipc_listener.h"
21 class SyncMessageFilter
;
24 // The NaClListener is an IPC channel listener that waits for a
25 // request to start a NaCl module.
26 class NaClListener
: public IPC::Listener
{
29 ~NaClListener() override
;
30 // Listen for a request to launch a NaCl module.
33 bool Send(IPC::Message
* msg
);
36 void set_prereserved_sandbox_size(size_t prereserved_sandbox_size
) {
37 prereserved_sandbox_size_
= prereserved_sandbox_size
;
41 void set_number_of_cores(int number_of_cores
) {
42 number_of_cores_
= number_of_cores
;
46 void* crash_info_shmem_memory() const { return crash_info_shmem_
->memory(); }
48 NaClTrustedListener
* trusted_listener() const {
49 return trusted_listener_
.get();
52 typedef base::Callback
<void(IPC::PlatformFileForTransit
, base::FilePath
)>
53 ResolveFileTokenCallback
;
54 void ResolveFileToken(uint64_t token_lo
,
56 ResolveFileTokenCallback cb
);
57 void OnFileTokenResolved(uint64_t token_lo
,
59 IPC::PlatformFileForTransit ipc_fd
,
60 base::FilePath file_path
);
63 bool OnMessageReceived(const IPC::Message
& msg
) override
;
65 typedef base::Callback
<void(const IPC::Message
&,
66 IPC::PlatformFileForTransit
,
67 base::FilePath
)> OpenResourceReplyCallback
;
69 bool OnOpenResource(const IPC::Message
& msg
,
70 const std::string
& key
,
71 OpenResourceReplyCallback cb
);
73 void OnAddPrefetchedResource(
74 const nacl::NaClResourcePrefetchResult
& prefetched_resource_file
);
75 void OnStart(const nacl::NaClStartParams
& params
);
77 // A channel back to the browser.
78 scoped_ptr
<IPC::SyncChannel
> channel_
;
80 // A filter that allows other threads to use the channel.
81 scoped_refptr
<IPC::SyncMessageFilter
> filter_
;
83 base::WaitableEvent shutdown_event_
;
84 base::Thread io_thread_
;
87 size_t prereserved_sandbox_size_
;
90 // The outer sandbox on Linux and OSX prevents
91 // sysconf(_SC_NPROCESSORS) from working; in Windows, there are no
92 // problems with invoking GetSystemInfo. Therefore, only in
93 // OS_POSIX do we need to supply the number of cores into the
94 // NaClChromeMainArgs object.
98 scoped_ptr
<base::SharedMemory
> crash_info_shmem_
;
100 scoped_refptr
<NaClTrustedListener
> trusted_listener_
;
102 ResolveFileTokenCallback resolved_cb_
;
104 // Used to identify what thread we're on.
105 base::MessageLoop
* main_loop_
;
108 std::string
, // manifest key
109 std::pair
<IPC::PlatformFileForTransit
,
110 base::FilePath
> > PrefetchedResourceFilesMap
;
111 PrefetchedResourceFilesMap prefetched_resource_files_
;
115 DISALLOW_COPY_AND_ASSIGN(NaClListener
);
118 #endif // CHROME_NACL_NACL_LISTENER_H_