summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy
diff options
context:
space:
mode:
authorbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 16:47:01 +0000
committerbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 16:47:01 +0000
commit3acf981dd525529668c3e38e9b014b88865a7141 (patch)
treed8a53dd42a90cc00eb04a0714c00a6f3ed5f416b /ppapi/proxy
parent81ab34960a1cbd29db2814211b58c010240d6ba2 (diff)
downloadchromium_src-3acf981dd525529668c3e38e9b014b88865a7141.zip
chromium_src-3acf981dd525529668c3e38e9b014b88865a7141.tar.gz
chromium_src-3acf981dd525529668c3e38e9b014b88865a7141.tar.bz2
Move PPB_FileIO Query and Read implementation from the renderer to the plugin process.
This sends the file descriptor to the plugin side and moves some FileIO implementation from the renderer to the plugin, using that file descriptor. BUG=194304 R=dmichael@chromium.org, sky@chromium.org, teravest@chromium.org Review URL: https://codereview.chromium.org/18063005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r--ppapi/proxy/file_io_resource.cc200
-rw-r--r--ppapi/proxy/file_io_resource.h24
-rw-r--r--ppapi/proxy/ppapi_messages.h6
3 files changed, 152 insertions, 78 deletions
diff --git a/ppapi/proxy/file_io_resource.cc b/ppapi/proxy/file_io_resource.cc
index 7d98356..0f6ad00 100644
--- a/ppapi/proxy/file_io_resource.cc
+++ b/ppapi/proxy/file_io_resource.cc
@@ -5,11 +5,15 @@
#include "ppapi/proxy/file_io_resource.h"
#include "base/bind.h"
+#include "base/files/file_util_proxy.h"
#include "ipc/ipc_message.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/array_writer.h"
+#include "ppapi/shared_impl/file_type_conversion.h"
#include "ppapi/shared_impl/ppapi_globals.h"
+#include "ppapi/shared_impl/proxy_lock.h"
#include "ppapi/shared_impl/resource_tracker.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_file_ref_api.h"
@@ -25,17 +29,24 @@ void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) {
return user_data;
}
+// Dummy close callback allows us to call CloseFileHandle in the destructor.
+void DummyCloseCallback(base::PlatformFileError error_code) {
+}
+
} // namespace
namespace ppapi {
namespace proxy {
FileIOResource::FileIOResource(Connection connection, PP_Instance instance)
- : PluginResource(connection, instance) {
+ : PluginResource(connection, instance),
+ file_handle_(PP_kInvalidFileHandle),
+ file_system_type_(PP_FILESYSTEMTYPE_INVALID) {
SendCreate(RENDERER, PpapiHostMsg_FileIO_Create());
}
FileIOResource::~FileIOResource() {
+ CloseFileHandle();
}
PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() {
@@ -49,6 +60,17 @@ int32_t FileIOResource::Open(PP_Resource file_ref,
if (enter.failed())
return PP_ERROR_BADRESOURCE;
+ PPB_FileRef_API* file_ref_api = enter.object();
+ PP_FileSystemType type = file_ref_api->GetFileSystemType();
+ if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
+ type != PP_FILESYSTEMTYPE_LOCALTEMPORARY &&
+ type != PP_FILESYSTEMTYPE_EXTERNAL &&
+ type != PP_FILESYSTEMTYPE_ISOLATED) {
+ NOTREACHED();
+ return PP_ERROR_FAILED;
+ }
+ file_system_type_ = type;
+
int32_t rv = state_manager_.CheckOperationState(
FileIOStateManager::OPERATION_EXCLUSIVE, false);
if (rv != PP_OK)
@@ -72,10 +94,16 @@ int32_t FileIOResource::Query(PP_FileInfo* info,
if (rv != PP_OK)
return rv;
- Call<PpapiPluginMsg_FileIO_QueryReply>(RENDERER,
- PpapiHostMsg_FileIO_Query(),
- base::Bind(&FileIOResource::OnPluginMsgQueryComplete, this,
- callback, info));
+ if (file_handle_ == base::kInvalidPlatformFileValue)
+ return PP_ERROR_FAILED;
+
+ if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
+ PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()),
+ file_handle_,
+ RunWhileLocked(base::Bind(&FileIOResource::OnQueryComplete, this,
+ callback, info)))) {
+ return PP_ERROR_FAILED;
+ }
state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
return PP_OK_COMPLETIONPENDING;
@@ -110,7 +138,6 @@ int32_t FileIOResource::Read(int64_t offset,
PP_ArrayOutput output_adapter;
output_adapter.GetDataBuffer = &DummyGetDataBuffer;
output_adapter.user_data = buffer;
- state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
return ReadValidated(offset, bytes_to_read, output_adapter, callback);
}
@@ -124,7 +151,6 @@ int32_t FileIOResource::ReadToArray(int64_t offset,
if (rv != PP_OK)
return rv;
- state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
return ReadValidated(offset, max_read_length, *array_output, callback);
}
@@ -181,6 +207,7 @@ int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) {
}
void FileIOResource::Close() {
+ CloseFileHandle();
Post(RENDERER, PpapiHostMsg_FileIO_Close());
}
@@ -192,6 +219,23 @@ int32_t FileIOResource::GetOSFileDescriptor() {
return file_descriptor;
}
+int32_t FileIOResource::RequestOSFileHandle(
+ PP_FileHandle* handle,
+ scoped_refptr<TrackedCallback> callback) {
+ int32_t rv = state_manager_.CheckOperationState(
+ FileIOStateManager::OPERATION_EXCLUSIVE, true);
+ if (rv != PP_OK)
+ return rv;
+
+ Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER,
+ PpapiHostMsg_FileIO_RequestOSFileHandle(),
+ base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this,
+ callback, handle));
+
+ state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
+ return PP_OK_COMPLETIONPENDING;
+}
+
int32_t FileIOResource::WillWrite(int64_t offset,
int32_t bytes_to_write,
scoped_refptr<TrackedCallback> callback) {
@@ -199,6 +243,7 @@ int32_t FileIOResource::WillWrite(int64_t offset,
PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write),
base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
callback));
+
state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
return PP_OK_COMPLETIONPENDING;
}
@@ -209,6 +254,7 @@ int32_t FileIOResource::WillSetLength(int64_t length,
PpapiHostMsg_FileIO_WillSetLength(length),
base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
callback));
+
state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
return PP_OK_COMPLETIONPENDING;
}
@@ -217,28 +263,86 @@ int32_t FileIOResource::ReadValidated(int64_t offset,
int32_t bytes_to_read,
const PP_ArrayOutput& array_output,
scoped_refptr<TrackedCallback> callback) {
- Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER,
- PpapiHostMsg_FileIO_Read(offset, bytes_to_read),
- base::Bind(&FileIOResource::OnPluginMsgReadComplete, this,
- callback, array_output));
+ if (file_handle_ == base::kInvalidPlatformFileValue)
+ return PP_ERROR_FAILED;
+
+ if (!base::FileUtilProxy::Read(
+ PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()),
+ file_handle_,
+ offset,
+ bytes_to_read,
+ RunWhileLocked(base::Bind(&FileIOResource::OnReadComplete, this,
+ callback, array_output)))) {
+ return PP_ERROR_FAILED;
+ }
+
+ state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
return PP_OK_COMPLETIONPENDING;
}
-int32_t FileIOResource::RequestOSFileHandle(
- PP_FileHandle* handle,
- scoped_refptr<TrackedCallback> callback) {
- int32_t rv = state_manager_.CheckOperationState(
- FileIOStateManager::OPERATION_EXCLUSIVE, true);
- if (rv != PP_OK)
- return rv;
+void FileIOResource::CloseFileHandle() {
+ if (file_handle_ != base::kInvalidPlatformFileValue) {
+ base::FileUtilProxy::Close(
+ PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()),
+ file_handle_,
+ base::Bind(&DummyCloseCallback));
+ file_handle_ = base::kInvalidPlatformFileValue;
+ }
+}
- Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER,
- PpapiHostMsg_FileIO_RequestOSFileHandle(),
- base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this,
- callback, handle));
+void FileIOResource::OnQueryComplete(
+ scoped_refptr<TrackedCallback> callback,
+ PP_FileInfo* output_info,
+ base::PlatformFileError error_code,
+ const base::PlatformFileInfo& file_info) {
+ DCHECK(state_manager_.get_pending_operation() ==
+ FileIOStateManager::OPERATION_EXCLUSIVE);
- state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
- return PP_OK_COMPLETIONPENDING;
+ if (!TrackedCallback::IsPending(callback)) {
+ state_manager_.SetOperationFinished();
+ return;
+ }
+
+ int32_t result = ::ppapi::PlatformFileErrorToPepperError(error_code);
+ if (result == PP_OK) {
+ ppapi::PlatformFileInfoToPepperFileInfo(file_info, file_system_type_,
+ output_info);
+ }
+
+ // End this operation now, so the user's callback can execute another FileIO
+ // operation, assuming there are no other pending operations.
+ state_manager_.SetOperationFinished();
+ callback->Run(result);
+}
+
+void FileIOResource::OnReadComplete(
+ scoped_refptr<TrackedCallback> callback,
+ PP_ArrayOutput array_output,
+ base::PlatformFileError error_code,
+ const char* data, int bytes_read) {
+ DCHECK(state_manager_.get_pending_operation() ==
+ FileIOStateManager::OPERATION_READ);
+
+ if (!TrackedCallback::IsPending(callback)) {
+ state_manager_.SetOperationFinished();
+ return;
+ }
+
+ int32_t result = ::ppapi::PlatformFileErrorToPepperError(error_code);
+ if (result == PP_OK) {
+ result = std::max(0, bytes_read);
+ ArrayWriter output;
+ output.set_pp_array_output(array_output);
+ if (output.is_valid())
+ output.StoreArray(data, result);
+ else
+ result = PP_ERROR_FAILED;
+ }
+
+ // End this operation now, so the user's callback can execute another FileIO
+ // operation, assuming there are no other pending operations.
+ state_manager_.SetOperationFinished();
+ callback->Run(result);
}
void FileIOResource::OnPluginMsgGeneralComplete(
@@ -248,7 +352,8 @@ void FileIOResource::OnPluginMsgGeneralComplete(
FileIOStateManager::OPERATION_EXCLUSIVE ||
state_manager_.get_pending_operation() ==
FileIOStateManager::OPERATION_WRITE);
- // End the operation now. The callback may perform another file operation.
+ // End this operation now, so the user's callback can execute another FileIO
+ // operation, assuming there are no other pending operations.
state_manager_.SetOperationFinished();
callback->Run(params.result());
}
@@ -260,47 +365,17 @@ void FileIOResource::OnPluginMsgOpenFileComplete(
FileIOStateManager::OPERATION_EXCLUSIVE);
if (params.result() == PP_OK)
state_manager_.SetOpenSucceed();
- // End the operation now. The callback may perform another file operation.
- state_manager_.SetOperationFinished();
- callback->Run(params.result());
-}
-void FileIOResource::OnPluginMsgQueryComplete(
- scoped_refptr<TrackedCallback> callback,
- PP_FileInfo* output_info,
- const ResourceMessageReplyParams& params,
- const PP_FileInfo& info) {
- DCHECK(state_manager_.get_pending_operation() ==
- FileIOStateManager::OPERATION_EXCLUSIVE);
- *output_info = info;
- // End the operation now. The callback may perform another file operation.
- state_manager_.SetOperationFinished();
- callback->Run(params.result());
-}
-
-void FileIOResource::OnPluginMsgReadComplete(
- scoped_refptr<TrackedCallback> callback,
- PP_ArrayOutput array_output,
- const ResourceMessageReplyParams& params,
- const std::string& data) {
- DCHECK(state_manager_.get_pending_operation() ==
- FileIOStateManager::OPERATION_READ);
-
- // The result code should contain the data size if it's positive.
int32_t result = params.result();
- DCHECK((result < 0 && data.size() == 0) ||
- result == static_cast<int32_t>(data.size()));
-
- ArrayWriter output;
- output.set_pp_array_output(array_output);
- if (output.is_valid())
- output.StoreArray(data.data(), std::max(0, result));
- else
+ IPC::PlatformFileForTransit transit_file;
+ if (result == PP_OK && !params.TakeFileHandleAtIndex(0, &transit_file))
result = PP_ERROR_FAILED;
+ file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file);
- // End the operation now. The callback may perform another file operation.
+ // End this operation now, so the user's callback can execute another FileIO
+ // operation, assuming there are no other pending operations.
state_manager_.SetOperationFinished();
- callback->Run(result);
+ callback->Run(params.result());
}
void FileIOResource::OnPluginMsgRequestOSFileHandleComplete(
@@ -321,7 +396,8 @@ void FileIOResource::OnPluginMsgRequestOSFileHandleComplete(
result = PP_ERROR_FAILED;
*output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file);
- // End the operation now. The callback may perform another file operation.
+ // End this operation now, so the user's callback can execute another FileIO
+ // operation, assuming there are no other pending operations.
state_manager_.SetOperationFinished();
callback->Run(result);
}
diff --git a/ppapi/proxy/file_io_resource.h b/ppapi/proxy/file_io_resource.h
index a2b928d..44eb8fec 100644
--- a/ppapi/proxy/file_io_resource.h
+++ b/ppapi/proxy/file_io_resource.h
@@ -71,26 +71,30 @@ class PPAPI_PROXY_EXPORT FileIOResource
int32_t bytes_to_read,
const PP_ArrayOutput& array_output,
scoped_refptr<TrackedCallback> callback);
+ void CloseFileHandle();
- // Handlers of reply messages. Note that all of them have a callback
- // parameters bound when call to the host.
+ // Reply message handlers for operations that are done in the host.
void OnPluginMsgGeneralComplete(scoped_refptr<TrackedCallback> callback,
const ResourceMessageReplyParams& params);
void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback,
const ResourceMessageReplyParams& params);
- void OnPluginMsgQueryComplete(scoped_refptr<TrackedCallback> callback,
- PP_FileInfo* output_info_,
- const ResourceMessageReplyParams& params,
- const PP_FileInfo& info);
- void OnPluginMsgReadComplete(scoped_refptr<TrackedCallback> callback,
- PP_ArrayOutput array_output,
- const ResourceMessageReplyParams& params,
- const std::string& data);
void OnPluginMsgRequestOSFileHandleComplete(
scoped_refptr<TrackedCallback> callback,
PP_FileHandle* output_handle,
const ResourceMessageReplyParams& params);
+ // Reply message handlers for operations that are done in the plugin.
+ void OnQueryComplete(scoped_refptr<TrackedCallback> callback,
+ PP_FileInfo* output_info,
+ base::PlatformFileError error_code,
+ const base::PlatformFileInfo& file_info);
+ void OnReadComplete(scoped_refptr<TrackedCallback> callback,
+ PP_ArrayOutput array_output,
+ base::PlatformFileError error_code,
+ const char* data, int bytes_read);
+
+ PP_FileHandle file_handle_;
+ PP_FileSystemType file_system_type_;
FileIOStateManager state_manager_;
DISALLOW_COPY_AND_ASSIGN(FileIOResource);
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 68f202d..8cb5576 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -1377,15 +1377,9 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_FileIO_Open,
int32_t /* open_flags */)
IPC_MESSAGE_CONTROL0(PpapiPluginMsg_FileIO_OpenReply)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileIO_Close)
-IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileIO_Query)
-IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileIO_QueryReply, PP_FileInfo /* info */)
IPC_MESSAGE_CONTROL2(PpapiHostMsg_FileIO_Touch,
PP_Time /* last_access_time */,
PP_Time /* last_modified_time */)
-IPC_MESSAGE_CONTROL2(PpapiHostMsg_FileIO_Read,
- int64_t /* offset */,
- int32_t /* bytes_to_read */)
-IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileIO_ReadReply, std::string /* data */)
IPC_MESSAGE_CONTROL2(PpapiHostMsg_FileIO_Write,
int64_t /* offset */,
std::string /* data */)