Bug 1615998 - QM: Remove nsIQuotaOriginsResult interface; r=ttung,dom-workers-and-storage-reviewers,sg

Differential Revision: https://phabricator.services.mozilla.com/D63051

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan Varga 2020-02-22 01:03:26 +00:00
Родитель f68792741e
Коммит 0e36a593fa
10 изменённых файлов: 61 добавлений и 110 удалений

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

@ -770,7 +770,7 @@ class PrincipalsCollector {
async getAllPrincipalsInternal(progress) {
progress.step = "principals-quota-manager";
let principals = await new Promise(resolve => {
quotaManagerService.listOrigins(request => {
quotaManagerService.listOrigins().callback = request => {
progress.step = "principals-quota-manager-listOrigins";
if (request.resultCode != Cr.NS_OK) {
// We are probably shutting down. We don't want to propagate the
@ -780,9 +780,9 @@ class PrincipalsCollector {
}
let list = [];
for (let item of request.result) {
for (const origin of request.result) {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
item.origin
origin
);
let uri = principal.URI;
if (isSupportedURI(uri)) {
@ -792,7 +792,7 @@ class PrincipalsCollector {
progress.step = "principals-quota-manager-completed";
resolve(list);
});
};
}).catch(ex => {
Cu.reportError("QuotaManagerService promise failed: " + ex);
return [];

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

@ -136,20 +136,12 @@ void QuotaUsageRequestChild::HandleResponse(
if (aResponse.IsEmpty()) {
variant->SetAsEmptyArray();
} else {
nsTArray<RefPtr<UsageResult>> usageResults;
nsTArray<RefPtr<UsageResult>> usageResults(aResponse.Length());
const uint32_t count = aResponse.Length();
usageResults.SetCapacity(count);
for (uint32_t index = 0; index < count; index++) {
auto& originUsage = aResponse[index];
RefPtr<UsageResult> usageResult =
new UsageResult(originUsage.origin(), originUsage.persisted(),
originUsage.usage(), originUsage.lastAccessed());
usageResults.AppendElement(usageResult.forget());
for (const auto& originUsage : aResponse) {
usageResults.AppendElement(MakeRefPtr<UsageResult>(
originUsage.origin(), originUsage.persisted(), originUsage.usage(),
originUsage.lastAccessed()));
}
variant->SetAsArray(nsIDataType::VTYPE_INTERFACE_IS,
@ -285,16 +277,14 @@ void QuotaRequestChild::HandleResponse(const nsTArray<nsCString>& aResponse) {
if (aResponse.IsEmpty()) {
variant->SetAsEmptyArray();
} else {
nsTArray<RefPtr<OriginsResult>> originsResults(aResponse.Length());
for (auto& origin : aResponse) {
RefPtr<OriginsResult> originsResult = new OriginsResult(origin);
nsTArray<const char*> stringPointers(aResponse.Length());
originsResults.AppendElement(originsResult.forget());
for (const auto& string : aResponse) {
stringPointers.AppendElement(string.get());
}
variant->SetAsArray(
nsIDataType::VTYPE_INTERFACE_IS, &NS_GET_IID(nsIQuotaOriginsResult),
originsResults.Length(), static_cast<void*>(originsResults.Elements()));
variant->SetAsArray(nsIDataType::VTYPE_CHAR_STR, nullptr,
stringPointers.Length(), stringPointers.Elements());
}
mRequest->SetResult(variant);

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

@ -781,12 +781,10 @@ QuotaManagerService::Estimate(nsIPrincipal* aPrincipal,
}
NS_IMETHODIMP
QuotaManagerService::ListOrigins(nsIQuotaCallback* aCallback,
nsIQuotaRequest** _retval) {
QuotaManagerService::ListOrigins(nsIQuotaRequest** _retval) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aCallback);
RefPtr<Request> request = new Request(aCallback);
RefPtr<Request> request = new Request();
ListOriginsParams params;

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

@ -91,16 +91,6 @@ EstimateResult::GetLimit(uint64_t* aLimit) {
return NS_OK;
}
OriginsResult::OriginsResult(const nsACString& aOrigin) : mOrigin(aOrigin) {}
NS_IMPL_ISUPPORTS(OriginsResult, nsIQuotaOriginsResult)
NS_IMETHODIMP
OriginsResult::GetOrigin(nsACString& aOrigin) {
aOrigin = mOrigin;
return NS_OK;
}
} // namespace quota
} // namespace dom
} // namespace mozilla

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

@ -58,19 +58,6 @@ class EstimateResult : public nsIQuotaEstimateResult {
NS_DECL_NSIQUOTAESTIMATERESULT
};
class OriginsResult : public nsIQuotaOriginsResult {
nsCString mOrigin;
public:
explicit OriginsResult(const nsACString& aOrigin);
private:
virtual ~OriginsResult() = default;
NS_DECL_ISUPPORTS
NS_DECL_NSIQUOTAORIGINSRESULT
};
} // namespace quota
} // namespace dom
} // namespace mozilla

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

@ -94,14 +94,10 @@ interface nsIQuotaManagerService : nsISupports
[optional] in boolean aFromMemory);
/**
* Schedules an asynchronous callback that will inspect all origins and
* just returns the origin strings of origins.
*
* @param aCallback
* The callback that will be called when the origin is collected.
* Asynchronously lists all origins and returns them as plain strings.
*/
[must_use] nsIQuotaRequest
listOrigins(in nsIQuotaCallback aCallback);
listOrigins();
/**
* Removes all storages. The files may not be deleted immediately depending

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

@ -39,7 +39,8 @@ interface nsIQuotaRequest : nsIQuotaRequestBase
// The result can contain one of these types:
// void
// bool
// array of nsIQuotaOriginsResult
// nsIQuotaEstimateResult
// array of strings
[must_use] readonly attribute nsIVariant result;
attribute nsIQuotaCallback callback;

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

@ -33,9 +33,3 @@ interface nsIQuotaEstimateResult : nsISupports
readonly attribute unsigned long long limit;
};
[scriptable, function, uuid(5d8c2fbe-9ccc-4bab-8f03-8591dfc8e351)]
interface nsIQuotaOriginsResult : nsISupports
{
readonly attribute ACString origin;
};

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

@ -3,33 +3,11 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
async function CreateTestEnvironment(origins) {
let request;
for (let origin of origins) {
request = initStorageAndOrigin(getPrincipal(origin.origin), "default");
await requestFinished(request);
}
request = reset();
await requestFinished(request);
}
async function testSteps() {
const origins = [
{
origin: "https://example.com",
path: "https+++example.com",
},
{
origin: "https://localhost",
path: "https+++localhost",
},
{
origin: "https://www.mozilla.org",
path: "https+++www.mozilla.org",
},
"https://example.com",
"https://localhost",
"https://www.mozilla.org",
];
function verifyResult(result, expectedOrigins) {
@ -39,13 +17,10 @@ async function testSteps() {
info("Sorting elements");
result.sort(function(a, b) {
let originA = a.origin;
let originB = b.origin;
if (originA < originB) {
if (a < b) {
return -1;
}
if (originA > originB) {
if (a > b) {
return 1;
}
return 0;
@ -54,22 +29,42 @@ async function testSteps() {
info("Verifying elements");
for (let i = 0; i < result.length; i++) {
let a = result[i];
let b = expectedOrigins[i];
ok(a.origin == b.origin, "Origin equals");
ok(result[i] == expectedOrigins[i], "Result matches expected origin");
}
}
info("Creating test environment");
info("Clearing");
await CreateTestEnvironment(origins);
let request = clear();
await requestFinished(request);
info("Getting origins after initializing the storage");
info("Listing origins");
await new Promise(resolve => {
listOrigins(req => {
verifyResult(req.result, origins);
resolve();
});
});
request = listOrigins();
await requestFinished(request);
info("Verifying result");
verifyResult(request.result, []);
info("Clearing");
request = clear();
await requestFinished(request);
info("Initializing origins");
for (const origin of origins) {
request = initStorageAndOrigin(getPrincipal(origin), "default");
await requestFinished(request);
}
info("Listing origins");
request = listOrigins();
await requestFinished(request);
info("Verifying result");
verifyResult(request.result, origins);
}

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

@ -533,16 +533,16 @@ const QuotaCleaner = {
// wiped if we are provided an aHost of "example.com".
promises.push(
new Promise((aResolve, aReject) => {
Services.qms.listOrigins(aRequest => {
Services.qms.listOrigins().callback = aRequest => {
if (aRequest.resultCode != Cr.NS_OK) {
aReject({ message: "Delete by host failed" });
return;
}
let promises = [];
for (let item of aRequest.result) {
for (const origin of aRequest.result) {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
item.origin
origin
);
let host;
try {
@ -573,7 +573,7 @@ const QuotaCleaner = {
}
Promise.all(promises).then(aResolve);
});
};
})
);
}