Index: webkit/plugins/ppapi/quota_file_io.cc |
diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc |
index 82fdf9f1acdba4ce3439eb7a4f7145334b0d0380..cc06ef39fe1a6ae18021ba2f14bb46d386ece982 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; |
@@ -91,7 +93,7 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { |
} |
DCHECK(buffer_.get()); |
if (!base::FileUtilProxy::Write( |
- quota_io_->instance_->delegate()->GetFileThreadMessageLoopProxy(), |
+ quota_io_->GetPluginDelegate()->GetFileThreadMessageLoopProxy(), |
quota_io_->file_, offset_, buffer_.get(), bytes_to_write_, |
callback_factory_.NewCallback(&WriteOperation::DidFinish))) { |
DidFail(base::PLATFORM_FILE_ERROR_FAILED); |
@@ -164,7 +166,7 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase { |
return; |
} |
if (!base::FileUtilProxy::Truncate( |
- quota_io_->instance_->delegate()->GetFileThreadMessageLoopProxy(), |
+ quota_io_->GetPluginDelegate()->GetFileThreadMessageLoopProxy(), |
quota_io_->file_, length_, |
callback_factory_.NewCallback(&SetLengthOperation::DidFinish))) { |
DidFail(base::PLATFORM_FILE_ERROR_FAILED); |
@@ -193,11 +195,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 +210,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 +254,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); |
@@ -265,7 +273,7 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks( |
// Query the file size. |
++outstanding_quota_queries_; |
if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
- instance_->delegate()->GetFileThreadMessageLoopProxy(), file_, |
+ GetPluginDelegate()->GetFileThreadMessageLoopProxy(), file_, |
callback_factory_.NewCallback( |
&QuotaFileIO::DidQueryInfoForQuota))) { |
// This makes the call fail synchronously; we do not fire the callback |
@@ -275,7 +283,7 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks( |
// Query the current available space. |
++outstanding_quota_queries_; |
- instance_->delegate()->QueryAvailableSpace( |
+ GetPluginDelegate()->QueryAvailableSpace( |
GURL(file_url_.path()).GetOrigin(), storage_type_, |
callback_factory_.NewCallback(&QuotaFileIO::DidQueryAvailableSpace)); |
} |
@@ -324,7 +332,7 @@ bool QuotaFileIO::CheckIfExceedsQuota(int64_t new_file_size) const { |
void QuotaFileIO::WillUpdate() { |
if (inflight_operations_++ == 0) { |
- instance_->delegate()->WillUpdateFile(file_url_); |
+ GetPluginDelegate()->WillUpdateFile(file_url_); |
DCHECK_EQ(0, max_written_offset_); |
} |
} |
@@ -349,7 +357,7 @@ 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); |
+ GetPluginDelegate()->DidUpdateFile(file_url_, growth); |
max_written_offset_ = 0; |
} |
} |
@@ -360,7 +368,7 @@ 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); |
+ GetPluginDelegate()->DidUpdateFile(file_url_, delta); |
inflight_operations_ = 0; |
} |