1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "TimeoutBudgetManager.h"
8 
9 #include "mozilla/dom/Timeout.h"
10 
11 namespace mozilla {
12 namespace dom {
13 
Get()14 /* static */ TimeoutBudgetManager& TimeoutBudgetManager::Get() {
15   static TimeoutBudgetManager gTimeoutBudgetManager;
16   return gTimeoutBudgetManager;
17 }
18 
StartRecording(const TimeStamp & aNow)19 void TimeoutBudgetManager::StartRecording(const TimeStamp& aNow) {
20   mStart = aNow;
21 }
22 
StopRecording()23 void TimeoutBudgetManager::StopRecording() { mStart = TimeStamp(); }
24 
RecordExecution(const TimeStamp & aNow,const Timeout * aTimeout)25 TimeDuration TimeoutBudgetManager::RecordExecution(const TimeStamp& aNow,
26                                                    const Timeout* aTimeout) {
27   if (!mStart) {
28     // If we've started a sync operation mStart might be null, in
29     // which case we should not record this piece of execution.
30     return TimeDuration();
31   }
32 
33   return aNow - mStart;
34 }
35 
36 }  // namespace dom
37 }  // namespace mozilla
38