Bug 1068787 - Quota usage not decreased when removing unsuccessfully copied files; r=bent

This commit is contained in:
Jan Varga 2014-10-28 20:06:54 +01:00
Родитель c9f9da3520
Коммит 049c6364b8
5 изменённых файлов: 53 добавлений и 46 удалений

Просмотреть файл

@ -46,7 +46,6 @@
#include "mozilla/dom/quota/FileStreams.h"
#include "mozilla/dom/quota/OriginOrPatternString.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozilla/dom/quota/StoragePrivilege.h"
#include "mozilla/dom/quota/UsageInfo.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/BackgroundUtils.h"
@ -3885,7 +3884,6 @@ protected:
nsCString mOrigin;
nsCString mDatabaseId;
State mState;
StoragePrivilege mStoragePrivilege;
bool mEnforcingQuota;
const bool mDeleting;
bool mBlockedQuotaManager;
@ -8590,14 +8588,14 @@ Cursor::RecvContinue(const CursorRequestParams& aParams)
FileManager::FileManager(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin,
StoragePrivilege aPrivilege,
const nsAString& aDatabaseName)
const nsAString& aDatabaseName,
bool aEnforcingQuota)
: mPersistenceType(aPersistenceType)
, mGroup(aGroup)
, mOrigin(aOrigin)
, mPrivilege(aPrivilege)
, mDatabaseName(aDatabaseName)
, mLastFileId(0)
, mEnforcingQuota(aEnforcingQuota)
, mInvalidated(false)
{ }
@ -10436,7 +10434,6 @@ FactoryOp::FactoryOp(Factory* aFactory,
, mContentParent(Move(aContentParent))
, mCommonParams(aCommonParams)
, mState(State_Initial)
, mStoragePrivilege(mozilla::dom::quota::Content)
, mEnforcingQuota(true)
, mDeleting(aDeleting)
, mBlockedQuotaManager(false)
@ -10735,9 +10732,7 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
}
if (State_Initial == mState) {
QuotaManager::GetInfoForChrome(&mGroup, &mOrigin, &mStoragePrivilege,
nullptr);
MOZ_ASSERT(mStoragePrivilege == mozilla::dom::quota::Chrome);
QuotaManager::GetInfoForChrome(&mGroup, &mOrigin, nullptr, nullptr);
mEnforcingQuota = false;
}
@ -10789,12 +10784,10 @@ FactoryOp::CheckPermission(ContentParent* aContentParent,
if (permission != PermissionRequestBase::kPermissionDenied &&
State_Initial == mState) {
rv = QuotaManager::GetInfoFromPrincipal(principal, &mGroup, &mOrigin,
&mStoragePrivilege, nullptr);
nullptr, nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(mStoragePrivilege != mozilla::dom::quota::Chrome);
}
if (permission == PermissionRequestBase::kPermissionAllowed &&
@ -11326,8 +11319,8 @@ OpenDatabaseOp::DoDatabaseWork()
fileManager = new FileManager(persistenceType,
mGroup,
mOrigin,
mStoragePrivilege,
databaseName);
databaseName,
mEnforcingQuota);
rv = fileManager->Init(fmDirectory, connection);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -12704,7 +12697,7 @@ VersionChangeOp::RunOnIOThread()
if (exists) {
int64_t fileSize;
if (mDeleteDatabaseOp->mStoragePrivilege != Chrome) {
if (mDeleteDatabaseOp->mEnforcingQuota) {
rv = dbFile->GetFileSize(&fileSize);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -12716,7 +12709,7 @@ VersionChangeOp::RunOnIOThread()
return rv;
}
if (mDeleteDatabaseOp->mStoragePrivilege != Chrome) {
if (mDeleteDatabaseOp->mEnforcingQuota) {
quotaManager->DecreaseUsageForOrigin(persistenceType,
mDeleteDatabaseOp->mGroup,
mDeleteDatabaseOp->mOrigin,
@ -12781,7 +12774,7 @@ VersionChangeOp::RunOnIOThread()
uint64_t usage = 0;
if (mDeleteDatabaseOp->mStoragePrivilege != Chrome) {
if (mDeleteDatabaseOp->mEnforcingQuota) {
rv = FileManager::GetUsage(fmDirectory, &usage);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -12793,7 +12786,7 @@ VersionChangeOp::RunOnIOThread()
return rv;
}
if (mDeleteDatabaseOp->mStoragePrivilege != Chrome) {
if (mDeleteDatabaseOp->mEnforcingQuota) {
quotaManager->DecreaseUsageForOrigin(persistenceType,
mDeleteDatabaseOp->mGroup,
mDeleteDatabaseOp->mOrigin,
@ -14425,12 +14418,14 @@ ObjectStoreAddOrPutRequestOp::CopyFileData(nsIInputStream* aInputStream,
}
} while (true);
nsresult rv2 = aOutputStream->Flush();
if (NS_WARN_IF(NS_FAILED(rv2))) {
return NS_SUCCEEDED(rv) ? rv2 : rv;
if (NS_SUCCEEDED(rv)) {
rv = aOutputStream->Flush();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
rv2 = aOutputStream->Close();
nsresult rv2 = aOutputStream->Close();
if (NS_WARN_IF(NS_FAILED(rv2))) {
return NS_SUCCEEDED(rv) ? rv2 : rv;
}
@ -14804,9 +14799,31 @@ ObjectStoreAddOrPutRequestOp::DoDatabaseWork(TransactionBase* aTransaction)
}
if (NS_WARN_IF(NS_FAILED(rv))) {
// Try to remove the file if the copy failed.
if (NS_FAILED(diskFile->Remove(false))) {
NS_WARNING("Failed to remove file after copying failed!");
nsresult rv2;
int64_t fileSize;
if (mFileManager->EnforcingQuota()) {
rv2 = diskFile->GetFileSize(&fileSize);
if (NS_WARN_IF(NS_FAILED(rv2))) {
return rv;
}
}
rv2 = diskFile->Remove(false);
if (NS_WARN_IF(NS_FAILED(rv2))) {
return rv;
}
if (mFileManager->EnforcingQuota()) {
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
quotaManager->DecreaseUsageForOrigin(mFileManager->Type(),
mFileManager->Group(),
mFileManager->Origin(),
fileSize);
}
return rv;
}

Просмотреть файл

@ -9,7 +9,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/StoragePrivilege.h"
#include "nsDataHashtable.h"
#include "nsHashKeys.h"
#include "nsISupportsImpl.h"
@ -29,12 +28,10 @@ class FileManager MOZ_FINAL
friend class FileInfo;
typedef mozilla::dom::quota::PersistenceType PersistenceType;
typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
PersistenceType mPersistenceType;
nsCString mGroup;
nsCString mOrigin;
StoragePrivilege mPrivilege;
nsString mDatabaseName;
nsString mDirectoryPath;
@ -45,6 +42,7 @@ class FileManager MOZ_FINAL
// Protected by IndexedDatabaseManager::FileMutex()
nsDataHashtable<nsUint64HashKey, FileInfo*> mFileInfos;
const bool mEnforcingQuota;
bool mInvalidated;
public:
@ -64,8 +62,8 @@ public:
FileManager(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin,
StoragePrivilege aPrivilege,
const nsAString& aDatabaseName);
const nsAString& aDatabaseName,
bool aEnforcingQuota);
PersistenceType
Type() const
@ -85,18 +83,18 @@ public:
return mOrigin;
}
const StoragePrivilege&
Privilege() const
{
return mPrivilege;
}
const nsAString&
DatabaseName() const
{
return mDatabaseName;
}
bool
EnforcingQuota() const
{
return mEnforcingQuota;
}
bool
Invalidated() const
{

Просмотреть файл

@ -848,7 +848,7 @@ AsyncDeleteFileRunnable::Run()
nsresult rv;
int64_t fileSize;
if (mFileManager->Privilege() != Chrome) {
if (mFileManager->EnforcingQuota()) {
rv = file->GetFileSize(&fileSize);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
}
@ -856,7 +856,7 @@ AsyncDeleteFileRunnable::Run()
rv = file->Remove(false);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
if (mFileManager->Privilege() != Chrome) {
if (mFileManager->EnforcingQuota()) {
QuotaManager* quotaManager = QuotaManager::Get();
NS_ASSERTION(quotaManager, "Shouldn't be null!");

Просмотреть файл

@ -12,7 +12,6 @@
#include "mozilla/dom/indexedDB/IDBCursor.h"
#include "mozilla/dom/indexedDB/IDBTransaction.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/StoragePrivilege.h"
namespace IPC {
@ -24,13 +23,6 @@ struct ParamTraits<mozilla::dom::quota::PersistenceType> :
mozilla::dom::quota::PERSISTENCE_TYPE_INVALID>
{ };
template <>
struct ParamTraits<mozilla::dom::quota::StoragePrivilege> :
public ContiguousEnumSerializer<mozilla::dom::quota::StoragePrivilege,
mozilla::dom::quota::Chrome,
mozilla::dom::quota::Invalid>
{ };
template <>
struct ParamTraits<mozilla::dom::indexedDB::Key>
{

Просмотреть файл

@ -1101,7 +1101,7 @@ QuotaManager::DecreaseUsageForOrigin(PersistenceType aPersistenceType,
const nsACString& aOrigin,
int64_t aSize)
{
AssertIsOnIOThread();
MOZ_ASSERT(!NS_IsMainThread());
MutexAutoLock lock(mQuotaMutex);