diff --git a/ppapi/nacl_irt/ppapi_dispatcher.h b/ppapi/nacl_irt/ppapi_dispatcher.h index 21829db12e7c81..ebbef8207f9bc3 100644 --- a/ppapi/nacl_irt/ppapi_dispatcher.h +++ b/ppapi/nacl_irt/ppapi_dispatcher.h @@ -9,8 +9,8 @@ #include #include +#include "base/files/file.h" #include "base/memory/ref_counted.h" -#include "base/platform_file.h" #include "base/process/process_handle.h" #include "ipc/ipc_listener.h" #include "ipc/ipc_platform_file.h" diff --git a/ppapi/proxy/file_io_resource.cc b/ppapi/proxy/file_io_resource.cc index 0564fdfbb69364..61b1a2037ec465 100644 --- a/ppapi/proxy/file_io_resource.cc +++ b/ppapi/proxy/file_io_resource.cc @@ -39,8 +39,7 @@ void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { } // File thread task to close the file handle. -void DoClose(base::PlatformFile file) { - base::ClosePlatformFile(file); +void DoClose(base::File auto_close_file) { } } // namespace @@ -48,29 +47,25 @@ void DoClose(base::PlatformFile file) { namespace ppapi { namespace proxy { -FileIOResource::QueryOp::QueryOp(scoped_refptr file_handle) - : file_handle_(file_handle) { - DCHECK(file_handle_); +FileIOResource::QueryOp::QueryOp(scoped_refptr file_holder) + : file_holder_(file_holder) { + DCHECK(file_holder_); } FileIOResource::QueryOp::~QueryOp() { } int32_t FileIOResource::QueryOp::DoWork() { - // TODO(rvargas): Convert this code to use base::File. - base::File file(file_handle_->raw_handle()); - bool success = file.GetInfo(&file_info_); - file.TakePlatformFile(); - return success ? PP_OK : PP_ERROR_FAILED; + return file_holder_->file()->GetInfo(&file_info_) ? PP_OK : PP_ERROR_FAILED; } -FileIOResource::ReadOp::ReadOp(scoped_refptr file_handle, +FileIOResource::ReadOp::ReadOp(scoped_refptr file_holder, int64_t offset, int32_t bytes_to_read) - : file_handle_(file_handle), + : file_holder_(file_holder), offset_(offset), bytes_to_read_(bytes_to_read) { - DCHECK(file_handle_); + DCHECK(file_holder_); } FileIOResource::ReadOp::~ReadOp() { @@ -79,16 +74,15 @@ FileIOResource::ReadOp::~ReadOp() { int32_t FileIOResource::ReadOp::DoWork() { DCHECK(!buffer_.get()); buffer_.reset(new char[bytes_to_read_]); - return base::ReadPlatformFile( - file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); + return file_holder_->file()->Read(offset_, buffer_.get(), bytes_to_read_); } -FileIOResource::WriteOp::WriteOp(scoped_refptr file_handle, +FileIOResource::WriteOp::WriteOp(scoped_refptr file_holder, int64_t offset, scoped_ptr buffer, int32_t bytes_to_write, bool append) - : file_handle_(file_handle), + : file_holder_(file_holder), offset_(offset), buffer_(buffer.Pass()), bytes_to_write_(bytes_to_write), @@ -102,11 +96,10 @@ int32_t FileIOResource::WriteOp::DoWork() { // In append mode, we can't call WritePlatformFile, since NaCl doesn't // implement fcntl, causing the function to call pwrite, which is incorrect. if (append_) { - return base::WritePlatformFileAtCurrentPos( - file_handle_->raw_handle(), buffer_.get(), bytes_to_write_); + return file_holder_->file()->WriteAtCurrentPos(buffer_.get(), + bytes_to_write_); } else { - return base::WritePlatformFile( - file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_write_); + return file_holder_->file()->Write(offset_, buffer_.get(), bytes_to_write_); } } @@ -183,7 +176,7 @@ int32_t FileIOResource::Query(PP_FileInfo* info, return rv; if (!info) return PP_ERROR_BADARGUMENT; - if (!FileHandleHolder::IsValid(file_handle_)) + if (!FileHolder::IsValid(file_holder_)) return PP_ERROR_FAILED; state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); @@ -198,11 +191,7 @@ int32_t FileIOResource::Query(PP_FileInfo* info, { // Release the proxy lock while making a potentially slow file call. ProxyAutoUnlock unlock; - // TODO(rvargas): Convert this code to base::File. - base::File file(file_handle_->raw_handle()); - bool success = file.GetInfo(&file_info); - file.TakePlatformFile(); - if (success) + if (file_holder_->file()->GetInfo(&file_info)) result = PP_OK; } if (result == PP_OK) { @@ -217,7 +206,7 @@ int32_t FileIOResource::Query(PP_FileInfo* info, // For the non-blocking case, post a task to the file thread and add a // completion task to write the result. - scoped_refptr query_op(new QueryOp(file_handle_)); + scoped_refptr query_op(new QueryOp(file_holder_)); base::PostTaskAndReplyWithResult( PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE, @@ -282,7 +271,7 @@ int32_t FileIOResource::Write(int64_t offset, return PP_ERROR_FAILED; if (offset < 0 || bytes_to_write < 0) return PP_ERROR_FAILED; - if (!FileHandleHolder::IsValid(file_handle_)) + if (!FileHolder::IsValid(file_holder_)) return PP_ERROR_FAILED; int32_t rv = state_manager_.CheckOperationState( @@ -408,8 +397,8 @@ void FileIOResource::Close() { pp_resource()); } - if (file_handle_) - file_handle_ = NULL; + if (file_holder_) + file_holder_ = NULL; Post(BROWSER, PpapiHostMsg_FileIO_Close( FileGrowth(max_written_offset_, append_mode_write_amount_))); @@ -432,22 +421,22 @@ int32_t FileIOResource::RequestOSFileHandle( return PP_OK_COMPLETIONPENDING; } -FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) - : raw_handle_(file_handle) { +FileIOResource::FileHolder::FileHolder(PP_FileHandle file_handle) + : file_(file_handle) { } // static -bool FileIOResource::FileHandleHolder::IsValid( - const scoped_refptr& handle) { - return handle && (handle->raw_handle() != base::kInvalidPlatformFileValue); +bool FileIOResource::FileHolder::IsValid( + const scoped_refptr& handle) { + return handle && handle->file_.IsValid(); } -FileIOResource::FileHandleHolder::~FileHandleHolder() { - if (raw_handle_ != base::kInvalidPlatformFileValue) { +FileIOResource::FileHolder::~FileHolder() { + if (file_.IsValid()) { base::TaskRunner* file_task_runner = PpapiGlobals::Get()->GetFileTaskRunner(); file_task_runner->PostTask(FROM_HERE, - base::Bind(&DoClose, raw_handle_)); + base::Bind(&DoClose, Passed(&file_))); } } @@ -457,7 +446,7 @@ int32_t FileIOResource::ReadValidated(int64_t offset, scoped_refptr callback) { if (bytes_to_read < 0) return PP_ERROR_FAILED; - if (!FileHandleHolder::IsValid(file_handle_)) + if (!FileHolder::IsValid(file_holder_)) return PP_ERROR_FAILED; state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); @@ -473,8 +462,7 @@ int32_t FileIOResource::ReadValidated(int64_t offset, if (buffer) { // Release the proxy lock while making a potentially slow file call. ProxyAutoUnlock unlock; - result = base::ReadPlatformFile( - file_handle_->raw_handle(), offset, buffer, bytes_to_read); + result = file_holder_->file()->Read(offset, buffer, bytes_to_read); if (result < 0) result = PP_ERROR_FAILED; } @@ -484,7 +472,7 @@ int32_t FileIOResource::ReadValidated(int64_t offset, // For the non-blocking case, post a task to the file thread. scoped_refptr read_op( - new ReadOp(file_handle_, offset, bytes_to_read)); + new ReadOp(file_holder_, offset, bytes_to_read)); base::PostTaskAndReplyWithResult( PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE, @@ -508,11 +496,10 @@ int32_t FileIOResource::WriteValidated( // Release the proxy lock while making a potentially slow file call. ProxyAutoUnlock unlock; if (append) { - result = base::WritePlatformFileAtCurrentPos( - file_handle_->raw_handle(), buffer, bytes_to_write); + result = file_holder_->file()->WriteAtCurrentPos(buffer, + bytes_to_write); } else { - result = base::WritePlatformFile( - file_handle_->raw_handle(), offset, buffer, bytes_to_write); + result = file_holder_->file()->Write(offset, buffer, bytes_to_write); } } if (result < 0) @@ -527,7 +514,7 @@ int32_t FileIOResource::WriteValidated( scoped_ptr copy(new char[bytes_to_write]); memcpy(copy.get(), buffer, bytes_to_write); scoped_refptr write_op( - new WriteOp(file_handle_, offset, copy.Pass(), bytes_to_write, append)); + new WriteOp(file_holder_, offset, copy.Pass(), bytes_to_write, append)); base::PostTaskAndReplyWithResult( PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE, @@ -619,7 +606,7 @@ void FileIOResource::OnRequestWriteQuotaComplete( } else { bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; scoped_refptr write_op(new WriteOp( - file_handle_, offset, buffer.Pass(), bytes_to_write, append)); + file_holder_, offset, buffer.Pass(), bytes_to_write, append)); base::PostTaskAndReplyWithResult( PpapiGlobals::Get()->GetFileTaskRunner(), FROM_HERE, @@ -693,7 +680,7 @@ void FileIOResource::OnPluginMsgOpenFileComplete( IPC::PlatformFileForTransit transit_file; if (params.TakeFileHandleAtIndex(0, &transit_file)) { - file_handle_ = new FileHandleHolder( + file_holder_ = new FileHolder( IPC::PlatformFileForTransitToPlatformFile(transit_file)); } } diff --git a/ppapi/proxy/file_io_resource.h b/ppapi/proxy/file_io_resource.h index 557847f81d1d61..c9e15df01dbaa7 100644 --- a/ppapi/proxy/file_io_resource.h +++ b/ppapi/proxy/file_io_resource.h @@ -69,8 +69,8 @@ class PPAPI_PROXY_EXPORT FileIOResource PP_FileHandle* handle, scoped_refptr callback) OVERRIDE; - // FileHandleHolder is used to guarantee that file operations will have a - // valid FD to operate on, even if they're in a different thread. + // FileHolder is used to guarantee that file operations will have a valid FD + // to operate on, even if they're in a different thread. // If instead we just passed the raw FD, the FD could be closed before the // file operation has a chance to run. It could interact with an invalid FD, // or worse, the FD value could be reused if another file is opened quickly @@ -80,36 +80,37 @@ class PPAPI_PROXY_EXPORT FileIOResource // // Operations that run on a background thread should hold one of these to // ensure they have a valid file descriptor. The file handle is only closed - // when the last reference to the FileHandleHolder is removed, so we are - // guaranteed to operate on the correct file descriptor. It *is* still - // possible that the FileIOResource will be destroyed and "Abort" callbacks - // just before the operation does its task (e.g., Reading). In that case, we - // might for example Read from a file even though the FileIO has been - // destroyed and the plugin's callback got a PP_ERROR_ABORTED result. In the - // case of a write, we could write some data to the file despite the plugin - // receiving a PP_ERROR_ABORTED instead of a successful result. - class FileHandleHolder : public base::RefCountedThreadSafe { + // when the last reference to the FileHolder is removed, so we are guaranteed + // to operate on the correct file descriptor. It *is* still possible that the + // FileIOResource will be destroyed and "Abort" callbacks just before the + // operation does its task (e.g., Reading). In that case, we might for example + // Read from a file even though the FileIO has been destroyed and the plugin's + // callback got a PP_ERROR_ABORTED result. In the case of a write, we could + // write some data to the file despite the plugin receiving a + // PP_ERROR_ABORTED instead of a successful result. + class FileHolder : public base::RefCountedThreadSafe { public: - explicit FileHandleHolder(PP_FileHandle file_handle_); - PP_FileHandle raw_handle() { - return raw_handle_; + explicit FileHolder(PP_FileHandle file_handle); + base::File* file() { + return &file_; } static bool IsValid( - const scoped_refptr& handle); + const scoped_refptr& handle); private: - friend class base::RefCountedThreadSafe; - ~FileHandleHolder(); - PP_FileHandle raw_handle_; + friend class base::RefCountedThreadSafe; + ~FileHolder(); + base::File file_; }; - scoped_refptr file_handle() { - return file_handle_; + + scoped_refptr file_holder() { + return file_holder_; } private: // Class to perform file query operations across multiple threads. class QueryOp : public base::RefCountedThreadSafe { public: - explicit QueryOp(scoped_refptr file_handle); + explicit QueryOp(scoped_refptr file_holder); // Queries the file. Called on the file thread (non-blocking) or the plugin // thread (blocking). This should not be called when we hold the proxy lock. @@ -121,14 +122,14 @@ class PPAPI_PROXY_EXPORT FileIOResource friend class base::RefCountedThreadSafe; ~QueryOp(); - scoped_refptr file_handle_; + scoped_refptr file_holder_; base::File::Info file_info_; }; // Class to perform file read operations across multiple threads. class ReadOp : public base::RefCountedThreadSafe { public: - ReadOp(scoped_refptr file_handle, + ReadOp(scoped_refptr file_holder, int64_t offset, int32_t bytes_to_read); @@ -142,7 +143,7 @@ class PPAPI_PROXY_EXPORT FileIOResource friend class base::RefCountedThreadSafe; ~ReadOp(); - scoped_refptr file_handle_; + scoped_refptr file_holder_; int64_t offset_; int32_t bytes_to_read_; scoped_ptr buffer_; @@ -151,7 +152,7 @@ class PPAPI_PROXY_EXPORT FileIOResource // Class to perform file write operations across multiple threads. class WriteOp : public base::RefCountedThreadSafe { public: - WriteOp(scoped_refptr file_handle, + WriteOp(scoped_refptr file_holder, int64_t offset, scoped_ptr buffer, int32_t bytes_to_write, @@ -165,7 +166,7 @@ class PPAPI_PROXY_EXPORT FileIOResource friend class base::RefCountedThreadSafe; ~WriteOp(); - scoped_refptr file_handle_; + scoped_refptr file_holder_; int64_t offset_; scoped_ptr buffer_; int32_t bytes_to_write_; @@ -213,7 +214,7 @@ class PPAPI_PROXY_EXPORT FileIOResource PP_FileHandle* output_handle, const ResourceMessageReplyParams& params); - scoped_refptr file_handle_; + scoped_refptr file_holder_; PP_FileSystemType file_system_type_; scoped_refptr file_system_resource_; FileIOStateManager state_manager_; diff --git a/ppapi/proxy/file_mapping_resource.cc b/ppapi/proxy/file_mapping_resource.cc index 5b18dbb916b36c..c620c06dd29968 100644 --- a/ppapi/proxy/file_mapping_resource.cc +++ b/ppapi/proxy/file_mapping_resource.cc @@ -41,9 +41,9 @@ int32_t FileMappingResource::Map(PP_Instance /* instance */, return PP_ERROR_BADARGUMENT; FileIOResource* file_io_resource = static_cast(enter.object()); - scoped_refptr file_handle = - file_io_resource->file_handle(); - if (!FileIOResource::FileHandleHolder::IsValid(file_handle)) + scoped_refptr file_holder = + file_io_resource->file_holder(); + if (!FileIOResource::FileHolder::IsValid(file_holder)) return PP_ERROR_FAILED; if (length < 0 || offset < 0 || !base::IsValueInRangeForNumericType(offset)) { @@ -75,7 +75,7 @@ int32_t FileMappingResource::Map(PP_Instance /* instance */, return PP_ERROR_BADARGUMENT; base::Callback map_cb( - base::Bind(&FileMappingResource::DoMapBlocking, file_handle, *address, + base::Bind(&FileMappingResource::DoMapBlocking, file_holder, *address, length, protection, flags, offset)); if (callback->is_blocking()) { // The plugin could release its reference to this instance when we release diff --git a/ppapi/proxy/file_mapping_resource.h b/ppapi/proxy/file_mapping_resource.h index 240da211b513a6..31c49f9d17bd42 100644 --- a/ppapi/proxy/file_mapping_resource.h +++ b/ppapi/proxy/file_mapping_resource.h @@ -57,7 +57,7 @@ class PPAPI_PROXY_EXPORT FileMappingResource // implementation is platform specific. See file_mapping_resource_posix.cc and // file_mapping_resource_win.cc. static MapResult DoMapBlocking( - scoped_refptr handle, + scoped_refptr file_holder, void* address_hint, int64_t length, uint32_t protection, diff --git a/ppapi/proxy/file_mapping_resource_posix.cc b/ppapi/proxy/file_mapping_resource_posix.cc index b1aff777083c0e..24ce546916cc49 100644 --- a/ppapi/proxy/file_mapping_resource_posix.cc +++ b/ppapi/proxy/file_mapping_resource_posix.cc @@ -35,7 +35,7 @@ int32_t ErrnoToPPError(int error_code) { // static FileMappingResource::MapResult FileMappingResource::DoMapBlocking( - scoped_refptr handle, + scoped_refptr file_holder, void* address_hint, int64_t length, uint32_t map_protection, @@ -63,7 +63,7 @@ FileMappingResource::MapResult FileMappingResource::DoMapBlocking( static_cast(length), prot_for_mmap, flags_for_mmap, - handle->raw_handle(), + file_holder->file()->GetPlatformFile(), static_cast(offset)); if (map_result.address != MAP_FAILED) map_result.result = PP_OK; diff --git a/ppapi/proxy/file_mapping_resource_win.cc b/ppapi/proxy/file_mapping_resource_win.cc index 70c3d208198f7f..c5d9353f3d4f03 100644 --- a/ppapi/proxy/file_mapping_resource_win.cc +++ b/ppapi/proxy/file_mapping_resource_win.cc @@ -11,7 +11,7 @@ namespace proxy { // static FileMappingResource::MapResult FileMappingResource::DoMapBlocking( - scoped_refptr handle, + scoped_refptr file_holder, void* address_hint, int64_t length, uint32_t map_protection, diff --git a/ppapi/proxy/ppp_content_decryptor_private_proxy.cc b/ppapi/proxy/ppp_content_decryptor_private_proxy.cc index da0209764baedb..1058a2e92ca72e 100644 --- a/ppapi/proxy/ppp_content_decryptor_private_proxy.cc +++ b/ppapi/proxy/ppp_content_decryptor_private_proxy.cc @@ -4,7 +4,7 @@ #include "ppapi/proxy/ppp_content_decryptor_private_proxy.h" -#include "base/platform_file.h" +#include "base/files/file.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/ppb_core.h" #include "ppapi/proxy/content_decryptor_private_serializer.h" diff --git a/ppapi/proxy/proxy_channel.cc b/ppapi/proxy/proxy_channel.cc index b7f8a826ce3245..c1f48de6b42982 100644 --- a/ppapi/proxy/proxy_channel.cc +++ b/ppapi/proxy/proxy_channel.cc @@ -64,11 +64,7 @@ IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote( // Channel could be closed if the plugin crashes. if (!channel_.get()) { if (should_close_source) { -#if !defined(OS_NACL) - base::ClosePlatformFile(handle); -#else - close(handle); -#endif + base::File file_closer(handle); } return IPC::InvalidPlatformFileForTransit(); } diff --git a/ppapi/proxy/serialized_handle.cc b/ppapi/proxy/serialized_handle.cc index a59b27d7493bac..7d06c763b31c8a 100644 --- a/ppapi/proxy/serialized_handle.cc +++ b/ppapi/proxy/serialized_handle.cc @@ -4,9 +4,9 @@ #include "ppapi/proxy/serialized_handle.h" +#include "base/files/file.h" #include "base/memory/shared_memory.h" #include "base/pickle.h" -#include "base/platform_file.h" #include "build/build_config.h" #include "ipc/ipc_platform_file.h" @@ -81,13 +81,7 @@ void SerializedHandle::Close() { break; case SOCKET: case FILE: - base::PlatformFile file = - IPC::PlatformFileForTransitToPlatformFile(descriptor_); -#if !defined(OS_NACL) - base::ClosePlatformFile(file); -#else - close(file); -#endif + base::File file_closer = IPC::PlatformFileForTransitToFile(descriptor_); break; // No default so the compiler will warn us if a new type is added. } diff --git a/ppapi/shared_impl/file_type_conversion.cc b/ppapi/shared_impl/file_type_conversion.cc index 0b94725cc114d9..8d7eaf3ca4a2e8 100644 --- a/ppapi/shared_impl/file_type_conversion.cc +++ b/ppapi/shared_impl/file_type_conversion.cc @@ -5,7 +5,6 @@ #include "ppapi/shared_impl/file_type_conversion.h" #include "base/logging.h" -#include "base/platform_file.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_file_io.h" #include "ppapi/shared_impl/time_conversion.h" @@ -46,17 +45,17 @@ bool PepperFileOpenFlagsToPlatformFileFlags(int32_t pp_open_flags, bool pp_append = !!(pp_open_flags & PP_FILEOPENFLAG_APPEND); // Pepper allows Touch on any open file, so always set this Windows-only flag. - int flags = base::PLATFORM_FILE_WRITE_ATTRIBUTES; + int flags = base::File::FLAG_WRITE_ATTRIBUTES; if (pp_read) - flags |= base::PLATFORM_FILE_READ; + flags |= base::File::FLAG_READ; if (pp_write) { - flags |= base::PLATFORM_FILE_WRITE; + flags |= base::File::FLAG_WRITE; } if (pp_append) { if (pp_write) return false; - flags |= base::PLATFORM_FILE_APPEND; + flags |= base::File::FLAG_APPEND; } if (pp_truncate && !pp_write) @@ -64,16 +63,16 @@ bool PepperFileOpenFlagsToPlatformFileFlags(int32_t pp_open_flags, if (pp_create) { if (pp_exclusive) { - flags |= base::PLATFORM_FILE_CREATE; + flags |= base::File::FLAG_CREATE; } else if (pp_truncate) { - flags |= base::PLATFORM_FILE_CREATE_ALWAYS; + flags |= base::File::FLAG_CREATE_ALWAYS; } else { - flags |= base::PLATFORM_FILE_OPEN_ALWAYS; + flags |= base::File::FLAG_OPEN_ALWAYS; } } else if (pp_truncate) { - flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; + flags |= base::File::FLAG_OPEN_TRUNCATED; } else { - flags |= base::PLATFORM_FILE_OPEN; + flags |= base::File::FLAG_OPEN; } if (flags_out) diff --git a/ppapi/shared_impl/platform_file.h b/ppapi/shared_impl/platform_file.h index d2313eccabba93..05462c4a91ebaf 100644 --- a/ppapi/shared_impl/platform_file.h +++ b/ppapi/shared_impl/platform_file.h @@ -5,7 +5,7 @@ #ifndef PPAPI_SHARED_IMPL_PLATFORM_FILE_H_ #define PPAPI_SHARED_IMPL_PLATFORM_FILE_H_ -#include "base/platform_file.h" +#include "base/files/file.h" #include "ppapi/c/pp_stdint.h" #include "ppapi/shared_impl/ppapi_shared_export.h" diff --git a/ppapi/shared_impl/var.h b/ppapi/shared_impl/var.h index a8dec33719c2b0..d5a7a558297864 100644 --- a/ppapi/shared_impl/var.h +++ b/ppapi/shared_impl/var.h @@ -10,7 +10,6 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/shared_memory.h" -#include "base/platform_file.h" #include "ppapi/c/pp_var.h" #include "ppapi/shared_impl/host_resource.h" #include "ppapi/shared_impl/ppapi_shared_export.h"