cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / nacl / loader / nacl_listener.h
blob883f616f70f0feeb0e3f8851d9d8cbd96cf6a6fc
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_
8 #include <map>
9 #include <vector>
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"
19 namespace IPC {
20 class SyncChannel;
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 {
27 public:
28 NaClListener();
29 ~NaClListener() override;
30 // Listen for a request to launch a NaCl module.
31 void Listen();
33 bool Send(IPC::Message* msg);
35 #if defined(OS_LINUX)
36 void set_prereserved_sandbox_size(size_t prereserved_sandbox_size) {
37 prereserved_sandbox_size_ = prereserved_sandbox_size;
39 #endif
40 #if defined(OS_POSIX)
41 void set_number_of_cores(int number_of_cores) {
42 number_of_cores_ = number_of_cores;
44 #endif
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,
55 uint64_t token_hi,
56 ResolveFileTokenCallback cb);
57 void OnFileTokenResolved(uint64_t token_lo,
58 uint64_t token_hi,
59 IPC::PlatformFileForTransit ipc_fd,
60 base::FilePath file_path);
62 private:
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_;
86 #if defined(OS_LINUX)
87 size_t prereserved_sandbox_size_;
88 #endif
89 #if defined(OS_POSIX)
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.
95 int number_of_cores_;
96 #endif
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_;
107 typedef std::map<
108 std::string, // manifest key
109 std::pair<IPC::PlatformFileForTransit,
110 base::FilePath> > PrefetchedResourceFilesMap;
111 PrefetchedResourceFilesMap prefetched_resource_files_;
113 bool is_started_;
115 DISALLOW_COPY_AND_ASSIGN(NaClListener);
118 #endif // CHROME_NACL_NACL_LISTENER_H_