Bug 1685279 - Change QuotaManager::ParseOrigin to return a Result<PrincipalInfo, nsresult>. r=dom-workers-and-storage-reviewers,janv

ParseOrigin is only used to construct a PrincipalInfo, so it makes sense to
return it directly.

Differential Revision: https://phabricator.services.mozilla.com/D100889
This commit is contained in:
Simon Giesecke 2021-01-15 10:53:02 +00:00
Родитель 9d4e29c97f
Коммит 1575347021
3 изменённых файлов: 22 добавлений и 37 удалений

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

@ -8800,37 +8800,21 @@ QuotaClient::CreateArchivedOriginScope(const OriginScope& aOriginScope) {
AssertIsOnIOThread(); AssertIsOnIOThread();
if (aOriginScope.IsOrigin()) { if (aOriginScope.IsOrigin()) {
nsCString spec; LS_TRY_INSPECT(const auto& principalInfo,
OriginAttributes attrs; QuotaManager::ParseOrigin(aOriginScope.GetOrigin()));
LS_TRY(
OkIf(QuotaManager::ParseOrigin(aOriginScope.GetOrigin(), spec, &attrs)),
Err(NS_ERROR_FAILURE));
ContentPrincipalInfo contentPrincipalInfo; LS_TRY_INSPECT((const auto& [originAttrSuffix, originKey]),
contentPrincipalInfo.attrs() = std::move(attrs); GenerateOriginKey2(principalInfo));
contentPrincipalInfo.spec() = std::move(spec);
LS_TRY_INSPECT(
(const auto& [originAttrSuffix, originKey]),
GenerateOriginKey2(PrincipalInfo(std::move(contentPrincipalInfo))));
return ArchivedOriginScope::CreateFromOrigin(originAttrSuffix, originKey); return ArchivedOriginScope::CreateFromOrigin(originAttrSuffix, originKey);
} }
if (aOriginScope.IsPrefix()) { if (aOriginScope.IsPrefix()) {
nsCString spec; LS_TRY_INSPECT(const auto& principalInfo,
OriginAttributes attrs; QuotaManager::ParseOrigin(aOriginScope.GetOriginNoSuffix()));
LS_TRY(OkIf(QuotaManager::ParseOrigin(aOriginScope.GetOriginNoSuffix(),
spec, &attrs)),
Err(NS_ERROR_FAILURE));
ContentPrincipalInfo contentPrincipalInfo; LS_TRY_INSPECT((const auto& [originAttrSuffix, originKey]),
contentPrincipalInfo.attrs() = std::move(attrs); GenerateOriginKey2(principalInfo));
contentPrincipalInfo.spec() = std::move(spec);
LS_TRY_INSPECT(
(const auto& [originAttrSuffix, originKey]),
GenerateOriginKey2(PrincipalInfo(std::move(contentPrincipalInfo))));
Unused << originAttrSuffix; Unused << originAttrSuffix;

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

@ -6960,23 +6960,25 @@ bool QuotaManager::AreOriginsEqualOnDisk(const nsACString& aOrigin1,
} }
// static // static
bool QuotaManager::ParseOrigin(const nsACString& aOrigin, nsCString& aSpec, Result<PrincipalInfo, nsresult> QuotaManager::ParseOrigin(
OriginAttributes* aAttrs) { const nsACString& aOrigin) {
MOZ_ASSERT(aAttrs); // An origin string either corresponds to a SystemPrincipalInfo or a
// ContentPrincipalInfo, see
// QuotaManager::GetOriginFromValidatedPrincipalInfo.
if (aOrigin.Equals(kChromeOrigin)) { if (aOrigin.Equals(kChromeOrigin)) {
aSpec = kChromeOrigin; return PrincipalInfo{SystemPrincipalInfo{}};
return true;
} }
ContentPrincipalInfo contentPrincipalInfo;
nsCString originalSuffix; nsCString originalSuffix;
OriginParser::ResultType result = OriginParser::ParseOrigin( const OriginParser::ResultType result = OriginParser::ParseOrigin(
MakeSanitizedOriginCString(aOrigin), aSpec, aAttrs, originalSuffix); MakeSanitizedOriginCString(aOrigin), contentPrincipalInfo.spec(),
if (NS_WARN_IF(result != OriginParser::ValidOrigin)) { &contentPrincipalInfo.attrs(), originalSuffix);
return false; QM_TRY(OkIf(result == OriginParser::ValidOrigin), Err(NS_ERROR_FAILURE));
}
return true; return PrincipalInfo{std::move(contentPrincipalInfo)};
} }
// static // static

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

@ -469,8 +469,7 @@ class QuotaManager final : public BackgroundThreadObject {
static bool AreOriginsEqualOnDisk(const nsACString& aOrigin1, static bool AreOriginsEqualOnDisk(const nsACString& aOrigin1,
const nsACString& aOrigin2); const nsACString& aOrigin2);
static bool ParseOrigin(const nsACString& aOrigin, nsCString& aSpec, static Result<PrincipalInfo, nsresult> ParseOrigin(const nsACString& aOrigin);
OriginAttributes* aAttrs);
static void InvalidateQuotaCache(); static void InvalidateQuotaCache();