зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1624146 - Cookie code refactoring - part 9 - DB handling in CookieDefaultStorage, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D67758 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0fa65a1483
Коммит
97c9328d8f
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "CookieKey.h"
|
||||
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozIStorageBindingParamsArray.h"
|
||||
#include "mozIStorageCompletionCallback.h"
|
||||
#include "mozIStorageStatement.h"
|
||||
|
@ -16,6 +18,8 @@
|
|||
#include "nsTHashtable.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class mozIStorageService;
|
||||
class nsICookieTransactionCallback;
|
||||
class nsIPrefBranch;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -68,7 +72,7 @@ struct CookieListIter {
|
|||
|
||||
class CookieStorage : public nsIObserver, public nsSupportsWeakReference {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
|
||||
|
@ -117,12 +121,6 @@ class CookieStorage : public nsIObserver, public nsSupportsWeakReference {
|
|||
int64_t aCurrentTimeInUsec, nsIURI* aHostURI,
|
||||
const nsACString& aCookieHeader, bool aFromHttp);
|
||||
|
||||
void AddCookieToList(const nsACString& aBaseDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
mozilla::net::Cookie* aCookie,
|
||||
mozIStorageBindingParamsArray* aParamsArray,
|
||||
bool aWriteToDB = true);
|
||||
|
||||
void CreateOrUpdatePurgeList(nsIArray** aPurgeList, nsICookie* aCookie);
|
||||
|
||||
virtual void StaleCookies(const nsTArray<Cookie*>& aCookieList,
|
||||
|
@ -130,18 +128,18 @@ class CookieStorage : public nsIObserver, public nsSupportsWeakReference {
|
|||
|
||||
virtual void Close() = 0;
|
||||
|
||||
// TODO: private:
|
||||
nsTHashtable<CookieEntry> hostTable;
|
||||
|
||||
uint32_t cookieCount;
|
||||
int64_t cookieOldestTime;
|
||||
|
||||
protected:
|
||||
CookieStorage();
|
||||
virtual ~CookieStorage();
|
||||
|
||||
void Init();
|
||||
|
||||
void AddCookieToList(const nsACString& aBaseDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
mozilla::net::Cookie* aCookie,
|
||||
mozIStorageBindingParamsArray* aParamsArray,
|
||||
bool aWriteToDB = true);
|
||||
|
||||
virtual const char* NotificationTopic() const = 0;
|
||||
|
||||
virtual void NotifyChangedInternal(nsISupports* aSubject,
|
||||
|
@ -168,6 +166,10 @@ class CookieStorage : public nsIObserver, public nsSupportsWeakReference {
|
|||
|
||||
virtual void DeleteFromDB(mozIStorageBindingParamsArray* aParamsArray) = 0;
|
||||
|
||||
nsTHashtable<CookieEntry> mHostTable;
|
||||
|
||||
uint32_t mCookieCount;
|
||||
|
||||
private:
|
||||
void PrefChanged(nsIPrefBranch* aPrefBranch);
|
||||
|
||||
|
@ -187,6 +189,8 @@ class CookieStorage : public nsIObserver, public nsSupportsWeakReference {
|
|||
uint16_t aMaxNumberOfCookies,
|
||||
int64_t aCookiePurgeAge);
|
||||
|
||||
int64_t mCookieOldestTime;
|
||||
|
||||
uint16_t mMaxNumberOfCookies;
|
||||
uint16_t mMaxCookiesPerHost;
|
||||
uint16_t mCookieQuotaPerHost;
|
||||
|
@ -229,6 +233,9 @@ class CookiePrivateStorage final : public CookieStorage {
|
|||
|
||||
class CookieDefaultStorage final : public CookieStorage {
|
||||
public:
|
||||
// Result codes for TryInitDB() and Read().
|
||||
enum OpenDBResult { RESULT_OK, RESULT_RETRY, RESULT_FAILURE };
|
||||
|
||||
static already_AddRefed<CookieDefaultStorage> Create();
|
||||
|
||||
void HandleCorruptDB();
|
||||
|
@ -246,11 +253,30 @@ class CookieDefaultStorage final : public CookieStorage {
|
|||
|
||||
void Close() override;
|
||||
|
||||
void EnsureReadComplete();
|
||||
|
||||
void CleanupCachedStatements();
|
||||
void CleanupDefaultDBConnection();
|
||||
|
||||
nsresult ImportCookies(nsIFile* aCookieFile,
|
||||
nsIEffectiveTLDService* aTLDService);
|
||||
nsresult ImportCookies(nsIFile* aCookieFile);
|
||||
|
||||
void Activate();
|
||||
|
||||
void RebuildCorruptDB();
|
||||
void HandleDBClosed();
|
||||
|
||||
nsresult RunInTransaction(nsICookieTransactionCallback* aCallback);
|
||||
|
||||
// State of the database connection.
|
||||
enum CorruptFlag {
|
||||
OK, // normal
|
||||
CLOSING_FOR_REBUILD, // corruption detected, connection closing
|
||||
REBUILDING // close complete, rebuilding database from memory
|
||||
};
|
||||
|
||||
CorruptFlag GetCorruptFlag() const { return mCorruptFlag; }
|
||||
|
||||
void SetCorruptFlag(CorruptFlag aFlag) { mCorruptFlag = aFlag; }
|
||||
|
||||
protected:
|
||||
const char* NotificationTopic() const override { return "cookie-changed"; }
|
||||
|
@ -280,33 +306,56 @@ class CookieDefaultStorage final : public CookieStorage {
|
|||
void UpdateCookieInList(Cookie* aCookie, int64_t aLastAccessed,
|
||||
mozIStorageBindingParamsArray* aParamsArray);
|
||||
|
||||
// TODO: private:
|
||||
public:
|
||||
nsCOMPtr<nsIFile> cookieFile;
|
||||
nsCOMPtr<mozIStorageConnection> dbConn;
|
||||
nsCOMPtr<mozIStorageAsyncStatement> stmtInsert;
|
||||
nsCOMPtr<mozIStorageAsyncStatement> stmtDelete;
|
||||
nsCOMPtr<mozIStorageAsyncStatement> stmtUpdate;
|
||||
void InitDBConn();
|
||||
nsresult InitDBConnInternal();
|
||||
|
||||
// State of the database connection.
|
||||
enum CorruptFlag {
|
||||
OK, // normal
|
||||
CLOSING_FOR_REBUILD, // corruption detected, connection closing
|
||||
REBUILDING // close complete, rebuilding database from memory
|
||||
OpenDBResult TryInitDB(bool aDeleteExistingDB);
|
||||
OpenDBResult Read();
|
||||
|
||||
nsresult CreateTableWorker(const char* aName);
|
||||
nsresult CreateTable();
|
||||
nsresult CreateTableForSchemaVersion6();
|
||||
nsresult CreateTableForSchemaVersion5();
|
||||
|
||||
mozilla::UniquePtr<CookieStruct> GetCookieFromRow(mozIStorageStatement* aRow);
|
||||
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
nsCOMPtr<mozIStorageService> mStorageService;
|
||||
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
|
||||
|
||||
// encapsulates a (key, Cookie) tuple for temporary storage purposes.
|
||||
struct CookieDomainTuple {
|
||||
CookieKey key;
|
||||
OriginAttributes originAttributes;
|
||||
mozilla::UniquePtr<mozilla::net::CookieStruct> cookie;
|
||||
};
|
||||
|
||||
CorruptFlag corruptFlag;
|
||||
// thread
|
||||
mozilla::TimeStamp mEndInitDBConn;
|
||||
nsTArray<CookieDomainTuple> mReadArray;
|
||||
|
||||
mozilla::Monitor mMonitor;
|
||||
|
||||
mozilla::Atomic<bool> mInitialized;
|
||||
mozilla::Atomic<bool> mInitializedDBConn;
|
||||
|
||||
nsCOMPtr<nsIFile> mCookieFile;
|
||||
nsCOMPtr<mozIStorageConnection> mDBConn;
|
||||
nsCOMPtr<mozIStorageAsyncStatement> mStmtInsert;
|
||||
nsCOMPtr<mozIStorageAsyncStatement> mStmtDelete;
|
||||
nsCOMPtr<mozIStorageAsyncStatement> mStmtUpdate;
|
||||
|
||||
CorruptFlag mCorruptFlag;
|
||||
|
||||
// Various parts representing asynchronous read state. These are useful
|
||||
// while the background read is taking place.
|
||||
nsCOMPtr<mozIStorageConnection> syncConn;
|
||||
nsCOMPtr<mozIStorageStatement> stmtReadDomain;
|
||||
nsCOMPtr<mozIStorageConnection> mSyncConn;
|
||||
|
||||
// DB completion handlers.
|
||||
nsCOMPtr<mozIStorageStatementCallback> insertListener;
|
||||
nsCOMPtr<mozIStorageStatementCallback> updateListener;
|
||||
nsCOMPtr<mozIStorageStatementCallback> removeListener;
|
||||
nsCOMPtr<mozIStorageCompletionCallback> closeListener;
|
||||
nsCOMPtr<mozIStorageStatementCallback> mInsertListener;
|
||||
nsCOMPtr<mozIStorageStatementCallback> mUpdateListener;
|
||||
nsCOMPtr<mozIStorageStatementCallback> mRemoveListener;
|
||||
nsCOMPtr<mozIStorageCompletionCallback> mCloseListener;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -23,11 +23,9 @@
|
|||
#include "mozIStorageAsyncStatement.h"
|
||||
#include "mozIStorageConnection.h"
|
||||
#include "nsIFile.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
using mozilla::OriginAttributes;
|
||||
|
@ -41,7 +39,6 @@ class nsIURI;
|
|||
class nsIChannel;
|
||||
class nsIArray;
|
||||
class nsIThread;
|
||||
class mozIStorageService;
|
||||
class mozIThirdPartyUtil;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -52,13 +49,6 @@ class CookieServiceParent;
|
|||
|
||||
using mozilla::net::CookieKey;
|
||||
|
||||
// encapsulates a (key, Cookie) tuple for temporary storage purposes.
|
||||
struct CookieDomainTuple {
|
||||
CookieKey key;
|
||||
OriginAttributes originAttributes;
|
||||
mozilla::UniquePtr<mozilla::net::CookieStruct> cookie;
|
||||
};
|
||||
|
||||
// these constants represent an operation being performed on cookies
|
||||
enum CookieOperation { OPERATION_READ, OPERATION_WRITE };
|
||||
|
||||
|
@ -74,9 +64,6 @@ enum CookieStatus {
|
|||
STATUS_REJECTED_WITH_ERROR
|
||||
};
|
||||
|
||||
// Result codes for TryInitDB() and Read().
|
||||
enum OpenDBResult { RESULT_OK, RESULT_RETRY, RESULT_FAILURE };
|
||||
|
||||
/******************************************************************************
|
||||
* nsCookieService:
|
||||
* class declaration
|
||||
|
@ -161,19 +148,8 @@ class nsCookieService final : public nsICookieService,
|
|||
bool IsInitialized() const;
|
||||
|
||||
void InitCookieStorages();
|
||||
OpenDBResult TryInitDB(bool aDeleteExistingDB);
|
||||
void InitDBConn();
|
||||
nsresult InitDBConnInternal();
|
||||
nsresult CreateTableWorker(const char* aName);
|
||||
nsresult CreateTable();
|
||||
nsresult CreateTableForSchemaVersion6();
|
||||
nsresult CreateTableForSchemaVersion5();
|
||||
void CloseCookieStorages();
|
||||
void HandleDBClosed(mozilla::net::CookieDefaultStorage* aCookieStorage);
|
||||
void RebuildCorruptDB(mozilla::net::CookieDefaultStorage* aCookieStorage);
|
||||
OpenDBResult Read();
|
||||
mozilla::UniquePtr<mozilla::net::CookieStruct> GetCookieFromRow(
|
||||
mozIStorageStatement* aRow);
|
||||
|
||||
void EnsureReadComplete(bool aInitDBConn);
|
||||
nsresult NormalizeHost(nsCString& aHost);
|
||||
nsresult GetCookieStringCommon(nsIURI* aHostURI, nsIChannel* aChannel,
|
||||
|
@ -255,21 +231,12 @@ class nsCookieService final : public nsICookieService,
|
|||
nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
|
||||
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
|
||||
nsCOMPtr<nsIIDNService> mIDNService;
|
||||
nsCOMPtr<mozIStorageService> mStorageService;
|
||||
|
||||
// we have two separate Cookie Storages: one for normal browsing and one for
|
||||
// private browsing.
|
||||
RefPtr<mozilla::net::CookieDefaultStorage> mDefaultStorage;
|
||||
RefPtr<mozilla::net::CookiePrivateStorage> mPrivateStorage;
|
||||
|
||||
// thread
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
mozilla::Monitor mMonitor;
|
||||
mozilla::Atomic<bool> mInitializedCookieStorages;
|
||||
mozilla::Atomic<bool> mInitializedDBConn;
|
||||
mozilla::TimeStamp mEndInitDBConn;
|
||||
nsTArray<CookieDomainTuple> mReadArray;
|
||||
|
||||
// friends!
|
||||
friend class DBListenerErrorHandler;
|
||||
friend class CloseCookieDBListener;
|
||||
|
|
Загрузка…
Ссылка в новой задаче