summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppb_file_io_impl.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 15:19:37 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 15:19:37 +0000
commitbbf076f18dbb27fba74de06f4994aa1480690ea3 (patch)
tree6dcabc6d408c997b18f8762fee0fac8470770fb4 /webkit/plugins/ppapi/ppb_file_io_impl.cc
parent081c03452bb7d97b138bed3ccc7cbe0903eae05c (diff)
downloadchromium_src-bbf076f18dbb27fba74de06f4994aa1480690ea3.zip
chromium_src-bbf076f18dbb27fba74de06f4994aa1480690ea3.tar.gz
chromium_src-bbf076f18dbb27fba74de06f4994aa1480690ea3.tar.bz2
Remove webkit::ppapi::Resource.
This makes all resource _impl's derive directly from ppapi::Resource so we can share code better. This means removing PluginInstances and converting them to PP_Instances. This adds a new ResourceHelper static class to help in the conversion of resources to PluginInstances for the _impl classes. Overall the new code is in general slightly worse than the old because using the ResourceHelper is more annoying than just calling instance() on the old webkit::ppapi::Resource object. However, I'm hoping that, because this will allow us to move more code into shared_impl and reduce duplicate logic, it will eventually have a net positive effect. This also adds a ScopedPPResource class that works just like a scoped_refptr. We need this in a few places. Most of the places that used the old ScopedResourceId class could be removed now since resources have PP_Resource IDs generated even when there's no plugin reference (this didn't use to be the case) so we can pass resources as input params to the plugin even when there's no plugin ref, as long as there's a scoped_refptr to the Resource. Review URL: http://codereview.chromium.org/7669055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/ppb_file_io_impl.cc')
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.cc60
1 files changed, 47 insertions, 13 deletions
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc
index 63021fa..faa0870 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc
@@ -24,6 +24,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/quota_file_io.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
using ppapi::PPTimeToTime;
@@ -47,7 +48,7 @@ PPB_FileIO_Impl::CallbackEntry::CallbackEntry(const CallbackEntry& entry)
PPB_FileIO_Impl::CallbackEntry::~CallbackEntry() {
}
-PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance)
+PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance)
: Resource(instance),
ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
file_(base::kInvalidPlatformFileValue),
@@ -80,10 +81,14 @@ int32_t PPB_FileIO_Impl::Open(PP_Resource pp_file_ref,
if (!PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags))
return PP_ERROR_BADARGUMENT;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return false;
+
file_system_type_ = file_ref->GetFileSystemType();
switch (file_system_type_) {
case PP_FILESYSTEMTYPE_EXTERNAL:
- if (!instance()->delegate()->AsyncOpenFile(
+ if (!plugin_delegate->AsyncOpenFile(
file_ref->GetSystemPath(), flags,
callback_factory_.NewCallback(
&PPB_FileIO_Impl::AsyncOpenFileCallback)))
@@ -92,7 +97,7 @@ int32_t PPB_FileIO_Impl::Open(PP_Resource pp_file_ref,
case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
file_system_url_ = file_ref->GetFileSystemURL();
- if (!instance()->delegate()->AsyncOpenFileSystemURL(
+ if (!plugin_delegate->AsyncOpenFileSystemURL(
file_system_url_, flags,
callback_factory_.NewCallback(
&PPB_FileIO_Impl::AsyncOpenFileCallback)))
@@ -118,8 +123,12 @@ int32_t PPB_FileIO_Impl::Query(PP_FileInfo* info,
DCHECK(!info_); // If |info_|, a callback should be pending (caught above).
info_ = info;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
- instance()->delegate()->GetFileThreadMessageLoopProxy(), file_,
+ plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback)))
return PP_ERROR_FAILED;
@@ -134,8 +143,12 @@ int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time,
if (rv != PP_OK)
return rv;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
if (!base::FileUtilProxy::Touch(
- instance()->delegate()->GetFileThreadMessageLoopProxy(),
+ plugin_delegate->GetFileThreadMessageLoopProxy(),
file_, PPTimeToTime(last_access_time),
PPTimeToTime(last_modified_time),
callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback)))
@@ -153,8 +166,12 @@ int32_t PPB_FileIO_Impl::Read(int64_t offset,
if (rv != PP_OK)
return rv;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
if (!base::FileUtilProxy::Read(
- instance()->delegate()->GetFileThreadMessageLoopProxy(),
+ plugin_delegate->GetFileThreadMessageLoopProxy(),
file_, offset, bytes_to_read,
callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadCallback)))
return PP_ERROR_FAILED;
@@ -171,6 +188,10 @@ int32_t PPB_FileIO_Impl::Write(int64_t offset,
if (rv != PP_OK)
return rv;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
if (quota_file_io_.get()) {
if (!quota_file_io_->Write(
offset, buffer, bytes_to_write,
@@ -178,7 +199,7 @@ int32_t PPB_FileIO_Impl::Write(int64_t offset,
return PP_ERROR_FAILED;
} else {
if (!base::FileUtilProxy::Write(
- instance()->delegate()->GetFileThreadMessageLoopProxy(),
+ plugin_delegate->GetFileThreadMessageLoopProxy(),
file_, offset, buffer, bytes_to_write,
callback_factory_.NewCallback(&PPB_FileIO_Impl::WriteCallback)))
return PP_ERROR_FAILED;
@@ -194,6 +215,10 @@ int32_t PPB_FileIO_Impl::SetLength(int64_t length,
if (rv != PP_OK)
return rv;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
if (quota_file_io_.get()) {
if (!quota_file_io_->SetLength(
length,
@@ -201,7 +226,7 @@ int32_t PPB_FileIO_Impl::SetLength(int64_t length,
return PP_ERROR_FAILED;
} else {
if (!base::FileUtilProxy::Truncate(
- instance()->delegate()->GetFileThreadMessageLoopProxy(),
+ plugin_delegate->GetFileThreadMessageLoopProxy(),
file_, length,
callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback)))
return PP_ERROR_FAILED;
@@ -216,8 +241,12 @@ int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) {
if (rv != PP_OK)
return rv;
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
if (!base::FileUtilProxy::Flush(
- instance()->delegate()->GetFileThreadMessageLoopProxy(), file_,
+ plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback)))
return PP_ERROR_FAILED;
@@ -226,9 +255,10 @@ int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) {
}
void PPB_FileIO_Impl::Close() {
- if (file_ != base::kInvalidPlatformFileValue) {
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (file_ != base::kInvalidPlatformFileValue && plugin_delegate) {
base::FileUtilProxy::Close(
- instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, NULL);
+ plugin_delegate->GetFileThreadMessageLoopProxy(), file_, NULL);
file_ = base::kInvalidPlatformFileValue;
quota_file_io_.reset();
}
@@ -313,9 +343,13 @@ void PPB_FileIO_Impl::RegisterCallback(OperationType op,
DCHECK(pending_op_ == OPERATION_NONE ||
(pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op));
+ PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
+ if (!plugin_module)
+ return;
+
CallbackEntry entry;
entry.callback = new TrackedCompletionCallback(
- instance()->module()->GetCallbackTracker(), pp_resource(), callback);
+ plugin_module->GetCallbackTracker(), pp_resource(), callback);
entry.read_buffer = read_buffer;
callbacks_.push(entry);
@@ -358,7 +392,7 @@ void PPB_FileIO_Impl::AsyncOpenFileCallback(
(file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY ||
file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT)) {
quota_file_io_.reset(new QuotaFileIO(
- instance(), file_, file_system_url_, file_system_type_));
+ pp_instance(), file_, file_system_url_, file_system_type_));
}
RunAndRemoveFirstPendingCallback(PlatformFileErrorToPepperError(error_code));