Bug 1399922 - Use a static mutex for getting deviceId keys in MediaParent. r=jesup

MozReview-Commit-ID: E6pzyAM4jOQ

--HG--
extra : rebase_source : f6a893508e4f5d1b426a62b6c549aba1e1f2041d
This commit is contained in:
Jan-Ivar Bruaroey 2017-09-21 10:45:56 -04:00
Родитель 7c2bd5ab17
Коммит 630e3ccfc3
1 изменённых файлов: 21 добавлений и 11 удалений

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

@ -37,6 +37,7 @@ mozilla::LazyLogModule gMediaParentLog("MediaParent");
namespace mozilla {
namespace media {
StaticMutex sOriginKeyStoreMutex;
static OriginKeyStore* sOriginKeyStore = nullptr;
class OriginKeyStore : public nsISupports
@ -396,6 +397,7 @@ class OriginKeyStore : public nsISupports
private:
virtual ~OriginKeyStore()
{
StaticMutexAutoLock lock(sOriginKeyStoreMutex);
sOriginKeyStore = nullptr;
LOG((__FUNCTION__));
}
@ -404,6 +406,7 @@ public:
static OriginKeyStore* Get()
{
MOZ_ASSERT(NS_IsMainThread());
StaticMutexAutoLock lock(sOriginKeyStoreMutex);
if (!sOriginKeyStore) {
sOriginKeyStore = new OriginKeyStore();
}
@ -447,8 +450,8 @@ Parent<Super>::RecvGetPrincipalKey(const uint32_t& aRequestId,
return IPCResult(this, 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);
@ -460,14 +463,18 @@ Parent<Super>::RecvGetPrincipalKey(const uint32_t& aRequestId,
rv = sts->Dispatch(NewRunnableFrom([this, that, id, profileDir,
aPrincipalInfo, aPersist]() -> nsresult {
MOZ_ASSERT(!NS_IsMainThread());
mOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
StaticMutexAutoLock lock(sOriginKeyStoreMutex);
if (!sOriginKeyStore) {
return NS_ERROR_FAILURE;
}
sOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
nsresult rv;
nsAutoCString result;
if (IsPincipalInfoPrivate(aPrincipalInfo)) {
rv = mOriginKeyStore->mPrivateBrowsingOriginKeys.GetPrincipalKey(aPrincipalInfo, result);
rv = sOriginKeyStore->mPrivateBrowsingOriginKeys.GetPrincipalKey(aPrincipalInfo, result);
} else {
rv = mOriginKeyStore->mOriginKeys.GetPrincipalKey(aPrincipalInfo, result, aPersist);
rv = sOriginKeyStore->mOriginKeys.GetPrincipalKey(aPrincipalInfo, result, aPersist);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -518,19 +525,22 @@ Parent<Super>::RecvSanitizeOriginKeys(const uint64_t& aSinceWhen,
if (NS_WARN_IF(NS_FAILED(rv))) {
return IPCResult(this, 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);