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

Unified Diff: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h

Issue 10377157: Refactor Pnacl coordinator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sehr comments Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h
diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h
index 5643a6dd72273e8d62d21710c964a884b13ac3ee..96f8cbd3aea13a053d614538c639ef6d48ae0099 100644
--- a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h
+++ b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h
@@ -11,13 +11,13 @@
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/nacl_string.h"
-#include "native_client/src/shared/platform/nacl_sync_checked.h"
#include "native_client/src/shared/platform/nacl_sync_raii.h"
-#include "native_client/src/shared/platform/nacl_threads.h"
+
#include "native_client/src/shared/srpc/nacl_srpc.h"
-#include "native_client/src/trusted/desc/nacl_desc_rng.h"
+
#include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
#include "native_client/src/trusted/plugin/delayed_callback.h"
+#include "native_client/src/trusted/plugin/local_temp_file.h"
#include "native_client/src/trusted/plugin/nacl_subprocess.h"
#include "native_client/src/trusted/plugin/plugin_error.h"
#include "native_client/src/trusted/plugin/pnacl_resources.h"
@@ -29,114 +29,13 @@
#include "ppapi/cpp/file_ref.h"
#include "ppapi/cpp/file_system.h"
-struct NaClMutex;
namespace plugin {
class Manifest;
class Plugin;
class PnaclCoordinator;
-
-// Translation creates two temporary files. The first temporary file holds
-// the object file created by llc. The second holds the nexe produced by
-// the linker. Both of these temporary files are used to both write and
-// read according to the following matrix:
-//
-// PnaclCoordinator::obj_file_:
-// written by: llc (passed in explicitly through SRPC)
-// read by: ld (returned via lookup service from SRPC)
-// PnaclCoordinator::nexe_file_:
-// written by: ld (passed in explicitly through SRPC)
-// read by: sel_ldr (passed in explicitly to command channel)
-//
-
-// LocalTempFile represents a file used as a temporary between stages in
-// translation. It is created in the local temporary file system of the page
-// being processed. The name of the temporary file is a random 32-character
-// hex string. Because both reading and writing are necessary, two I/O objects
-// for the file are opened.
-class LocalTempFile {
- public:
- // Create a LocalTempFile with a random name.
- LocalTempFile(Plugin* plugin,
- pp::FileSystem* file_system);
- // Create a LocalTempFile with a specific filename.
- LocalTempFile(Plugin* plugin,
- pp::FileSystem* file_system,
- const nacl::string& filename);
- ~LocalTempFile();
- // Opens a writeable file IO object and descriptor referring to the file.
- void OpenWrite(const pp::CompletionCallback& cb);
- // Opens a read only file IO object and descriptor referring to the file.
- void OpenRead(const pp::CompletionCallback& cb);
- // Closes the open descriptors.
- void Close(const pp::CompletionCallback& cb);
- // Deletes the temporary file.
- void Delete(const pp::CompletionCallback& cb);
- // Renames the temporary file.
- void Rename(const nacl::string& new_name,
- const pp::CompletionCallback& cb);
- void FinishRename();
-
- // Accessors.
- // The nacl::DescWrapper* for the writeable version of the file.
- nacl::DescWrapper* write_wrapper() { return write_wrapper_.get(); }
- nacl::DescWrapper* release_write_wrapper() {
- return write_wrapper_.release();
- }
- // The nacl::DescWrapper* for the read-only version of the file.
- nacl::DescWrapper* read_wrapper() { return read_wrapper_.get(); }
- nacl::DescWrapper* release_read_wrapper() {
- return read_wrapper_.release();
- }
- // For quota management.
- const nacl::string identifier() const {
- return nacl::string(reinterpret_cast<const char*>(identifier_));
- }
- const pp::FileIO& write_file_io() const { return *write_io_; }
-
- private:
- NACL_DISALLOW_COPY_AND_ASSIGN(LocalTempFile);
-
- void Initialize();
-
- // Gets the POSIX file descriptor for a resource.
- int32_t GetFD(int32_t pp_error,
- const pp::Resource& resource,
- bool is_writable);
- // Called when the writable file IO was opened.
- void WriteFileDidOpen(int32_t pp_error);
- // Called when the readable file IO was opened.
- void ReadFileDidOpen(int32_t pp_error);
- // Completes the close operation after quota update.
- void CloseContinuation(int32_t pp_error);
-
- Plugin* plugin_;
- pp::FileSystem* file_system_;
- const PPB_FileIOTrusted* file_io_trusted_;
- pp::CompletionCallbackFactory<LocalTempFile> callback_factory_;
- nacl::string filename_;
- nacl::scoped_ptr<pp::FileRef> file_ref_;
- // Temporarily holds the previous file ref during a rename operation.
- nacl::scoped_ptr<pp::FileRef> old_ref_;
- // The PPAPI and wrapper state for the writeable file.
- nacl::scoped_ptr<pp::FileIO> write_io_;
- nacl::scoped_ptr<nacl::DescWrapper> write_wrapper_;
- // The PPAPI and wrapper state for the read-only file.
- nacl::scoped_ptr<pp::FileIO> read_io_;
- nacl::scoped_ptr<nacl::DescWrapper> read_wrapper_;
- // The callback invoked when both file I/O objects are created.
- pp::CompletionCallback done_callback_;
- // Random number generator used to create filenames.
- struct NaClDescRng *rng_desc_;
- // An identifier string used for quota request processing. The quota
- // interface needs a string that is unique per sel_ldr instance only, so
- // the identifiers can be reused between runs of the translator, start-ups of
- // the browser, etc.
- uint8_t identifier_[16];
- // A counter to dole out unique identifiers.
- static uint32_t next_identifier;
-};
+class PnaclTranslateThread;
// A thread safe reference counting class Needed for CompletionCallbackFactory
// in PnaclCoordinator.
@@ -284,25 +183,12 @@ class PnaclCoordinator {
// been created, this starts the translation. Translation starts two
// subprocesses, one for llc and one for ld.
void RunTranslate(int32_t pp_error);
- // Starts an individual llc or ld subprocess used for translation.
- NaClSubprocess* StartSubprocess(const nacl::string& url,
- const Manifest* manifest);
- // PnaclCoordinator creates a helper thread to allow translations to be
- // invoked via SRPC. This is the helper thread function for translation.
- static void WINAPI DoTranslateThread(void* arg);
- // Returns true if a the translate thread and subprocesses should stop.
- bool SubprocessesShouldDie();
- // Signal the translate thread and subprocesses that they should stop.
- void SetSubprocessesShouldDie(bool subprocesses_should_die);
- // Signal that Pnacl translation completed normally.
+
void TranslateFinished(int32_t pp_error);
// Keeps track of the pp_error upon entry to TranslateFinished,
// for inspection after cleanup.
int32_t translate_finish_error_;
- // Signal that Pnacl translation failed, from the translation thread only.
- void TranslateFailed(const nacl::string& error_string);
-
// The plugin owning the nexe for which we are doing translation.
Plugin* plugin_;
@@ -312,16 +198,11 @@ class PnaclCoordinator {
pp::CompletionCallbackFactory<PnaclCoordinator,
PnaclRefCount> callback_factory_;
- // True if the translation thread and related subprocesses should exit.
- bool subprocesses_should_die_;
- // Used to guard and publish subprocesses_should_die_.
- struct NaClMutex subprocess_mu_;
-
// Nexe from the final native Link.
nacl::scoped_ptr<nacl::DescWrapper> translated_fd_;
// The helper thread used to do translations via SRPC.
- nacl::scoped_ptr<NaClThread> translate_thread_;
+ nacl::scoped_ptr<PnaclTranslateThread> translate_thread_;
// Translation creates local temporary files.
nacl::scoped_ptr<pp::FileSystem> file_system_;
// The manifest used by resource loading and llc's reverse service to look up
@@ -352,8 +233,6 @@ class PnaclCoordinator {
nacl::scoped_ptr<LocalTempFile> obj_file_;
// Translated nexe file, produced by the linker and consumed by sel_ldr.
nacl::scoped_ptr<LocalTempFile> nexe_file_;
- // Callback to run when tasks are completed or an error has occurred.
- pp::CompletionCallback report_translate_finished_;
// Used to report information when errors (PPAPI or otherwise) are reported.
ErrorInfo error_info_;
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.gypi ('k') | ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698