Bug 1546723 - Part 5: Generalize code for getting datastores; r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D31200
This commit is contained in:
Jan Varga 2019-05-15 06:11:11 +02:00
Родитель b5acd8a9aa
Коммит 55c0e5ec44
1 изменённых файлов: 19 добавлений и 5 удалений

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

@ -2876,6 +2876,22 @@ void AssertIsOnConnectionThread() {
gConnectionThread->AssertIsOnConnectionThread();
}
already_AddRefed<Datastore> GetDatastore(const nsACString& aOrigin) {
AssertIsOnBackgroundThread();
if (gDatastores) {
CheckedUnsafePtr<Datastore> datastore;
if (gDatastores->Get(aOrigin, &datastore)) {
MOZ_ASSERT(datastore);
RefPtr<Datastore> result(datastore);
return result.forget();
}
}
return nullptr;
}
void InitUsageForOrigin(const nsACString& aOrigin, int64_t aUsage) {
AssertIsOnIOThread();
@ -6709,8 +6725,7 @@ nsresult PrepareDatastoreOp::CheckClosingDatastoreInternal() {
mNestedState = NestedState::PreparationPending;
RefPtr<Datastore> datastore;
if (gDatastores && (datastore = gDatastores->Get(mOrigin)) &&
datastore->IsClosed()) {
if ((datastore = GetDatastore(mOrigin)) && datastore->IsClosed()) {
datastore->WaitForConnectionToComplete(this);
return NS_OK;
@ -6749,7 +6764,7 @@ nsresult PrepareDatastoreOp::BeginDatastorePreparationInternal() {
MOZ_ASSERT(!QuotaClient::IsShuttingDownOnBackgroundThread());
MOZ_ASSERT(MayProceed());
if (gDatastores && (mDatastore = gDatastores->Get(mOrigin))) {
if ((mDatastore = GetDatastore(mOrigin))) {
MOZ_ASSERT(!mDatastore->IsClosed());
mDatastore->NoteLivePrepareDatastoreOp(this);
@ -8062,8 +8077,7 @@ void PreloadedOp::GetResponse(LSSimpleRequestResponse& aResponse) {
bool preloaded;
RefPtr<Datastore> datastore;
if (gDatastores && (datastore = gDatastores->Get(mOrigin)) &&
!datastore->IsClosed()) {
if ((datastore = GetDatastore(mOrigin)) && !datastore->IsClosed()) {
preloaded = true;
} else {
preloaded = false;