OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ | 5 #ifndef COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ |
6 #define COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ | 6 #define COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/containers/mru_cache.h" | 11 #include "base/containers/mru_cache.h" |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/nacl/browser/nacl_browser_delegate.h" | 16 #include "components/nacl/browser/nacl_browser_delegate.h" |
17 #include "components/nacl/browser/nacl_validation_cache.h" | 17 #include "components/nacl/browser/nacl_validation_cache.h" |
18 | 18 |
19 class URLPattern; | 19 class URLPattern; |
20 class GURL; | 20 class GURL; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class FileProxy; | 23 class FileProxy; |
24 } | 24 } |
25 | 25 |
26 namespace nacl { | 26 namespace nacl { |
27 | 27 |
28 static const int kGdbDebugStubPortUnknown = -1; | |
29 static const int kGdbDebugStubPortUnused = 0; | |
30 | |
31 // Open an immutable executable file that can be mmapped. | 28 // Open an immutable executable file that can be mmapped. |
32 // This function should only be called on a thread that can perform file IO. | 29 // This function should only be called on a thread that can perform file IO. |
33 base::File OpenNaClExecutableImpl(const base::FilePath& file_path); | 30 base::File OpenNaClExecutableImpl(const base::FilePath& file_path); |
34 | 31 |
35 // Represents shared state for all NaClProcessHost objects in the browser. | 32 // Represents shared state for all NaClProcessHost objects in the browser. |
36 class NaClBrowser { | 33 class NaClBrowser { |
37 public: | 34 public: |
38 static NaClBrowser* GetInstance(); | 35 static NaClBrowser* GetInstance(); |
39 | 36 |
40 // Will it be possible to launch a NaCl process, eventually? | 37 // Will it be possible to launch a NaCl process, eventually? |
(...skipping 20 matching lines...) Expand all Loading... |
61 const base::FilePath& GetIrtFilePath(); | 58 const base::FilePath& GetIrtFilePath(); |
62 | 59 |
63 // IRT file handle, only available when IsReady(). | 60 // IRT file handle, only available when IsReady(). |
64 const base::File& IrtFile() const; | 61 const base::File& IrtFile() const; |
65 | 62 |
66 // Methods for testing GDB debug stub in browser. If test adds debug stub | 63 // Methods for testing GDB debug stub in browser. If test adds debug stub |
67 // port listener, Chrome will allocate a currently-unused TCP port number for | 64 // port listener, Chrome will allocate a currently-unused TCP port number for |
68 // debug stub server instead of a fixed one. | 65 // debug stub server instead of a fixed one. |
69 | 66 |
70 // Notify listener that new debug stub TCP port is allocated. | 67 // Notify listener that new debug stub TCP port is allocated. |
71 void SetProcessGdbDebugStubPort(int process_id, int port); | 68 void FireGdbDebugStubPortOpened(int port); |
| 69 bool HasGdbDebugStubPortListener(); |
72 void SetGdbDebugStubPortListener(base::Callback<void(int)> listener); | 70 void SetGdbDebugStubPortListener(base::Callback<void(int)> listener); |
73 void ClearGdbDebugStubPortListener(); | 71 void ClearGdbDebugStubPortListener(); |
74 | 72 |
75 int GetProcessGdbDebugStubPort(int process_id); | |
76 | |
77 bool ValidationCacheIsEnabled() const { | 73 bool ValidationCacheIsEnabled() const { |
78 return validation_cache_is_enabled_; | 74 return validation_cache_is_enabled_; |
79 } | 75 } |
80 | 76 |
81 const std::string& GetValidationCacheKey() const { | 77 const std::string& GetValidationCacheKey() const { |
82 return validation_cache_.GetValidationCacheKey(); | 78 return validation_cache_.GetValidationCacheKey(); |
83 } | 79 } |
84 | 80 |
85 // The NaCl singleton keeps information about NaCl executable files opened via | 81 // The NaCl singleton keeps information about NaCl executable files opened via |
86 // PPAPI. This allows the NaCl process to get trusted information about the | 82 // PPAPI. This allows the NaCl process to get trusted information about the |
(...skipping 27 matching lines...) Expand all Loading... |
114 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
115 // Get path to NaCl loader on the filesystem if possible. | 111 // Get path to NaCl loader on the filesystem if possible. |
116 // |exe_path| does not change if the method fails. | 112 // |exe_path| does not change if the method fails. |
117 bool GetNaCl64ExePath(base::FilePath* exe_path); | 113 bool GetNaCl64ExePath(base::FilePath* exe_path); |
118 #endif | 114 #endif |
119 | 115 |
120 void EarlyStartup(); | 116 void EarlyStartup(); |
121 static void SetDelegate(NaClBrowserDelegate* delegate); | 117 static void SetDelegate(NaClBrowserDelegate* delegate); |
122 static NaClBrowserDelegate* GetDelegate(); | 118 static NaClBrowserDelegate* GetDelegate(); |
123 | 119 |
124 // Each time a NaCl process ends, the browser is notified. | |
125 void OnProcessEnd(int process_id); | |
126 // Support for NaCl crash throttling. | 120 // Support for NaCl crash throttling. |
127 // Each time a NaCl module crashes, the browser is notified. | 121 // Each time a NaCl module crashes, the browser is notified. |
128 void OnProcessCrashed(); | 122 void OnProcessCrashed(); |
129 // If "too many" crashes occur within a given time period, NaCl is throttled | 123 // If "too many" crashes occur within a given time period, NaCl is throttled |
130 // until the rate again drops below the threshold. | 124 // until the rate again drops below the threshold. |
131 bool IsThrottled(); | 125 bool IsThrottled(); |
132 | 126 |
133 private: | 127 private: |
134 friend struct DefaultSingletonTraits<NaClBrowser>; | 128 friend struct DefaultSingletonTraits<NaClBrowser>; |
135 | 129 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 base::FilePath irt_filepath_; | 164 base::FilePath irt_filepath_; |
171 NaClResourceState irt_state_; | 165 NaClResourceState irt_state_; |
172 NaClValidationCache validation_cache_; | 166 NaClValidationCache validation_cache_; |
173 NaClValidationCache off_the_record_validation_cache_; | 167 NaClValidationCache off_the_record_validation_cache_; |
174 base::FilePath validation_cache_file_path_; | 168 base::FilePath validation_cache_file_path_; |
175 bool validation_cache_is_enabled_; | 169 bool validation_cache_is_enabled_; |
176 bool validation_cache_is_modified_; | 170 bool validation_cache_is_modified_; |
177 NaClResourceState validation_cache_state_; | 171 NaClResourceState validation_cache_state_; |
178 base::Callback<void(int)> debug_stub_port_listener_; | 172 base::Callback<void(int)> debug_stub_port_listener_; |
179 | 173 |
180 // Map from process id to debug stub port if any. | |
181 typedef std::map<int, int> GdbDebugStubPortMap; | |
182 GdbDebugStubPortMap gdb_debug_stub_port_map_; | |
183 | |
184 typedef base::HashingMRUCache<std::string, base::FilePath> PathCacheType; | 174 typedef base::HashingMRUCache<std::string, base::FilePath> PathCacheType; |
185 PathCacheType path_cache_; | 175 PathCacheType path_cache_; |
186 | 176 |
187 bool ok_; | 177 bool ok_; |
188 | 178 |
189 // A list of pending tasks to start NaCl processes. | 179 // A list of pending tasks to start NaCl processes. |
190 std::vector<base::Closure> waiting_; | 180 std::vector<base::Closure> waiting_; |
191 | 181 |
192 scoped_ptr<NaClBrowserDelegate> browser_delegate_; | 182 scoped_ptr<NaClBrowserDelegate> browser_delegate_; |
193 | 183 |
194 std::deque<base::Time> crash_times_; | 184 std::deque<base::Time> crash_times_; |
195 | 185 |
196 DISALLOW_COPY_AND_ASSIGN(NaClBrowser); | 186 DISALLOW_COPY_AND_ASSIGN(NaClBrowser); |
197 }; | 187 }; |
198 | 188 |
199 } // namespace nacl | 189 } // namespace nacl |
200 | 190 |
201 #endif // COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ | 191 #endif // COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ |
OLD | NEW |