Bug 1479841 - Apply ipdl changes to MediaParent and pass back the key through the resolver. r=jib

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Chronopoulos 2018-09-25 17:03:37 +00:00
Родитель d34aa387fd
Коммит f4fc798776
2 изменённых файлов: 46 добавлений и 75 удалений

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

@ -420,29 +420,15 @@ public:
NS_IMPL_ISUPPORTS0(OriginKeyStore) NS_IMPL_ISUPPORTS0(OriginKeyStore)
bool NonE10s::SendGetPrincipalKeyResponse(const uint32_t& aRequestId,
nsCString aKey) {
MediaManager* mgr = MediaManager::GetIfExists();
if (!mgr) {
return false;
}
RefPtr<Pledge<nsCString>> pledge = mgr->mGetPrincipalKeyPledges.Remove(aRequestId);
if (pledge) {
pledge->Resolve(aKey);
}
return true;
}
template<class Super> mozilla::ipc::IPCResult template<class Super> mozilla::ipc::IPCResult
Parent<Super>::RecvGetPrincipalKey(const uint32_t& aRequestId, Parent<Super>::RecvGetPrincipalKey(const ipc::PrincipalInfo& aPrincipalInfo,
const ipc::PrincipalInfo& aPrincipalInfo, const bool& aPersist,
const bool& aPersist) PMediaParent::GetPrincipalKeyResolver&& aResolve)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
// First, get profile dir. // First, get profile dir.
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIFile> profileDir; nsCOMPtr<nsIFile> profileDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir)); getter_AddRefs(profileDir));
@ -450,67 +436,55 @@ Parent<Super>::RecvGetPrincipalKey(const uint32_t& aRequestId,
return IPCResult(this, false); return IPCResult(this, false);
} }
// Then over to stream-transport thread (a thread pool) to do the actual // Resolver has to be called in MainThread but the key is discovered
// file io. Stash a pledge to hold the answer and get an id for this request. // in a different thread. We wrap the resolver around a MozPromise to make
// it more flexible and pass it to the new task. When this is done the
// resolver is resolved in MainThread.
RefPtr<Pledge<nsCString>> p = new Pledge<nsCString>(); // Then over to stream-transport thread (a thread pool) to do the actual
uint32_t id = mOutstandingPledges.Append(*p); // file io. Stash a promise to hold the answer and get an id for this request.
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
MOZ_ASSERT(sts); MOZ_ASSERT(sts);
auto taskQueue = MakeRefPtr<TaskQueue>(sts.forget(), "RecvGetPrincipalKey");
RefPtr<Parent<Super>> that(this); RefPtr<Parent<Super>> that(this);
rv = sts->Dispatch(NewRunnableFrom([this, that, id, profileDir, InvokeAsync(
aPrincipalInfo, aPersist]() -> nsresult { taskQueue, __func__,
MOZ_ASSERT(!NS_IsMainThread()); [that, profileDir, aPrincipalInfo, aPersist]() {
StaticMutexAutoLock lock(sOriginKeyStoreMutex); MOZ_ASSERT(!NS_IsMainThread());
if (!sOriginKeyStore) {
return NS_ERROR_FAILURE;
}
sOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
nsresult rv; StaticMutexAutoLock lock(sOriginKeyStoreMutex);
nsAutoCString result; if (!sOriginKeyStore) {
if (IsPincipalInfoPrivate(aPrincipalInfo)) { return PrincipalKeyPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
rv = sOriginKeyStore->mPrivateBrowsingOriginKeys.GetPrincipalKey(aPrincipalInfo, result);
} else {
rv = sOriginKeyStore->mOriginKeys.GetPrincipalKey(aPrincipalInfo, result, aPersist);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Pass result back to main thread.
rv = NS_DispatchToMainThread(NewRunnableFrom([this, that, id,
result]() -> nsresult {
if (mDestroyed) {
return NS_OK;
} }
RefPtr<Pledge<nsCString>> p = mOutstandingPledges.Remove(id); sOriginKeyStore->mOriginKeys.SetProfileDir(profileDir);
if (!p) {
return NS_ERROR_UNEXPECTED; nsresult rv;
nsAutoCString result;
if (IsPincipalInfoPrivate(aPrincipalInfo)) {
rv = sOriginKeyStore->mPrivateBrowsingOriginKeys.
GetPrincipalKey(aPrincipalInfo, result);
} else {
rv = sOriginKeyStore->mOriginKeys.
GetPrincipalKey(aPrincipalInfo, result, aPersist);
} }
p->Resolve(result);
return NS_OK;
}), NS_DISPATCH_NORMAL);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return PrincipalKeyPromise::CreateAndReject(rv, __func__);
}
return PrincipalKeyPromise::CreateAndResolve(result, __func__);
} }
return NS_OK; )->Then(GetCurrentThreadSerialEventTarget(), __func__,
}), NS_DISPATCH_NORMAL); [aResolve](const PrincipalKeyPromise::ResolveOrRejectValue& aValue) {
if (aValue.IsReject()) {
aResolve(NS_LITERAL_CSTRING(""));
} else {
aResolve(aValue.ResolveValue());
}
}
);
if (NS_WARN_IF(NS_FAILED(rv))) {
return IPCResult(this, false);
}
p->Then([this, that, aRequestId](const nsCString& aKey) mutable {
if (mDestroyed) {
return NS_OK;
}
Unused << this->SendGetPrincipalKeyResponse(aRequestId, aKey);
return NS_OK;
});
return IPC_OK(); return IPC_OK();
} }

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

@ -28,16 +28,13 @@ public:
virtual ~NonE10s() {} virtual ~NonE10s() {}
protected: protected:
virtual mozilla::ipc::IPCResult virtual mozilla::ipc::IPCResult
RecvGetPrincipalKey(const uint32_t& aRequestId, RecvGetPrincipalKey(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const bool& aPersist,
const bool& aPersist) = 0; PMediaParent::GetPrincipalKeyResolver&& aResolve) = 0;
virtual mozilla::ipc::IPCResult RecvSanitizeOriginKeys(const uint64_t& aSinceWhen, virtual mozilla::ipc::IPCResult RecvSanitizeOriginKeys(const uint64_t& aSinceWhen,
const bool& aOnlyPrivateBrowsing) = 0; const bool& aOnlyPrivateBrowsing) = 0;
virtual void virtual void
ActorDestroy(ActorDestroyReason aWhy) = 0; ActorDestroy(ActorDestroyReason aWhy) = 0;
bool SendGetPrincipalKeyResponse(const uint32_t& aRequestId,
nsCString aKey);
}; };
/** /**
@ -62,9 +59,9 @@ class Parent : public RefCountedParent, public Super
ActorDestroyReason; ActorDestroyReason;
public: public:
virtual mozilla::ipc::IPCResult virtual mozilla::ipc::IPCResult
RecvGetPrincipalKey(const uint32_t& aRequestId, RecvGetPrincipalKey(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const bool& aPersist,
const bool& aPersist) override; PMediaParent::GetPrincipalKeyResolver&& aResolve) override;
virtual mozilla::ipc::IPCResult RecvSanitizeOriginKeys(const uint64_t& aSinceWhen, virtual mozilla::ipc::IPCResult RecvSanitizeOriginKeys(const uint64_t& aSinceWhen,
const bool& aOnlyPrivateBrowsing) override; const bool& aOnlyPrivateBrowsing) override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override; virtual void ActorDestroy(ActorDestroyReason aWhy) override;