Esempio n. 1
0
NotNull<AllocPolicy*> GlobalAllocPolicy::Instance(TrackType aTrack) {
  StaticMutexAutoLock lock(sMutex);
  if (aTrack == TrackType::kAudioTrack) {
    static RefPtr<AllocPolicyImpl> sAudioPolicy = []() {
      SystemGroup::Dispatch(
          TaskCategory::Other,
          NS_NewRunnableFunction(
              "GlobalAllocPolicy::GlobalAllocPolicy:Audio", []() {
                ClearOnShutdown(&sAudioPolicy, ShutdownPhase::ShutdownThreads);
              }));
      return new AllocPolicyImpl(MediaDecoderLimitDefault());
    }();
    return WrapNotNull(sAudioPolicy.get());
  }
  static RefPtr<AllocPolicyImpl> sVideoPolicy = []() {
    SystemGroup::Dispatch(
        TaskCategory::Other,
        NS_NewRunnableFunction(
            "GlobalAllocPolicy::GlobalAllocPolicy:Audio", []() {
              ClearOnShutdown(&sVideoPolicy, ShutdownPhase::ShutdownThreads);
            }));
    return new AllocPolicyImpl(MediaDecoderLimitDefault());
  }();
  return WrapNotNull(sVideoPolicy.get());
}
Esempio n. 2
0
void
PDMFactory::EnsureInit() const
{
  {
    StaticMutexAutoLock mon(sMonitor);
    if (sInstance) {
      // Quick exit if we already have an instance.
      return;
    }
    if (NS_IsMainThread()) {
      // On the main thread and holding the lock -> Create instance.
      sInstance = new PDMFactoryImpl();
      ClearOnShutdown(&sInstance);
      return;
    }
  }

  // Not on the main thread -> Sync-dispatch creation to main thread.
  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
  nsCOMPtr<nsIRunnable> runnable =
    NS_NewRunnableFunction([]() {
      StaticMutexAutoLock mon(sMonitor);
      if (!sInstance) {
        sInstance = new PDMFactoryImpl();
        ClearOnShutdown(&sInstance);
      }
    });
  SyncRunnable::DispatchToThread(mainThread, runnable);
}
Esempio n. 3
0
static void
InitializeFMRadioObserver()
{
  if (!sFMRadioObservers) {
    sFMRadioObservers = new ObserverList<FMRadioOperationInformation>;
    sFMRadioRDSObservers = new ObserverList<FMRadioRDSGroup>;
    ClearOnShutdown(&sFMRadioRDSObservers);
    ClearOnShutdown(&sFMRadioObservers);
  }
}
Esempio n. 4
0
/* static */
void BrowsingContext::Init() {
  if (!sBrowsingContexts) {
    sBrowsingContexts = new BrowsingContextMap<WeakPtr>();
    ClearOnShutdown(&sBrowsingContexts);
  }

  if (!sCachedBrowsingContexts) {
    sCachedBrowsingContexts = new BrowsingContextMap<RefPtr>();
    ClearOnShutdown(&sCachedBrowsingContexts);
  }
}
Esempio n. 5
0
/* static */ bool
DecoderDoctorLogger::EnsureLogIsEnabled()
{
  for (;;) {
    LogState state = static_cast<LogState>(sLogState);
    switch (state) {
      case scDisabled:
        // Currently disabled, try to be the one to enable.
        if (sLogState.compareExchange(scDisabled, scEnabling)) {
          // We are the one to enable logging, state won't change (except for
          // possible shutdown.)
          // Create DDMediaLogs singleton, which will process the message queue.
          DDMediaLogs::ConstructionResult mediaLogsConstruction =
            DDMediaLogs::New();
          if (NS_FAILED(mediaLogsConstruction.mRv)) {
            PanicInternal("Failed to enable logging", /* aDontBlock */ true);
            return false;
          }
          MOZ_ASSERT(mediaLogsConstruction.mMediaLogs);
          sMediaLogs = mediaLogsConstruction.mMediaLogs;
          // Setup shutdown-time clean-up.
          MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(
            TaskCategory::Other,
            NS_NewRunnableFunction("DDLogger shutdown setup", [] {
              sDDLogShutdowner = MakeUnique<DDLogShutdowner>();
              ClearOnShutdown(&sDDLogShutdowner, ShutdownPhase::Shutdown);
              sDDLogDeleter = MakeUnique<DDLogDeleter>();
              ClearOnShutdown(&sDDLogDeleter, ShutdownPhase::ShutdownThreads);
            })));

          // Nobody else should change the state when *we* are enabling logging.
          MOZ_ASSERT(sLogState == scEnabling);
          sLogState = scEnabled;
          DDL_INFO("Logging enabled");
          return true;
        }
        // Someone else changed the state before our compareExchange, just loop
        // around to examine the new situation.
        break;
      case scEnabled:
        return true;
      case scEnabling:
        // Someone else is currently enabling logging, actively wait by just
        // looping, until the state changes.
        break;
      case scShutdown:
        // Shutdown is non-recoverable, we cannot enable logging again.
        return false;
    }
    // Not returned yet, loop around to examine the new situation.
  }
}
Esempio n. 6
0
void
PDMFactory::EnsureInit() const
{
  StaticMutexAutoLock mon(sMonitor);
  if (!sInstance) {
    sInstance = new PDMFactoryImpl();
    if (NS_IsMainThread()) {
      ClearOnShutdown(&sInstance);
    } else {
      nsCOMPtr<nsIRunnable> runnable =
        NS_NewRunnableFunction([]() { ClearOnShutdown(&sInstance); });
      NS_DispatchToMainThread(runnable);
    }
  }
}
Esempio n. 7
0
TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
  : mMediaElement(aMediaElement)
  , mHasSeeked(false)
  , mLastTimeMarchesOnCalled(0.0)
  , mTimeMarchesOnDispatched(false)
  , mUpdateCueDisplayDispatched(false)
  , performedTrackSelection(false)
  , mCueTelemetryReported(false)
  , mShutdown(false)
{
  nsISupports* parentObject =
    mMediaElement->OwnerDoc()->GetParentObject();

  NS_ENSURE_TRUE_VOID(parentObject);
  WEBVTT_LOG("%p Create TextTrackManager",this);
  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentObject);
  mNewCues = new TextTrackCueList(window);
  mLastActiveCues = new TextTrackCueList(window);
  mTextTracks = new TextTrackList(window, this);
  mPendingTextTracks = new TextTrackList(window, this);

  if (!sParserWrapper) {
    nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
      do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID);
    sParserWrapper = parserWrapper;
    ClearOnShutdown(&sParserWrapper);
  }
  mShutdownProxy = new ShutdownObserverProxy(this);
}
Esempio n. 8
0
uint32_t
MsaaIdGenerator::GetContentProcessIDFor(dom::ContentParentId aIPCContentProcessID)
{
  MOZ_ASSERT(XRE_IsParentProcess() && NS_IsMainThread());
  if (!sContentParentIdMap) {
    sContentParentIdMap = new detail::ContentParentIdMap();
    ClearOnShutdown(&sContentParentIdMap);
  }

  uint32_t value = 0;
  if (sContentParentIdMap->Get(aIPCContentProcessID, &value)) {
    return value;
  }

  uint32_t index = 0;
  for (; index < ArrayLength(sContentProcessIdBitmap); ++index) {
    if (sContentProcessIdBitmap[index] == UINT64_MAX) {
      continue;
    }
    uint32_t bitIndex = CountTrailingZeroes64(~sContentProcessIdBitmap[index]);
    MOZ_ASSERT(!(sContentProcessIdBitmap[index] & (1ULL << bitIndex)));
    MOZ_ASSERT(bitIndex != 0 || index != 0);
    sContentProcessIdBitmap[index] |= (1ULL << bitIndex);
    value = index * kBitsPerElement + bitIndex;
    break;
  }

  // If we run out of content process IDs, we're in trouble
  MOZ_RELEASE_ASSERT(index < ArrayLength(sContentProcessIdBitmap));

  sContentParentIdMap->Put(aIPCContentProcessID, value);
  return value;
}
Esempio n. 9
0
already_AddRefed<DocumentFragment>
TextTrackCue::GetCueAsHTML()
{
  MOZ_ASSERT(mDocument);

  if (!sParserWrapper) {
    nsresult rv;
    nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
      do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) {
      return mDocument->CreateDocumentFragment();
    }
    sParserWrapper = parserWrapper;
    ClearOnShutdown(&sParserWrapper);
  }

  nsPIDOMWindow* window = mDocument->GetWindow();
  if (!window) {
    return mDocument->CreateDocumentFragment();
  }

  nsCOMPtr<nsIDOMHTMLElement> div;
  sParserWrapper->ConvertCueToDOMTree(window, this,
                                      getter_AddRefs(div));
  if (!div) {
    return mDocument->CreateDocumentFragment();
  }
  nsRefPtr<DocumentFragment> docFrag = mDocument->CreateDocumentFragment();
  nsCOMPtr<nsIDOMNode> throwAway;
  docFrag->AppendChild(div, getter_AddRefs(throwAway));

  return docFrag.forget();
}
Esempio n. 10
0
/* static */ TabGroup* TabGroup::GetChromeTabGroup() {
  if (!sChromeTabGroup) {
    sChromeTabGroup = new TabGroup(true /* chrome tab group */);
    ClearOnShutdown(&sChromeTabGroup);
  }
  return sChromeTabGroup;
}
Esempio n. 11
0
already_AddRefed<BasicCardService> BasicCardService::GetService() {
  if (!gBasicCardService) {
    gBasicCardService = new BasicCardService();
    ClearOnShutdown(&gBasicCardService);
  }
  RefPtr<BasicCardService> service = gBasicCardService;
  return service.forget();
}
void
InitializeDateCacheCleaner()
{
  if (!sDateCacheCleaner) {
    sDateCacheCleaner = new DateCacheCleaner();
    ClearOnShutdown(&sDateCacheCleaner);
  }
}
Esempio n. 13
0
 static FlaggedArray<T>* GetListenersToRemove(bool aDoNotInit = false) {
   MOZ_ASSERT(NS_IsMainThread());
   if (!gListenersToRemove && !aDoNotInit) {
     gListenersToRemove = new FlaggedArray<T>();
     ClearOnShutdown(&gListenersToRemove);
   }
   return gListenersToRemove;
 }
