2019-12-11 11:22:47 +03:00
|
|
|
/* -*- 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_quota_InitializationTypes_h
|
|
|
|
#define mozilla_dom_quota_InitializationTypes_h
|
|
|
|
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TypedEnumBits.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace quota {
|
|
|
|
|
|
|
|
enum class Initialization {
|
|
|
|
None = 0,
|
|
|
|
Storage = 1 << 0,
|
|
|
|
TemporaryStorage = 1 << 1,
|
2019-12-11 11:27:01 +03:00
|
|
|
DefaultRepository = 1 << 2,
|
|
|
|
TemporaryRepository = 1 << 3,
|
|
|
|
UpgradeStorageFrom0_0To1_0 = 1 << 4,
|
|
|
|
UpgradeStorageFrom1_0To2_0 = 1 << 5,
|
|
|
|
UpgradeStorageFrom2_0To2_1 = 1 << 6,
|
|
|
|
UpgradeStorageFrom2_1To2_2 = 1 << 7,
|
|
|
|
UpgradeStorageFrom2_2To2_3 = 1 << 8,
|
2020-03-11 15:52:04 +03:00
|
|
|
UpgradeFromIndexedDBDirectory = 1 << 9,
|
|
|
|
UpgradeFromPersistentStorageDirectory = 1 << 10,
|
2019-12-11 11:22:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Initialization)
|
|
|
|
|
|
|
|
class InitializationInfo final {
|
|
|
|
Initialization mInitializationAttempts = Initialization::None;
|
|
|
|
|
|
|
|
public:
|
|
|
|
template <typename SuccessFunction>
|
|
|
|
class AutoInitializationAttempt {
|
|
|
|
InitializationInfo& mOwner;
|
|
|
|
const Initialization mInitialization;
|
|
|
|
const SuccessFunction mSuccessFunction;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoInitializationAttempt(InitializationInfo& aOwner,
|
|
|
|
const Initialization aInitialization,
|
2019-12-11 13:40:49 +03:00
|
|
|
SuccessFunction&& aSuccessFunction)
|
2019-12-11 11:22:47 +03:00
|
|
|
: mOwner(aOwner),
|
|
|
|
mInitialization(aInitialization),
|
2019-12-11 13:40:49 +03:00
|
|
|
mSuccessFunction(std::move(aSuccessFunction)) {}
|
2019-12-11 11:22:47 +03:00
|
|
|
|
|
|
|
~AutoInitializationAttempt() {
|
2019-12-11 11:27:01 +03:00
|
|
|
if (mOwner.InitializationAttempted(mInitialization)) {
|
|
|
|
return;
|
2019-12-11 11:22:47 +03:00
|
|
|
}
|
2019-12-11 11:27:01 +03:00
|
|
|
|
|
|
|
mOwner.ReportFirstInitializationAttempt(mInitialization,
|
|
|
|
mSuccessFunction());
|
2019-12-11 11:22:47 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename SuccessFunction>
|
|
|
|
AutoInitializationAttempt<SuccessFunction> RecordFirstInitializationAttempt(
|
|
|
|
const Initialization aInitialization,
|
|
|
|
SuccessFunction&& aSuccessFunction) {
|
|
|
|
return AutoInitializationAttempt<SuccessFunction>(
|
|
|
|
*this, aInitialization, std::move(aSuccessFunction));
|
|
|
|
}
|
|
|
|
|
2019-12-11 11:27:01 +03:00
|
|
|
void RecordFirstInitializationAttempt(const Initialization aInitialization,
|
|
|
|
const nsresult aRv) {
|
|
|
|
if (InitializationAttempted(aInitialization)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReportFirstInitializationAttempt(aInitialization, NS_SUCCEEDED(aRv));
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:40:49 +03:00
|
|
|
void AssertInitializationAttempted(const Initialization aInitialization) {
|
2019-12-11 11:27:01 +03:00
|
|
|
MOZ_ASSERT(InitializationAttempted(aInitialization));
|
2019-12-11 11:22:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResetInitializationAttempts() {
|
|
|
|
mInitializationAttempts = Initialization::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// TODO: Use constexpr here once bug 1594094 is addressed.
|
2019-12-11 13:40:49 +03:00
|
|
|
static nsLiteralCString GetInitializationString(
|
|
|
|
const Initialization aInitialization) {
|
2019-12-11 11:22:47 +03:00
|
|
|
switch (aInitialization) {
|
|
|
|
case Initialization::Storage:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "Storage"_ns;
|
2019-12-11 11:22:47 +03:00
|
|
|
case Initialization::TemporaryStorage:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "TemporaryStorage"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::DefaultRepository:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "DefaultRepository"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::TemporaryRepository:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "TemporaryRepository"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::UpgradeStorageFrom0_0To1_0:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeStorageFrom0_0To1_0"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::UpgradeStorageFrom1_0To2_0:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeStorageFrom1_0To2_0"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::UpgradeStorageFrom2_0To2_1:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeStorageFrom2_0To2_1"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::UpgradeStorageFrom2_1To2_2:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeStorageFrom2_1To2_2"_ns;
|
2019-12-11 11:27:01 +03:00
|
|
|
case Initialization::UpgradeStorageFrom2_2To2_3:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeStorageFrom2_2To2_3"_ns;
|
2020-03-11 15:52:04 +03:00
|
|
|
case Initialization::UpgradeFromIndexedDBDirectory:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeFromIndexedDBDirectory"_ns;
|
2020-03-11 15:52:04 +03:00
|
|
|
case Initialization::UpgradeFromPersistentStorageDirectory:
|
2020-07-01 11:29:29 +03:00
|
|
|
return "UpgradeFromPersistentStorageDirectory"_ns;
|
2019-12-11 11:22:47 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Bad initialization value!");
|
|
|
|
}
|
|
|
|
}
|
2019-12-11 11:27:01 +03:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2019-12-11 11:22:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace quota
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_quota_InitializationTypes_h
|