OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ | 5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ |
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ | 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "native_client/src/include/nacl_macros.h" | 12 #include "native_client/src/include/nacl_macros.h" |
13 #include "native_client/src/include/nacl_string.h" | 13 #include "native_client/src/include/nacl_string.h" |
14 #include "native_client/src/shared/platform/nacl_sync_raii.h" | 14 #include "native_client/src/shared/platform/nacl_sync_raii.h" |
15 | 15 |
16 #include "native_client/src/shared/srpc/nacl_srpc.h" | 16 #include "native_client/src/shared/srpc/nacl_srpc.h" |
17 | 17 |
18 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 18 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
19 #include "native_client/src/trusted/plugin/callback_source.h" | 19 #include "native_client/src/trusted/plugin/callback_source.h" |
20 #include "native_client/src/trusted/plugin/delayed_callback.h" | 20 #include "native_client/src/trusted/plugin/delayed_callback.h" |
21 #include "native_client/src/trusted/plugin/file_downloader.h" | 21 #include "native_client/src/trusted/plugin/file_downloader.h" |
22 #include "native_client/src/trusted/plugin/local_temp_file.h" | 22 #include "native_client/src/trusted/plugin/local_temp_file.h" |
23 #include "native_client/src/trusted/plugin/nacl_subprocess.h" | 23 #include "native_client/src/trusted/plugin/nacl_subprocess.h" |
24 #include "native_client/src/trusted/plugin/plugin_error.h" | 24 #include "native_client/src/trusted/plugin/plugin_error.h" |
| 25 #include "native_client/src/trusted/plugin/pnacl_options.h" |
25 #include "native_client/src/trusted/plugin/pnacl_resources.h" | 26 #include "native_client/src/trusted/plugin/pnacl_resources.h" |
26 | 27 |
27 #include "ppapi/c/pp_file_info.h" | 28 #include "ppapi/c/pp_file_info.h" |
28 #include "ppapi/c/trusted/ppb_file_io_trusted.h" | 29 #include "ppapi/c/trusted/ppb_file_io_trusted.h" |
29 #include "ppapi/cpp/completion_callback.h" | 30 #include "ppapi/cpp/completion_callback.h" |
30 #include "ppapi/cpp/file_io.h" | 31 #include "ppapi/cpp/file_io.h" |
31 #include "ppapi/cpp/file_ref.h" | 32 #include "ppapi/cpp/file_ref.h" |
32 #include "ppapi/cpp/file_system.h" | 33 #include "ppapi/cpp/file_system.h" |
33 | 34 |
34 | 35 |
35 namespace plugin { | 36 namespace plugin { |
36 | 37 |
37 class Manifest; | 38 class Manifest; |
38 class Plugin; | 39 class Plugin; |
39 class PnaclCoordinator; | 40 class PnaclCoordinator; |
40 class PnaclTranslateThread; | 41 class PnaclTranslateThread; |
41 class TempFile; | 42 class TempFile; |
42 | 43 |
43 // A class invoked by Plugin to handle PNaCl client-side translation. | 44 // A class invoked by Plugin to handle PNaCl client-side translation. |
44 // Usage: | 45 // Usage: |
45 // (1) Invoke the factory method, e.g., | 46 // (1) Invoke the factory method, e.g., |
46 // PnaclCoordinator* coord = BitcodeToNative(plugin, | 47 // PnaclCoordinator* coord = BitcodeToNative(plugin, |
47 // "http://foo.com/my.pexe", | 48 // "http://foo.com/my.pexe", |
| 49 // pnacl_options, |
48 // TranslateNotifyCallback); | 50 // TranslateNotifyCallback); |
49 // (2) TranslateNotifyCallback gets invoked when translation is complete. | 51 // (2) TranslateNotifyCallback gets invoked when translation is complete. |
50 // If the translation was successful, the pp_error argument is PP_OK. | 52 // If the translation was successful, the pp_error argument is PP_OK. |
51 // Other values indicate errors. | 53 // Other values indicate errors. |
52 // (3) After finish_callback runs, get the file descriptor of the translated | 54 // (3) After finish_callback runs, get the file descriptor of the translated |
53 // nexe, e.g., | 55 // nexe, e.g., |
54 // fd = coord->ReleaseTranslatedFD(); | 56 // fd = coord->ReleaseTranslatedFD(); |
55 // (4) Load the nexe from "fd". | 57 // (4) Load the nexe from "fd". |
56 // (5) delete coord. | 58 // (5) delete coord. |
57 // | 59 // |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // OPEN_NEXE_FOR_SEL_LDR | 96 // OPEN_NEXE_FOR_SEL_LDR |
95 // Complete when NexeReadDidOpen is invoked. | 97 // Complete when NexeReadDidOpen is invoked. |
96 class PnaclCoordinator: public CallbackSource<FileStreamData> { | 98 class PnaclCoordinator: public CallbackSource<FileStreamData> { |
97 public: | 99 public: |
98 virtual ~PnaclCoordinator(); | 100 virtual ~PnaclCoordinator(); |
99 | 101 |
100 // The factory method for translations. | 102 // The factory method for translations. |
101 static PnaclCoordinator* BitcodeToNative( | 103 static PnaclCoordinator* BitcodeToNative( |
102 Plugin* plugin, | 104 Plugin* plugin, |
103 const nacl::string& pexe_url, | 105 const nacl::string& pexe_url, |
104 const nacl::string& cache_identity, | 106 const PnaclOptions& pnacl_options, |
105 const pp::CompletionCallback& translate_notify_callback); | 107 const pp::CompletionCallback& translate_notify_callback); |
106 | 108 |
107 // Call this to take ownership of the FD of the translated nexe after | 109 // Call this to take ownership of the FD of the translated nexe after |
108 // BitcodeToNative has completed (and the finish_callback called). | 110 // BitcodeToNative has completed (and the finish_callback called). |
109 nacl::DescWrapper* ReleaseTranslatedFD() { return translated_fd_.release(); } | 111 nacl::DescWrapper* ReleaseTranslatedFD() { return translated_fd_.release(); } |
110 | 112 |
111 // Looks up a file descriptor for an url that was already downloaded. | 113 // Looks up a file descriptor for an url that was already downloaded. |
112 // This is used for getting the descriptor for llc and ld nexes as well | 114 // This is used for getting the descriptor for llc and ld nexes as well |
113 // as the libraries and object files used by the linker. | 115 // as the libraries and object files used by the linker. |
114 int32_t GetLoadedFileDesc(int32_t pp_error, | 116 int32_t GetLoadedFileDesc(int32_t pp_error, |
(...skipping 26 matching lines...) Expand all Loading... |
141 // Get the last known load progress. | 143 // Get the last known load progress. |
142 void GetCurrentProgress(int64_t* bytes_loaded, int64_t* bytes_total); | 144 void GetCurrentProgress(int64_t* bytes_loaded, int64_t* bytes_total); |
143 | 145 |
144 private: | 146 private: |
145 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator); | 147 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator); |
146 | 148 |
147 // BitcodeToNative is the factory method for PnaclCoordinators. | 149 // BitcodeToNative is the factory method for PnaclCoordinators. |
148 // Therefore the constructor is private. | 150 // Therefore the constructor is private. |
149 PnaclCoordinator(Plugin* plugin, | 151 PnaclCoordinator(Plugin* plugin, |
150 const nacl::string& pexe_url, | 152 const nacl::string& pexe_url, |
151 const nacl::string& cache_identity, | 153 const PnaclOptions& pnacl_options, |
152 const pp::CompletionCallback& translate_notify_callback); | 154 const pp::CompletionCallback& translate_notify_callback); |
153 | 155 |
154 // Callback for when llc and ld have been downloaded. | 156 // Callback for when llc and ld have been downloaded. |
155 // This is the first callback invoked in response to BitcodeToNative. | 157 // This is the first callback invoked in response to BitcodeToNative. |
156 void ResourcesDidLoad(int32_t pp_error); | 158 void ResourcesDidLoad(int32_t pp_error); |
157 | 159 |
158 // Callbacks for temporary file related stages. | 160 // Callbacks for temporary file related stages. |
159 // They are invoked from ResourcesDidLoad and proceed in declaration order. | 161 // They are invoked from ResourcesDidLoad and proceed in declaration order. |
160 // Invoked when the temporary file system is successfully opened in PPAPI. | 162 // Invoked when the temporary file system is successfully opened in PPAPI. |
161 void FileSystemDidOpen(int32_t pp_error); | 163 void FileSystemDidOpen(int32_t pp_error); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // The manifest used by ld's reverse service to look up objects and libraries. | 227 // The manifest used by ld's reverse service to look up objects and libraries. |
226 nacl::scoped_ptr<const Manifest> ld_manifest_; | 228 nacl::scoped_ptr<const Manifest> ld_manifest_; |
227 // An auxiliary class that manages downloaded resources (llc and ld nexes). | 229 // An auxiliary class that manages downloaded resources (llc and ld nexes). |
228 nacl::scoped_ptr<PnaclResources> resources_; | 230 nacl::scoped_ptr<PnaclResources> resources_; |
229 | 231 |
230 // State used for querying the temporary directory. | 232 // State used for querying the temporary directory. |
231 nacl::scoped_ptr<pp::FileRef> dir_ref_; | 233 nacl::scoped_ptr<pp::FileRef> dir_ref_; |
232 | 234 |
233 // The URL for the pexe file. | 235 // The URL for the pexe file. |
234 nacl::string pexe_url_; | 236 nacl::string pexe_url_; |
235 // Optional cache identity for translation caching. | 237 // Options for translation. |
236 nacl::string cache_identity_; | 238 PnaclOptions pnacl_options_; |
| 239 |
237 // Object file, produced by the translator and consumed by the linker. | 240 // Object file, produced by the translator and consumed by the linker. |
238 nacl::scoped_ptr<TempFile> obj_file_; | 241 nacl::scoped_ptr<TempFile> obj_file_; |
239 // Translated nexe file, produced by the linker. | 242 // Translated nexe file, produced by the linker. |
240 nacl::scoped_ptr<TempFile> temp_nexe_file_; | 243 nacl::scoped_ptr<TempFile> temp_nexe_file_; |
241 // Cached nexe file, consumed by sel_ldr. This will be NULL if we do | 244 // Cached nexe file, consumed by sel_ldr. This will be NULL if we do |
242 // not have a writeable cache file. That is currently the case when | 245 // not have a writeable cache file. That is currently the case when |
243 // off_the_record_ is true. | 246 // off_the_record_ is true. |
244 nacl::scoped_ptr<LocalTempFile> cached_nexe_file_; | 247 nacl::scoped_ptr<LocalTempFile> cached_nexe_file_; |
245 | 248 |
246 // Downloader for streaming translation | 249 // Downloader for streaming translation |
247 nacl::scoped_ptr<FileDownloader> streaming_downloader_; | 250 nacl::scoped_ptr<FileDownloader> streaming_downloader_; |
248 | 251 |
249 // Used to report information when errors (PPAPI or otherwise) are reported. | 252 // Used to report information when errors (PPAPI or otherwise) are reported. |
250 ErrorInfo error_info_; | 253 ErrorInfo error_info_; |
| 254 |
251 // True if an error was already reported, and translate_notify_callback_ | 255 // True if an error was already reported, and translate_notify_callback_ |
252 // was already run/consumed. | 256 // was already run/consumed. |
253 bool error_already_reported_; | 257 bool error_already_reported_; |
254 | 258 |
255 // True if compilation is off_the_record. | 259 // True if compilation is off_the_record. |
256 bool off_the_record_; | 260 bool off_the_record_; |
257 | 261 |
258 // State for timing and size information for UMA stats. | 262 // State for timing and size information for UMA stats. |
259 int64_t pnacl_init_time_; | 263 int64_t pnacl_init_time_; |
260 int64_t pexe_size_; // Count as we stream -- will converge to pexe size. | 264 int64_t pexe_size_; // Count as we stream -- will converge to pexe size. |
261 int64_t pexe_bytes_compiled_; // Count as we compile. | 265 int64_t pexe_bytes_compiled_; // Count as we compile. |
262 int64_t expected_pexe_size_; // Expected download total (-1 if unknown). | 266 int64_t expected_pexe_size_; // Expected download total (-1 if unknown). |
263 | 267 |
264 // The helper thread used to do translations via SRPC. | 268 // The helper thread used to do translations via SRPC. |
265 // Keep this last in declaration order to ensure the other variables | 269 // Keep this last in declaration order to ensure the other variables |
266 // haven't been destroyed yet when its destructor runs. | 270 // haven't been destroyed yet when its destructor runs. |
267 nacl::scoped_ptr<PnaclTranslateThread> translate_thread_; | 271 nacl::scoped_ptr<PnaclTranslateThread> translate_thread_; |
268 }; | 272 }; |
269 | 273 |
270 //---------------------------------------------------------------------- | 274 //---------------------------------------------------------------------- |
271 | 275 |
272 } // namespace plugin; | 276 } // namespace plugin; |
273 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ | 277 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ |
OLD | NEW |