summaryrefslogtreecommitdiffstats
path: root/dom/media/systemservices/MediaParent.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-09 08:53:46 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-09 08:53:46 +0100
commit8cecf8d5208f3945b35f879bba3015bb1a11bec6 (patch)
tree0926f5c21f9d10cf929e4c35e7d7e8e8c084dbf5 /dom/media/systemservices/MediaParent.cpp
parent8cd777888a40e987ad536ab68421068f5c06d83b (diff)
parent92104eb6828ba026550e1f4a3c6890c5b8254d36 (diff)
downloadUXP-8cecf8d5208f3945b35f879bba3015bb1a11bec6.tar
UXP-8cecf8d5208f3945b35f879bba3015bb1a11bec6.tar.gz
UXP-8cecf8d5208f3945b35f879bba3015bb1a11bec6.tar.lz
UXP-8cecf8d5208f3945b35f879bba3015bb1a11bec6.tar.xz
UXP-8cecf8d5208f3945b35f879bba3015bb1a11bec6.zip
Merge branch 'ported-upstream'
Diffstat (limited to 'dom/media/systemservices/MediaParent.cpp')
-rw-r--r--dom/media/systemservices/MediaParent.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/dom/media/systemservices/MediaParent.cpp b/dom/media/systemservices/MediaParent.cpp
index 109a44a28..89a495f6a 100644
--- a/dom/media/systemservices/MediaParent.cpp
+++ b/dom/media/systemservices/MediaParent.cpp
@@ -37,6 +37,7 @@ mozilla::LazyLogModule gMediaParentLog("MediaParent");
namespace mozilla {
namespace media {
+StaticMutex sOriginKeyStoreMutex;
static OriginKeyStore* sOriginKeyStore = nullptr;
class OriginKeyStore : public nsISupports
@@ -332,6 +333,7 @@ class OriginKeyStore : public nsISupports
private:
virtual ~OriginKeyStore()
{
+ StaticMutexAutoLock lock(sOriginKeyStoreMutex);
sOriginKeyStore = nullptr;
LOG((__FUNCTION__));
}
@@ -340,6 +342,7 @@ public:
static OriginKeyStore* Get()
{
MOZ_ASSERT(NS_IsMainThread());
+ StaticMutexAutoLock lock(sOriginKeyStoreMutex);
if (!sOriginKeyStore) {
sOriginKeyStore = new OriginKeyStore();
}
@@ -384,8 +387,8 @@ Parent<Super>::RecvGetOriginKey(const uint32_t& aRequestId,
return false;
}
- // Then over to stream-transport thread to do the actual file io.
- // Stash a pledge to hold the answer and get an id for this request.
+ // Then over to stream-transport thread (a thread pool) to do the actual
+ // file io. Stash a pledge to hold the answer and get an id for this request.
RefPtr<Pledge<nsCString>> p = new Pledge<nsCString>();
uint32_t id = mOutstandingPledges.Append(*p);
@@ -397,12 +400,17 @@ Parent<Super>::RecvGetOriginKey(const uint32_t& aRequestId,
rv = sts->Dispatch(NewRunnableFrom([this, that, id, profileDir, aOrigin,
aPrivateBrowsing, aPersist]() -> nsresult {
MOZ_ASSERT(!NS_IsMainThread());
- mOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
+ StaticMutexAutoLock lock(sOriginKeyStoreMutex);
+ if (!sOriginKeyStore) {
+ return NS_ERROR_FAILURE;
+ }
+ sOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
+
nsCString result;
if (aPrivateBrowsing) {
- mOriginKeyStore->mPrivateBrowsingOriginKeys.GetOriginKey(aOrigin, result);
+ sOriginKeyStore->mPrivateBrowsingOriginKeys.GetOriginKey(aOrigin, result);
} else {
- mOriginKeyStore->mOriginKeys.GetOriginKey(aOrigin, result, aPersist);
+ sOriginKeyStore->mOriginKeys.GetOriginKey(aOrigin, result, aPersist);
}
// Pass result back to main thread.
@@ -450,19 +458,21 @@ Parent<Super>::RecvSanitizeOriginKeys(const uint64_t& aSinceWhen,
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
- // Over to stream-transport thread to do the file io.
+ // Over to stream-transport thread (a thread pool) to do the file io.
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
MOZ_ASSERT(sts);
- RefPtr<OriginKeyStore> store(mOriginKeyStore);
-
- rv = sts->Dispatch(NewRunnableFrom([profileDir, store, aSinceWhen,
+ rv = sts->Dispatch(NewRunnableFrom([profileDir, aSinceWhen,
aOnlyPrivateBrowsing]() -> nsresult {
MOZ_ASSERT(!NS_IsMainThread());
- store->mPrivateBrowsingOriginKeys.Clear(aSinceWhen);
+ StaticMutexAutoLock lock(sOriginKeyStoreMutex);
+ if (!sOriginKeyStore) {
+ return NS_ERROR_FAILURE;
+ }
+ sOriginKeyStore->mPrivateBrowsingOriginKeys.Clear(aSinceWhen);
if (!aOnlyPrivateBrowsing) {
- store->mOriginKeys.SetProfileDir(profileDir);
- store->mOriginKeys.Clear(aSinceWhen);
+ sOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
+ sOriginKeyStore->mOriginKeys.Clear(aSinceWhen);
}
return NS_OK;
}), NS_DISPATCH_NORMAL);