Chromium Code Reviews| 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 "components/nacl/renderer/plugin/temporary_file.h" | 5 #include "components/nacl/renderer/plugin/temporary_file.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "components/nacl/renderer/plugin/plugin.h" | 9 #include "components/nacl/renderer/plugin/plugin.h" |
| 10 #include "components/nacl/renderer/plugin/utility.h" | 10 #include "components/nacl/renderer/plugin/utility.h" |
| 11 #include "native_client/src/include/portability_io.h" | |
| 12 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" | |
| 13 #include "ppapi/c/private/pp_file_handle.h" | 11 #include "ppapi/c/private/pp_file_handle.h" |
| 14 #include "ppapi/cpp/core.h" | 12 #include "ppapi/cpp/core.h" |
| 15 #include "ppapi/cpp/instance.h" | 13 #include "ppapi/cpp/instance.h" |
| 16 #include "ppapi/cpp/module.h" | 14 #include "ppapi/cpp/module.h" |
| 17 | 15 |
| 18 namespace plugin { | 16 namespace plugin { |
| 19 | 17 |
| 20 TempFile::TempFile(Plugin* plugin, PP_FileHandle handle) | 18 TempFile::TempFile(Plugin* plugin, PP_FileHandle handle) |
| 21 : plugin_(plugin), | 19 : plugin_(plugin), |
| 22 file_handle_(handle) { } | 20 file_handle_(handle) { } |
| 23 | 21 |
| 24 TempFile::~TempFile() { } | 22 TempFile::~TempFile() { } |
| 25 | 23 |
| 26 nacl::DescWrapper* TempFile::MakeDescWrapper(int nacl_file_flags) { | 24 int32_t TempFile::CheckValidity() { |
| 27 base::File file_dup = file_handle_.Duplicate(); | 25 if (!file_handle_.IsValid()) |
| 28 if (!file_dup.IsValid()) | |
| 29 return NULL; | |
| 30 #if defined(OS_WIN) | |
| 31 int fd = _open_osfhandle( | |
| 32 reinterpret_cast<intptr_t>(file_dup.TakePlatformFile()), | |
| 33 _O_RDWR | _O_BINARY | _O_TEMPORARY | _O_SHORT_LIVED); | |
| 34 if (fd < 0) | |
| 35 return NULL; | |
| 36 #else | |
| 37 int fd = file_dup.TakePlatformFile(); | |
| 38 #endif | |
| 39 return plugin_->wrapper_factory()->MakeFileDesc(fd, nacl_file_flags); | |
| 40 } | |
| 41 | |
| 42 int32_t TempFile::Open(bool writeable) { | |
| 43 read_wrapper_.reset(MakeDescWrapper(O_RDONLY)); | |
| 44 if (!read_wrapper_) | |
| 45 return PP_ERROR_FAILED; | 26 return PP_ERROR_FAILED; |
| 46 | |
| 47 if (writeable) { | |
| 48 write_wrapper_.reset(MakeDescWrapper(O_RDWR)); | |
| 49 if (!write_wrapper_) | |
| 50 return PP_ERROR_FAILED; | |
| 51 } | |
| 52 | |
| 53 return PP_OK; | 27 return PP_OK; |
|
bbudge
2016/01/08 21:37:06
nit: you can simplify this a bit by using PP_FromB
Mark Seaborn
2016/01/08 22:02:27
Doesn't that convert to a PP_Bool rather than to a
| |
| 54 } | 28 } |
| 55 | 29 |
| 56 bool TempFile::Reset() { | 30 bool TempFile::Reset() { |
| 57 // file_handle_, read_wrapper_ and write_wrapper_ are all backed by the | 31 // file_handle_, read_wrapper_ and write_wrapper_ are all backed by the |
| 58 // same file handle/descriptor, so resetting the seek position of one | 32 // same file handle/descriptor, so resetting the seek position of one |
| 59 // will reset them all. | 33 // will reset them all. |
| 60 int64_t newpos = file_handle_.Seek(base::File::FROM_BEGIN, 0); | 34 int64_t newpos = file_handle_.Seek(base::File::FROM_BEGIN, 0); |
| 61 return newpos == 0; | 35 return newpos == 0; |
| 62 } | 36 } |
| 63 | 37 |
| 64 int64_t TempFile::GetLength() { | 38 int64_t TempFile::GetLength() { |
| 65 return file_handle_.GetLength(); | 39 return file_handle_.GetLength(); |
| 66 } | 40 } |
| 67 | 41 |
| 68 PP_FileHandle TempFile::TakeFileHandle() { | 42 PP_FileHandle TempFile::TakeFileHandle() { |
| 69 DCHECK(file_handle_.IsValid()); | 43 DCHECK(file_handle_.IsValid()); |
| 70 return file_handle_.TakePlatformFile(); | 44 return file_handle_.TakePlatformFile(); |
| 71 } | 45 } |
| 72 | 46 |
| 73 PP_FileHandle TempFile::GetFileHandle() { | 47 PP_FileHandle TempFile::GetFileHandle() { |
| 74 DCHECK(file_handle_.IsValid()); | 48 DCHECK(file_handle_.IsValid()); |
| 75 return file_handle_.GetPlatformFile(); | 49 return file_handle_.GetPlatformFile(); |
| 76 } | 50 } |
| 77 | 51 |
| 78 } // namespace plugin | 52 } // namespace plugin |
| OLD | NEW |