Bug 984789 - FileHandle: Eliminate nsIFileStorage; r=bent

This commit is contained in:
Jan Varga 2014-05-07 16:33:02 +02:00
parent 6c4d8f4644
commit 69b11a141b
18 changed files with 211 additions and 258 deletions

View File

@ -20,7 +20,6 @@
#include "nsError.h"
#include "nsIDOMFile.h"
#include "nsIFile.h"
#include "nsIFileStorage.h"
#include "nsNetUtil.h"
namespace mozilla {
@ -71,35 +70,10 @@ FileHandle::~FileHandle()
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileHandle, DOMEventTargetHelper,
mFileStorage)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileHandle)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(FileHandle, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(FileHandle, DOMEventTargetHelper)
// static
already_AddRefed<FileHandle>
FileHandle::Create(nsPIDOMWindow* aWindow,
nsIFileStorage* aFileStorage,
nsIFile* aFile)
bool
FileHandle::IsShuttingDown()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
nsRefPtr<FileHandle> newFileHandle = new FileHandle(aWindow);
newFileHandle->mFileStorage = aFileStorage;
nsresult rv = aFile->GetLeafName(newFileHandle->mName);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
newFileHandle->mFile = aFile;
newFileHandle->mFileName = newFileHandle->mName;
return newFileHandle.forget();
return FileService::IsShuttingDown();
}
// virtual
@ -149,7 +123,7 @@ FileHandle::Open(FileMode aMode, ErrorResult& aError)
{
MOZ_ASSERT(NS_IsMainThread());
if (FileService::IsShuttingDown() || mFileStorage->IsShuttingDown()) {
if (IsShuttingDown()) {
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
return nullptr;
}

View File

@ -12,12 +12,11 @@
#include "mozilla/dom/FileModeBinding.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsString.h"
class nsIDOMFile;
class nsIFile;
class nsIFileStorage;
class nsIOfflineStorage;
class nsPIDOMWindow;
namespace mozilla {
@ -39,7 +38,8 @@ class FileInfo;
/**
* This class provides a default FileHandle implementation, but it can be also
* subclassed. The subclass can override implementation of GetFileId,
* GetFileInfo, CreateStream and CreateFileObject.
* GetFileInfo, IsShuttingDown, IsInvalid, CreateStream, SetThreadLocals,
* UnsetThreadLocals and CreateFileObject.
* (for example IDBFileHandle provides IndexedDB specific implementation).
*/
class FileHandle : public DOMEventTargetHelper
@ -50,15 +50,6 @@ class FileHandle : public DOMEventTargetHelper
friend class FileHelper;
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper)
static already_AddRefed<FileHandle>
Create(nsPIDOMWindow* aWindow,
nsIFileStorage* aFileStorage,
nsIFile* aFile);
const nsAString&
Name() const
{
@ -83,9 +74,33 @@ public:
return nullptr;
}
virtual bool
IsShuttingDown();
virtual bool
IsInvalid()
{
return false;
}
// A temporary method that will be removed along with nsIOfflineStorage
// interface.
virtual nsIOfflineStorage*
Storage() = 0;
virtual already_AddRefed<nsISupports>
CreateStream(nsIFile* aFile, bool aReadOnly);
virtual void
SetThreadLocals()
{
}
virtual void
UnsetThreadLocals()
{
}
virtual already_AddRefed<nsIDOMFile>
CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize);
@ -128,12 +143,12 @@ protected:
virtual ~FileHandle();
nsCOMPtr<nsIFileStorage> mFileStorage;
nsString mName;
nsString mType;
nsCOMPtr<nsIFile> mFile;
nsCString mStorageId;
nsString mFileName;
};

View File

