Chromium Code Reviews| Index: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc |
| diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc |
| index cd0df60c6fb182a9115dced221b0c89b74fcaaa8..1756fc58e0b74001e4df59607a2c605911ad9f4e 100644 |
| --- a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc |
| +++ b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc |
| @@ -74,15 +74,29 @@ const bool kWriteable = true; |
| uint32_t LocalTempFile::next_identifier = 0; |
| LocalTempFile::LocalTempFile(Plugin* plugin, |
| + pp::FileSystem* file_system) |
| + : plugin_(plugin), |
| + file_system_(file_system) { |
| + PLUGIN_PRINTF(("LocalTempFile::LocalTempFile (plugin=%p, " |
| + "file_system=%p)\n", |
| + static_cast<void*>(plugin), static_cast<void*>(file_system))); |
| + Initialize(); |
| +} |
| + |
| +LocalTempFile::LocalTempFile(Plugin* plugin, |
| pp::FileSystem* file_system, |
| - PnaclCoordinator* coordinator) |
| + const nacl::string &filename) |
| : plugin_(plugin), |
| file_system_(file_system), |
| - coordinator_(coordinator) { |
| + filename_(nacl::string(kPnaclTempDir) + "/" + filename) { |
| PLUGIN_PRINTF(("LocalTempFile::LocalTempFile (plugin=%p, " |
| - "file_system=%p, coordinator=%p)\n", |
| + "file_system=%p, filename=%s)\n", |
| static_cast<void*>(plugin), static_cast<void*>(file_system), |
| - static_cast<void*>(coordinator))); |
| + filename.c_str())); |
| + Initialize(); |
| +} |
| + |
| +void LocalTempFile::Initialize() { |
| callback_factory_.Initialize(this); |
| rng_desc_ = (struct NaClDescRng *) malloc(sizeof *rng_desc_); |
| CHECK(rng_desc_ != NULL); |
| @@ -160,17 +174,21 @@ void LocalTempFile::WriteFileDidOpen(int32_t pp_error) { |
| filename_ = ""; |
| OpenWrite(done_callback_); |
| } |
| + // Run the client's completion callback. |
| + pp::Core* core = pp::Module::Get()->core(); |
| + if (pp_error != PP_OK) { |
| + core->CallOnMainThread(0, done_callback_, pp_error); |
| + return; |
| + } |
| // Remember the object temporary file descriptor. |
| int32_t fd = GetFD(pp_error, *write_io_, kWriteable); |
| if (fd < 0) { |
| - coordinator_->ReportNonPpapiError("could not open write temp file."); |
| + core->CallOnMainThread(0, done_callback_, pp_error); |
| return; |
| } |
| // The descriptor for a writeable file needs to have quota management. |
| write_wrapper_.reset( |
| plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_)); |
| - // Run the client's completion callback. |
| - pp::Core* core = pp::Module::Get()->core(); |
| core->CallOnMainThread(0, done_callback_, PP_OK); |
| } |
| @@ -187,18 +205,22 @@ void LocalTempFile::OpenRead(const pp::CompletionCallback& cb) { |
| void LocalTempFile::ReadFileDidOpen(int32_t pp_error) { |
| PLUGIN_PRINTF(("LocalTempFile::ReadFileDidOpen (pp_error=%" |
| NACL_PRId32")\n", pp_error)); |
| + // Run the client's completion callback. |
| + pp::Core* core = pp::Module::Get()->core(); |
| + if (pp_error != PP_OK) { |
| + core->CallOnMainThread(0, done_callback_, pp_error); |
| + return; |
| + } |
| // Remember the object temporary file descriptor. |
| int32_t fd = GetFD(pp_error, *read_io_, kReadOnly); |
| if (fd < 0) { |
| - coordinator_->ReportNonPpapiError("could not open read temp file."); |
| + core->CallOnMainThread(0, done_callback_, PP_ERROR_FAILED); |
| return; |
| } |
| read_wrapper_.reset(plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY)); |
| - // Run the client's completion callback. |
| - pp::Core* core = pp::Module::Get()->core(); |
| core->CallOnMainThread(0, done_callback_, PP_OK); |
| } |
| - |
| + |
|
sehr (please use chromium)
2012/02/22 19:30:37
stray character?
jvoung - send to chromium...
2012/02/22 19:45:37
Done.
|
| void LocalTempFile::Close(const pp::CompletionCallback& cb) { |
| PLUGIN_PRINTF(("LocalTempFile::Close\n")); |
| // Close the open DescWrappers and FileIOs. |
| @@ -226,7 +248,7 @@ void LocalTempFile::Rename(const nacl::string& new_name, |
| const pp::CompletionCallback& cb) { |
| PLUGIN_PRINTF(("LocalTempFile::Rename\n")); |
| // Rename the temporary file. |
| - filename_ = new_name; |
| + filename_ = nacl::string(kPnaclTempDir) + "/" + new_name; |
| nacl::scoped_ptr<pp::FileRef> old_ref(file_ref_.release()); |
| file_ref_.reset(new pp::FileRef(*file_system_, new_name.c_str())); |
| old_ref->Rename(*file_ref_, cb); |
| @@ -243,10 +265,12 @@ class ExtensionManifest : public Manifest { |
| virtual ~ExtensionManifest() { } |
| virtual bool GetProgramURL(nacl::string* full_url, |
| + nacl::string* cache_identity, |
| ErrorInfo* error_info, |
| bool* pnacl_translate) const { |
| // Does not contain program urls. |
| UNREFERENCED_PARAMETER(full_url); |
| + UNREFERENCED_PARAMETER(cache_identity); |
| UNREFERENCED_PARAMETER(error_info); |
| UNREFERENCED_PARAMETER(pnacl_translate); |
| PLUGIN_PRINTF(("ExtensionManifest does not contain a program\n")); |
| @@ -274,10 +298,13 @@ class ExtensionManifest : public Manifest { |
| virtual bool ResolveKey(const nacl::string& key, |
| nacl::string* full_url, |
| + nacl::string* cache_identity, |
| ErrorInfo* error_info, |
| bool* pnacl_translate) const { |
| // All of the extension files are native (do not require pnacl translate). |
| *pnacl_translate = false; |
| + // Do not cache these entries. |
| + *cache_identity = ""; |
| // We can only resolve keys in the files/ namespace. |
| const nacl::string kFilesPrefix = "files/"; |
| size_t files_prefix_pos = key.find(kFilesPrefix); |
| @@ -315,13 +342,15 @@ class PnaclLDManifest : public Manifest { |
| virtual ~PnaclLDManifest() { } |
| virtual bool GetProgramURL(nacl::string* full_url, |
| + nacl::string* cache_identity, |
| ErrorInfo* error_info, |
| bool* pnacl_translate) const { |
| - if (nexe_manifest_->GetProgramURL(full_url, error_info, pnacl_translate)) { |
| + if (nexe_manifest_->GetProgramURL(full_url, cache_identity, |
| + error_info, pnacl_translate)) { |
| return true; |
| } |
| - return extension_manifest_->GetProgramURL(full_url, error_info, |
| - pnacl_translate); |
| + return extension_manifest_->GetProgramURL(full_url, cache_identity, |
| + error_info, pnacl_translate); |
| } |
| virtual bool ResolveURL(const nacl::string& relative_url, |
| @@ -342,13 +371,14 @@ class PnaclLDManifest : public Manifest { |
| virtual bool ResolveKey(const nacl::string& key, |
| nacl::string* full_url, |
| + nacl::string* cache_identity, |
| ErrorInfo* error_info, |
| bool* pnacl_translate) const { |
| - if (nexe_manifest_->ResolveKey(key, full_url, |
| + if (nexe_manifest_->ResolveKey(key, full_url, cache_identity, |
| error_info, pnacl_translate)) { |
| return true; |
| } |
| - return extension_manifest_->ResolveKey(key, full_url, |
| + return extension_manifest_->ResolveKey(key, full_url, cache_identity, |
| error_info, pnacl_translate); |
| } |
| @@ -365,11 +395,13 @@ class PnaclLDManifest : public Manifest { |
| PnaclCoordinator* PnaclCoordinator::BitcodeToNative( |
| Plugin* plugin, |
| const nacl::string& pexe_url, |
| + const nacl::string& cache_identity, |
| const pp::CompletionCallback& translate_notify_callback) { |
| PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", |
| static_cast<void*>(plugin), pexe_url.c_str())); |
| PnaclCoordinator* coordinator = |
| - new PnaclCoordinator(plugin, pexe_url, translate_notify_callback); |
| + new PnaclCoordinator(plugin, pexe_url, |
| + cache_identity, translate_notify_callback); |
| PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n", |
| reinterpret_cast<const void*>(coordinator->manifest_.get()))); |
| // Load llc and ld. |
| @@ -419,6 +451,7 @@ int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, |
| PnaclCoordinator::PnaclCoordinator( |
| Plugin* plugin, |
| const nacl::string& pexe_url, |
| + const nacl::string& cache_identity, |
| const pp::CompletionCallback& translate_notify_callback) |
| : plugin_(plugin), |
| translate_notify_callback_(translate_notify_callback), |
| @@ -426,6 +459,7 @@ PnaclCoordinator::PnaclCoordinator( |
| file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)), |
| manifest_(new ExtensionManifest(plugin->url_util())), |
| pexe_url_(pexe_url), |
| + cache_identity_(cache_identity), |
| error_already_reported_(false) { |
| PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", |
| static_cast<void*>(this), static_cast<void*>(plugin))); |
| @@ -530,18 +564,25 @@ void PnaclCoordinator::NexeFileWasClosed(int32_t pp_error) { |
| ReportPpapiError(pp_error); |
| return; |
| } |
| - // TODO(sehr): enable renaming once cache ids are available. |
| // Rename the nexe file to the cache id. |
| - // pp::CompletionCallback cb = |
| - // callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); |
| - // nexe_file_->Rename(new_name, cb); |
| - NexeFileWasRenamed(PP_OK); |
| + if (cache_identity_ != "") { |
| + pp::CompletionCallback cb = |
| + callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasRenamed); |
| + nexe_file_->Rename(cache_identity_, cb); |
| + } else { |
| + // For now tolerate bitcode that is missing a cache identity. |
| + PLUGIN_PRINTF(("PnaclCoordinator::WARNING: missing cache identity," |
| + " not caching.\n")); |
| + NexeFileWasRenamed(PP_OK); |
| + } |
| } |
| void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) { |
| PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%" |
| NACL_PRId32")\n", pp_error)); |
| if (pp_error != PP_OK) { |
| + // TODO(jvoung): Do something if there was a simultaneous/racy rename |
| + // (PP_FILEEXISTS?). |
| ReportPpapiError(pp_error); |
| return; |
| } |
| @@ -612,8 +653,18 @@ void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) { |
| ReportPpapiError(pp_error, "directory creation/check failed."); |
| return; |
| } |
| + // TODO(jvoung): Check if a cached value already exists. |
| + if (cache_identity_ != "") { |
| + nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), |
| + cache_identity_)); |
| + } else { |
| + // For now, tolerate lack of cache identity... |
| + |
| + } |
| + |
| + // TODO move this to CacheOpenDidFail. |
| // Create the object file pair for connecting llc and ld. |
| - obj_file_.reset(new LocalTempFile(plugin_, file_system_.get(), this)); |
| + obj_file_.reset(new LocalTempFile(plugin_, file_system_.get())); |
| pp::CompletionCallback cb = |
| callback_factory_.NewCallback(&PnaclCoordinator::ObjectWriteDidOpen); |
| obj_file_->OpenWrite(cb); |
| @@ -639,7 +690,7 @@ void PnaclCoordinator::ObjectReadDidOpen(int32_t pp_error) { |
| return; |
| } |
| // Create the nexe file for connecting ld and sel_ldr. |
| - nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), this)); |
| + nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get())); |
| pp::CompletionCallback cb = |
| callback_factory_.NewCallback(&PnaclCoordinator::NexeWriteDidOpen); |
| nexe_file_->OpenWrite(cb); |