Esempio n. 14
0
static void
InitializeSystemTimeChangeObserver()
{
  if (!sSystemTimeObserver) {
    sSystemTimeObserver = new ObserverList<SystemTimeChange>;
    ClearOnShutdown(&sSystemTimeObserver);
  }
}
/* static */ GeckoTouchDispatcher*
GeckoTouchDispatcher::GetInstance()
{
  if (!sTouchDispatcher) {
    sTouchDispatcher = new GeckoTouchDispatcher();
    ClearOnShutdown(&sTouchDispatcher);
  }
  return sTouchDispatcher;
}
Esempio n. 16
0
/*static*/ void
VRManager::ManagerInit()
{
  MOZ_ASSERT(NS_IsMainThread());

  if (sVRManagerSingleton == nullptr) {
    sVRManagerSingleton = new VRManager();
    ClearOnShutdown(&sVRManagerSingleton);
  }
}
Esempio n. 17
0
/* static */
ConsoleUtils* ConsoleUtils::GetOrCreate() {
  if (!gConsoleUtilsService) {
    MOZ_ASSERT(NS_IsMainThread());

    gConsoleUtilsService = new ConsoleUtils();
    ClearOnShutdown(&gConsoleUtilsService);
  }

  return gConsoleUtilsService;
}
Esempio n. 18
0
GlobalAllocPolicy::GlobalAllocPolicy()
  : mMonitor("DecoderAllocPolicy::mMonitor")
  , mDecoderLimit(MediaDecoderLimitDefault())
{
  SystemGroup::Dispatch(
    TaskCategory::Other,
    NS_NewRunnableFunction("GlobalAllocPolicy::GlobalAllocPolicy", [this]() {
      ClearOnShutdown(this, ShutdownPhase::ShutdownThreads);
    }));
}
Esempio n. 19
0
CompositorLRU*
CompositorLRU::GetSingleton()
{
  if (sSingleton) {
    return sSingleton;
  }
  sSingleton = new CompositorLRU();
  ClearOnShutdown(&sSingleton);

  return sSingleton;
}
Esempio n. 20
0
//static
void
U2FTokenManager::Initialize()
{
  if (!XRE_IsParentProcess()) {
    return;
  }
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!gU2FTokenManager);
  gU2FTokenManager = new U2FTokenManager();
  ClearOnShutdown(&gU2FTokenManager);
}
/* static */ ContentProcessManager*
ContentProcessManager::GetSingleton()
{
  MOZ_ASSERT(XRE_IsParentProcess());

  if (!sSingleton) {
    sSingleton = new ContentProcessManager();
    ClearOnShutdown(&sSingleton);
  }
  return sSingleton;
}
Esempio n. 22
0
DocAccessibleChild::DocAccessibleChild(DocAccessible* aDoc)
  : DocAccessibleChildBase(aDoc)
  , mEmulatedWindowHandle(nullptr)
  , mIsRemoteConstructed(false)
{
  MOZ_COUNT_CTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
  if (!sPlatformChild) {
    sPlatformChild = new PlatformChild();
    ClearOnShutdown(&sPlatformChild, ShutdownPhase::Shutdown);
  }
}
Esempio n. 23
0
/* static */ ContentProcessManager*
ContentProcessManager::GetSingleton()
{
  MOZ_ASSERT(XRE_GetProcessType() == GoannaProcessType_Default);

  if (!sSingleton) {
    sSingleton = new ContentProcessManager();
    ClearOnShutdown(&sSingleton);
  }
  return sSingleton;
}
Esempio n. 24
0
/* static */
nsresult
ImageEncoder::EnsureThreadPool()
{
  if (!sThreadPool) {
    nsCOMPtr<nsIThreadPool> threadPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
    sThreadPool = threadPool;
    if (!NS_IsMainThread()) {
      NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
        ClearOnShutdown(&sThreadPool);
      }));
    } else {
      ClearOnShutdown(&sThreadPool);
    }

    const uint32_t kThreadLimit = 2;
    const uint32_t kIdleThreadLimit = 1;
    const uint32_t kIdleThreadTimeoutMs = 30000;

    nsresult rv = sThreadPool->SetName(NS_LITERAL_CSTRING("EncodingRunnable"));
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }

    rv = sThreadPool->SetThreadLimit(kThreadLimit);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }

    rv = sThreadPool->SetIdleThreadLimit(kIdleThreadLimit);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }

    rv = sThreadPool->SetIdleThreadTimeout(kIdleThreadTimeoutMs);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }
  }

  return NS_OK;
}
Esempio n. 25
0
/* static */ already_AddRefed<RequestSyncWifiService>
RequestSyncWifiService::GetInstance()
{
  if (!sService) {
    sService = new RequestSyncWifiService();
    hal::RegisterNetworkObserver(sService);
    ClearOnShutdown(&sService);
  }

  RefPtr<RequestSyncWifiService> service = sService.get();
  return service.forget();
}
  static ReaderQueue& Instance()
  {
    static StaticMutex sMutex;
    StaticMutexAutoLock lock(sMutex);

    if (!sInstance) {
      sInstance = new ReaderQueue;
      sInstance->MaxNumActive(MediaPrefs::MediaDecoderLimit());
      ClearOnShutdown(&sInstance, ShutdownPhase::Shutdown);
    }
    MOZ_ASSERT(sInstance);
    return *sInstance;
  }
