Commit 5cf25409 authored by teravest@chromium.org's avatar teravest@chromium.org

Pepper: Simplify TempFile in trusted plugin.

This change makes the behavior of internal_handle_ in TempFile easier to reason
about. This change is possible after a large refactoring of PnaclCoordinator
that happened as a result of removing FileDownloader.

BUG=239656
R=bbudge@chromium.org

Review URL: https://codereview.chromium.org/413493002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284766 0039d316-1c4b-4281-b951-d872f2087c98
parent 711e9080
...@@ -338,8 +338,7 @@ void PnaclCoordinator::BitcodeStreamCacheHit(PP_FileHandle handle) { ...@@ -338,8 +338,7 @@ void PnaclCoordinator::BitcodeStreamCacheHit(PP_FileHandle handle) {
BitcodeStreamDidFinish(PP_ERROR_FAILED); BitcodeStreamDidFinish(PP_ERROR_FAILED);
return; return;
} }
*temp_nexe_file_->internal_handle() = handle; temp_nexe_file_.reset(new TempFile(plugin_, handle));
// Open it for reading as the cached nexe file.
NexeReadDidOpen(temp_nexe_file_->Open(false)); NexeReadDidOpen(temp_nexe_file_->Open(false));
} }
...@@ -347,12 +346,10 @@ void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size) { ...@@ -347,12 +346,10 @@ void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size) {
HistogramEnumerateTranslationCache(plugin_->uma_interface(), false); HistogramEnumerateTranslationCache(plugin_->uma_interface(), false);
expected_pexe_size_ = expected_pexe_size; expected_pexe_size_ = expected_pexe_size;
// Open an object file first so the translator can start writing to it
// during streaming translation.
temp_nexe_file_.reset(new TempFile(plugin_));
for (int i = 0; i < split_module_count_; i++) { for (int i = 0; i < split_module_count_; i++) {
nacl::scoped_ptr<TempFile> temp_file(new TempFile(plugin_)); PP_FileHandle obj_handle =
plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance());
nacl::scoped_ptr<TempFile> temp_file(new TempFile(plugin_, obj_handle));
int32_t pp_error = temp_file->Open(true); int32_t pp_error = temp_file->Open(true);
if (pp_error != PP_OK) { if (pp_error != PP_OK) {
ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP, ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP,
...@@ -367,6 +364,9 @@ void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size) { ...@@ -367,6 +364,9 @@ void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size) {
// Open the nexe file for connecting ld and sel_ldr. // Open the nexe file for connecting ld and sel_ldr.
// Start translation when done with this last step of setup! // Start translation when done with this last step of setup!
PP_FileHandle nexe_handle =
plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance());
temp_nexe_file_.reset(new TempFile(plugin_, nexe_handle));
RunTranslate(temp_nexe_file_->Open(true)); RunTranslate(temp_nexe_file_->Open(true));
} }
......
...@@ -18,20 +18,12 @@ ...@@ -18,20 +18,12 @@
namespace plugin { namespace plugin {
TempFile::TempFile(Plugin* plugin) : plugin_(plugin), TempFile::TempFile(Plugin* plugin, PP_FileHandle handle)
internal_handle_(PP_kInvalidFileHandle) { : plugin_(plugin), internal_handle_(handle) { }
}
TempFile::~TempFile() { } TempFile::~TempFile() { }
int32_t TempFile::Open(bool writeable) { int32_t TempFile::Open(bool writeable) {
// TODO(teravest): Clean up this Open() behavior; this is really confusing as
// written.
if (internal_handle_ == PP_kInvalidFileHandle) {
internal_handle_ =
plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance());
}
if (internal_handle_ == PP_kInvalidFileHandle) { if (internal_handle_ == PP_kInvalidFileHandle) {
PLUGIN_PRINTF(("TempFile::Open failed w/ PP_kInvalidFileHandle\n")); PLUGIN_PRINTF(("TempFile::Open failed w/ PP_kInvalidFileHandle\n"));
return PP_ERROR_FAILED; return PP_ERROR_FAILED;
......
...@@ -35,8 +35,7 @@ class Plugin; ...@@ -35,8 +35,7 @@ class Plugin;
// of the file between sessions. // of the file between sessions.
class TempFile { class TempFile {
public: public:
// Create a TempFile. TempFile(Plugin* plugin, PP_FileHandle handle);
explicit TempFile(Plugin* plugin);
~TempFile(); ~TempFile();
// Opens a temporary file object and descriptor wrapper referring to the file. // Opens a temporary file object and descriptor wrapper referring to the file.
...@@ -55,9 +54,6 @@ class TempFile { ...@@ -55,9 +54,6 @@ class TempFile {
// and all wrappers. // and all wrappers.
PP_FileHandle TakeFileHandle(); PP_FileHandle TakeFileHandle();
// Used by GetNexeFd() to set the underlying internal handle.
PP_FileHandle* internal_handle() { return &internal_handle_; }
private: private:
NACL_DISALLOW_COPY_AND_ASSIGN(TempFile); NACL_DISALLOW_COPY_AND_ASSIGN(TempFile);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment