Skip to content

Commit

Permalink
Merge mozilla-central to autoland. a=merge CLOSED TREE
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Pop Rus committed May 9, 2019
2 parents f5b7d13 + b9da45f commit c1f22ae
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 111 deletions.
137 changes: 130 additions & 7 deletions dom/localstorage/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "mozilla/ipc/PBackgroundParent.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/Logging.h"
#include "mozilla/storage/Variant.h"
#include "nsClassHashtable.h"
#include "nsDataHashtable.h"
#include "nsExceptionHandler.h"
Expand Down Expand Up @@ -2344,6 +2345,9 @@ class PrepareDatastoreOp
public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
class LoadDataOp;

class CompressFunction;
class CompressibleFunction;

enum class NestedState {
// The nesting has not yet taken place. Next step is
// CheckExistingOperations.
Expand Down Expand Up @@ -2537,6 +2541,23 @@ class PrepareDatastoreOp::LoadDataOp final
void Cleanup() override;
};

class PrepareDatastoreOp::CompressFunction final : public mozIStorageFunction {
private:
~CompressFunction() = default;

NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGEFUNCTION
};

class PrepareDatastoreOp::CompressibleFunction final
: public mozIStorageFunction {
private:
~CompressibleFunction() = default;

NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGEFUNCTION
};

class PrepareObserverOp : public LSRequestBase {
const LSRequestPrepareObserverParams mParams;
nsCString mOrigin;
Expand Down Expand Up @@ -7034,15 +7055,33 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
mozStorageTransaction transaction(
connection, false, mozIStorageConnection::TRANSACTION_IMMEDIATE);

nsCOMPtr<mozIStorageFunction> function = new CompressFunction();

rv =
connection->CreateFunction(NS_LITERAL_CSTRING("compress"), 1, function);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

function = new CompressibleFunction();

rv = connection->CreateFunction(NS_LITERAL_CSTRING("compressible"), 1,
function);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

nsCOMPtr<mozIStorageStatement> stmt;
rv = connection->CreateStatement(
NS_LITERAL_CSTRING("INSERT INTO data (key, value, utf16Length) "
"SELECT key, value, utf16Length(value) "
"FROM webappsstore2 "
"WHERE originKey = :originKey "
"AND originAttributes = :originAttributes;"

),
NS_LITERAL_CSTRING(
"INSERT INTO data (key, value, utf16Length, compressed) "
"SELECT key, compress(value), utf16Length(value), "
"compressible(value) "
"FROM webappsstore2 "
"WHERE originKey = :originKey "
"AND originAttributes = :originAttributes;"

),
getter_AddRefs(stmt));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
Expand All @@ -7058,6 +7097,16 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
return rv;
}

rv = connection->RemoveFunction(NS_LITERAL_CSTRING("compress"));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

rv = connection->RemoveFunction(NS_LITERAL_CSTRING("compressible"));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

rv = connection->CreateStatement(
NS_LITERAL_CSTRING("UPDATE database SET usage = :usage;"),
getter_AddRefs(stmt));
Expand Down Expand Up @@ -7766,6 +7815,80 @@ void PrepareDatastoreOp::LoadDataOp::Cleanup() {
ConnectionDatastoreOperationBase::Cleanup();
}

NS_IMPL_ISUPPORTS(PrepareDatastoreOp::CompressFunction, mozIStorageFunction)

NS_IMETHODIMP
PrepareDatastoreOp::CompressFunction::OnFunctionCall(
mozIStorageValueArray* aFunctionArguments, nsIVariant** aResult) {
AssertIsOnIOThread();
MOZ_ASSERT(aFunctionArguments);
MOZ_ASSERT(aResult);

#ifdef DEBUG
{
uint32_t argCount;
MOZ_ALWAYS_SUCCEEDS(aFunctionArguments->GetNumEntries(&argCount));
MOZ_ASSERT(argCount == 1);

int32_t type;
MOZ_ALWAYS_SUCCEEDS(aFunctionArguments->GetTypeOfIndex(0, &type));
MOZ_ASSERT(type == mozIStorageValueArray::VALUE_TYPE_TEXT);
}
#endif

nsCString value;
nsresult rv = aFunctionArguments->GetUTF8String(0, value);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

nsCString compressed;
if (!SnappyCompress(value, compressed)) {
compressed = value;
}

nsCOMPtr<nsIVariant> result = new storage::UTF8TextVariant(compressed);

result.forget(aResult);
return NS_OK;
}

NS_IMPL_ISUPPORTS(PrepareDatastoreOp::CompressibleFunction, mozIStorageFunction)

