tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaSystemResourceManagerParent.cpp (2255B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "MediaSystemResourceManagerParent.h"
      7 
      8 #include "mozilla/layers/PImageBridgeParent.h"
      9 
     10 namespace mozilla::media {
     11 
     12 using namespace ipc;
     13 
     14 MediaSystemResourceManagerParent::MediaSystemResourceManagerParent()
     15    : mDestroyed(false) {
     16  mMediaSystemResourceService = MediaSystemResourceService::Get();
     17 }
     18 
     19 MediaSystemResourceManagerParent::~MediaSystemResourceManagerParent() {
     20  MOZ_ASSERT(mDestroyed);
     21 }
     22 
     23 mozilla::ipc::IPCResult MediaSystemResourceManagerParent::RecvAcquire(
     24    const uint32_t& aId, const MediaSystemResourceType& aResourceType,
     25    const bool& aWillWait) {
     26  mResourceRequests.WithEntryHandle(aId, [&](auto&& request) {
     27    MOZ_ASSERT(!request);
     28    if (request) {
     29      // Send fail response
     30      (void)SendResponse(aId, false /* fail */);
     31      return;
     32    }
     33 
     34    request.Insert(MakeUnique<MediaSystemResourceRequest>(aId, aResourceType));
     35    mMediaSystemResourceService->Acquire(this, aId, aResourceType, aWillWait);
     36  });
     37 
     38  return IPC_OK();
     39 }
     40 
     41 mozilla::ipc::IPCResult MediaSystemResourceManagerParent::RecvRelease(
     42    const uint32_t& aId) {
     43  MediaSystemResourceRequest* request = mResourceRequests.Get(aId);
     44  if (!request) {
     45    return IPC_OK();
     46  }
     47 
     48  mMediaSystemResourceService->ReleaseResource(this, aId,
     49                                               request->mResourceType);
     50  mResourceRequests.Remove(aId);
     51  return IPC_OK();
     52 }
     53 
     54 mozilla::ipc::IPCResult
     55 MediaSystemResourceManagerParent::RecvRemoveResourceManager() {
     56  IProtocol* mgr = Manager();
     57  if (!PMediaSystemResourceManagerParent::Send__delete__(this)) {
     58    return IPC_FAIL_NO_REASON(mgr);
     59  }
     60  return IPC_OK();
     61 }
     62 
     63 void MediaSystemResourceManagerParent::ActorDestroy(
     64    ActorDestroyReason aReason) {
     65  MOZ_ASSERT(!mDestroyed);
     66 
     67  // Release all resource requests of the MediaSystemResourceManagerParent.
     68  // Clears all remaining pointers to this object.
     69  mMediaSystemResourceService->ReleaseResource(this);
     70 
     71  mDestroyed = true;
     72 }
     73 
     74 }  // namespace mozilla::media