| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h" | 5 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h" |
| 6 | 6 |
| 7 #include "native_client/src/include/portability_io.h" | 7 #include "native_client/src/include/portability_io.h" |
| 8 #include "native_client/src/shared/platform/nacl_check.h" | 8 #include "native_client/src/shared/platform/nacl_check.h" |
| 9 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" | 9 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" |
| 10 | 10 |
| 11 #include "ppapi/cpp/core.h" | 11 #include "ppapi/cpp/core.h" |
| 12 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance.h" |
| 13 #include "ppapi/cpp/module.h" | 13 #include "ppapi/cpp/module.h" |
| 14 #include "ppapi/c/private/pp_file_handle.h" | 14 #include "ppapi/c/private/pp_file_handle.h" |
| 15 | 15 |
| 16 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 16 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 17 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 17 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
| 18 | 18 |
| 19 namespace plugin { | 19 namespace plugin { |
| 20 | 20 |
| 21 TempFile::TempFile(Plugin* plugin, PP_FileHandle handle) | 21 TempFile::TempFile(Plugin* plugin) : plugin_(plugin), |
| 22 : plugin_(plugin), internal_handle_(handle) { } | 22 internal_handle_(PP_kInvalidFileHandle) { |
| 23 } |
| 23 | 24 |
| 24 TempFile::~TempFile() { } | 25 TempFile::~TempFile() { } |
| 25 | 26 |
| 26 int32_t TempFile::Open(bool writeable) { | 27 int32_t TempFile::Open(bool writeable) { |
| 28 // TODO(teravest): Clean up this Open() behavior; this is really confusing as |
| 29 // written. |
| 30 if (internal_handle_ == PP_kInvalidFileHandle) { |
| 31 internal_handle_ = |
| 32 plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance()); |
| 33 } |
| 34 |
| 27 if (internal_handle_ == PP_kInvalidFileHandle) { | 35 if (internal_handle_ == PP_kInvalidFileHandle) { |
| 28 PLUGIN_PRINTF(("TempFile::Open failed w/ PP_kInvalidFileHandle\n")); | 36 PLUGIN_PRINTF(("TempFile::Open failed w/ PP_kInvalidFileHandle\n")); |
| 29 return PP_ERROR_FAILED; | 37 return PP_ERROR_FAILED; |
| 30 } | 38 } |
| 31 | 39 |
| 32 #if NACL_WINDOWS | 40 #if NACL_WINDOWS |
| 33 HANDLE handle = internal_handle_; | 41 HANDLE handle = internal_handle_; |
| 34 | 42 |
| 35 //////// Now try the posix view. | 43 //////// Now try the posix view. |
| 36 int rdwr_flag = writeable ? _O_RDWR : _O_RDONLY; | 44 int rdwr_flag = writeable ? _O_RDWR : _O_RDONLY; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 88 |
| 81 PP_FileHandle TempFile::TakeFileHandle() { | 89 PP_FileHandle TempFile::TakeFileHandle() { |
| 82 PP_FileHandle to_return = internal_handle_; | 90 PP_FileHandle to_return = internal_handle_; |
| 83 internal_handle_ = PP_kInvalidFileHandle; | 91 internal_handle_ = PP_kInvalidFileHandle; |
| 84 read_wrapper_.release(); | 92 read_wrapper_.release(); |
| 85 write_wrapper_.release(); | 93 write_wrapper_.release(); |
| 86 return to_return; | 94 return to_return; |
| 87 } | 95 } |
| 88 | 96 |
| 89 } // namespace plugin | 97 } // namespace plugin |
| OLD | NEW |