Bug 1716568 - Move implementation details of InitializationInfo to a cpp file; r=dom-storage-reviewers,jstutte

Differential Revision: https://phabricator.services.mozilla.com/D118131
This commit is contained in:
Jan Varga 2021-06-23 21:26:07 +00:00
Родитель 482c419e44
Коммит 3a8312aeeb
4 изменённых файлов: 65 добавлений и 50 удалений

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

@ -23,6 +23,7 @@
#include "mozilla/ResultExtensions.h"
#include "mozilla/Services.h"
#include "mozilla/storage.h"
#include "mozilla/Telemetry.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/DOMStringListBinding.h"
#include "mozilla/dom/Exceptions.h"

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

@ -0,0 +1,61 @@
/* -*- 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/. */
#include "InitializationTypes.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryHistogramEnums.h"
#include "nsString.h"
namespace mozilla::dom::quota {
namespace {
// TODO: Use constexpr here once bug 1594094 is addressed.
nsLiteralCString GetInitializationString(const Initialization aInitialization) {
switch (aInitialization) {
case Initialization::Storage:
return "Storage"_ns;
case Initialization::TemporaryStorage:
return "TemporaryStorage"_ns;
case Initialization::DefaultRepository:
return "DefaultRepository"_ns;
case Initialization::TemporaryRepository:
return "TemporaryRepository"_ns;
case Initialization::UpgradeStorageFrom0_0To1_0:
return "UpgradeStorageFrom0_0To1_0"_ns;
case Initialization::UpgradeStorageFrom1_0To2_0:
return "UpgradeStorageFrom1_0To2_0"_ns;
case Initialization::UpgradeStorageFrom2_0To2_1:
return "UpgradeStorageFrom2_0To2_1"_ns;
case Initialization::UpgradeStorageFrom2_1To2_2:
return "UpgradeStorageFrom2_1To2_2"_ns;
case Initialization::UpgradeStorageFrom2_2To2_3:
return "UpgradeStorageFrom2_2To2_3"_ns;
case Initialization::UpgradeFromIndexedDBDirectory:
return "UpgradeFromIndexedDBDirectory"_ns;
case Initialization::UpgradeFromPersistentStorageDirectory:
return "UpgradeFromPersistentStorageDirectory"_ns;
default:
MOZ_CRASH("Bad initialization value!");
}
}
} // namespace
void InitializationInfo::ReportFirstInitializationAttempt(
const Initialization aInitialization, const bool aSuccess) {
MOZ_ASSERT(!InitializationAttempted(aInitialization));
mInitializationAttempts |= aInitialization;
Telemetry::Accumulate(Telemetry::QM_FIRST_INITIALIZATION_ATTEMPT,
GetInitializationString(aInitialization),
static_cast<uint32_t>(aSuccess));
}
} // namespace mozilla::dom::quota

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

@ -8,20 +8,11 @@
#define mozilla_dom_quota_InitializationTypes_h
#include <cstdint>
#include <utility>
#include "ErrorList.h"
#include "mozilla/Assertions.h"
#include "mozilla/TypedEnumBits.h"
#include "nsError.h"
#include "nsLiteralString.h"
#include "nsStringFwd.h"
// XXX Avoid these includes by moving ReportFirstInitializationAttempt to cpp
// file
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryHistogramEnums.h"
// Undo X11/X.h's definition of None
#undef None
namespace mozilla {
namespace dom {
@ -102,51 +93,12 @@ class InitializationInfo final {
}
private:
// TODO: Use constexpr here once bug 1594094 is addressed.
static nsLiteralCString GetInitializationString(
const Initialization aInitialization) {
switch (aInitialization) {
case Initialization::Storage:
return "Storage"_ns;
case Initialization::TemporaryStorage:
return "TemporaryStorage"_ns;
case Initialization::DefaultRepository:
return "DefaultRepository"_ns;
case Initialization::TemporaryRepository:
return "TemporaryRepository"_ns;
case Initialization::UpgradeStorageFrom0_0To1_0:
return "UpgradeStorageFrom0_0To1_0"_ns;
case Initialization::UpgradeStorageFrom1_0To2_0:
return "UpgradeStorageFrom1_0To2_0"_ns;
case Initialization::UpgradeStorageFrom2_0To2_1:
return "UpgradeStorageFrom2_0To2_1"_ns;
case Initialization::UpgradeStorageFrom2_1To2_2:
return "UpgradeStorageFrom2_1To2_2"_ns;
case Initialization::UpgradeStorageFrom2_2To2_3:
return "UpgradeStorageFrom2_2To2_3"_ns;
case Initialization::UpgradeFromIndexedDBDirectory:
return "UpgradeFromIndexedDBDirectory"_ns;
case Initialization::UpgradeFromPersistentStorageDirectory:
return "UpgradeFromPersistentStorageDirectory"_ns;
default:
MOZ_CRASH("Bad initialization value!");
}
}
bool InitializationAttempted(const Initialization aInitialization) const {
return static_cast<bool>(mInitializationAttempts & aInitialization);
}
void ReportFirstInitializationAttempt(const Initialization aInitialization,
const bool aSuccess) {
MOZ_ASSERT(!InitializationAttempted(aInitialization));
mInitializationAttempts |= aInitialization;
Telemetry::Accumulate(Telemetry::QM_FIRST_INITIALIZATION_ATTEMPT,
GetInitializationString(aInitialization),
static_cast<uint32_t>(aSuccess));
}
bool aSuccess);
};
} // namespace quota

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

@ -68,6 +68,7 @@ UNIFIED_SOURCES += [
"DirectoryLockImpl.cpp",
"EncryptingOutputStream.cpp",
"FileStreams.cpp",
"InitializationTypes.cpp",
"MemoryOutputStream.cpp",
"nsIndexedDBProtocolHandler.cpp",
"NSSCipherStrategy.cpp",