Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/Timeout.cpp
Line
Count
Source (jump to first uncovered line)
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 "Timeout.h"
8
9
#include "mozilla/dom/TimeoutManager.h"
10
11
namespace mozilla {
12
namespace dom {
13
14
Timeout::Timeout()
15
  : mTimeoutId(0),
16
    mFiringId(TimeoutManager::InvalidFiringId),
17
    mPopupState(openAllowed),
18
    mReason(Reason::eTimeoutOrInterval),
19
    mNestingLevel(0),
20
    mCleared(false),
21
    mRunning(false),
22
    mIsInterval(false),
23
    mIsTracking(false)
24
0
{
25
0
}
26
27
NS_IMPL_CYCLE_COLLECTION_CLASS(Timeout)
28
29
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Timeout)
30
0
  NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
31
0
  NS_IMPL_CYCLE_COLLECTION_UNLINK(mScriptHandler)
32
0
  if (tmp->isInList()) {
33
0
    tmp->remove();
34
0
  }
35
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
36
37
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Timeout)
38
0
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
39
0
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptHandler)
40
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
41
42
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Timeout, AddRef)
43
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Timeout, Release)
44
45
void
46
Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
47
                                const TimeDuration& aDelay)
48
0
{
49
0
  MOZ_DIAGNOSTIC_ASSERT(mWindow);
50
0
51
0
  // If we are frozen simply set mTimeRemaining to be the "time remaining" in
52
0
  // the timeout (i.e., the interval itself).  This will be used to create a
53
0
  // new mWhen time when the window is thawed.  The end effect is that time does
54
0
  // not appear to pass for frozen windows.
55
0
  if (mWindow->IsFrozen()) {
56
0
    mWhen = TimeStamp();
57
0
    mTimeRemaining = aDelay;
58
0
    return;
59
0
  }
60
0
61
0
  // Since we are not frozen we must set a precise mWhen target wakeup
62
0
  // time.  Even if we are suspended we want to use this target time so
63
0
  // that it appears time passes while suspended.
64
0
  mWhen = aBaseTime + aDelay;
65
0
  mTimeRemaining = TimeDuration(0);
66
0
}
67
68
const TimeStamp&
69
Timeout::When() const
70
0
{
71
0
  MOZ_DIAGNOSTIC_ASSERT(!mWhen.IsNull());
72
0
  // Note, mWindow->IsFrozen() can be true here.  The Freeze() method calls
73
0
  // When() to calculate the delay to populate mTimeRemaining.
74
0
  return mWhen;
75
0
}
76
77
const TimeDuration&
78
Timeout::TimeRemaining() const
79
0
{
80
0
  MOZ_DIAGNOSTIC_ASSERT(mWhen.IsNull());
81
0
  // Note, mWindow->IsFrozen() can be false here.  The Thaw() method calls
82
0
  // TimeRemaining() to calculate the new When() value.
83
0
  return mTimeRemaining;
84
0
}
85
86
} // namespace dom
87
} // namespace mozilla