Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: trunk/src/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h

Issue 406323003: Revert 284684 "Pepper: Delete FileDownloader in trusted plugin." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "native_client/src/shared/srpc/nacl_srpc.h" 15 #include "native_client/src/shared/srpc/nacl_srpc.h"
16 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 16 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
17 17
18 #include "ppapi/cpp/completion_callback.h" 18 #include "ppapi/cpp/completion_callback.h"
19 19
20 #include "ppapi/native_client/src/trusted/plugin/callback_source.h"
21 #include "ppapi/native_client/src/trusted/plugin/file_downloader.h"
20 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" 22 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h"
21 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" 23 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
22 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" 24 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
23 25
24 #include "ppapi/utility/completion_callback_factory.h"
25
26 struct PP_PNaClOptions; 26 struct PP_PNaClOptions;
27 27
28 namespace plugin { 28 namespace plugin {
29 29
30 class Plugin; 30 class Plugin;
31 class PnaclCoordinator; 31 class PnaclCoordinator;
32 class PnaclTranslateThread; 32 class PnaclTranslateThread;
33 class TempFile; 33 class TempFile;
34 34
35 // A class invoked by Plugin to handle PNaCl client-side translation. 35 // A class invoked by Plugin to handle PNaCl client-side translation.
36 // Usage: 36 // Usage:
37 // (1) Invoke the factory method, e.g., 37 // (1) Invoke the factory method, e.g.,
38 // PnaclCoordinator* coord = BitcodeToNative(plugin, 38 // PnaclCoordinator* coord = BitcodeToNative(plugin,
39 // "http://foo.com/my.pexe", 39 // "http://foo.com/my.pexe",
40 // pnacl_options, 40 // pnacl_options,
41 // TranslateNotifyCallback); 41 // TranslateNotifyCallback);
42 // (2) TranslateNotifyCallback gets invoked when translation is complete. 42 // (2) TranslateNotifyCallback gets invoked when translation is complete.
43 // If the translation was successful, the pp_error argument is PP_OK. 43 // If the translation was successful, the pp_error argument is PP_OK.
44 // Other values indicate errors. 44 // Other values indicate errors.
45 // (3) After finish_callback runs, get the file descriptor of the translated 45 // (3) After finish_callback runs, get the file descriptor of the translated
46 // nexe, e.g., 46 // nexe, e.g.,
47 // fd = coord->ReleaseTranslatedFD(); 47 // fd = coord->ReleaseTranslatedFD();
48 // (4) Load the nexe from "fd". 48 // (4) Load the nexe from "fd".
49 // (5) delete coord. 49 // (5) delete coord.
50 // 50 //
51 // Translation proceeds in two steps: 51 // Translation proceeds in two steps:
52 // (1) llc translates the bitcode in pexe_url_ to an object in obj_file_. 52 // (1) llc translates the bitcode in pexe_url_ to an object in obj_file_.
53 // (2) ld links the object code in obj_file_ and produces a nexe in nexe_file_. 53 // (2) ld links the object code in obj_file_ and produces a nexe in nexe_file_.
54 class PnaclCoordinator { 54 class PnaclCoordinator: public CallbackSource<FileStreamData> {
55 public: 55 public:
56 // Maximum number of object files passable to the translator. Cannot be 56 // Maximum number of object files passable to the translator. Cannot be
57 // changed without changing the RPC signatures. 57 // changed without changing the RPC signatures.
58 const static size_t kMaxTranslatorObjectFiles = 16; 58 const static size_t kMaxTranslatorObjectFiles = 16;
59 virtual ~PnaclCoordinator(); 59 virtual ~PnaclCoordinator();
60 60
61 // The factory method for translations. 61 // The factory method for translations.
62 static PnaclCoordinator* BitcodeToNative( 62 static PnaclCoordinator* BitcodeToNative(
63 Plugin* plugin, 63 Plugin* plugin,
64 const nacl::string& pexe_url, 64 const nacl::string& pexe_url,
65 const PP_PNaClOptions& pnacl_options, 65 const PP_PNaClOptions& pnacl_options,
66 const pp::CompletionCallback& translate_notify_callback); 66 const pp::CompletionCallback& translate_notify_callback);
67 67
68 // Call this to take ownership of the FD of the translated nexe after 68 // Call this to take ownership of the FD of the translated nexe after
69 // BitcodeToNative has completed (and the finish_callback called). 69 // BitcodeToNative has completed (and the finish_callback called).
70 PP_FileHandle TakeTranslatedFileHandle(); 70 PP_FileHandle TakeTranslatedFileHandle();
71 71
72 // Implement FileDownloader's template of the CallbackSource interface.
73 // This method returns a callback which will be called by the FileDownloader
74 // to stream the bitcode data as it arrives. The callback
75 // (BitcodeStreamGotData) passes it to llc over SRPC.
76 StreamCallback GetCallback();
77
72 // Return a callback that should be notified when |bytes_compiled| bytes 78 // Return a callback that should be notified when |bytes_compiled| bytes
73 // have been compiled. 79 // have been compiled.
74 pp::CompletionCallback GetCompileProgressCallback(int64_t bytes_compiled); 80 pp::CompletionCallback GetCompileProgressCallback(int64_t bytes_compiled);
75 81
76 // Get the last known load progress. 82 // Get the last known load progress.
77 void GetCurrentProgress(int64_t* bytes_loaded, int64_t* bytes_total); 83 void GetCurrentProgress(int64_t* bytes_loaded, int64_t* bytes_total);
78 84
79 // Return true if we should delay the progress event reporting. 85 // Return true if we should delay the progress event reporting.
80 // This delay approximates: 86 // This delay approximates:
81 // - the size of the buffer of bytes sent but not-yet-compiled by LLC. 87 // - the size of the buffer of bytes sent but not-yet-compiled by LLC.
82 // - the linking time. 88 // - the linking time.
83 bool ShouldDelayProgressEvent() { 89 bool ShouldDelayProgressEvent() {
84 const uint32_t kProgressEventSlopPct = 5; 90 const uint32_t kProgressEventSlopPct = 5;
85 return ((expected_pexe_size_ - pexe_bytes_compiled_) * 100 / 91 return ((expected_pexe_size_ - pexe_bytes_compiled_) * 100 /
86 expected_pexe_size_) < kProgressEventSlopPct; 92 expected_pexe_size_) < kProgressEventSlopPct;
87 } 93 }
88 94
89
90 void BitcodeStreamCacheHit(PP_FileHandle handle);
91 void BitcodeStreamCacheMiss(int64_t expected_pexe_size);
92
93 // Invoked when a pexe data chunk arrives (when using streaming translation)
94 void BitcodeStreamGotData(const void* data, int32_t length);
95
96 // Invoked when the pexe download finishes (using streaming translation)
97 void BitcodeStreamDidFinish(int32_t pp_error);
98
99 private: 95 private:
100 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator); 96 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator);
101 97
102 // BitcodeToNative is the factory method for PnaclCoordinators. 98 // BitcodeToNative is the factory method for PnaclCoordinators.
103 // Therefore the constructor is private. 99 // Therefore the constructor is private.
104 PnaclCoordinator(Plugin* plugin, 100 PnaclCoordinator(Plugin* plugin,
105 const nacl::string& pexe_url, 101 const nacl::string& pexe_url,
106 const PP_PNaClOptions& pnacl_options, 102 const PP_PNaClOptions& pnacl_options,
107 const pp::CompletionCallback& translate_notify_callback); 103 const pp::CompletionCallback& translate_notify_callback);
108 104
109 // Invoke to issue a GET request for bitcode. 105 // Invoke to issue a GET request for bitcode.
110 void OpenBitcodeStream(); 106 void OpenBitcodeStream();
107 // Invoked when we've started an URL fetch for the pexe to check for
108 // caching metadata.
109 void BitcodeStreamDidOpen(int32_t pp_error);
111 110
111 // Invoked when we've gotten a temp FD for the nexe, either with the nexe
112 // data, or a writeable fd to save to.
113 void NexeFdDidOpen(int32_t pp_error);
114 // Invoked when a pexe data chunk arrives (when using streaming translation)
115 void BitcodeStreamGotData(int32_t pp_error, FileStreamData data);
112 // Invoked when a pexe data chunk is compiled. 116 // Invoked when a pexe data chunk is compiled.
113 void BitcodeGotCompiled(int32_t pp_error, int64_t bytes_compiled); 117 void BitcodeGotCompiled(int32_t pp_error, int64_t bytes_compiled);
118 // Invoked when the pexe download finishes (using streaming translation)
119 void BitcodeStreamDidFinish(int32_t pp_error);
114 // Once llc and ld nexes have been loaded and the two temporary files have 120 // Once llc and ld nexes have been loaded and the two temporary files have
115 // been created, this starts the translation. Translation starts two 121 // been created, this starts the translation. Translation starts two
116 // subprocesses, one for llc and one for ld. 122 // subprocesses, one for llc and one for ld.
117 void RunTranslate(int32_t pp_error); 123 void RunTranslate(int32_t pp_error);
118 124
119 // Invoked when translation is finished. 125 // Invoked when translation is finished.
120 void TranslateFinished(int32_t pp_error); 126 void TranslateFinished(int32_t pp_error);
121 127
122 // Invoked when the read descriptor for nexe_file_ is created. 128 // Invoked when the read descriptor for nexe_file_ is created.
123 void NexeReadDidOpen(int32_t pp_error); 129 void NexeReadDidOpen(int32_t pp_error);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 nacl::string architecture_attributes_; 173 nacl::string architecture_attributes_;
168 174
169 // Object file, produced by the translator and consumed by the linker. 175 // Object file, produced by the translator and consumed by the linker.
170 std::vector<TempFile*> obj_files_; 176 std::vector<TempFile*> obj_files_;
171 nacl::scoped_ptr<nacl::DescWrapper> invalid_desc_wrapper_; 177 nacl::scoped_ptr<nacl::DescWrapper> invalid_desc_wrapper_;
172 // Number of split modules (threads) for llc 178 // Number of split modules (threads) for llc
173 int split_module_count_; 179 int split_module_count_;
174 180
175 // Translated nexe file, produced by the linker. 181 // Translated nexe file, produced by the linker.
176 nacl::scoped_ptr<TempFile> temp_nexe_file_; 182 nacl::scoped_ptr<TempFile> temp_nexe_file_;
183 // Passed to the browser, which sets it to true if there is a translation
184 // cache hit.
185 PP_Bool is_cache_hit_;
186
187 // Downloader for streaming translation
188 nacl::scoped_ptr<FileDownloader> streaming_downloader_;
177 189
178 // Used to report information when errors (PPAPI or otherwise) are reported. 190 // Used to report information when errors (PPAPI or otherwise) are reported.
179 ErrorInfo error_info_; 191 ErrorInfo error_info_;
180 192
181 // True if an error was already reported, and translate_notify_callback_ 193 // True if an error was already reported, and translate_notify_callback_
182 // was already run/consumed. 194 // was already run/consumed.
183 bool error_already_reported_; 195 bool error_already_reported_;
184 196
185 // State for timing and size information for UMA stats. 197 // State for timing and size information for UMA stats.
186 int64_t pexe_size_; // Count as we stream -- will converge to pexe size. 198 int64_t pexe_size_; // Count as we stream -- will converge to pexe size.
187 int64_t pexe_bytes_compiled_; // Count as we compile. 199 int64_t pexe_bytes_compiled_; // Count as we compile.
188 int64_t expected_pexe_size_; // Expected download total (-1 if unknown). 200 int64_t expected_pexe_size_; // Expected download total (-1 if unknown).
189 201
190 // The helper thread used to do translations via SRPC. 202 // The helper thread used to do translations via SRPC.
191 // It accesses fields of PnaclCoordinator so it must have a 203 // It accesses fields of PnaclCoordinator so it must have a
192 // shorter lifetime. 204 // shorter lifetime.
193 nacl::scoped_ptr<PnaclTranslateThread> translate_thread_; 205 nacl::scoped_ptr<PnaclTranslateThread> translate_thread_;
194 }; 206 };
195 207
196 //---------------------------------------------------------------------- 208 //----------------------------------------------------------------------
197 209
198 } // namespace plugin; 210 } // namespace plugin;
199 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ 211 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698