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) {
BitcodeStreamDidFinish(PP_ERROR_FAILED);
return;
}
*temp_nexe_file_->internal_handle() = handle;
// Open it for reading as the cached nexe file.
temp_nexe_file_.reset(new TempFile(plugin_, handle));
NexeReadDidOpen(temp_nexe_file_->Open(false));
}
......@@ -347,12 +346,10 @@ void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size) {
HistogramEnumerateTranslationCache(plugin_->uma_interface(), false);
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++) {
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);
if (pp_error != PP_OK) {
ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP,
......@@ -367,6 +364,9 @@ void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size) {
// Open the nexe file for connecting ld and sel_ldr.
// 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));
}
......
......@@ -18,20 +18,12 @@
namespace plugin {
TempFile::TempFile(Plugin* plugin) : plugin_(plugin),
internal_handle_(PP_kInvalidFileHandle) {
}
TempFile::TempFile(Plugin* plugin, PP_FileHandle handle)
: plugin_(plugin), internal_handle_(handle) { }
TempFile::~TempFile() { }
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) {
PLUGIN_PRINTF(("TempFile::Open failed w/ PP_kInvalidFileHandle\n"));
return PP_ERROR_FAILED;
......
......@@ -35,8 +35,7 @@ class Plugin;
// of the file between sessions.
class TempFile {
public:
// Create a TempFile.
explicit TempFile(Plugin* plugin);
TempFile(Plugin* plugin, PP_FileHandle handle);
~TempFile();
// Opens a temporary file object and descriptor wrapper referring to the file.
......@@ -55,9 +54,6 @@ class TempFile {
// and all wrappers.
PP_FileHandle TakeFileHandle();
// Used by GetNexeFd() to set the underlying internal handle.
PP_FileHandle* internal_handle() { return &internal_handle_; }
private:
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