Esempio n. 27
0
  NS_DECL_ISUPPORTS

  static U2FPrefManager* GetOrCreate()
  {
    MOZ_ASSERT(NS_IsMainThread());
    if (!gPrefManager) {
      gPrefManager = new U2FPrefManager();
      Preferences::AddStrongObserver(gPrefManager, PREF_WEBAUTHN_SOFTTOKEN_ENABLED);
      Preferences::AddStrongObserver(gPrefManager, PREF_U2F_NSSTOKEN_COUNTER);
      Preferences::AddStrongObserver(gPrefManager, PREF_WEBAUTHN_USBTOKEN_ENABLED);
      ClearOnShutdown(&gPrefManager, ShutdownPhase::ShutdownThreads);
    }
    return gPrefManager;
  }
Esempio n. 28
0
// static
already_AddRefed<GamepadService>
GamepadService::GetService()
{
  if (sShutdown) {
    return nullptr;
  }

  if (!gGamepadServiceSingleton) {
    gGamepadServiceSingleton = new GamepadService();
    ClearOnShutdown(&gGamepadServiceSingleton);
  }
  nsRefPtr<GamepadService> service(gGamepadServiceSingleton);
  return service.forget();
}
Esempio n. 29
0
/* static */ already_AddRefed<FileSystemSecurity>
FileSystemSecurity::GetOrCreate()
{
  MOZ_ASSERT(NS_IsMainThread());
  AssertIsInMainProcess();

  if (!gFileSystemSecurity) {
    gFileSystemSecurity = new FileSystemSecurity();
    ClearOnShutdown(&gFileSystemSecurity);
  }

  RefPtr<FileSystemSecurity> service = gFileSystemSecurity.get();
  return service.forget();
}
void
AbstractThread::InitStatics()
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!sMainThread);
  nsCOMPtr<nsIThread> mainThread;
  NS_GetMainThread(getter_AddRefs(mainThread));
  MOZ_DIAGNOSTIC_ASSERT(mainThread);
  sMainThread = new XPCOMThreadWrapper(mainThread.get(), /* aRequireTailDispatch = */ true);
  ClearOnShutdown(&sMainThread);

  if (!sCurrentThreadTLS.init()) {
    MOZ_CRASH();
  }
  sCurrentThreadTLS.set(sMainThread);
}