@ -12,9 +12,9 @@
#include "js/Value.h"
#include "LockedFile.h"
#include "MainThreadUtils.h"
#include "mozilla/Assertions.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsIFileStorage.h"
#include "nsIRequest.h"
namespace mozilla {
@ -28,7 +28,7 @@ LockedFile* gCurrentLockedFile = nullptr;
FileHelper::FileHelper(LockedFile* aLockedFile,
FileRequest* aFileRequest)
: mFileStorage(aLockedFile->mFileHandle->mFileStorage),
: mFileHandle(aLockedFile->mFileHandle),
mLockedFile(aLockedFile),
mFileRequest(aFileRequest),
mResultCode(NS_OK),
@ -39,8 +39,8 @@ FileHelper::FileHelper(LockedFile* aLockedFile,
FileHelper::~FileHelper()
{
NS_ASSERTION(!mFileStorage && !mLockedFile && !mFileRequest && !mListener &&
!mRequest, "Should have cleared this!");
MOZ_ASSERT(!mFileHandle && !mLockedFile && !mFileRequest && !mListener &&
!mRequest, "Should have cleared this!");
}
NS_IMPL_ISUPPORTS(FileHelper, nsIRequestObserver)
@ -169,7 +169,7 @@ FileHelper::ReleaseObjects()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
mFileStorage = nullptr;
mFileHandle = nullptr;
mLockedFile = nullptr;
mFileRequest = nullptr;
mListener = nullptr;
@ -212,8 +212,8 @@ FileHelper::Finish()
ReleaseObjects();
NS_ASSERTION(!(mFileStorage || mLockedFile || mFileRequest || mListener ||
mRequest), "Subclass didn't call FileHelper::ReleaseObjects!");
MOZ_ASSERT(!(mFileHandle || mLockedFile || mFileRequest || mListener ||
mRequest), "Subclass didn't call FileHelper::ReleaseObjects!");
}

View File

@ -12,12 +12,11 @@
#include "nsCOMPtr.h"
#include "nsIRequestObserver.h"
class nsIFileStorage;
namespace mozilla {
namespace dom {
class FileHelper;
class FileHandle;
class FileRequest;
class FileOutputStreamWrapper;
class LockedFile;
@ -84,7 +83,7 @@ protected:
void
Finish();
nsCOMPtr<nsIFileStorage> mFileStorage;
nsRefPtr<FileHandle> mFileHandle;
nsRefPtr<LockedFile> mLockedFile;
nsRefPtr<FileRequest> mFileRequest;

View File

@ -9,10 +9,11 @@
#include "FileHandle.h"
#include "LockedFile.h"
#include "MainThreadUtils.h"
#include "mozilla/Assertions.h"
#include "nsError.h"
#include "nsIEventTarget.h"
#include "nsIFileStorage.h"
#include "nsIObserverService.h"
#include "nsIOfflineStorage.h"
#include "nsNetCID.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
@ -55,7 +56,7 @@ FileService::Cleanup()
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsIThread* thread = NS_GetCurrentThread();
while (mFileStorageInfos.Count()) {
while (mStorageInfos.Count()) {
if (!NS_ProcessNextEvent(thread)) {
NS_ERROR("Failed to process next event!");
break;
@ -152,64 +153,64 @@ FileService::Enqueue(LockedFile* aLockedFile, FileHelper* aFileHelper)
FileHandle* fileHandle = aLockedFile->mFileHandle;
if (fileHandle->mFileStorage->IsInvalidated()) {
if (fileHandle->IsInvalid()) {
return NS_ERROR_NOT_AVAILABLE;
}
const nsACString& storageId = fileHandle->mFileStorage->Id();
const nsACString& storageId = fileHandle->mStorageId;
const nsAString& fileName = fileHandle->mFileName;
bool modeIsWrite = aLockedFile->mMode == FileMode::Readwrite;
FileStorageInfo* fileStorageInfo;
if (!mFileStorageInfos.Get(storageId, &fileStorageInfo)) {
nsAutoPtr<FileStorageInfo> newFileStorageInfo(new FileStorageInfo());
StorageInfo* storageInfo;
if (!mStorageInfos.Get(storageId, &storageInfo)) {
nsAutoPtr<StorageInfo> newStorageInfo(new StorageInfo());
mFileStorageInfos.Put(storageId, newFileStorageInfo);
mStorageInfos.Put(storageId, newStorageInfo);
fileStorageInfo = newFileStorageInfo.forget();
storageInfo = newStorageInfo.forget();
}
LockedFileQueue* existingLockedFileQueue =
fileStorageInfo->GetLockedFileQueue(aLockedFile);
storageInfo->GetLockedFileQueue(aLockedFile);
if (existingLockedFileQueue) {
existingLockedFileQueue->Enqueue(aFileHelper);
return NS_OK;
}
bool lockedForReading = fileStorageInfo->IsFileLockedForReading(fileName);
bool lockedForWriting = fileStorageInfo->IsFileLockedForWriting(fileName);
bool lockedForReading = storageInfo->IsFileLockedForReading(fileName);
bool lockedForWriting = storageInfo->IsFileLockedForWriting(fileName);
if (modeIsWrite) {
if (!lockedForWriting) {
fileStorageInfo->LockFileForWriting(fileName);
storageInfo->LockFileForWriting(fileName);
}
}
else {
if (!lockedForReading) {
fileStorageInfo->LockFileForReading(fileName);
storageInfo->LockFileForReading(fileName);
}
}
if (lockedForWriting || (lockedForReading && modeIsWrite)) {
fileStorageInfo->CreateDelayedEnqueueInfo(aLockedFile, aFileHelper);
storageInfo->CreateDelayedEnqueueInfo(aLockedFile, aFileHelper);
}
else {
LockedFileQueue* lockedFileQueue =
fileStorageInfo->CreateLockedFileQueue(aLockedFile);
storageInfo->CreateLockedFileQueue(aLockedFile);
if (aFileHelper) {
// Enqueue() will queue the file helper if there's already something
// running. That can't fail, so no need to eventually remove
// fileStorageInfo from the hash table.
// storageInfo from the hash table.
//
// If the file helper is free to run then AsyncRun() is called on the
// file helper. AsyncRun() is responsible for calling all necessary
// callbacks when something fails. We're propagating the error here,
// however there's no need to eventually remove fileStorageInfo from
// however there's no need to eventually remove storageInfo from
// the hash table. Code behind AsyncRun() will take care of it. The last
// item in the code path is NotifyLockedFileCompleted() which removes
// fileStorageInfo from the hash table if there are no locked files for
// storageInfo from the hash table if there are no locked files for
// the file storage.
nsresult rv = lockedFileQueue->Enqueue(aFileHelper);
NS_ENSURE_SUCCESS(rv, rv);
@ -226,18 +227,18 @@ FileService::NotifyLockedFileCompleted(LockedFile* aLockedFile)
NS_ASSERTION(aLockedFile, "Null pointer!");
FileHandle* fileHandle = aLockedFile->mFileHandle;
const nsACString& storageId = fileHandle->mFileStorage->Id();
const nsACString& storageId = fileHandle->mStorageId;
FileStorageInfo* fileStorageInfo;
if (!mFileStorageInfos.Get(storageId, &fileStorageInfo)) {
StorageInfo* storageInfo;
if (!mStorageInfos.Get(storageId, &storageInfo)) {
NS_ERROR("We don't know anyting about this locked file?!");
return;
}
fileStorageInfo->RemoveLockedFileQueue(aLockedFile);
storageInfo->RemoveLockedFileQueue(aLockedFile);
if (!fileStorageInfo->HasRunningLockedFiles()) {
mFileStorageInfos.Remove(storageId);
if (!storageInfo->HasRunningLockedFiles()) {
mStorageInfos.Remove(storageId);
// See if we need to fire any complete callbacks.
uint32_t index = 0;
@ -254,7 +255,7 @@ FileService::NotifyLockedFileCompleted(LockedFile* aLockedFile)
void
FileService::WaitForStoragesToComplete(
nsTArray<nsCOMPtr<nsIFileStorage> >& aStorages,
nsTArray<nsCOMPtr<nsIOfflineStorage> >& aStorages,
nsIRunnable* aCallback)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@ -271,19 +272,18 @@ FileService::WaitForStoragesToComplete(
}
void
FileService::AbortLockedFilesForStorage(nsIFileStorage* aFileStorage)
FileService::AbortLockedFilesForStorage(nsIOfflineStorage* aStorage)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aFileStorage, "Null pointer!");
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(aStorage, "Null pointer!");
FileStorageInfo* fileStorageInfo;
if (!mFileStorageInfos.Get(aFileStorage->Id(), &fileStorageInfo)) {
StorageInfo* storageInfo;
if (!mStorageInfos.Get(aStorage->Id(), &storageInfo)) {
return;
}
nsAutoTArray<nsRefPtr<LockedFile>, 10> lockedFiles;
fileStorageInfo->CollectRunningAndDelayedLockedFiles(aFileStorage,
lockedFiles);
storageInfo->CollectRunningAndDelayedLockedFiles(aStorage, lockedFiles);
for (uint32_t index = 0; index < lockedFiles.Length(); index++) {
ErrorResult ignored;
@ -292,17 +292,17 @@ FileService::AbortLockedFilesForStorage(nsIFileStorage* aFileStorage)
}
bool
FileService::HasLockedFilesForStorage(nsIFileStorage* aFileStorage)
FileService::HasLockedFilesForStorage(nsIOfflineStorage* aStorage)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aFileStorage, "Null pointer!");
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
MOZ_ASSERT(aStorage, "Null pointer!");
FileStorageInfo* fileStorageInfo;
if (!mFileStorageInfos.Get(aFileStorage->Id(), &fileStorageInfo)) {
StorageInfo* storageInfo;
if (!mStorageInfos.Get(aStorage->Id(), &storageInfo)) {
return false;
}
return fileStorageInfo->HasRunningLockedFiles(aFileStorage);
return storageInfo->HasRunningLockedFiles(aStorage);
}
NS_IMPL_ISUPPORTS(FileService, nsIObserver)
@ -325,7 +325,7 @@ FileService::MaybeFireCallback(StoragesCompleteCallback& aCallback)
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
for (uint32_t index = 0; index < aCallback.mStorages.Length(); index++) {
if (mFileStorageInfos.Get(aCallback.mStorages[index]->Id(), nullptr)) {
if (mStorageInfos.Get(aCallback.mStorages[index]->Id(), nullptr)) {
return false;
}
}
@ -406,7 +406,7 @@ FileService::DelayedEnqueueInfo::~DelayedEnqueueInfo()
}
FileService::LockedFileQueue*
FileService::FileStorageInfo::CreateLockedFileQueue(LockedFile* aLockedFile)
FileService::StorageInfo::CreateLockedFileQueue(LockedFile* aLockedFile)
{
nsRefPtr<LockedFileQueue>* lockedFileQueue =
mLockedFileQueues.AppendElement();
@ -415,7 +415,7 @@ FileService::FileStorageInfo::CreateLockedFileQueue(LockedFile* aLockedFile)
}
FileService::LockedFileQueue*
FileService::FileStorageInfo::GetLockedFileQueue(LockedFile* aLockedFile)
FileService::StorageInfo::GetLockedFileQueue(LockedFile* aLockedFile)
{
uint32_t count = mLockedFileQueues.Length();
for (uint32_t index = 0; index < count; index++) {
@ -428,7 +428,7 @@ FileService::FileStorageInfo::GetLockedFileQueue(LockedFile* aLockedFile)
}
void
FileService::FileStorageInfo::RemoveLockedFileQueue(LockedFile* aLockedFile)
FileService::StorageInfo::RemoveLockedFileQueue(LockedFile* aLockedFile)
{
for (uint32_t index = 0; index < mDelayedEnqueueInfos.Length(); index++) {
if (mDelayedEnqueueInfos[index].mLockedFile == aLockedFile) {
@ -489,12 +489,11 @@ FileService::FileStorageInfo::RemoveLockedFileQueue(LockedFile* aLockedFile)
}
bool
FileService::FileStorageInfo::HasRunningLockedFiles(
nsIFileStorage* aFileStorage)
FileService::StorageInfo::HasRunningLockedFiles(nsIOfflineStorage* aStorage)
{
for (uint32_t index = 0; index < mLockedFileQueues.Length(); index++) {
LockedFile* lockedFile = mLockedFileQueues[index]->mLockedFile;
if (lockedFile->mFileHandle->mFileStorage == aFileStorage) {
if (lockedFile->mFileHandle->Storage() == aStorage) {
return true;
}
}
@ -502,8 +501,8 @@ FileService::FileStorageInfo::HasRunningLockedFiles(
}
FileService::DelayedEnqueueInfo*
FileService::FileStorageInfo::CreateDelayedEnqueueInfo(LockedFile* aLockedFile,
FileHelper* aFileHelper)
FileService::StorageInfo::CreateDelayedEnqueueInfo(LockedFile* aLockedFile,
FileHelper* aFileHelper)
{
DelayedEnqueueInfo* info = mDelayedEnqueueInfos.AppendElement();
info->mLockedFile = aLockedFile;
@ -512,20 +511,20 @@ FileService::FileStorageInfo::CreateDelayedEnqueueInfo(LockedFile* aLockedFile,
}
void
FileService::FileStorageInfo::CollectRunningAndDelayedLockedFiles(
nsIFileStorage* aFileStorage,
FileService::StorageInfo::CollectRunningAndDelayedLockedFiles(
nsIOfflineStorage* aStorage,
nsTArray<nsRefPtr<LockedFile> >& aLockedFiles)
{
for (uint32_t index = 0; index < mLockedFileQueues.Length(); index++) {
LockedFile* lockedFile = mLockedFileQueues[index]->mLockedFile;
if (lockedFile->mFileHandle->mFileStorage == aFileStorage) {
if (lockedFile->mFileHandle->Storage() == aStorage) {
aLockedFiles.AppendElement(lockedFile);
}
}
for (uint32_t index = 0; index < mDelayedEnqueueInfos.Length(); index++) {
LockedFile* lockedFile = mDelayedEnqueueInfos[index].mLockedFile;
if (lockedFile->mFileHandle->mFileStorage == aFileStorage) {
if (lockedFile->mFileHandle->Storage() == aStorage) {
aLockedFiles.AppendElement(lockedFile);
}
}

View File

@ -20,7 +20,7 @@
class nsAString;
class nsIEventTarget;
class nsIFileStorage;
class nsIOfflineStorage;
class nsIRunnable;
namespace mozilla {
@ -56,14 +56,14 @@ public:
NotifyLockedFileCompleted(LockedFile* aLockedFile);
void
WaitForStoragesToComplete(nsTArray<nsCOMPtr<nsIFileStorage> >& aStorages,
WaitForStoragesToComplete(nsTArray<nsCOMPtr<nsIOfflineStorage> >& aStorages,
nsIRunnable* aCallback);
void
AbortLockedFilesForStorage(nsIFileStorage* aFileStorage);
AbortLockedFilesForStorage(nsIOfflineStorage* aStorage);
bool
HasLockedFilesForStorage(nsIFileStorage* aFileStorage);
HasLockedFilesForStorage(nsIOfflineStorage* aStorage);
nsIEventTarget*
StreamTransportTarget()
@ -113,7 +113,7 @@ private:
nsRefPtr<FileHelper> mFileHelper;
};
class FileStorageInfo
class StorageInfo
{
friend class FileService;
@ -134,14 +134,14 @@ private:
}
inline bool
HasRunningLockedFiles(nsIFileStorage* aFileStorage);
HasRunningLockedFiles(nsIOfflineStorage* aStorage);
inline DelayedEnqueueInfo*
CreateDelayedEnqueueInfo(LockedFile* aLockedFile, FileHelper* aFileHelper);
inline void
CollectRunningAndDelayedLockedFiles(
nsIFileStorage* aFileStorage,
nsIOfflineStorage* aStorage,
nsTArray<nsRefPtr<LockedFile> >& aLockedFiles);
void
@ -169,7 +169,7 @@ private:
}
private:
FileStorageInfo()
StorageInfo()
{
}
@ -181,7 +181,7 @@ private:
struct StoragesCompleteCallback
{
nsTArray<nsCOMPtr<nsIFileStorage> > mStorages;
nsTArray<nsCOMPtr<nsIOfflineStorage> > mStorages;
nsCOMPtr<nsIRunnable> mCallback;
};
@ -198,7 +198,7 @@ private:
MaybeFireCallback(StoragesCompleteCallback& aCallback);
nsCOMPtr<nsIEventTarget> mStreamTransportTarget;
nsClassHashtable<nsCStringHashKey, FileStorageInfo> mFileStorageInfos;
nsClassHashtable<nsCStringHashKey, StorageInfo> mStorageInfos;
nsTArray<StoragesCompleteCallback> mCompleteCallbacks;
};

View File

@ -6,12 +6,12 @@
#include "FileStreamWrappers.h"
#include "FileHandle.h"
#include "FileHelper.h"
#include "MainThreadUtils.h"
#include "mozilla/Attributes.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsIFileStorage.h"
#include "nsIRunnable.h"
#include "nsISeekableStream.h"
#include "nsThreadUtils.h"
@ -252,7 +252,7 @@ FileOutputStreamWrapper::Close()
if (!mFirstTime) {
NS_ASSERTION(PR_GetCurrentThread() == mWriteThread,
"Unsetting thread locals on wrong thread!");
mFileHelper->mFileStorage->UnsetThreadLocals();
mFileHelper->mFileHandle->UnsetThreadLocals();
}
if (mFlags & NOTIFY_CLOSE) {
@ -283,7 +283,7 @@ FileOutputStreamWrapper::Write(const char* aBuf, uint32_t aCount,
#ifdef DEBUG
mWriteThread = PR_GetCurrentThread();
#endif
mFileHelper->mFileStorage->SetThreadLocals();
mFileHelper->mFileHandle->SetThreadLocals();
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mOutputStream);
if (seekable) {

View File

@ -24,7 +24,6 @@
#include "nsIDOMEvent.h"
#include "nsIDOMFile.h"
#include "nsIEventTarget.h"
#include "nsIFileStorage.h"
#include "nsISeekableStream.h"
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h"
@ -316,8 +315,7 @@ LockedFile::CreateParallelStream(nsISupports** aStream)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsIFileStorage* fileStorage = mFileHandle->mFileStorage;
if (fileStorage->IsInvalidated()) {
if (mFileHandle->IsInvalid()) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -336,8 +334,7 @@ LockedFile::GetOrCreateStream(nsISupports** aStream)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsIFileStorage* fileStorage = mFileHandle->mFileStorage;
if (fileStorage->IsInvalidated()) {
if (mFileHandle->IsInvalid()) {
return NS_ERROR_NOT_AVAILABLE;
}
@ -853,8 +850,7 @@ FinishHelper::Run()
return NS_OK;
}
nsIFileStorage* fileStorage = mLockedFile->mFileHandle->mFileStorage;
if (fileStorage->IsInvalidated()) {
if (mLockedFile->mFileHandle->IsInvalid()) {
mAborted = true;
}

View File

@ -6,10 +6,6 @@
TEST_DIRS += ['test']
EXPORTS += [
'nsIFileStorage.h',
]
EXPORTS.mozilla.dom += [
'File.h',
'FileHandle.h',

View File

@ -1,59 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsIFileStorage_h__
#define nsIFileStorage_h__
#include "nsISupports.h"
#define NS_FILESTORAGE_IID \
{0x6278f453, 0xd557, 0x4a55, \
{ 0x99, 0x3e, 0xf4, 0x69, 0xe2, 0xa5, 0xe1, 0xd0 } }
class nsACString;
class nsIFileStorage : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_FILESTORAGE_IID)
NS_IMETHOD_(const nsACString&)
Id() = 0;
// Whether or not the storage has been invalidated. If it has then no further
// operations for this storage will be allowed to run.
NS_IMETHOD_(bool)
IsInvalidated() = 0;
NS_IMETHOD_(bool)
IsShuttingDown() = 0;
NS_IMETHOD_(void)
SetThreadLocals() = 0;
NS_IMETHOD_(void)
UnsetThreadLocals() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIFileStorage, NS_FILESTORAGE_IID)
#define NS_DECL_NSIFILESTORAGE \
NS_IMETHOD_(const nsACString&) \
Id() MOZ_OVERRIDE; \
\
NS_IMETHOD_(bool) \
IsInvalidated() MOZ_OVERRIDE; \
\
NS_IMETHOD_(bool) \
IsShuttingDown() MOZ_OVERRIDE; \
\
NS_IMETHOD_(void) \
SetThreadLocals() MOZ_OVERRIDE; \
\
NS_IMETHOD_(void) \
UnsetThreadLocals() MOZ_OVERRIDE;
#endif // nsIFileStorage_h__

View File

@ -487,7 +487,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBDatabase)
NS_INTERFACE_MAP_ENTRY(nsIFileStorage)
NS_INTERFACE_MAP_ENTRY(nsIOfflineStorage)
NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
@ -745,31 +744,6 @@ IDBDatabase::Id()
return mDatabaseId;
}
NS_IMETHODIMP_(bool)
IDBDatabase::IsInvalidated()
{
return mInvalidated;
}
NS_IMETHODIMP_(bool)
IDBDatabase::IsShuttingDown()
{
return QuotaManager::IsShuttingDown();
}
NS_IMETHODIMP_(void)
IDBDatabase::SetThreadLocals()
{
NS_ASSERTION(GetOwner(), "Should have owner!");
QuotaManager::SetCurrentWindow(GetOwner());
}
NS_IMETHODIMP_(void)
IDBDatabase::UnsetThreadLocals()
{
QuotaManager::SetCurrentWindow(nullptr);
}
NS_IMETHODIMP_(mozilla::dom::quota::Client*)
IDBDatabase::GetClient()
{
@ -954,7 +928,7 @@ CreateFileHelper::GetSuccessResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal)
{
nsRefPtr<IDBFileHandle> fileHandle =
IDBFileHandle::Create(mDatabase, mName, mType, mFileInfo.forget());
IDBFileHandle::Create(mName, mType, mDatabase, mFileInfo.forget());
IDB_ENSURE_TRUE(fileHandle, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, fileHandle), aVal);

View File

@ -10,7 +10,6 @@
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
#include "nsIDocument.h"
#include "nsIFileStorage.h"
#include "nsIOfflineStorage.h"
#include "mozilla/Attributes.h"
@ -59,7 +58,6 @@ class IDBDatabase : public IDBWrapperCache,
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIFILESTORAGE
NS_DECL_NSIOFFLINESTORAGE
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
@ -75,13 +73,6 @@ public:
static IDBDatabase*
FromStorage(nsIOfflineStorage* aStorage);
static IDBDatabase*
FromStorage(nsIFileStorage* aStorage)
{
nsCOMPtr<nsIOfflineStorage> storage = do_QueryInterface(aStorage);
return storage ? FromStorage(storage) : nullptr;
}
// nsIDOMEventTarget
virtual nsresult PostHandleEvent(
EventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
@ -111,6 +102,14 @@ public:
return doc.forget();
}
// Whether or not the database has been invalidated. If it has then no further
// transactions for this database will be allowed to run. This function may be
// called on any thread.
bool IsInvalidated() const
{
return mInvalidated;
}
void DisconnectFromActorParent();
void CloseInternal(bool aIsDead);

View File

@ -9,6 +9,7 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/IDBFileHandleBinding.h"
#include "mozilla/dom/quota/FileStreams.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "IDBDatabase.h"
@ -40,11 +41,19 @@ IDBFileHandle::IDBFileHandle(IDBDatabase* aOwner)
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(IDBFileHandle, FileHandle, mDatabase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBFileHandle)
NS_INTERFACE_MAP_END_INHERITING(FileHandle)
NS_IMPL_ADDREF_INHERITED(IDBFileHandle, FileHandle)
NS_IMPL_RELEASE_INHERITED(IDBFileHandle, FileHandle)
// static
already_AddRefed<IDBFileHandle>
IDBFileHandle::Create(IDBDatabase* aDatabase,
const nsAString& aName,
IDBFileHandle::Create(const nsAString& aName,
const nsAString& aType,
IDBDatabase* aDatabase,
already_AddRefed<FileInfo> aFileInfo)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@ -54,28 +63,45 @@ IDBFileHandle::Create(IDBDatabase* aDatabase,
nsRefPtr<IDBFileHandle> newFile = new IDBFileHandle(aDatabase);
newFile->mFileStorage = aDatabase;
newFile->mName = aName;
newFile->mType = aType;
newFile->mFile = GetFileFor(fileInfo);
NS_ENSURE_TRUE(newFile->mFile, nullptr);
newFile->mStorageId = aDatabase->Id();
newFile->mFileName.AppendInt(fileInfo->Id());
newFile->mDatabase = aDatabase;
fileInfo.swap(newFile->mFileInfo);
return newFile.forget();
}
bool
IDBFileHandle::IsShuttingDown()
{
return QuotaManager::IsShuttingDown() || FileHandle::IsShuttingDown();
}
bool
IDBFileHandle::IsInvalid()
{
return mDatabase->IsInvalidated();
}
nsIOfflineStorage*
IDBFileHandle::Storage()
{
return mDatabase;
}
already_AddRefed<nsISupports>
IDBFileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
{
nsCOMPtr<nsIOfflineStorage> storage = do_QueryInterface(mFileStorage);
NS_ASSERTION(storage, "This should always succeed!");
PersistenceType persistenceType = storage->Type();
const nsACString& group = storage->Group();
const nsACString& origin = storage->Origin();
PersistenceType persistenceType = mDatabase->Type();
const nsACString& group = mDatabase->Group();
const nsACString& origin = mDatabase->Origin();
nsCOMPtr<nsISupports> result;
@ -96,6 +122,19 @@ IDBFileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
return result.forget();
}
void
IDBFileHandle::SetThreadLocals()
{
MOZ_ASSERT(mDatabase->GetOwner(), "Should have owner!");
QuotaManager::SetCurrentWindow(mDatabase->GetOwner());
}
void
IDBFileHandle::UnsetThreadLocals()
{
QuotaManager::SetCurrentWindow(nullptr);
}
already_AddRefed<nsIDOMFile>
IDBFileHandle::CreateFileObject(mozilla::dom::LockedFile* aLockedFile,
uint32_t aFileSize)
@ -112,14 +151,3 @@ IDBFileHandle::WrapObject(JSContext* aCx)
{
return IDBFileHandleBinding::Wrap(aCx, this);
}
IDBDatabase*
IDBFileHandle::Database()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
IDBDatabase* database = static_cast<IDBDatabase*>(mFileStorage.get());
MOZ_ASSERT(database);
return database;
}

View File

@ -9,8 +9,12 @@
#include "IndexedDatabase.h"
#include "MainThreadUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/FileHandle.h"
#include "mozilla/dom/indexedDB/FileInfo.h"
#include "nsCycleCollectionParticipant.h"
BEGIN_INDEXEDDB_NAMESPACE
@ -21,9 +25,13 @@ class IDBFileHandle : public FileHandle
typedef mozilla::dom::LockedFile LockedFile;
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBFileHandle, FileHandle)
static already_AddRefed<IDBFileHandle>
Create(IDBDatabase* aDatabase, const nsAString& aName,
const nsAString& aType, already_AddRefed<FileInfo> aFileInfo);
Create(const nsAString& aName, const nsAString& aType,
IDBDatabase* aDatabase, already_AddRefed<FileInfo> aFileInfo);
virtual int64_t
@ -38,9 +46,24 @@ public:
return mFileInfo;
}
virtual bool
IsShuttingDown() MOZ_OVERRIDE;
virtual bool
IsInvalid() MOZ_OVERRIDE;
virtual nsIOfflineStorage*
Storage() MOZ_OVERRIDE;
virtual already_AddRefed<nsISupports>
CreateStream(nsIFile* aFile, bool aReadOnly) MOZ_OVERRIDE;
virtual void
SetThreadLocals() MOZ_OVERRIDE;
virtual void
UnsetThreadLocals() MOZ_OVERRIDE;
virtual already_AddRefed<nsIDOMFile>
CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) MOZ_OVERRIDE;
@ -50,7 +73,12 @@ public:
// WebIDL
IDBDatabase*
Database();
Database()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
return mDatabase;
}
private:
IDBFileHandle(IDBDatabase* aOwner);
@ -59,6 +87,7 @@ private:
{
}
nsRefPtr<IDBDatabase> mDatabase;
nsRefPtr<FileInfo> mFileInfo;
};

View File

@ -777,8 +777,8 @@ public:
nsRefPtr<FileInfo>& fileInfo = aFile.mFileInfo;
nsRefPtr<IDBFileHandle> fileHandle = IDBFileHandle::Create(aDatabase,
aData.name, aData.type, fileInfo.forget());
nsRefPtr<IDBFileHandle> fileHandle = IDBFileHandle::Create(aData.name,
aData.type, aDatabase, fileInfo.forget());
return fileHandle->WrapObject(aCx);
}

View File

@ -9,7 +9,6 @@
#include "nsIConsoleService.h"
#include "nsIDiskSpaceWatcher.h"
#include "nsIFile.h"
#include "nsIFileStorage.h"
#include "nsIObserverService.h"
#include "nsIScriptError.h"

View File

@ -2419,7 +2419,7 @@ QuotaManager::Observe(nsISupports* aSubject,
}
}
StorageMatcher<nsTArray<nsCOMPtr<nsIFileStorage> > > liveStorages;
StorageMatcher<nsTArray<nsCOMPtr<nsIOfflineStorage>>> liveStorages;
liveStorages.Find(mLiveStorages, &indexes);
if (!liveStorages.IsEmpty()) {
@ -2796,7 +2796,7 @@ QuotaManager::RunSynchronizedOp(nsIOfflineStorage* aStorage,
if (service) {
// Have to copy here in case a transaction service needs a list too.
nsTArray<nsCOMPtr<nsIFileStorage> > array;
nsTArray<nsCOMPtr<nsIOfflineStorage>> array;
for (uint32_t index = startIndex; index < endIndex; index++) {
if (!storages[index].IsEmpty() &&

View File

@ -7,13 +7,11 @@
#ifndef nsIOfflineStorage_h__
#define nsIOfflineStorage_h__
#include "nsIFileStorage.h"
#include "mozilla/dom/quota/PersistenceType.h"
#define NS_OFFLINESTORAGE_IID \
{0xec7e878d, 0xc8c1, 0x402e, \
{ 0xa2, 0xc4, 0xf6, 0x82, 0x29, 0x4e, 0x3c, 0xb1 } }
{0x3ae00063, 0x6c13, 0x4afd, \
{ 0x86, 0x7d, 0x33, 0xc2, 0x12, 0xd8, 0x97, 0x25 } }
class nsPIDOMWindow;
@ -25,7 +23,7 @@ class Client;
}
}
class nsIOfflineStorage : public nsIFileStorage
class nsIOfflineStorage : public nsISupports
{
public:
typedef mozilla::dom::quota::Client Client;
@ -33,6 +31,9 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_OFFLINESTORAGE_IID)
NS_IMETHOD_(const nsACString&)
Id() = 0;
NS_IMETHOD_(Client*)
GetClient() = 0;
@ -83,6 +84,9 @@ protected:
NS_DEFINE_STATIC_IID_ACCESSOR(nsIOfflineStorage, NS_OFFLINESTORAGE_IID)
#define NS_DECL_NSIOFFLINESTORAGE \
NS_IMETHOD_(const nsACString&) \
Id() MOZ_OVERRIDE; \
\
NS_IMETHOD_(Client*) \
GetClient() MOZ_OVERRIDE; \
\