Bug 1572043 - Introduce a check version method in the benchmark storage IPDL protocol.r=jya

The new protocol method transfers the database name and the version number from the content to the parent process. Then the parent process retrieves the stored version number from the database and compares it to the provided version number. If they are the same it stops there, otherwise it erases all the entries from the database and stores the new version number.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Chronopoulos 2019-08-13 09:29:19 +00:00
Родитель ef37f88221
Коммит 04185356f6
3 изменённых файлов: 24 добавлений и 0 удалений

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

@ -100,4 +100,25 @@ IPCResult BenchmarkStorageParent::RecvGet(const nsCString& aDbName,
return IPC_OK();
}
IPCResult BenchmarkStorageParent::RecvCheckVersion(const nsCString& aDbName,
int32_t aVersion) {
mStorage->Get(aDbName, NS_LITERAL_CSTRING("Version"))
->Then(
GetCurrentThreadSerialEventTarget(), __func__,
[storage = mStorage, aDbName, aVersion](int32_t aResult) {
if (aVersion != aResult) {
storage->Clear(aDbName)->Then(
GetCurrentThreadSerialEventTarget(), __func__,
[storage, aDbName, aVersion](bool) {
storage->Put(aDbName, NS_LITERAL_CSTRING("Version"),
aVersion);
},
[](nsresult rv) { /*do nothing*/ });
}
},
[](nsresult rv) { /*do nothing*/ });
return IPC_OK();
}
}; // namespace mozilla

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

@ -26,6 +26,8 @@ class BenchmarkStorageParent : public PBenchmarkStorageParent {
IPCResult RecvGet(const nsCString& aDbName, const nsCString& aKey,
GetResolver&& aResolve);
IPCResult RecvCheckVersion(const nsCString& aDbName, int32_t aVersion);
private:
RefPtr<KeyValueStorage> mStorage;
};

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

@ -14,6 +14,7 @@ async protocol PBenchmarkStorage
parent:
async Put(nsCString aDbName, nsCString aKey, int32_t aValue);
async Get(nsCString aDbName, nsCString aKey) returns(int32_t aValue);
async CheckVersion(nsCString aDbName, int32_t aVersion);
async __delete__();
};