Commit 35b05b17 authored by rvargas@chromium.org's avatar rvargas@chromium.org

Remove PlatformFile from ppapi

BUG=322664

Review URL: https://codereview.chromium.org/304513007

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