diff --git a/dom/media/mediacapabilities/BenchmarkStorageParent.cpp b/dom/media/mediacapabilities/BenchmarkStorageParent.cpp index 06a13f2ae9e9..54e5ad41fa76 100644 --- a/dom/media/mediacapabilities/BenchmarkStorageParent.cpp +++ b/dom/media/mediacapabilities/BenchmarkStorageParent.cpp @@ -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 diff --git a/dom/media/mediacapabilities/BenchmarkStorageParent.h b/dom/media/mediacapabilities/BenchmarkStorageParent.h index a1e663c0bd41..f94bff9aa68e 100644 --- a/dom/media/mediacapabilities/BenchmarkStorageParent.h +++ b/dom/media/mediacapabilities/BenchmarkStorageParent.h @@ -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 mStorage; }; diff --git a/dom/media/mediacapabilities/PBenchmarkStorage.ipdl b/dom/media/mediacapabilities/PBenchmarkStorage.ipdl index 52f639d885d8..21daf7dc8717 100644 --- a/dom/media/mediacapabilities/PBenchmarkStorage.ipdl +++ b/dom/media/mediacapabilities/PBenchmarkStorage.ipdl @@ -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__(); };