| 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/local_temp_file.h" | 5 #include "ppapi/native_client/src/trusted/plugin/local_temp_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 | 9 |
| 10 #include "ppapi/c/ppb_file_io.h" | 10 #include "ppapi/c/ppb_file_io.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 void LocalTempFile::Initialize() { | 78 void LocalTempFile::Initialize() { |
| 79 callback_factory_.Initialize(this); | 79 callback_factory_.Initialize(this); |
| 80 rng_desc_ = (struct NaClDescRng *) malloc(sizeof *rng_desc_); | 80 rng_desc_ = (struct NaClDescRng *) malloc(sizeof *rng_desc_); |
| 81 CHECK(rng_desc_ != NULL); | 81 CHECK(rng_desc_ != NULL); |
| 82 CHECK(NaClDescRngCtor(rng_desc_)); | 82 CHECK(NaClDescRngCtor(rng_desc_)); |
| 83 file_io_trusted_ = static_cast<const PPB_FileIOTrusted*>( | 83 file_io_trusted_ = static_cast<const PPB_FileIOTrusted*>( |
| 84 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); | 84 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); |
| 85 ++next_identifier; | 85 ++next_identifier; |
| 86 SNPRINTF(reinterpret_cast<char *>(identifier_), sizeof identifier_, | 86 SNPRINTF(reinterpret_cast<char *>(identifier_), sizeof identifier_, |
| 87 "%"NACL_PRIu32, next_identifier); | 87 "%" NACL_PRIu32, next_identifier); |
| 88 } | 88 } |
| 89 | 89 |
| 90 LocalTempFile::~LocalTempFile() { | 90 LocalTempFile::~LocalTempFile() { |
| 91 PLUGIN_PRINTF(("LocalTempFile::~LocalTempFile\n")); | 91 PLUGIN_PRINTF(("LocalTempFile::~LocalTempFile\n")); |
| 92 NaClDescUnref(reinterpret_cast<NaClDesc*>(rng_desc_)); | 92 NaClDescUnref(reinterpret_cast<NaClDesc*>(rng_desc_)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void LocalTempFile::OpenWrite(const pp::CompletionCallback& cb) { | 95 void LocalTempFile::OpenWrite(const pp::CompletionCallback& cb) { |
| 96 done_callback_ = cb; | 96 done_callback_ = cb; |
| 97 // If we don't already have a filename, generate one. | 97 // If we don't already have a filename, generate one. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 109 write_io_->Open(*file_ref_, | 109 write_io_->Open(*file_ref_, |
| 110 PP_FILEOPENFLAG_WRITE | | 110 PP_FILEOPENFLAG_WRITE | |
| 111 PP_FILEOPENFLAG_CREATE | | 111 PP_FILEOPENFLAG_CREATE | |
| 112 PP_FILEOPENFLAG_EXCLUSIVE, | 112 PP_FILEOPENFLAG_EXCLUSIVE, |
| 113 open_write_cb); | 113 open_write_cb); |
| 114 } | 114 } |
| 115 | 115 |
| 116 int32_t LocalTempFile::GetFD(int32_t pp_error, | 116 int32_t LocalTempFile::GetFD(int32_t pp_error, |
| 117 const pp::Resource& resource, | 117 const pp::Resource& resource, |
| 118 bool is_writable) { | 118 bool is_writable) { |
| 119 PLUGIN_PRINTF(("LocalTempFile::GetFD (pp_error=%"NACL_PRId32 | 119 PLUGIN_PRINTF(("LocalTempFile::GetFD (pp_error=%" NACL_PRId32 |
| 120 ", is_writable=%d)\n", pp_error, is_writable)); | 120 ", is_writable=%d)\n", pp_error, is_writable)); |
| 121 if (pp_error != PP_OK) { | 121 if (pp_error != PP_OK) { |
| 122 PLUGIN_PRINTF(("LocalTempFile::GetFD pp_error != PP_OK\n")); | 122 PLUGIN_PRINTF(("LocalTempFile::GetFD pp_error != PP_OK\n")); |
| 123 return -1; | 123 return -1; |
| 124 } | 124 } |
| 125 int32_t file_desc = | 125 int32_t file_desc = |
| 126 file_io_trusted_->GetOSFileDescriptor(resource.pp_resource()); | 126 file_io_trusted_->GetOSFileDescriptor(resource.pp_resource()); |
| 127 #if NACL_WINDOWS | 127 #if NACL_WINDOWS |
| 128 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. | 128 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. |
| 129 int32_t open_flags = ((is_writable ? _O_RDWR : _O_RDONLY) | _O_BINARY); | 129 int32_t open_flags = ((is_writable ? _O_RDWR : _O_RDONLY) | _O_BINARY); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 file_ref_.reset(new pp::FileRef(*file_system_, filename_.c_str())); | 234 file_ref_.reset(new pp::FileRef(*file_system_, filename_.c_str())); |
| 235 old_ref_->Rename(*file_ref_, cb); | 235 old_ref_->Rename(*file_ref_, cb); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void LocalTempFile::FinishRename() { | 238 void LocalTempFile::FinishRename() { |
| 239 // Now we can release the old ref. | 239 // Now we can release the old ref. |
| 240 old_ref_.reset(NULL); | 240 old_ref_.reset(NULL); |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace plugin | 243 } // namespace plugin |
| OLD | NEW |