Backed out 8 changesets (bug 1513937, bug 1546310, bug 1548788, bug 1547688, bug 1547452, bug 1540777, bug 1542669, bug 1547454) for causing bug 1549362.

Backed out changeset 8dca7df29492 (bug 1548788)
Backed out changeset 688f361e8bb6 (bug 1547688)
Backed out changeset b5d8d57838a3 (bug 1540777)
Backed out changeset d1bd31177b14 (bug 1513937)
Backed out changeset df97dfbb526a (bug 1546310)
Backed out changeset ade08d6dc361 (bug 1547454)
Backed out changeset b622431054b7 (bug 1547452)
Backed out changeset ad73e5604411 (bug 1542669)
This commit is contained in:
Ryan VanderMeulen 2019-05-06 09:02:54 -04:00
Родитель 0b3e8675a7
Коммит 4f044a29d2
27 изменённых файлов: 391 добавлений и 1540 удалений

3
dom/cache/Context.cpp поставляемый
Просмотреть файл

@ -389,7 +389,8 @@ Context::QuotaInitRunnable::Run() {
MOZ_DIAGNOSTIC_ASSERT(qm);
nsresult rv = qm->EnsureOriginIsInitialized(
PERSISTENCE_TYPE_DEFAULT, mQuotaInfo.mSuffix, mQuotaInfo.mGroup,
mQuotaInfo.mOrigin, getter_AddRefs(mQuotaInfo.mDir));
mQuotaInfo.mOrigin,
/* aCreateIfNotExists */ true, getter_AddRefs(mQuotaInfo.mDir));
if (NS_FAILED(rv)) {
resolver->Resolve(rv);
break;

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

@ -17159,7 +17159,8 @@ nsresult Maintenance::DirectoryWork() {
// Ensure origin is initialized first. It will initialize all origins
// for temporary storage including IDB origins.
rv = quotaManager->EnsureOriginIsInitialized(
persistenceType, suffix, group, origin, getter_AddRefs(directory));
persistenceType, suffix, group, origin,
/* aCreateIfNotExists */ true, getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -19868,7 +19869,8 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
nsCOMPtr<nsIFile> dbDirectory;
nsresult rv = quotaManager->EnsureOriginIsInitialized(
persistenceType, mSuffix, mGroup, mOrigin, getter_AddRefs(dbDirectory));
persistenceType, mSuffix, mGroup, mOrigin,
/* aCreateIfNotExists */ true, getter_AddRefs(dbDirectory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -70,9 +70,9 @@ mozilla::ipc::IPCResult LSDatabaseChild::RecvRequestAllowToClose() {
}
PBackgroundLSSnapshotChild* LSDatabaseChild::AllocPBackgroundLSSnapshotChild(
const nsString& aDocumentURI, const nsString& aKey,
const bool& aIncreasePeakUsage, const int64_t& aRequestedSize,
const int64_t& aMinSize, LSSnapshotInitInfo* aInitInfo) {
const nsString& aDocumentURI, const bool& aIncreasePeakUsage,
const int64_t& aRequestedSize, const int64_t& aMinSize,
LSSnapshotInitInfo* aInitInfo) {
MOZ_CRASH("PBackgroundLSSnapshotChild actor should be manually constructed!");
}
@ -126,7 +126,7 @@ void LSObserverChild::ActorDestroy(ActorDestroyReason aWhy) {
mozilla::ipc::IPCResult LSObserverChild::RecvObserve(
const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
const nsString& aDocumentURI, const nsString& aKey,
const LSValue& aOldValue, const LSValue& aNewValue) {
const nsString& aOldValue, const nsString& aNewValue) {
AssertIsOnOwningThread();
if (!mObserver) {
@ -140,8 +140,8 @@ mozilla::ipc::IPCResult LSObserverChild::RecvObserve(
return IPC_FAIL_NO_REASON(this);
}
Storage::NotifyChange(/* aStorage */ nullptr, principal, aKey,
aOldValue.AsString(), aNewValue.AsString(),
Storage::NotifyChange(/* aStorage */ nullptr, principal, aKey, aOldValue,
aNewValue,
/* aStorageType */ kLocalStorageType, aDocumentURI,
/* aIsPrivate */ !!aPrivateBrowsingId,
/* aImmediateDispatch */ true);

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

@ -78,9 +78,9 @@ class LSDatabaseChild final : public PBackgroundLSDatabaseChild {
mozilla::ipc::IPCResult RecvRequestAllowToClose() override;
PBackgroundLSSnapshotChild* AllocPBackgroundLSSnapshotChild(
const nsString& aDocumentURI, const nsString& aKey,
const bool& aIncreasePeakUsage, const int64_t& aRequestedSize,
const int64_t& aMinSize, LSSnapshotInitInfo* aInitInfo) override;
const nsString& aDocumentURI, const bool& aIncreasePeakUsage,
const int64_t& aRequestedSize, const int64_t& aMinSize,
LSSnapshotInitInfo* aInitInfo) override;
bool DeallocPBackgroundLSSnapshotChild(
PBackgroundLSSnapshotChild* aActor) override;
@ -124,8 +124,8 @@ class LSObserverChild final : public PBackgroundLSObserverChild {
const uint32_t& aPrivateBrowsingId,
const nsString& aDocumentURI,
const nsString& aKey,
const LSValue& aOldValue,
const LSValue& aNewValue) override;
const nsString& aOldValue,
const nsString& aNewValue) override;
};
/**

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -120,7 +120,7 @@ nsresult LSDatabase::GetLength(LSObject* aObject, uint32_t* aResult) {
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, VoidString());
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -140,7 +140,7 @@ nsresult LSDatabase::GetKey(LSObject* aObject, uint32_t aIndex,
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, VoidString());
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -160,7 +160,7 @@ nsresult LSDatabase::GetItem(LSObject* aObject, const nsAString& aKey,
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, aKey);
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -179,7 +179,7 @@ nsresult LSDatabase::GetKeys(LSObject* aObject, nsTArray<nsString>& aKeys) {
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, VoidString());
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -200,7 +200,7 @@ nsresult LSDatabase::SetItem(LSObject* aObject, const nsAString& aKey,
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, aKey);
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -220,7 +220,7 @@ nsresult LSDatabase::RemoveItem(LSObject* aObject, const nsAString& aKey,
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, aKey);
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -239,7 +239,7 @@ nsresult LSDatabase::Clear(LSObject* aObject, LSNotifyInfo& aNotifyInfo) {
MOZ_ASSERT(mActor);
MOZ_ASSERT(!mAllowedToClose);
nsresult rv = EnsureSnapshot(aObject, VoidString());
nsresult rv = EnsureSnapshot(aObject);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -262,7 +262,7 @@ nsresult LSDatabase::BeginExplicitSnapshot(LSObject* aObject) {
return NS_ERROR_ALREADY_INITIALIZED;
}
nsresult rv = EnsureSnapshot(aObject, VoidString(), /* aExplicit */ true);
nsresult rv = EnsureSnapshot(aObject, /* aExplicit */ true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -290,8 +290,7 @@ nsresult LSDatabase::EndExplicitSnapshot(LSObject* aObject) {
return NS_OK;
}
nsresult LSDatabase::EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
bool aExplicit) {
nsresult LSDatabase::EnsureSnapshot(LSObject* aObject, bool aExplicit) {
MOZ_ASSERT(aObject);
MOZ_ASSERT(mActor);
MOZ_ASSERT_IF(mSnapshot, !aExplicit);
@ -307,7 +306,7 @@ nsresult LSDatabase::EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
LSSnapshotInitInfo initInfo;
bool ok = mActor->SendPBackgroundLSSnapshotConstructor(
actor, aObject->DocumentURI(), nsString(aKey),
actor, aObject->DocumentURI(),
/* increasePeakUsage */ true,
/* requestedSize */ 131072,
/* minSize */ 4096, &initInfo);
@ -318,7 +317,7 @@ nsresult LSDatabase::EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
snapshot->SetActor(actor);
// This add refs snapshot.
nsresult rv = snapshot->Init(aKey, initInfo, aExplicit);
nsresult rv = snapshot->Init(initInfo, aExplicit);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -79,8 +79,7 @@ class LSDatabase final {
private:
~LSDatabase();
nsresult EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
bool aExplicit = false);
nsresult EnsureSnapshot(LSObject* aObject, bool aExplicit = false);
void AllowToClose();
};

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

@ -59,8 +59,7 @@ void LSSnapshot::SetActor(LSSnapshotChild* aActor) {
mActor = aActor;
}
nsresult LSSnapshot::Init(const nsAString& aKey,
const LSSnapshotInitInfo& aInitInfo, bool aExplicit) {
nsresult LSSnapshot::Init(const LSSnapshotInitInfo& aInitInfo, bool aExplicit) {
AssertIsOnOwningThread();
MOZ_ASSERT(!mSelfRef);
MOZ_ASSERT(mActor);
@ -76,19 +75,16 @@ nsresult LSSnapshot::Init(const nsAString& aKey,
for (uint32_t i = 0; i < itemInfos.Length(); i++) {
const LSItemInfo& itemInfo = itemInfos[i];
const LSValue& value = itemInfo.value();
const nsString& value = itemInfo.value();
if (loadState != LoadState::AllOrderedItems && !value.IsVoid()) {
mLoadedItems.PutEntry(itemInfo.key());
}
mValues.Put(itemInfo.key(), value.AsString());
mValues.Put(itemInfo.key(), value);
}
if (loadState == LoadState::Partial) {
if (aInitInfo.addKeyToUnknownItems()) {
mUnknownItems.PutEntry(aKey);
}
mInitLength = aInitInfo.totalLength();
mLength = mInitLength;
} else if (loadState == LoadState::AllOrderedKeys) {
@ -243,8 +239,8 @@ nsresult LSSnapshot::SetItem(const nsAString& aKey, const nsAString& aValue,
LSSetItemInfo setItemInfo;
setItemInfo.key() = aKey;
setItemInfo.oldValue() = LSValue(oldValue);
setItemInfo.value() = LSValue(aValue);
setItemInfo.oldValue() = oldValue;
setItemInfo.value() = aValue;
mWriteInfos.AppendElement(std::move(setItemInfo));
}
@ -289,7 +285,7 @@ nsresult LSSnapshot::RemoveItem(const nsAString& aKey,
LSRemoveItemInfo removeItemInfo;
removeItemInfo.key() = aKey;
removeItemInfo.oldValue() = LSValue(oldValue);
removeItemInfo.oldValue() = oldValue;
mWriteInfos.AppendElement(std::move(removeItemInfo));
}
@ -436,15 +432,12 @@ nsresult LSSnapshot::GetItemInternal(const nsAString& aKey,
} else if (mLoadedItems.GetEntry(aKey) || mUnknownItems.GetEntry(aKey)) {
result.SetIsVoid(true);
} else {
LSValue value;
nsTArray<LSItemInfo> itemInfos;
if (NS_WARN_IF(!mActor->SendLoadValueAndMoreItems(
nsString(aKey), &value, &itemInfos))) {
nsString(aKey), &result, &itemInfos))) {
return NS_ERROR_FAILURE;
}
result = value.AsString();
if (result.IsVoid()) {
mUnknownItems.PutEntry(aKey);
} else {
@ -458,7 +451,7 @@ nsresult LSSnapshot::GetItemInternal(const nsAString& aKey,
const LSItemInfo& itemInfo = itemInfos[i];
mLoadedItems.PutEntry(itemInfo.key());
mValues.Put(itemInfo.key(), itemInfo.value().AsString());
mValues.Put(itemInfo.key(), itemInfo.value());
}
if (mLoadedItems.Count() == mInitLength) {
@ -484,15 +477,12 @@ nsresult LSSnapshot::GetItemInternal(const nsAString& aKey,
case LoadState::AllOrderedKeys: {
if (mValues.Get(aKey, &result)) {
if (result.IsVoid()) {
LSValue value;
nsTArray<LSItemInfo> itemInfos;
if (NS_WARN_IF(!mActor->SendLoadValueAndMoreItems(
nsString(aKey), &value, &itemInfos))) {
nsString(aKey), &result, &itemInfos))) {
return NS_ERROR_FAILURE;
}
result = value.AsString();
MOZ_ASSERT(!result.IsVoid());
mLoadedItems.PutEntry(aKey);
@ -504,7 +494,7 @@ nsresult LSSnapshot::GetItemInternal(const nsAString& aKey,
const LSItemInfo& itemInfo = itemInfos[i];
mLoadedItems.PutEntry(itemInfo.key());
mValues.Put(itemInfo.key(), itemInfo.value().AsString());
mValues.Put(itemInfo.key(), itemInfo.value());
}
if (mLoadedItems.Count() == mInitLength) {

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

@ -7,8 +7,6 @@
#ifndef mozilla_dom_localstorage_LSSnapshot_h
#define mozilla_dom_localstorage_LSSnapshot_h
#include "LSValue.h"
namespace mozilla {
namespace dom {
@ -114,8 +112,7 @@ class LSSnapshot final : public nsIRunnable {
bool Explicit() const { return mExplicit; }
nsresult Init(const nsAString& aKey, const LSSnapshotInitInfo& aInitInfo,
bool aExplicit);
nsresult Init(const LSSnapshotInitInfo& aInitInfo, bool aExplicit);
nsresult GetLength(uint32_t* aResult);

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

@ -1,19 +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/. */
#include "LSValue.h"
namespace mozilla {
namespace dom {
const LSValue& VoidLSValue() {
static const LSValue sVoidLSValue(VoidCString(), 0, false);
return sVoidLSValue;
}
} // namespace dom
} // namespace mozilla

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

@ -1,123 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=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 mozilla_dom_localstorage_LSValue_h
#define mozilla_dom_localstorage_LSValue_h
#include "SnappyUtils.h"
namespace mozilla {
namespace dom {
/**
* Represents a LocalStorage value. From content's perspective, values (if
* present) are always DOMStrings. This is also true from a quota-tracking
* perspective. However, for memory and disk efficiency it's preferable to store
* the value in alternate compressed or utf-8 encoding representations. The
* LSValue type exists to support these alternate representations, dynamically
* decompressing/re-encoding to utf-16 while still tracking value size on a
* utf-16 basis for quota purposes.
*/
class LSValue final {
friend struct IPC::ParamTraits<LSValue>;
nsCString mBuffer;
uint32_t mUTF16Length;
bool mCompressed;
public:
LSValue() : mUTF16Length(0), mCompressed(false) {}
explicit LSValue(const nsACString& aBuffer, uint32_t aUTF16Length,
bool aCompressed)
: mBuffer(aBuffer),
mUTF16Length(aUTF16Length),
mCompressed(aCompressed) {}
explicit LSValue(const nsAString& aBuffer) : mUTF16Length(aBuffer.Length()) {
if (aBuffer.IsVoid()) {
mBuffer.SetIsVoid(true);
mCompressed = false;
} else {
CopyUTF16toUTF8(aBuffer, mBuffer);
nsCString buffer;
if ((mCompressed = SnappyCompress(mBuffer, buffer))) {
mBuffer = buffer;
}
}
}
bool IsVoid() const { return mBuffer.IsVoid(); }
void SetIsVoid(bool aVal) { mBuffer.SetIsVoid(aVal); }
/**
* This represents the "physical" length that the parent process uses for
* the size of value/item computation. This can also be used to see how much
* memory the value is using at rest or what the cost is for sending the value
* over IPC.
*/
uint32_t Length() const { return mBuffer.Length(); }
/*
* This represents the "logical" length that content sees and that is also
* used for quota management purposes.
*/
uint32_t UTF16Length() const { return mUTF16Length; }
bool IsCompressed() const { return mCompressed; }
bool Equals(const LSValue& aOther) const {
return mBuffer == aOther.mBuffer &&
mBuffer.IsVoid() == aOther.mBuffer.IsVoid() &&
mUTF16Length == aOther.mUTF16Length &&
mCompressed == aOther.mCompressed;
}
bool operator==(const LSValue& aOther) const { return Equals(aOther); }
bool operator!=(const LSValue& aOther) const { return !Equals(aOther); }
operator const nsCString&() const { return mBuffer; }
operator Span<const char>() const { return mBuffer; }
class Converter {
nsString mBuffer;
public:
explicit Converter(const LSValue& aValue) {
if (aValue.mBuffer.IsVoid()) {
mBuffer.SetIsVoid(true);
} else if (aValue.mCompressed) {
nsCString buffer;
MOZ_ALWAYS_TRUE(SnappyUncompress(aValue.mBuffer, buffer));
CopyUTF8toUTF16(buffer, mBuffer);
} else {
CopyUTF8toUTF16(aValue.mBuffer, mBuffer);
}
}
Converter(Converter&& aOther) : mBuffer(aOther.mBuffer) {}
~Converter() {}
operator const nsString&() const { return mBuffer; }
private:
Converter() = delete;
Converter(const Converter&) = delete;
Converter& operator=(const Converter&) = delete;
Converter& operator=(const Converter&&) = delete;
};
Converter AsString() const { return Converter(const_cast<LSValue&>(*this)); }
};
const LSValue& VoidLSValue();
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_localstorage_LSValue_h

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

@ -22,14 +22,6 @@ namespace dom {
*/
struct LSSnapshotInitInfo
{
/**
* Boolean indicating whether the `key` provided as an argument to the
* PBackgroundLSSnapshot constructor did not exist in the Datastore and should
* be treated as an unknown and therefore undefined value. Note that `key` may
* have been provided as a void string, in which case this value is forced to
* be false.
*/
bool addKeyToUnknownItems;
/**
* As many key/value or key/void pairs as the snapshot prefill byte budget
* allowed.
@ -107,20 +99,11 @@ parent:
* consult any other threads or perform any I/O. Additionally, the response
* is explicitly bounded in size by the tunable snapshot prefill byte limit.
*
* @param key
* If key is non-void, then the snapshot is being triggered by a direct
* access to a localStorage key (get, set, or removal, with set/removal
* requiring the old value in order to properly populate the "storage"
* event), the key being requested. It's possible the key is not present in
* localStorage, in which case LSSnapshotInitInfo::addKeyToUnknownItems will
* be true indicating that there is no such key/value pair, otherwise it
* will be false.
* @param increasePeakUsage
* Whether the parent should attempt to pre-allocate some amount of quota
* usage to the Snapshot.
*/
sync PBackgroundLSSnapshot(nsString documentURI,
nsString key,
bool increasePeakUsage,
int64_t requestedSize,
int64_t minSize)

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

@ -6,11 +6,6 @@ include protocol PBackground;
include PBackgroundSharedTypes;
include "mozilla/dom/localstorage/SerializationHelpers.h";
using mozilla::dom::LSValue
from "mozilla/dom/LSValue.h";
namespace mozilla {
namespace dom {
@ -54,8 +49,8 @@ child:
uint32_t privateBrowsingId,
nsString documentURI,
nsString key,
LSValue oldValue,
LSValue newValue);
nsString oldValue,
nsString newValue);
};
} // namespace dom

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

@ -5,11 +5,6 @@
include PBackgroundSharedTypes;
include ProtocolTypes;
include "mozilla/dom/localstorage/SerializationHelpers.h";
using mozilla::dom::LSValue
from "mozilla/dom/LSValue.h";
namespace mozilla {
namespace dom {
@ -62,7 +57,7 @@ union LSSimpleRequestParams
struct LSItemInfo
{
nsString key;
LSValue value;
nsString value;
};
} // namespace dom

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

@ -7,25 +7,20 @@ include protocol PBackgroundLSDatabase;
include PBackgroundLSSharedTypes;
include "mozilla/dom/localstorage/SerializationHelpers.h";
using mozilla::dom::LSValue
from "mozilla/dom/LSValue.h";
namespace mozilla {
namespace dom {
struct LSSetItemInfo
{
nsString key;
LSValue oldValue;
LSValue value;
nsString oldValue;
nsString value;
};
struct LSRemoveItemInfo
{
nsString key;
LSValue oldValue;
nsString oldValue;
};
struct LSClearInfo
@ -66,7 +61,7 @@ parent:
* consult any other threads or perform any I/O.
*/
sync LoadValueAndMoreItems(nsString key)
returns (LSValue value, LSItemInfo[] itemInfos);
returns (nsString value, LSItemInfo[] itemInfos);
/**
* Invoked on demand to load all keys in in their canonical order if they

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

@ -10,7 +10,6 @@
#include "ipc/IPCMessageUtils.h"
#include "mozilla/dom/LSSnapshot.h"
#include "mozilla/dom/LSValue.h"
namespace IPC {
@ -21,30 +20,6 @@ struct ParamTraits<mozilla::dom::LSSnapshot::LoadState>
mozilla::dom::LSSnapshot::LoadState::Initial,
mozilla::dom::LSSnapshot::LoadState::EndGuard> {};
template <>
struct ParamTraits<mozilla::dom::LSValue> {
typedef mozilla::dom::LSValue paramType;
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mBuffer);
WriteParam(aMsg, aParam.mUTF16Length);
WriteParam(aMsg, aParam.mCompressed);
}
static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->mBuffer) &&
ReadParam(aMsg, aIter, &aResult->mUTF16Length) &&
ReadParam(aMsg, aIter, &aResult->mCompressed);
}
static void Log(const paramType& aParam, std::wstring* aLog) {
LogParam(aParam.mBuffer, aLog);
LogParam(aParam.mUTF16Length, aLog);
LogParam(aParam.mCompressed, aLog);
}
};
} // namespace IPC
#endif // mozilla_dom_localstorage_SerializationHelpers_h

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

@ -1,63 +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/. */
#include "SnappyUtils.h"
#include "snappy/snappy.h"
namespace mozilla {
namespace dom {
bool SnappyCompress(const nsACString& aSource, nsACString& aDest) {
MOZ_ASSERT(!aSource.IsVoid());
size_t uncompressedLength = aSource.Length();
if (uncompressedLength <= 16) {
return false;
}
size_t compressedLength = snappy::MaxCompressedLength(uncompressedLength);
aDest.SetLength(compressedLength);
snappy::RawCompress(aSource.BeginReading(), uncompressedLength,
aDest.BeginWriting(), &compressedLength);
if (compressedLength >= uncompressedLength) {
return false;
}
aDest.SetLength(compressedLength);
return true;
}
bool SnappyUncompress(const nsACString& aSource, nsACString& aDest) {
MOZ_ASSERT(!aSource.IsVoid());
const char* compressed = aSource.BeginReading();
size_t compressedLength = aSource.Length();
size_t uncompressedLength;
if (!snappy::GetUncompressedLength(compressed, compressedLength,
&uncompressedLength)) {
return false;
}
aDest.SetLength(uncompressedLength);
if (!snappy::RawUncompress(compressed, compressedLength,
aDest.BeginWriting())) {
return false;
}
return true;
}
} // namespace dom
} // namespace mozilla

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

@ -1,20 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=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 mozilla_dom_localstorage_SnappyUtils_h
#define mozilla_dom_localstorage_SnappyUtils_h
namespace mozilla {
namespace dom {
bool SnappyCompress(const nsACString& aSource, nsACString& aDest);
bool SnappyUncompress(const nsACString& aSource, nsACString& aDest);
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_localstorage_SnappyUtils_h

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

@ -34,8 +34,6 @@ EXPORTS.mozilla.dom += [
'LSObject.h',
'LSObserver.h',
'LSSnapshot.h',
'LSValue.h',
'SnappyUtils.h',
]
UNIFIED_SOURCES += [
@ -47,9 +45,7 @@ UNIFIED_SOURCES += [
'LSObject.cpp',
'LSObserver.cpp',
'LSSnapshot.cpp',
'LSValue.cpp',
'ReportInternalError.cpp',
'SnappyUtils.cpp',
]
IPDL_SOURCES += [

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

@ -218,7 +218,7 @@ const char kResourceOriginPrefix[] = "resource://";
#define LS_ARCHIVE_FILE_NAME "ls-archive.sqlite"
#define LS_ARCHIVE_TMP_FILE_NAME "ls-archive-tmp.sqlite"
const uint32_t kLocalStorageArchiveVersion = 3;
const uint32_t kLocalStorageArchiveVersion = 1;
const char kProfileDoChangeTopic[] = "profile-do-change";
@ -446,6 +446,7 @@ nsresult LoadLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
return NS_OK;
}
/*
nsresult SaveLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
uint32_t aVersion) {
AssertIsOnIOThread();
@ -471,6 +472,7 @@ nsresult SaveLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
return NS_OK;
}
*/
/******************************************************************************
* Quota manager class declarations
@ -613,20 +615,10 @@ class OriginInfo final {
public:
OriginInfo(GroupInfo* aGroupInfo, const nsACString& aOrigin, uint64_t aUsage,
int64_t aAccessTime, bool aPersisted, bool aDirectoryExists);
int64_t aAccessTime, bool aPersisted);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OriginInfo)
GroupInfo* GetGroupInfo() const { return mGroupInfo; }
const nsCString& Origin() const { return mOrigin; }
int64_t LockedUsage() const {
AssertCurrentThreadOwnsQuotaMutex();
return mUsage;
}
int64_t LockedAccessTime() const {
AssertCurrentThreadOwnsQuotaMutex();
@ -664,19 +656,6 @@ class OriginInfo final {
uint64_t mUsage;
int64_t mAccessTime;
bool mPersisted;
/**
* In some special cases like the LocalStorage client where it's possible to
* create a Quota-using representation but not actually write any data, we
* want to be able to track quota for an origin without creating its origin
* directory or the per-client files until they are actually needed to store
* data. In those cases, the OriginInfo will be created by
* EnsureQuotaForOrigin and the resulting mDirectoryExists will be false until
* the origin actually needs to be created. It is possible for mUsage to be
* greater than zero while mDirectoryExists is false, representing a state
* where a client like LocalStorage has reserved quota for disk writes, but
* has not yet flushed the data to disk.
*/
bool mDirectoryExists;
};
class OriginInfoLRUComparator {
@ -712,8 +691,6 @@ class GroupInfo final {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GroupInfo)
PersistenceType GetPersistenceType() const { return mPersistenceType; }
private:
// Private destructor, to discourage deletion outside of Release():
~GroupInfo() { MOZ_COUNT_DTOR(GroupInfo); }
@ -1149,12 +1126,6 @@ class GetUsageOp final : public QuotaUsageRequestBase,
private:
~GetUsageOp() {}
void ProcessOriginInternal(QuotaManager* aQuotaManager,
const PersistenceType aPersistenceType,
const nsACString& aOrigin,
const int64_t aTimestamp, const bool aPersisted,
const uint64_t aUsage);
nsresult DoDirectoryWork(QuotaManager* aQuotaManager) override;
bool IsCanceled() override;
@ -2255,21 +2226,26 @@ nsresult CreateDirectoryMetadataFiles(nsIFile* aDirectory, bool aPersisted,
const nsACString& aSuffix,
const nsACString& aGroup,
const nsACString& aOrigin,
int64_t aTimestamp) {
int64_t* aTimestamp) {
AssertIsOnIOThread();
int64_t timestamp = PR_Now();
nsresult rv =
CreateDirectoryMetadata(aDirectory, aTimestamp, aSuffix, aGroup, aOrigin);
CreateDirectoryMetadata(aDirectory, timestamp, aSuffix, aGroup, aOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = CreateDirectoryMetadata2(aDirectory, aTimestamp, aPersisted, aSuffix,
rv = CreateDirectoryMetadata2(aDirectory, timestamp, aPersisted, aSuffix,
aGroup, aOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (aTimestamp) {
*aTimestamp = timestamp;
}
return NS_OK;
}
@ -3411,28 +3387,6 @@ uint64_t QuotaManager::CollectOriginsForEviction(
return 0;
}
template <typename P>
void QuotaManager::CollectPendingOriginsForListing(P aPredicate) {
MutexAutoLock lock(mQuotaMutex);
for (auto iter = mGroupInfoPairs.Iter(); !iter.Done(); iter.Next()) {
GroupInfoPair* pair = iter.UserData();
MOZ_ASSERT(!iter.Key().IsEmpty());
MOZ_ASSERT(pair);
RefPtr<GroupInfo> groupInfo =
pair->LockedGetGroupInfo(PERSISTENCE_TYPE_DEFAULT);
if (groupInfo) {
for (RefPtr<OriginInfo>& originInfo : groupInfo->mOriginInfos) {
if (!originInfo->mDirectoryExists) {
aPredicate(originInfo);
}
}
}
}
}
nsresult QuotaManager::Init(const nsAString& aBasePath) {
mBasePath = aBasePath;
@ -3569,66 +3523,24 @@ void QuotaManager::InitQuotaForOrigin(PersistenceType aPersistenceType,
MutexAutoLock lock(mQuotaMutex);
RefPtr<GroupInfo> groupInfo =
LockedGetOrCreateGroupInfo(aPersistenceType, aGroup);
GroupInfoPair* pair;
if (!mGroupInfoPairs.Get(aGroup, &pair)) {
pair = new GroupInfoPair();
mGroupInfoPairs.Put(aGroup, pair);
// The hashtable is now responsible to delete the GroupInfoPair.
}
RefPtr<GroupInfo> groupInfo = pair->LockedGetGroupInfo(aPersistenceType);
if (!groupInfo) {
groupInfo = new GroupInfo(pair, aPersistenceType, aGroup);
pair->LockedSetGroupInfo(aPersistenceType, groupInfo);
}
RefPtr<OriginInfo> originInfo =
new OriginInfo(groupInfo, aOrigin, aUsageBytes, aAccessTime, aPersisted,
/* aDirectoryExists */ true);
new OriginInfo(groupInfo, aOrigin, aUsageBytes, aAccessTime, aPersisted);
groupInfo->LockedAddOriginInfo(originInfo);
}
void QuotaManager::EnsureQuotaForOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin) {
AssertIsOnIOThread();
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
MutexAutoLock lock(mQuotaMutex);
RefPtr<GroupInfo> groupInfo =
LockedGetOrCreateGroupInfo(aPersistenceType, aGroup);
RefPtr<OriginInfo> originInfo = groupInfo->LockedGetOriginInfo(aOrigin);
if (!originInfo) {
originInfo = new OriginInfo(
groupInfo, aOrigin, /* aUsageBytes */ 0, /* aAccessTime */ PR_Now(),
/* aPersisted */ false, /* aDirectoryExists */ false);
groupInfo->LockedAddOriginInfo(originInfo);
}
}
void QuotaManager::NoteOriginDirectoryCreated(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin,
bool aPersisted,
int64_t& aTimestamp) {
AssertIsOnIOThread();
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
int64_t timestamp;
MutexAutoLock lock(mQuotaMutex);
RefPtr<GroupInfo> groupInfo =
LockedGetOrCreateGroupInfo(aPersistenceType, aGroup);
RefPtr<OriginInfo> originInfo = groupInfo->LockedGetOriginInfo(aOrigin);
if (originInfo) {
originInfo->mPersisted = aPersisted;
originInfo->mDirectoryExists = true;
timestamp = originInfo->LockedAccessTime();
} else {
timestamp = PR_Now();
RefPtr<OriginInfo> originInfo = new OriginInfo(
groupInfo, aOrigin, /* aUsageBytes */ 0, /* aAccessTime */ timestamp,
aPersisted, /* aDirectoryExists */ true);
groupInfo->LockedAddOriginInfo(originInfo);
}
aTimestamp = timestamp;
}
void QuotaManager::DecreaseUsageForOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin,
@ -5349,6 +5261,7 @@ nsresult QuotaManager::UpgradeLocalStorageArchiveFrom0To1(
return NS_OK;
}
/*
nsresult QuotaManager::UpgradeLocalStorageArchiveFrom1To2(
nsCOMPtr<mozIStorageConnection>& aConnection) {
nsresult rv = SaveLocalStorageArchiveVersion(aConnection, 2);
@ -5358,16 +5271,7 @@ nsresult QuotaManager::UpgradeLocalStorageArchiveFrom1To2(
return NS_OK;
}
nsresult QuotaManager::UpgradeLocalStorageArchiveFrom2To3(
nsCOMPtr<mozIStorageConnection>& aConnection) {
nsresult rv = SaveLocalStorageArchiveVersion(aConnection, 3);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
*/
#ifdef DEBUG
@ -5591,18 +5495,17 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
return rv;
}
} else {
static_assert(kLocalStorageArchiveVersion == 3,
static_assert(kLocalStorageArchiveVersion == 1,
"Upgrade function needed due to LocalStorage archive "
"version increase.");
while (version != kLocalStorageArchiveVersion) {
if (version == 0) {
rv = UpgradeLocalStorageArchiveFrom0To1(connection);
} else if (version == 1) {
} /* else if (version == 1) {
rv = UpgradeLocalStorageArchiveFrom1To2(connection);
} else if (version == 2) {
rv = UpgradeLocalStorageArchiveFrom2To3(connection);
} else {
} */
else {
QM_WARNING(
"Unable to initialize LocalStorage archive, no upgrade path is "
"available!");
@ -5719,15 +5622,19 @@ void QuotaManager::OpenDirectoryInternal(
nsresult QuotaManager::EnsureOriginIsInitialized(
PersistenceType aPersistenceType, const nsACString& aSuffix,
const nsACString& aGroup, const nsACString& aOrigin, nsIFile** aDirectory) {
const nsACString& aGroup, const nsACString& aOrigin,
bool aCreateIfNotExists, nsIFile** aDirectory) {
AssertIsOnIOThread();
MOZ_ASSERT(aDirectory);
nsCOMPtr<nsIFile> directory;
bool created;
nsresult rv = EnsureOriginIsInitializedInternal(
aPersistenceType, aSuffix, aGroup, aOrigin, getter_AddRefs(directory),
&created);
aPersistenceType, aSuffix, aGroup, aOrigin, aCreateIfNotExists,
getter_AddRefs(directory), &created);
if (rv == NS_ERROR_NOT_AVAILABLE) {
return rv;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -5738,8 +5645,8 @@ nsresult QuotaManager::EnsureOriginIsInitialized(
nsresult QuotaManager::EnsureOriginIsInitializedInternal(
PersistenceType aPersistenceType, const nsACString& aSuffix,
const nsACString& aGroup, const nsACString& aOrigin, nsIFile** aDirectory,
bool* aCreated) {
const nsACString& aGroup, const nsACString& aOrigin,
bool aCreateIfNotExists, nsIFile** aDirectory, bool* aCreated) {
AssertIsOnIOThread();
MOZ_ASSERT(aDirectory);
MOZ_ASSERT(aCreated);
@ -5767,7 +5674,10 @@ nsresult QuotaManager::EnsureOriginIsInitializedInternal(
}
bool created;
rv = EnsureOriginDirectory(directory, &created);
rv = EnsureOriginDirectory(directory, aCreateIfNotExists, &created);
if (rv == NS_ERROR_NOT_AVAILABLE) {
return rv;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -5775,11 +5685,9 @@ nsresult QuotaManager::EnsureOriginIsInitializedInternal(
int64_t timestamp;
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
if (created) {
timestamp = PR_Now();
rv = CreateDirectoryMetadataFiles(directory,
/* aPersisted */ true, aSuffix, aGroup,
aOrigin, timestamp);
aOrigin, &timestamp);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -5800,15 +5708,17 @@ nsresult QuotaManager::EnsureOriginIsInitializedInternal(
mInitializedOrigins.AppendElement(aOrigin);
} else if (created) {
NoteOriginDirectoryCreated(aPersistenceType, aGroup, aOrigin,
/* aPersisted */ false, timestamp);
rv = CreateDirectoryMetadataFiles(directory,
/* aPersisted */ false, aSuffix, aGroup,
aOrigin, timestamp);
aOrigin, &timestamp);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Don't need to traverse the directory, since it's empty.
InitQuotaForOrigin(aPersistenceType, aGroup, aOrigin,
/* aUsageBytes */ 0, timestamp,
/* aPersisted */ false);
}
directory.forget(aDirectory);
@ -5886,6 +5796,7 @@ nsresult QuotaManager::EnsureTemporaryStorageIsInitialized() {
}
nsresult QuotaManager::EnsureOriginDirectory(nsIFile* aDirectory,
bool aCreateIfNotExists,
bool* aCreated) {
AssertIsOnIOThread();
MOZ_ASSERT(aDirectory);
@ -5898,6 +5809,10 @@ nsresult QuotaManager::EnsureOriginDirectory(nsIFile* aDirectory,
}
if (!exists) {
if (!aCreateIfNotExists) {
return NS_ERROR_NOT_AVAILABLE;
}
nsString leafName;
rv = aDirectory->GetLeafName(leafName);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -6346,27 +6261,6 @@ void QuotaManager::LockedRemoveQuotaForOrigin(PersistenceType aPersistenceType,
}
}
already_AddRefed<GroupInfo> QuotaManager::LockedGetOrCreateGroupInfo(
PersistenceType aPersistenceType, const nsACString& aGroup) {
mQuotaMutex.AssertCurrentThreadOwns();
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
GroupInfoPair* pair;
if (!mGroupInfoPairs.Get(aGroup, &pair)) {
pair = new GroupInfoPair();
mGroupInfoPairs.Put(aGroup, pair);
// The hashtable is now responsible to delete the GroupInfoPair.
}
RefPtr<GroupInfo> groupInfo = pair->LockedGetGroupInfo(aPersistenceType);
if (!groupInfo) {
groupInfo = new GroupInfo(pair, aPersistenceType, aGroup);
pair->LockedSetGroupInfo(aPersistenceType, groupInfo);
}
return groupInfo.forget();
}
already_AddRefed<OriginInfo> QuotaManager::LockedGetOriginInfo(
PersistenceType aPersistenceType, const nsACString& aGroup,
const nsACString& aOrigin) {
@ -6622,14 +6516,12 @@ bool QuotaManager::IsSanitizedOriginValid(const nsACString& aSanitizedOrigin) {
******************************************************************************/
OriginInfo::OriginInfo(GroupInfo* aGroupInfo, const nsACString& aOrigin,
uint64_t aUsage, int64_t aAccessTime, bool aPersisted,
bool aDirectoryExists)
uint64_t aUsage, int64_t aAccessTime, bool aPersisted)
: mGroupInfo(aGroupInfo),
mOrigin(aOrigin),
mUsage(aUsage),
mAccessTime(aAccessTime),
mPersisted(aPersisted),
mDirectoryExists(aDirectoryExists) {
mPersisted(aPersisted) {
MOZ_ASSERT(aGroupInfo);
MOZ_ASSERT_IF(aPersisted,
aGroupInfo->mPersistenceType == PERSISTENCE_TYPE_DEFAULT);
@ -7732,47 +7624,6 @@ GetUsageOp::GetUsageOp(const UsageRequestParams& aParams)
MOZ_ASSERT(aParams.type() == UsageRequestParams::TAllUsageParams);
}
void GetUsageOp::ProcessOriginInternal(QuotaManager* aQuotaManager,
const PersistenceType aPersistenceType,
const nsACString& aOrigin,
const int64_t aTimestamp,
const bool aPersisted,
const uint64_t aUsage) {
if (!mGetAll && aQuotaManager->IsOriginInternal(aOrigin)) {
return;
}
OriginUsage* originUsage;
// We can't store pointers to OriginUsage objects in the hashtable
// since AppendElement() reallocates its internal array buffer as number
// of elements grows.
uint32_t index;
if (mOriginUsagesIndex.Get(aOrigin, &index)) {
originUsage = &mOriginUsages[index];
} else {
index = mOriginUsages.Length();
originUsage = mOriginUsages.AppendElement();
originUsage->origin() = aOrigin;
originUsage->persisted() = false;
originUsage->usage() = 0;
originUsage->lastAccessed() = 0;
mOriginUsagesIndex.Put(aOrigin, index);
}
if (aPersistenceType == PERSISTENCE_TYPE_DEFAULT) {
originUsage->persisted() = aPersisted;
}
originUsage->usage() = originUsage->usage() + aUsage;
originUsage->lastAccessed() =
std::max<int64_t>(originUsage->lastAccessed(), aTimestamp);
}
bool GetUsageOp::IsCanceled() {
AssertIsOnIOThread();
@ -7797,6 +7648,36 @@ nsresult GetUsageOp::ProcessOrigin(QuotaManager* aQuotaManager,
return rv;
}
if (!mGetAll && aQuotaManager->IsOriginInternal(origin)) {
return NS_OK;
}
OriginUsage* originUsage;
// We can't store pointers to OriginUsage objects in the hashtable
// since AppendElement() reallocates its internal array buffer as number
// of elements grows.
uint32_t index;
if (mOriginUsagesIndex.Get(origin, &index)) {
originUsage = &mOriginUsages[index];
} else {
index = mOriginUsages.Length();
originUsage = mOriginUsages.AppendElement();
originUsage->origin() = origin;
originUsage->persisted() = false;
originUsage->usage() = 0;
mOriginUsagesIndex.Put(origin, index);
}
if (aPersistenceType == PERSISTENCE_TYPE_DEFAULT) {
originUsage->persisted() = persisted;
}
originUsage->lastAccessed() = timestamp;
UsageInfo usageInfo;
rv = GetUsageForOrigin(aQuotaManager, aPersistenceType, group, origin,
&usageInfo);
@ -7804,8 +7685,7 @@ nsresult GetUsageOp::ProcessOrigin(QuotaManager* aQuotaManager,
return rv;
}
ProcessOriginInternal(aQuotaManager, aPersistenceType, origin, timestamp,
persisted, usageInfo.TotalUsage());
originUsage->usage() = originUsage->usage() + usageInfo.TotalUsage();
return NS_OK;
}
@ -7824,18 +7704,6 @@ nsresult GetUsageOp::DoDirectoryWork(QuotaManager* aQuotaManager) {
}
}
// TraverseRepository above only consulted the filesystem. We also need to
// consider origins which may have pending quota usage, such as buffered
// LocalStorage writes for an origin which didn't previously have any
// LocalStorage data.
aQuotaManager->CollectPendingOriginsForListing([&](OriginInfo* aOriginInfo) {
ProcessOriginInternal(
aQuotaManager, aOriginInfo->GetGroupInfo()->GetPersistenceType(),
aOriginInfo->Origin(), aOriginInfo->LockedAccessTime(),
aOriginInfo->LockedPersisted(), aOriginInfo->LockedUsage());
});
return NS_OK;
}
@ -8051,7 +7919,7 @@ nsresult InitOriginOp::DoDirectoryWork(QuotaManager* aQuotaManager) {
bool created;
nsresult rv = aQuotaManager->EnsureOriginIsInitializedInternal(
mPersistenceType.Value(), mSuffix, mGroup, mOriginScope.GetOrigin(),
getter_AddRefs(directory), &created);
/* aCreateIfNotExists */ true, getter_AddRefs(directory), &created);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -8564,30 +8432,30 @@ nsresult PersistOp::DoDirectoryWork(QuotaManager* aQuotaManager) {
}
bool created;
rv = aQuotaManager->EnsureOriginDirectory(directory, &created);
rv = aQuotaManager->EnsureOriginDirectory(directory,
/* aCreateIfNotExists */ true,
&created);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (created) {
int64_t timestamp;
// Origin directory has been successfully created.
// Create OriginInfo too if temporary storage was already initialized.
if (aQuotaManager->IsTemporaryStorageInitialized()) {
aQuotaManager->NoteOriginDirectoryCreated(
mPersistenceType.Value(), mGroup, mOriginScope.GetOrigin(),
/* aPersisted */ true, timestamp);
} else {
timestamp = PR_Now();
}
rv = CreateDirectoryMetadataFiles(directory,
/* aPersisted */ true, mSuffix, mGroup,
mOriginScope.GetOrigin(), timestamp);
mOriginScope.GetOrigin(), &timestamp);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Directory metadata has been successfully created.
// Create OriginInfo too if temporary storage was already initialized.
if (aQuotaManager->IsTemporaryStorageInitialized()) {
aQuotaManager->InitQuotaForOrigin(mPersistenceType.Value(), mGroup,
mOriginScope.GetOrigin(),
/* aUsageBytes */ 0, timestamp,
/* aPersisted */ true);
}
} else {
// Get the persisted flag (restore the metadata file if necessary).
bool persisted;
@ -8681,14 +8549,6 @@ nsresult ListInitializedOriginsOp::DoDirectoryWork(
}
}
// TraverseRepository above only consulted the file-system to get a list of
// known origins, but we also need to include origins that have pending quota
// usage.
aQuotaManager->CollectPendingOriginsForListing([&](OriginInfo* aOriginInfo) {
mOrigins.AppendElement(aOriginInfo->Origin());
});
return NS_OK;
}

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

@ -145,41 +145,11 @@ class QuotaManager final : public BackgroundThreadObject {
return mTemporaryStorageInitialized;
}
/**
* For initialization of an origin where the directory already exists. This is
* used by EnsureTemporaryStorageIsInitialized/InitializeRepository once it
* has tallied origin usage by calling each of the QuotaClient InitOrigin
* methods.
*/
void InitQuotaForOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup, const nsACString& aOrigin,
uint64_t aUsageBytes, int64_t aAccessTime,
bool aPersisted);
/**
* For use in special-cases like LSNG where we need to be able to know that
* there is no data stored for an origin. LSNG knows that there is 0 usage for
* its storage of an origin and wants to make sure there is a QuotaObject
* tracking this. This method will create a non-persisted, 0-usage,
* mDirectoryExists=false OriginInfo if there isn't already an OriginInfo. If
* an OriginInfo already exists, it will be left as-is, because that implies a
* different client has usages for the origin (and there's no need to add
* LSNG's 0 usage to the QuotaObject).
*/
void EnsureQuotaForOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin);
/**
* For use when creating an origin directory. It's possible that origin usage
* is already being tracked due to a call to EnsureQuotaForOrigin, and in that
* case we need to update the existing OriginInfo rather than create a new one.
*/
void NoteOriginDirectoryCreated(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin, bool aPersisted,
int64_t& aTimestamp);
void DecreaseUsageForOrigin(PersistenceType aPersistenceType,
const nsACString& aGroup,
const nsACString& aOrigin, int64_t aSize);
@ -278,19 +248,6 @@ class QuotaManager final : public BackgroundThreadObject {
uint64_t CollectOriginsForEviction(
uint64_t aMinSizeToBeFreed, nsTArray<RefPtr<DirectoryLockImpl>>& aLocks);
/**
* Helper method to invoke the provided predicate on all "pending" OriginInfo
* instances. These are origins for which the origin directory has not yet
* been created but for which quota is already being tracked. This happens,
* for example, for the LocalStorage client where an origin that previously
* was not using LocalStorage can start issuing writes which it buffers until
* eventually flushing them. We defer creating the origin directory for as
* long as possible in that case, so the directory won't exist. Logic that
* would otherwise only consult the filesystem also needs to use this method.
*/
template <typename P>
void CollectPendingOriginsForListing(P aPredicate);
void AssertStorageIsInitialized() const
#ifdef DEBUG
;
@ -305,18 +262,18 @@ class QuotaManager final : public BackgroundThreadObject {
const nsACString& aSuffix,
const nsACString& aGroup,
const nsACString& aOrigin,
bool aCreateIfNotExists,
nsIFile** aDirectory);
nsresult EnsureOriginIsInitializedInternal(PersistenceType aPersistenceType,
const nsACString& aSuffix,
const nsACString& aGroup,
const nsACString& aOrigin,
nsIFile** aDirectory,
bool* aCreated);
nsresult EnsureOriginIsInitializedInternal(
PersistenceType aPersistenceType, const nsACString& aSuffix,
const nsACString& aGroup, const nsACString& aOrigin,
bool aCreateIfNotExists, nsIFile** aDirectory, bool* aCreated);
nsresult EnsureTemporaryStorageIsInitialized();
nsresult EnsureOriginDirectory(nsIFile* aDirectory, bool* aCreated);
nsresult EnsureOriginDirectory(nsIFile* aDirectory, bool aCreateIfNotExists,
bool* aCreated);
nsresult AboutToClearOrigins(
const Nullable<PersistenceType>& aPersistenceType,
@ -442,9 +399,6 @@ class QuotaManager final : public BackgroundThreadObject {
const nsACString& aGroup,
const nsACString& aOrigin);
already_AddRefed<GroupInfo> LockedGetOrCreateGroupInfo(
PersistenceType aPersistenceType, const nsACString& aGroup);
already_AddRefed<OriginInfo> LockedGetOriginInfo(
PersistenceType aPersistenceType, const nsACString& aGroup,
const nsACString& aOrigin);
@ -486,11 +440,10 @@ class QuotaManager final : public BackgroundThreadObject {
nsresult UpgradeLocalStorageArchiveFrom0To1(
nsCOMPtr<mozIStorageConnection>& aConnection);
nsresult UpgradeLocalStorageArchiveFrom1To2(
nsCOMPtr<mozIStorageConnection>& aConnection);
nsresult UpgradeLocalStorageArchiveFrom2To3(
nsCOMPtr<mozIStorageConnection>& aConnection);
/*
nsresult UpgradeLocalStorageArchiveFrom1To2(
nsCOMPtr<mozIStorageConnection>& aConnection);
*/
nsresult InitializeRepository(PersistenceType aPersistenceType);

Двоичный файл не отображается.

Двоичный файл не отображается.

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

@ -1,65 +0,0 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/**
* This test is mainly to verify that local storage directories are not removed
* during local storage archive upgrade from version 1 to version 2.
* See bug 1546310.
*/
async function testSteps() {
const lsDirs = [
"storage/default/http+++example.com/ls",
"storage/default/http+++localhost/ls",
"storage/default/http+++www.mozilla.org/ls",
];
info("Clearing");
let request = clear();
await requestFinished(request);
info("Installing package");
// The profile contains three initialized origin directories with local
// storage data, local storage archive, a script for origin initialization,
// the storage database and the web apps store database:
// - storage/default/https+++example.com
// - storage/default/https+++localhost
// - storage/default/https+++www.mozilla.org
// - storage/ls-archive.sqlite
// - create_db.js
// - storage.sqlite
// - webappsstore.sqlite
// The file create_db.js in the package was run locally (with a build with
// local storage archive version 1), specifically it was temporarily added to
// xpcshell.ini and then executed:
// mach xpcshell-test --interactive dom/localstorage/test/unit/create_db.js
// Note: to make it become the profile in the test, additional manual steps
// are needed.
// 1. Remove the folder "storage/temporary".
installPackage("localStorageArchive2upgrade_profile");
info("Checking ls dirs");
for (let lsDir of lsDirs) {
let dir = getRelativeFile(lsDir);
exists = dir.exists();
ok(exists, "ls directory does exist");
}
request = init();
request = await requestFinished(request);
info("Checking ls dirs");
for (let lsDir of lsDirs) {
let dir = getRelativeFile(lsDir);
exists = dir.exists();
ok(exists, "ls directory does exist");
}
}

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

@ -1,65 +0,0 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/**
* This test is mainly to verify that local storage directories are not removed
* during local storage archive upgrade from version 2 to version 3.
* See bug 1513937.
*/
async function testSteps() {
const lsDirs = [
"storage/default/http+++example.com/ls",
"storage/default/http+++localhost/ls",
"storage/default/http+++www.mozilla.org/ls",
];
info("Clearing");
let request = clear();
await requestFinished(request);
info("Installing package");
// The profile contains three initialized origin directories with local
// storage data, local storage archive, a script for origin initialization,
// the storage database and the web apps store database:
// - storage/default/https+++example.com
// - storage/default/https+++localhost
// - storage/default/https+++www.mozilla.org
// - storage/ls-archive.sqlite
// - create_db.js
// - storage.sqlite
// - webappsstore.sqlite
// The file create_db.js in the package was run locally (with a build with
// local storage archive version 2), specifically it was temporarily added to
// xpcshell.ini and then executed:
// mach xpcshell-test --interactive dom/localstorage/test/unit/create_db.js
// Note: to make it become the profile in the test, additional manual steps
// are needed.
// 1. Remove the folder "storage/temporary".
installPackage("localStorageArchive3upgrade_profile");
info("Checking ls dirs");
for (let lsDir of lsDirs) {
let dir = getRelativeFile(lsDir);
exists = dir.exists();
ok(exists, "ls directory does exist");
}
request = init();
request = await requestFinished(request);
info("Checking ls dirs");
for (let lsDir of lsDirs) {
let dir = getRelativeFile(lsDir);
exists = dir.exists();
ok(exists, "ls directory does exist");
}
}

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

@ -14,8 +14,6 @@ support-files =
idbSubdirUpgrade1_profile.zip
idbSubdirUpgrade2_profile.zip
localStorageArchive1upgrade_profile.zip
localStorageArchive2upgrade_profile.zip
localStorageArchive3upgrade_profile.zip
localStorageArchiveDowngrade_profile.zip
morgueCleanup_profile.zip
obsoleteOriginAttributes_profile.zip
@ -38,8 +36,6 @@ support-files =
[test_initTemporaryStorage.js]
[test_listInitializedOrigins.js]
[test_localStorageArchive1upgrade.js]
[test_localStorageArchive2upgrade.js]
[test_localStorageArchive3upgrade.js]
[test_localStorageArchiveDowngrade.js]
[test_morgueCleanup.js]
[test_obsoleteOriginAttributesUpgrade.js]

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

@ -1152,7 +1152,7 @@ nsresult OpenOp::DatabaseWork() {
nsCOMPtr<nsIFile> dbDirectory;
nsresult rv = quotaManager->EnsureOriginIsInitialized(
PERSISTENCE_TYPE_DEFAULT, mSuffix, mGroup, mOrigin,
getter_AddRefs(dbDirectory));
/* aCreateIfNotExists */ true, getter_AddRefs(dbDirectory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}