mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1719811 - QM: Replace FirstInitializationAttempt method with WithFirstInitializationAttempt; r=dom-storage-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D119496
This commit is contained in:
parent
480491b2be
commit
064a1e6a2a
@ -39,9 +39,12 @@ class FirstInitializationAttempts {
|
||||
}
|
||||
};
|
||||
|
||||
FirstInitializationAttemptImpl FirstInitializationAttempt(
|
||||
const Initialization aInitialization) {
|
||||
return FirstInitializationAttemptImpl(*this, aInitialization);
|
||||
template <typename Func>
|
||||
auto WithFirstInitializationAttempt(const Initialization aInitialization,
|
||||
Func&& aFunc)
|
||||
-> std::invoke_result_t<Func, FirstInitializationAttemptImpl&&> {
|
||||
return std::forward<Func>(aFunc)(
|
||||
FirstInitializationAttemptImpl(*this, aInitialization));
|
||||
}
|
||||
|
||||
bool FirstInitializationAttemptRecorded(
|
||||
|
@ -1557,39 +1557,42 @@ auto ExecuteInitialization(
|
||||
const Initialization aInitialization, Func&& aFunc)
|
||||
-> std::invoke_result_t<Func, const FirstInitializationAttempt<
|
||||
Initialization, StringGenerator>&> {
|
||||
using RetType = std::invoke_result_t<
|
||||
Func, const FirstInitializationAttempt<Initialization, StringGenerator>&>;
|
||||
return aFirstInitializationAttempts.WithFirstInitializationAttempt(
|
||||
aInitialization, [&aFunc](auto&& firstInitializationAttempt) {
|
||||
auto res = std::forward<Func>(aFunc)(firstInitializationAttempt);
|
||||
|
||||
auto firstInitializationAttempt =
|
||||
aFirstInitializationAttempts.FirstInitializationAttempt(aInitialization);
|
||||
const auto rv = [&res]() -> nsresult {
|
||||
using RetType =
|
||||
std::invoke_result_t<Func, const FirstInitializationAttempt<
|
||||
Initialization, StringGenerator>&>;
|
||||
|
||||
auto res = std::forward<Func>(aFunc)(firstInitializationAttempt);
|
||||
if constexpr (std::is_same_v<RetType, nsresult>) {
|
||||
return res;
|
||||
} else if constexpr (mozilla::detail::IsResult<RetType>::value &&
|
||||
std::is_same_v<typename RetType::err_type,
|
||||
nsresult>) {
|
||||
return res.isOk() ? NS_OK : res.inspectErr();
|
||||
} else {
|
||||
detail::UnsupportedReturnType();
|
||||
}
|
||||
}();
|
||||
|
||||
const auto rv = [&res]() -> nsresult {
|
||||
if constexpr (std::is_same_v<RetType, nsresult>) {
|
||||
return res;
|
||||
} else if constexpr (mozilla::detail::IsResult<RetType>::value &&
|
||||
std::is_same_v<typename RetType::err_type, nsresult>) {
|
||||
return res.isOk() ? NS_OK : res.inspectErr();
|
||||
} else {
|
||||
detail::UnsupportedReturnType();
|
||||
}
|
||||
}();
|
||||
// NS_ERROR_ABORT signals a non-fatal, recoverable problem during
|
||||
// initialization. We do not want these kind of failures to count
|
||||
// against our overall first initialization attempt telemetry. Thus we
|
||||
// just ignore this kind of failure and keep
|
||||
// aFirstInitializationAttempts unflagged to stay ready to record a real
|
||||
// success or failure on the next attempt.
|
||||
if (rv == NS_ERROR_ABORT) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// NS_ERROR_ABORT signals a non-fatal, recoverable problem during
|
||||
// initialization. We do not want these kind of failures to count against our
|
||||
// overall first initialization attempt telemetry. Thus we just ignore this
|
||||
// kind of failure and keep aFirstInitializationAttempts unflagged to stay
|
||||
// ready to record a real success or failure on the next attempt.
|
||||
if (rv == NS_ERROR_ABORT) {
|
||||
return res;
|
||||
}
|
||||
if (!firstInitializationAttempt.Recorded()) {
|
||||
firstInitializationAttempt.Record(rv);
|
||||
}
|
||||
|
||||
if (!firstInitializationAttempt.Recorded()) {
|
||||
firstInitializationAttempt.Record(rv);
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Initialization, typename StringGenerator, typename Func>
|
||||
|
Loading…
Reference in New Issue
Block a user