2012-12-17 23:25:10 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-12-17 23:25:10 +04:00
|
|
|
/* 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 mozilla_dom_quota_quotamanager_h__
|
|
|
|
#define mozilla_dom_quota_quotamanager_h__
|
|
|
|
|
|
|
|
#include "QuotaCommon.h"
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2015-06-30 15:59:27 +03:00
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
2012-12-17 23:25:10 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2013-09-11 08:18:36 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
#include "nsClassHashtable.h"
|
2012-12-17 23:25:10 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
#include "Client.h"
|
2013-09-11 08:18:36 +04:00
|
|
|
#include "PersistenceType.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2016-12-01 06:48:32 +03:00
|
|
|
#include "prenv.h"
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
#define QUOTA_MANAGER_CONTRACTID "@mozilla.org/dom/quota/manager;1"
|
|
|
|
|
2016-06-05 22:42:25 +03:00
|
|
|
class mozIStorageConnection;
|
2015-11-22 12:43:55 +03:00
|
|
|
class nsIEventTarget;
|
2013-03-26 15:13:17 +04:00
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIThread;
|
|
|
|
class nsITimer;
|
|
|
|
class nsIURI;
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowOuter;
|
2013-09-19 17:54:39 +04:00
|
|
|
class nsIRunnable;
|
2012-12-19 21:45:57 +04:00
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
BEGIN_QUOTA_NAMESPACE
|
|
|
|
|
2015-06-30 15:59:53 +03:00
|
|
|
class DirectoryLockImpl;
|
2013-09-11 08:18:36 +04:00
|
|
|
class GroupInfo;
|
2015-01-22 11:40:42 +03:00
|
|
|
class GroupInfoPair;
|
2012-12-17 23:25:10 +04:00
|
|
|
class OriginInfo;
|
2015-06-30 15:59:27 +03:00
|
|
|
class OriginScope;
|
2013-03-26 15:13:17 +04:00
|
|
|
class QuotaObject;
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2015-06-30 15:59:53 +03:00
|
|
|
class NS_NO_VTABLE RefCountedObject
|
|
|
|
{
|
|
|
|
public:
|
2017-01-25 22:51:34 +03:00
|
|
|
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
2015-06-30 15:59:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DirectoryLock
|
2015-11-22 12:43:55 +03:00
|
|
|
: public RefCountedObject
|
2015-06-30 15:59:53 +03:00
|
|
|
{
|
|
|
|
friend class DirectoryLockImpl;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DirectoryLock()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~DirectoryLock()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
class NS_NO_VTABLE OpenDirectoryListener
|
|
|
|
: public RefCountedObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void
|
|
|
|
DirectoryLockAcquired(DirectoryLock* aLock) = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
DirectoryLockFailed() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~OpenDirectoryListener()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
struct OriginParams
|
|
|
|
{
|
|
|
|
OriginParams(PersistenceType aPersistenceType,
|
2014-11-28 11:44:12 +03:00
|
|
|
const nsACString& aOrigin,
|
|
|
|
bool aIsApp)
|
2014-11-04 23:44:56 +03:00
|
|
|
: mOrigin(aOrigin)
|
|
|
|
, mPersistenceType(aPersistenceType)
|
2014-11-28 11:44:12 +03:00
|
|
|
, mIsApp(aIsApp)
|
2014-11-04 23:44:56 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
nsCString mOrigin;
|
|
|
|
PersistenceType mPersistenceType;
|
2014-11-28 11:44:12 +03:00
|
|
|
bool mIsApp;
|
2014-11-04 23:44:56 +03:00
|
|
|
};
|
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
class QuotaManager final
|
|
|
|
: public BackgroundThreadObject
|
2012-12-17 23:25:10 +04:00
|
|
|
{
|
2015-06-30 15:59:53 +03:00
|
|
|
friend class DirectoryLockImpl;
|
2013-09-11 08:18:36 +04:00
|
|
|
friend class GroupInfo;
|
2012-12-17 23:25:10 +04:00
|
|
|
friend class OriginInfo;
|
|
|
|
friend class QuotaObject;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
typedef nsClassHashtable<nsCStringHashKey,
|
2015-06-30 15:59:27 +03:00
|
|
|
nsTArray<DirectoryLockImpl*>> DirectoryLockTable;
|
2014-11-04 23:44:56 +03:00
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
public:
|
2015-11-22 12:43:55 +03:00
|
|
|
class CreateRunnable;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class ShutdownRunnable;
|
|
|
|
class ShutdownObserver;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(QuotaManager)
|
|
|
|
|
2016-12-01 06:48:32 +03:00
|
|
|
static bool IsRunningXPCShellTests()
|
|
|
|
{
|
|
|
|
static bool kRunningXPCShellTests = !!PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR");
|
|
|
|
return kRunningXPCShellTests;
|
|
|
|
}
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2015-08-19 21:13:15 +03:00
|
|
|
static const char kReplaceChars[];
|
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
static void
|
|
|
|
GetOrCreate(nsIRunnable* aCallback);
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
// Returns a non-owning reference.
|
|
|
|
static QuotaManager*
|
|
|
|
Get();
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
// Returns true if we've begun the shutdown process.
|
|
|
|
static bool IsShuttingDown();
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
bool
|
|
|
|
IsOriginInitialized(const nsACString& aOrigin) const
|
|
|
|
{
|
|
|
|
AssertIsOnIOThread();
|
|
|
|
|
|
|
|
return mInitializedOrigins.Contains(aOrigin);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsTemporaryStorageInitialized() const
|
|
|
|
{
|
|
|
|
AssertIsOnIOThread();
|
|
|
|
|
|
|
|
return mTemporaryStorageInitialized;
|
|
|
|
}
|
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
InitQuotaForOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2014-11-04 23:44:56 +03:00
|
|
|
bool aIsApp,
|
2013-09-11 08:18:36 +04:00
|
|
|
uint64_t aUsageBytes,
|
|
|
|
int64_t aAccessTime);
|
2012-12-17 23:25:10 +04:00
|
|
|
|
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
DecreaseUsageForOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2012-12-17 23:25:10 +04:00
|
|
|
int64_t aSize);
|
|
|
|
|
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
UpdateOriginAccessTime(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveQuota();
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveQuotaForOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mQuotaMutex);
|
|
|
|
LockedRemoveQuotaForOrigin(aPersistenceType, aGroup, aOrigin);
|
|
|
|
}
|
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
already_AddRefed<QuotaObject>
|
2013-09-11 08:18:36 +04:00
|
|
|
GetQuotaObject(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2012-12-17 23:25:10 +04:00
|
|
|
nsIFile* aFile);
|
|
|
|
|
|
|
|
already_AddRefed<QuotaObject>
|
2013-09-11 08:18:36 +04:00
|
|
|
GetQuotaObject(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2012-12-17 23:25:10 +04:00
|
|
|
const nsAString& aPath);
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
// Called when a process is being shot down. Aborts any running operations
|
|
|
|
// for the given process.
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2015-06-30 15:59:27 +03:00
|
|
|
AbortOperationsForProcess(ContentParentId aContentParentId);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
nsresult
|
2013-09-11 08:18:36 +04:00
|
|
|
GetDirectoryForOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aASCIIOrigin,
|
2013-03-26 15:13:17 +04:00
|
|
|
nsIFile** aDirectory) const;
|
|
|
|
|
2016-06-05 22:42:25 +03:00
|
|
|
nsresult
|
|
|
|
RestoreDirectoryMetadata2(nsIFile* aDirectory, bool aPersistent);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryMetadata2(nsIFile* aDirectory,
|
|
|
|
int64_t* aTimestamp,
|
|
|
|
nsACString& aSuffix,
|
|
|
|
nsACString& aGroup,
|
|
|
|
nsACString& aOrigin,
|
|
|
|
bool* aIsApp);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryMetadata2WithRestore(nsIFile* aDirectory,
|
|
|
|
bool aPersistent,
|
|
|
|
int64_t* aTimestamp,
|
|
|
|
nsACString& aSuffix,
|
|
|
|
nsACString& aGroup,
|
|
|
|
nsACString& aOrigin,
|
|
|
|
bool* aIsApp);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryMetadata2(nsIFile* aDirectory, int64_t* aTimestamp);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryMetadata2WithRestore(nsIFile* aDirectory,
|
|
|
|
bool aPersistent,
|
|
|
|
int64_t* aTimestamp);
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
// This is the main entry point into the QuotaManager API.
|
|
|
|
// Any storage API implementation (quota client) that participates in
|
|
|
|
// centralized quota and storage handling should call this method to get
|
|
|
|
// a directory lock which will protect client's files from being deleted
|
|
|
|
// while they are still in use.
|
|
|
|
// After a lock is acquired, client is notified via the open listener's
|
|
|
|
// method DirectoryLockAcquired. If the lock couldn't be acquired, client
|
|
|
|
// gets DirectoryLockFailed notification.
|
|
|
|
// A lock is a reference counted object and at the time DirectoryLockAcquired
|
|
|
|
// is called, quota manager holds just one strong reference to it which is
|
|
|
|
// then immediatelly cleared by quota manager. So it's up to client to add
|
|
|
|
// a new reference in order to keep the lock alive.
|
|
|
|
// Unlocking is simply done by dropping all references to the lock object.
|
|
|
|
// In other words, protection which the lock represents dies with the lock
|
|
|
|
// object itself.
|
|
|
|
void
|
|
|
|
OpenDirectory(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
|
|
|
bool aIsApp,
|
|
|
|
Client::Type aClientType,
|
|
|
|
bool aExclusive,
|
|
|
|
OpenDirectoryListener* aOpenListener);
|
|
|
|
|
|
|
|
// XXX RemoveMe once bug 1170279 gets fixed.
|
|
|
|
void
|
|
|
|
OpenDirectoryInternal(Nullable<PersistenceType> aPersistenceType,
|
|
|
|
const OriginScope& aOriginScope,
|
2016-03-01 12:44:39 +03:00
|
|
|
Nullable<Client::Type> aClientType,
|
2015-06-30 15:59:27 +03:00
|
|
|
bool aExclusive,
|
|
|
|
OpenDirectoryListener* aOpenListener);
|
|
|
|
|
|
|
|
// Collect inactive and the least recently used origins.
|
|
|
|
uint64_t
|
|
|
|
CollectOriginsForEviction(uint64_t aMinSizeToBeFreed,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DirectoryLockImpl>>& aLocks);
|
2015-06-30 15:59:27 +03:00
|
|
|
|
2016-06-05 22:42:25 +03:00
|
|
|
nsresult
|
|
|
|
EnsureStorageIsInitialized();
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
nsresult
|
2013-09-11 08:18:36 +04:00
|
|
|
EnsureOriginIsInitialized(PersistenceType aPersistenceType,
|
2016-06-05 22:42:25 +03:00
|
|
|
const nsACString& aSuffix,
|
2013-09-11 08:18:36 +04:00
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2014-11-04 23:44:56 +03:00
|
|
|
bool aIsApp,
|
2013-03-26 15:13:17 +04:00
|
|
|
nsIFile** aDirectory);
|
|
|
|
|
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
OriginClearCompleted(PersistenceType aPersistenceType,
|
2014-11-28 11:44:12 +03:00
|
|
|
const nsACString& aOrigin,
|
|
|
|
bool aIsApp);
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
ResetOrClearCompleted();
|
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
void
|
|
|
|
StartIdleMaintenance()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
for (auto& client : mClients) {
|
|
|
|
client->StartIdleMaintenance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StopIdleMaintenance()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
for (auto& client : mClients) {
|
|
|
|
client->StopIdleMaintenance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
void
|
|
|
|
AssertCurrentThreadOwnsQuotaMutex()
|
|
|
|
{
|
|
|
|
mQuotaMutex.AssertCurrentThreadOwns();
|
|
|
|
}
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
nsIThread*
|
|
|
|
IOThread()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIOThread, "This should never be null!");
|
|
|
|
return mIOThread;
|
|
|
|
}
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
Client*
|
2013-03-26 15:13:17 +04:00
|
|
|
GetClient(Client::Type aClientType);
|
|
|
|
|
2016-06-05 22:42:25 +03:00
|
|
|
const nsString&
|
|
|
|
GetBasePath() const
|
|
|
|
{
|
|
|
|
return mBasePath;
|
|
|
|
}
|
|
|
|
|
2014-10-13 23:12:25 +04:00
|
|
|
const nsString&
|
|
|
|
GetStoragePath() const
|
|
|
|
{
|
|
|
|
return mStoragePath;
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
const nsString&
|
2013-09-11 08:18:36 +04:00
|
|
|
GetStoragePath(PersistenceType aPersistenceType) const
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
2014-11-28 11:44:12 +03:00
|
|
|
return mPermanentStoragePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPersistenceType == PERSISTENCE_TYPE_TEMPORARY) {
|
|
|
|
return mTemporaryStoragePath;
|
2013-09-11 08:18:36 +04:00
|
|
|
}
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
MOZ_ASSERT(aPersistenceType == PERSISTENCE_TYPE_DEFAULT);
|
2013-09-11 08:18:36 +04:00
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
return mDefaultStoragePath;
|
2013-09-11 08:18:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2014-05-21 02:19:59 +04:00
|
|
|
GetGroupLimit() const;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2016-06-24 05:24:06 +03:00
|
|
|
void
|
|
|
|
GetGroupUsageAndLimit(const nsACString& aGroup,
|
|
|
|
UsageInfo* aUsageInfo);
|
|
|
|
|
2013-11-25 20:53:48 +04:00
|
|
|
static void
|
2013-09-11 08:18:36 +04:00
|
|
|
GetStorageId(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2013-11-19 01:49:53 +04:00
|
|
|
Client::Type aClientType,
|
2013-11-25 20:53:48 +04:00
|
|
|
nsACString& aDatabaseId);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
static nsresult
|
2013-09-11 08:18:36 +04:00
|
|
|
GetInfoFromPrincipal(nsIPrincipal* aPrincipal,
|
2016-06-05 22:42:25 +03:00
|
|
|
nsACString* aSuffix,
|
2013-09-11 08:18:36 +04:00
|
|
|
nsACString* aGroup,
|
2014-09-27 03:21:57 +04:00
|
|
|
nsACString* aOrigin,
|
2015-01-22 11:40:42 +03:00
|
|
|
bool* aIsApp);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
static nsresult
|
2016-01-30 20:05:36 +03:00
|
|
|
GetInfoFromWindow(nsPIDOMWindowOuter* aWindow,
|
2016-06-05 22:42:25 +03:00
|
|
|
nsACString* aSuffix,
|
2013-09-11 08:18:36 +04:00
|
|
|
nsACString* aGroup,
|
2014-09-27 03:21:57 +04:00
|
|
|
nsACString* aOrigin,
|
2015-01-22 11:40:42 +03:00
|
|
|
bool* aIsApp);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-19 16:45:25 +04:00
|
|
|
static void
|
2016-06-05 22:42:25 +03:00
|
|
|
GetInfoForChrome(nsACString* aSuffix,
|
|
|
|
nsACString* aGroup,
|
2014-09-27 03:21:57 +04:00
|
|
|
nsACString* aOrigin,
|
2015-01-22 11:40:42 +03:00
|
|
|
bool* aIsApp);
|
2014-11-04 23:44:56 +03:00
|
|
|
|
|
|
|
static bool
|
2015-01-09 18:56:23 +03:00
|
|
|
IsOriginWhitelistedForPersistentStorage(const nsACString& aOrigin);
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
static bool
|
|
|
|
IsFirstPromptRequired(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
|
|
|
bool aIsApp);
|
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
static bool
|
|
|
|
IsQuotaEnforced(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin,
|
2015-01-22 11:40:42 +03:00
|
|
|
bool aIsApp);
|
2013-09-19 16:45:25 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
static void
|
|
|
|
ChromeOrigin(nsACString& aOrigin);
|
|
|
|
|
2012-12-19 21:45:57 +04:00
|
|
|
private:
|
|
|
|
QuotaManager();
|
|
|
|
|
|
|
|
virtual ~QuotaManager();
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
nsresult
|
2015-11-22 12:43:55 +03:00
|
|
|
Init(const nsAString& aBaseDirPath);
|
|
|
|
|
|
|
|
void
|
|
|
|
Shutdown();
|
2012-12-19 21:45:57 +04:00
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
already_AddRefed<DirectoryLockImpl>
|
|
|
|
CreateDirectoryLock(Nullable<PersistenceType> aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const OriginScope& aOriginScope,
|
|
|
|
Nullable<bool> aIsApp,
|
|
|
|
Nullable<Client::Type> aClientType,
|
|
|
|
bool aExclusive,
|
|
|
|
bool aInternal,
|
|
|
|
OpenDirectoryListener* aOpenListener);
|
|
|
|
|
|
|
|
already_AddRefed<DirectoryLockImpl>
|
|
|
|
CreateDirectoryLockForEviction(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
|
|
|
bool aIsApp);
|
|
|
|
|
|
|
|
void
|
|
|
|
RegisterDirectoryLock(DirectoryLockImpl* aLock);
|
|
|
|
|
|
|
|
void
|
|
|
|
UnregisterDirectoryLock(DirectoryLockImpl* aLock);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemovePendingDirectoryLock(DirectoryLockImpl* aLock);
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
uint64_t
|
2015-06-30 15:59:42 +03:00
|
|
|
LockedCollectOriginsForEviction(
|
|
|
|
uint64_t aMinSizeToBeFreed,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DirectoryLockImpl>>& aLocks);
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
LockedRemoveQuotaForOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin);
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
nsresult
|
2013-09-11 08:18:36 +04:00
|
|
|
MaybeUpgradeIndexedDBDirectory();
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
nsresult
|
|
|
|
MaybeUpgradePersistentStorageDirectory();
|
|
|
|
|
2016-06-05 22:42:55 +03:00
|
|
|
nsresult
|
|
|
|
MaybeRemoveOldDirectories();
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
nsresult
|
2017-01-10 13:44:32 +03:00
|
|
|
UpgradeStorageFrom0_0To1_0(mozIStorageConnection* aConnection);
|
2016-06-05 22:42:25 +03:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
nsresult
|
2017-01-10 13:44:32 +03:00
|
|
|
UpgradeStorageFrom1_0To2_0(mozIStorageConnection* aConnection);
|
2016-06-05 22:42:25 +03:00
|
|
|
#endif
|
2014-11-28 11:44:12 +03:00
|
|
|
|
2014-11-04 23:44:56 +03:00
|
|
|
nsresult
|
|
|
|
InitializeRepository(PersistenceType aPersistenceType);
|
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
nsresult
|
|
|
|
InitializeOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2014-11-04 23:44:56 +03:00
|
|
|
bool aIsApp,
|
2013-09-11 08:18:36 +04:00
|
|
|
int64_t aAccessTime,
|
|
|
|
nsIFile* aDirectory);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-09-11 08:18:36 +04:00
|
|
|
void
|
|
|
|
CheckTemporaryStorageLimits();
|
|
|
|
|
|
|
|
void
|
2014-11-04 23:44:56 +03:00
|
|
|
DeleteFilesForOrigin(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aOrigin);
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
void
|
2015-10-18 08:24:48 +03:00
|
|
|
FinalizeOriginEviction(nsTArray<RefPtr<DirectoryLockImpl>>& aLocks);
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2013-06-05 12:11:23 +04:00
|
|
|
void
|
|
|
|
ReleaseIOThreadObjects()
|
|
|
|
{
|
|
|
|
AssertIsOnIOThread();
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < Client::TYPE_MAX; index++) {
|
|
|
|
mClients[index]->ReleaseIOThreadObjects();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
DirectoryLockTable&
|
|
|
|
GetDirectoryLockTable(PersistenceType aPersistenceType);
|
2014-11-04 23:44:56 +03:00
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
static void
|
|
|
|
ShutdownTimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
mozilla::Mutex mQuotaMutex;
|
|
|
|
|
2015-01-22 11:40:42 +03:00
|
|
|
nsClassHashtable<nsCStringHashKey, GroupInfoPair> mGroupInfoPairs;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
// Maintains a list of directory locks that are queued.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DirectoryLockImpl>> mPendingDirectoryLocks;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
// Maintains a list of directory locks that are acquired or queued.
|
|
|
|
nsTArray<DirectoryLockImpl*> mDirectoryLocks;
|
2014-11-04 23:44:56 +03:00
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
// Directory lock tables that are used to update origin access time.
|
|
|
|
DirectoryLockTable mTemporaryDirectoryLockTable;
|
|
|
|
DirectoryLockTable mDefaultDirectoryLockTable;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
|
|
|
// Thread on which IO is performed.
|
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
|
|
|
|
|
|
|
// A timer that gets activated at shutdown to ensure we close all storages.
|
|
|
|
nsCOMPtr<nsITimer> mShutdownTimer;
|
|
|
|
|
|
|
|
// A list of all successfully initialized origins. This list isn't protected
|
|
|
|
// by any mutex but it is only ever touched on the IO thread.
|
|
|
|
nsTArray<nsCString> mInitializedOrigins;
|
|
|
|
|
2016-07-18 19:51:54 +03:00
|
|
|
// This array is populated at initialization time and then never modified, so
|
|
|
|
// it can be iterated on any thread.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<Client>, Client::TYPE_MAX> mClients;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2016-06-05 22:42:25 +03:00
|
|
|
nsString mBasePath;
|
2013-09-11 08:18:36 +04:00
|
|
|
nsString mIndexedDBPath;
|
2014-10-13 23:12:25 +04:00
|
|
|
nsString mStoragePath;
|
2014-11-28 11:44:12 +03:00
|
|
|
nsString mPermanentStoragePath;
|
2013-09-11 08:18:36 +04:00
|
|
|
nsString mTemporaryStoragePath;
|
2014-11-28 11:44:12 +03:00
|
|
|
nsString mDefaultStoragePath;
|
2013-09-11 08:18:36 +04:00
|
|
|
|
|
|
|
uint64_t mTemporaryStorageLimit;
|
|
|
|
uint64_t mTemporaryStorageUsage;
|
|
|
|
bool mTemporaryStorageInitialized;
|
|
|
|
|
2016-06-05 22:42:25 +03:00
|
|
|
bool mStorageInitialized;
|
2012-12-19 21:45:57 +04:00
|
|
|
};
|
|
|
|
|
2012-12-17 23:25:10 +04:00
|
|
|
END_QUOTA_NAMESPACE
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_quota_quotamanager_h__ */
|