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