tor-browser

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

GMPTimerChild.cpp (1594B)


      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 "GMPTimerChild.h"
      7 
      8 #include "GMPChild.h"
      9 #include "GMPPlatform.h"
     10 
     11 #define MAX_NUM_TIMERS 1000
     12 
     13 namespace mozilla::gmp {
     14 
     15 GMPTimerChild::GMPTimerChild(GMPChild* aPlugin)
     16    : mTimerCount(1), mPlugin(aPlugin) {
     17  MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
     18 }
     19 
     20 GMPTimerChild::~GMPTimerChild() {
     21  MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
     22 }
     23 
     24 GMPErr GMPTimerChild::SetTimer(GMPTask* aTask, int64_t aTimeoutMS) {
     25  if (!aTask) {
     26    NS_WARNING("Tried to set timer with null task!");
     27    return GMPGenericErr;
     28  }
     29 
     30  if (mPlugin->GMPMessageLoop() != MessageLoop::current()) {
     31    NS_WARNING("Tried to set GMP timer on non-main thread.");
     32    return GMPGenericErr;
     33  }
     34 
     35  if (mTimers.Count() > MAX_NUM_TIMERS) {
     36    return GMPQuotaExceededErr;
     37  }
     38  uint32_t timerId = mTimerCount;
     39  mTimers.InsertOrUpdate(timerId, aTask);
     40  mTimerCount++;
     41 
     42  if (!SendSetTimer(timerId, aTimeoutMS)) {
     43    return GMPGenericErr;
     44  }
     45  return GMPNoErr;
     46 }
     47 
     48 mozilla::ipc::IPCResult GMPTimerChild::RecvTimerExpired(
     49    const uint32_t& aTimerId) {
     50  MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
     51 
     52  GMPTask* task = mTimers.Get(aTimerId);
     53  mTimers.Remove(aTimerId);
     54  if (task) {
     55    RunOnMainThread(task);
     56  }
     57  return IPC_OK();
     58 }
     59 
     60 }  // namespace mozilla::gmp