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,
|
2017-03-06 20:38:42 +03:00
|
|
|
const nsACString& aOrigin)
|
2014-11-04 23:44:56 +03:00
|
|
|
: mOrigin(aOrigin)
|
|
|
|
, mPersistenceType(aPersistenceType)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsCString mOrigin;
|
|
|
|
PersistenceType mPersistenceType;
|
|
|
|
};
|
|
|
|
|
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
|
2018-11-29 23:47:30 +03:00
|
|
|
GetOrCreate(nsIRunnable* aCallback,
|
|
|
|
nsIEventTarget* aMainEventTarget = nullptr);
|
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,
|
|
|
|
uint64_t aUsageBytes,
|
2017-01-17 04:41:00 +03:00
|
|
|
int64_t aAccessTime,
|
|
|
|
bool aPersisted);
|
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,
|
2017-07-10 12:02:44 +03:00
|
|
|
nsIFile* aFile,
|
2018-11-29 23:48:34 +03:00
|
|
|
int64_t aFileSize = -1,
|
2017-07-10 12:02:44 +03:00
|
|
|
int64_t* aFileSizeOut = nullptr);
|
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,
|
2017-07-10 12:02:44 +03:00
|
|
|
const nsAString& aPath,
|
2018-11-29 23:48:34 +03:00
|
|
|
int64_t aFileSize = -1,
|
2017-07-10 12:02:44 +03:00
|
|
|
int64_t* aFileSizeOut = nullptr);
|
2012-12-17 23:25:10 +04:00
|
|
|
|
2016-08-25 05:19:31 +03:00
|
|
|
Nullable<bool>
|
|
|
|
OriginPersisted(const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin);
|
|
|
|
|
|
|
|
void
|
|
|
|
PersistOrigin(const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin);
|
|
|
|
|
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,
|
2016-08-25 05:19:31 +03:00
|
|
|
bool* aPersisted,
|
2016-06-05 22:42:25 +03:00
|
|
|
nsACString& aSuffix,
|
|
|
|
nsACString& aGroup,
|
2017-03-06 20:38:42 +03:00
|
|
|
nsACString& aOrigin);
|
2016-06-05 22:42:25 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryMetadata2WithRestore(nsIFile* aDirectory,
|
|
|
|
bool aPersistent,
|
|
|
|
int64_t* aTimestamp,
|
2016-08-25 05:19:31 +03:00
|
|
|
bool* aPersisted,
|
2016-06-05 22:42:25 +03:00
|
|
|
nsACString& aSuffix,
|
|
|
|
nsACString& aGroup,
|
2017-03-06 20:38:42 +03:00
|
|
|
nsACString& aOrigin);
|
2016-06-05 22:42:25 +03:00
|
|
|
|
|
|
|
nsresult
|
2016-08-25 05:19:31 +03:00
|
|
|
GetDirectoryMetadata2(nsIFile* aDirectory,
|
|
|
|
int64_t* aTimestamp,
|
|
|
|
bool* aPersisted);
|
2016-06-05 22:42:25 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetDirectoryMetadata2WithRestore(nsIFile* aDirectory,
|
|
|
|
bool aPersistent,
|
2016-08-25 05:19:31 +03:00
|
|
|
int64_t* aTimestamp,
|
|
|
|
bool* aPersisted);
|
2016-06-05 22:42:25 +03:00
|
|
|
|
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,
|
|
|
|
Client::Type aClientType,
|
|
|
|
bool aExclusive,
|
|
|
|
OpenDirectoryListener* aOpenListener);
|
|
|
|
|
|
|
|
// XXX RemoveMe once bug 1170279 gets fixed.
|
|
|
|
void
|
2017-02-13 20:07:40 +03:00
|
|
|
OpenDirectoryInternal(const Nullable<PersistenceType>& aPersistenceType,
|
2015-06-30 15:59:27 +03:00
|
|
|
const OriginScope& aOriginScope,
|
2017-02-13 20:07:40 +03:00
|
|
|
const 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
|
|
|
|
2017-03-06 20:39:21 +03:00
|
|
|
void
|
|
|
|
AssertStorageIsInitialized() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
|
|
|
|
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,
|
2018-11-29 23:48:25 +03:00
|
|
|
bool aCreateIfNotExists,
|
2013-03-26 15:13:17 +04:00
|
|
|
nsIFile** aDirectory);
|
|
|
|
|
2017-03-06 20:39:33 +03:00
|
|
|
nsresult
|
|
|
|
EnsureOriginIsInitializedInternal(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aSuffix,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
2018-11-29 23:48:25 +03:00
|
|
|
bool aCreateIfNotExists,
|
2017-03-06 20:39:33 +03:00
|
|
|
nsIFile** aDirectory,
|
|
|
|
bool* aCreated);
|
|
|
|
|
2017-08-23 10:22:47 +03:00
|
|
|
nsresult
|
2017-08-23 10:56:06 +03:00
|
|
|
EnsureTemporaryStorageIsInitialized();
|
2017-08-23 10:22:47 +03:00
|
|
|
|
2018-08-15 17:59:26 +03:00
|
|
|
nsresult
|
|
|
|
EnsureOriginDirectory(nsIFile* aDirectory,
|
2018-11-29 23:48:25 +03:00
|
|
|
bool aCreateIfNotExists,
|
2018-08-15 17:59:26 +03:00
|
|
|
bool* aCreated);
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
void
|
2013-09-11 08:18:36 +04:00
|
|
|
OriginClearCompleted(PersistenceType aPersistenceType,
|
2018-11-29 23:47:58 +03:00
|
|
|
const nsACString& aOrigin,
|
|
|
|
const Nullable<Client::Type>& aClientType);
|
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);
|
|
|
|
|
2017-09-06 12:25:13 +03:00
|
|
|
void
|
|
|
|
NotifyStoragePressure(uint64_t aUsage);
|
|
|
|
|
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,
|
2017-03-06 20:38:42 +03:00
|
|
|
nsACString* aOrigin);
|
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,
|
2017-03-06 20:38:42 +03:00
|
|
|
nsACString* aOrigin);
|
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,
|
2017-03-06 20:38:42 +03:00
|
|
|
nsACString* aOrigin);
|
2014-11-04 23:44:56 +03:00
|
|
|
|
|
|
|
static bool
|
2017-03-22 14:14:09 +03:00
|
|
|
IsOriginInternal(const nsACString& aOrigin);
|
2015-01-09 18:56:23 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
static void
|
|
|
|
ChromeOrigin(nsACString& aOrigin);
|
|
|
|
|
2017-03-06 20:40:37 +03:00
|
|
|
static bool
|
|
|
|
AreOriginsEqualOnDisk(nsACString& aOrigin1,
|
|
|
|
nsACString& aOrigin2);
|
|
|
|
|
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>
|
2017-02-13 20:07:40 +03:00
|
|
|
CreateDirectoryLock(const Nullable<PersistenceType>& aPersistenceType,
|
2015-06-30 15:59:27 +03:00
|
|
|
const nsACString& aGroup,
|
|
|
|
const OriginScope& aOriginScope,
|
2017-02-13 20:07:40 +03:00
|
|
|
const Nullable<Client::Type>& aClientType,
|
2015-06-30 15:59:27 +03:00
|
|
|
bool aExclusive,
|
|
|
|
bool aInternal,
|
|
|
|
OpenDirectoryListener* aOpenListener);
|
|
|
|
|
|
|
|
already_AddRefed<DirectoryLockImpl>
|
|
|
|
CreateDirectoryLockForEviction(PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
2017-03-06 20:38:42 +03:00
|
|
|
const nsACString& aOrigin);
|
2015-06-30 15:59:27 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-08-25 05:19:31 +03:00
|
|
|
already_AddRefed<OriginInfo>
|
|
|
|
LockedGetOriginInfo(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();
|
|
|
|
|
2018-10-17 16:37:16 +03:00
|
|
|
template<typename Helper>
|
|
|
|
nsresult
|
|
|
|
UpgradeStorage(const int32_t aOldVersion,
|
|
|
|
const int32_t aNewVersion,
|
|
|
|
mozIStorageConnection* aConnection);
|
|
|
|
|
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
|
|
|
|
|
|
|
nsresult
|
2017-01-10 13:44:32 +03:00
|
|
|
UpgradeStorageFrom1_0To2_0(mozIStorageConnection* aConnection);
|
2014-11-28 11:44:12 +03:00
|
|
|
|
2017-07-18 13:54:20 +03:00
|
|
|
nsresult
|
2017-10-03 17:02:27 +03:00
|
|
|
UpgradeStorageFrom2_0To2_1(mozIStorageConnection* aConnection);
|
2017-07-18 13:54:20 +03:00
|
|
|
|
2018-06-29 10:58:09 +03:00
|
|
|
nsresult
|
|
|
|
MaybeRemoveLocalStorageData();
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MaybeRemoveLocalStorageDirectories();
|
|
|
|
|
2018-11-29 23:48:38 +03:00
|
|
|
nsresult
|
|
|
|
MaybeCreateLocalStorageArchive();
|
|
|
|
|
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,
|
|
|
|
int64_t aAccessTime,
|
2017-01-17 04:41:00 +03:00
|
|
|
bool aPersisted,
|
2013-09-11 08:18:36 +04:00
|
|
|
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();
|
|
|
|
|
2018-11-29 23:47:24 +03:00
|
|
|
for (uint32_t index = 0; index < uint32_t(Client::TypeMax()); index++) {
|
2013-06-05 12:11:23 +04:00
|
|
|
mClients[index]->ReleaseIOThreadObjects();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 15:59:27 +03:00
|
|
|
DirectoryLockTable&
|
|
|
|
GetDirectoryLockTable(PersistenceType aPersistenceType);
|
2014-11-04 23:44:56 +03:00
|
|
|
|
2018-08-15 17:59:26 +03:00
|
|
|
bool
|
|
|
|
IsSanitizedOriginValid(const nsACString& aSanitizedOrigin);
|
|
|
|
|
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;
|
|
|
|
|
2018-08-15 17:59:26 +03:00
|
|
|
// A list of all successfully initialized persistent origins. This list isn't
|
|
|
|
// protected by any mutex but it is only ever touched on the IO thread.
|
2013-03-26 15:13:17 +04:00
|
|
|
nsTArray<nsCString> mInitializedOrigins;
|
|
|
|
|
2018-08-15 17:59:26 +03:00
|
|
|
// A hash table that is used to cache origin parser results for given
|
|
|
|
// sanitized origin strings. This hash table isn't protected by any mutex but
|
|
|
|
// it is only ever touched on the IO thread.
|
|
|
|
nsDataHashtable<nsCStringHashKey, bool> mValidOrigins;
|
|
|
|
|
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__ */
|