summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/quota_file_io.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/plugins/ppapi/quota_file_io.cc')
-rw-r--r--webkit/plugins/ppapi/quota_file_io.cc55
1 files changed, 45 insertions, 10 deletions
diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc
index 82fdf9f..63db38e 100644
--- a/webkit/plugins/ppapi/quota_file_io.cc
+++ b/webkit/plugins/ppapi/quota_file_io.cc
@@ -10,6 +10,8 @@
#include "base/message_loop_proxy.h"
#include "base/task.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
+#include "webkit/plugins/ppapi/resource_tracker.h"
using base::PlatformFile;
using base::PlatformFileError;
@@ -90,8 +92,15 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase {
return;
}
DCHECK(buffer_.get());
+
+ PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate();
+ if (!plugin_delegate) {
+ DidFail(base::PLATFORM_FILE_ERROR_FAILED);
+ return;
+ }
+
if (!base::FileUtilProxy::Write(
- quota_io_->instance_->delegate()->GetFileThreadMessageLoopProxy(),
+ plugin_delegate->GetFileThreadMessageLoopProxy(),
quota_io_->file_, offset_, buffer_.get(), bytes_to_write_,
callback_factory_.NewCallback(&WriteOperation::DidFinish))) {
DidFail(base::PLATFORM_FILE_ERROR_FAILED);
@@ -163,8 +172,15 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase {
DidFinish(base::PLATFORM_FILE_OK);
return;
}
+
+ PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate();
+ if (!plugin_delegate) {
+ DidFail(base::PLATFORM_FILE_ERROR_FAILED);
+ return;
+ }
+
if (!base::FileUtilProxy::Truncate(
- quota_io_->instance_->delegate()->GetFileThreadMessageLoopProxy(),
+ plugin_delegate->GetFileThreadMessageLoopProxy(),
quota_io_->file_, length_,
callback_factory_.NewCallback(&SetLengthOperation::DidFinish))) {
DidFail(base::PLATFORM_FILE_ERROR_FAILED);
@@ -193,11 +209,11 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase {
// QuotaFileIO --------------------------------------------------------------
QuotaFileIO::QuotaFileIO(
- PluginInstance* instance,
+ PP_Instance instance,
PlatformFile file,
const GURL& file_url,
PP_FileSystemType type)
- : instance_(instance),
+ : pp_instance_(instance),
file_(file),
file_url_(file_url),
storage_type_(PPFileSystemTypeToQuotaStorageType(type)),
@@ -208,7 +224,6 @@ QuotaFileIO::QuotaFileIO(
max_written_offset_(0),
inflight_operations_(0),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
- DCHECK(instance_);
DCHECK_NE(base::kInvalidPlatformFileValue, file_);
DCHECK_NE(quota::kStorageTypeUnknown, storage_type_);
}
@@ -253,6 +268,13 @@ bool QuotaFileIO::WillSetLength(int64_t length, StatusCallback* callback) {
return RegisterOperationForQuotaChecks(op);
}
+PluginDelegate* QuotaFileIO::GetPluginDelegate() const {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance_);
+ if (instance)
+ return instance->delegate();
+ return NULL;
+}
+
bool QuotaFileIO::RegisterOperationForQuotaChecks(
PendingOperationBase* op_ptr) {
scoped_ptr<PendingOperationBase> op(op_ptr);
@@ -262,10 +284,14 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks(
outstanding_quota_queries_ = 0;
outstanding_errors_ = 0;
+ PluginDelegate* plugin_delegate = GetPluginDelegate();
+ if (!plugin_delegate)
+ return false;
+
// Query the file size.
++outstanding_quota_queries_;
if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
- instance_->delegate()->GetFileThreadMessageLoopProxy(), file_,
+ plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
callback_factory_.NewCallback(
&QuotaFileIO::DidQueryInfoForQuota))) {
// This makes the call fail synchronously; we do not fire the callback
@@ -275,7 +301,7 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks(
// Query the current available space.
++outstanding_quota_queries_;
- instance_->delegate()->QueryAvailableSpace(
+ plugin_delegate->QueryAvailableSpace(
GURL(file_url_.path()).GetOrigin(), storage_type_,
callback_factory_.NewCallback(&QuotaFileIO::DidQueryAvailableSpace));
}
@@ -324,7 +350,9 @@ bool QuotaFileIO::CheckIfExceedsQuota(int64_t new_file_size) const {
void QuotaFileIO::WillUpdate() {
if (inflight_operations_++ == 0) {
- instance_->delegate()->WillUpdateFile(file_url_);
+ PluginDelegate* plugin_delegate = GetPluginDelegate();
+ if (plugin_delegate)
+ plugin_delegate->WillUpdateFile(file_url_);
DCHECK_EQ(0, max_written_offset_);
}
}
@@ -349,7 +377,10 @@ void QuotaFileIO::DidWrite(WriteOperation* op,
DCHECK(pending_operations_.empty());
int64_t growth = max_written_offset_ - cached_file_size_;
growth = growth < 0 ? 0 : growth;
- instance_->delegate()->DidUpdateFile(file_url_, growth);
+
+ PluginDelegate* plugin_delegate = GetPluginDelegate();
+ if (plugin_delegate)
+ plugin_delegate->DidUpdateFile(file_url_, growth);
max_written_offset_ = 0;
}
}
@@ -360,7 +391,11 @@ void QuotaFileIO::DidSetLength(PlatformFileError error, int64_t new_file_size) {
DCHECK(pending_callbacks_.empty());
int64_t delta = (error != base::PLATFORM_FILE_OK) ? 0 :
new_file_size - cached_file_size_;
- instance_->delegate()->DidUpdateFile(file_url_, delta);
+
+
+ PluginDelegate* plugin_delegate = GetPluginDelegate();
+ if (plugin_delegate)
+ plugin_delegate->DidUpdateFile(file_url_, delta);
inflight_operations_ = 0;
}