NS_IMETHODIMP
PrepareDatastoreOp::CompressibleFunction::OnFunctionCall(
mozIStorageValueArray* aFunctionArguments, nsIVariant** aResult) {
AssertIsOnIOThread();
MOZ_ASSERT(aFunctionArguments);
MOZ_ASSERT(aResult);

#ifdef DEBUG
{
uint32_t argCount;
MOZ_ALWAYS_SUCCEEDS(aFunctionArguments->GetNumEntries(&argCount));
MOZ_ASSERT(argCount == 1);

int32_t type;
MOZ_ALWAYS_SUCCEEDS(aFunctionArguments->GetTypeOfIndex(0, &type));
MOZ_ASSERT(type == mozIStorageValueArray::VALUE_TYPE_TEXT);
}
#endif

nsCString value;
nsresult rv = aFunctionArguments->GetUTF8String(0, value);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

nsCString compressed;
bool compressible = SnappyCompress(value, compressed);

nsCOMPtr<nsIVariant> result = new storage::IntegerVariant(compressible);

result.forget(aResult);
return NS_OK;
}

/*******************************************************************************
* PrepareObserverOp
******************************************************************************/
Expand Down
Binary file modified dom/localstorage/test/unit/corruptedDatabase_profile.zip
Binary file not shown.
40 changes: 18 additions & 22 deletions dom/quota/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 4;

const char kProfileDoChangeTopic[] = "profile-do-change";

Expand Down Expand Up @@ -446,6 +446,7 @@ nsresult LoadLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
return NS_OK;
}

/*
nsresult SaveLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
uint32_t aVersion) {
AssertIsOnIOThread();
Expand All @@ -471,6 +472,7 @@ nsresult SaveLocalStorageArchiveVersion(mozIStorageConnection* aConnection,
return NS_OK;
}
*/

/******************************************************************************
* Quota manager class declarations
Expand Down Expand Up @@ -5331,7 +5333,7 @@ nsresult QuotaManager::DowngradeLocalStorageArchive(
return NS_OK;
}

nsresult QuotaManager::UpgradeLocalStorageArchiveFrom0To1(
nsresult QuotaManager::UpgradeLocalStorageArchiveFromLessThan4To4(
nsCOMPtr<mozIStorageConnection>& aConnection) {
AssertIsOnIOThread();
MOZ_ASSERT(CachedNextGenLocalStorageEnabled());
Expand All @@ -5341,33 +5343,28 @@ nsresult QuotaManager::UpgradeLocalStorageArchiveFrom0To1(
return rv;
}

rv = InitializeLocalStorageArchive(aConnection, 1);
rv = InitializeLocalStorageArchive(aConnection, 4);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

return NS_OK;
}

nsresult QuotaManager::UpgradeLocalStorageArchiveFrom1To2(
/*
nsresult QuotaManager::UpgradeLocalStorageArchiveFrom4To5(
nsCOMPtr<mozIStorageConnection>& aConnection) {
nsresult rv = SaveLocalStorageArchiveVersion(aConnection, 2);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

return NS_OK;
}
AssertIsOnIOThread();
MOZ_ASSERT(CachedNextGenLocalStorageEnabled());
nsresult QuotaManager::UpgradeLocalStorageArchiveFrom2To3(
nsCOMPtr<mozIStorageConnection>& aConnection) {
nsresult rv = SaveLocalStorageArchiveVersion(aConnection, 3);
nsresult rv = SaveLocalStorageArchiveVersion(aConnection, 5);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
*/

#ifdef DEBUG

Expand Down Expand Up @@ -5591,18 +5588,17 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
return rv;
}
} else {
static_assert(kLocalStorageArchiveVersion == 3,
static_assert(kLocalStorageArchiveVersion == 4,
"Upgrade function needed due to LocalStorage archive "
"version increase.");

while (version != kLocalStorageArchiveVersion) {
if (version == 0) {
rv = UpgradeLocalStorageArchiveFrom0To1(connection);
} else if (version == 1) {
rv = UpgradeLocalStorageArchiveFrom1To2(connection);
} else if (version == 2) {
rv = UpgradeLocalStorageArchiveFrom2To3(connection);
} else {
if (version < 4) {
rv = UpgradeLocalStorageArchiveFromLessThan4To4(connection);
} /* else if (version == 4) {
rv = UpgradeLocalStorageArchiveFrom4To5(connection);
} */
else {
QM_WARNING(
"Unable to initialize LocalStorage archive, no upgrade path is "
"available!");
Expand Down
10 changes: 4 additions & 6 deletions dom/quota/QuotaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,12 @@ class QuotaManager final : public BackgroundThreadObject {
nsresult DowngradeLocalStorageArchive(
nsCOMPtr<mozIStorageConnection>& aConnection);

nsresult UpgradeLocalStorageArchiveFrom0To1(
nsresult UpgradeLocalStorageArchiveFromLessThan4To4(
nsCOMPtr<mozIStorageConnection>& aConnection);

nsresult UpgradeLocalStorageArchiveFrom1To2(
nsCOMPtr<mozIStorageConnection>& aConnection);

nsresult UpgradeLocalStorageArchiveFrom2To3(
nsCOMPtr<mozIStorageConnection>& aConnection);
/*
nsresult UpgradeLocalStorageArchiveFrom4To5();
*/

nsresult InitializeRepository(PersistenceType aPersistenceType);

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
65 changes: 0 additions & 65 deletions dom/quota/test/unit/test_localStorageArchive3upgrade.js

This file was deleted.

Loading

0 comments on commit c1f22ae

Please sign in to comment.