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"));
+ if (internal_handle_ == PP_kInvalidFileHandle)
return PP_ERROR_FAILED;
- }
#if NACL_WINDOWS
HANDLE handle = internal_handle_;
int32_t posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(handle),
rdwr_flag | _O_BINARY
| _O_TEMPORARY | _O_SHORT_LIVED );
+
+ // Close the Windows HANDLE if it can't be converted.
if (posix_desc == -1) {
PLUGIN_PRINTF(("TempFile::Open failed to convert HANDLE to posix\n"));
- // Close the Windows HANDLE if it can't be converted.
CloseHandle(handle);
}
int32_t fd = posix_desc;
int32_t fd = internal_handle_;
#endif
- if (fd < 0) {
- PLUGIN_PRINTF(("TempFile::Open failed\n"));
+ if (fd < 0)
return PP_ERROR_FAILED;
- }
// dup the fd to make allow making separate read and write wrappers.
int32_t read_fd = DUP(fd);
- if (read_fd == NACL_NO_FILE_DESC) {
- PLUGIN_PRINTF(("TempFile::Open DUP failed\n"));
+ if (read_fd == NACL_NO_FILE_DESC)
return PP_ERROR_FAILED;
- }
if (writeable) {
write_wrapper_.reset(
}
bool TempFile::Reset() {
- PLUGIN_PRINTF(("TempFile::Reset\n"));
// Use the read_wrapper_ to reset the file pos. The write_wrapper_ is also
// backed by the same file, so it should also reset.
CHECK(read_wrapper_.get() != NULL);