summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/cryptotoken/window-timer.js
blob: b5ad2a6f5254fc5ed5045f77aa93f1568d12b8ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview Provides an implementation of the SystemTimer interface based
 * on window's timer methods.
 */
'use strict';

/**
 * Creates an implementation of the SystemTimer interface based on window's
 * timer methods.
 * @constructor
 * @implements {SystemTimer}
 */
function WindowTimer() {}

/**
 * Sets a single-shot timer.
 * @param {function()} func Called back when the timer expires.
 * @param {number} timeoutMillis How long until the timer fires, in
 *     milliseconds.
 * @return {number} A timeout ID, which can be used to cancel the timer.
 */
WindowTimer.prototype.setTimeout = function(func, timeoutMillis) {
  return window.setTimeout(func, timeoutMillis);
};

/**
 * Clears a previously set timer.
 * @param {number} timeoutId The ID of the timer to clear.
 */
WindowTimer.prototype.clearTimeout = function(timeoutId) {
  window.clearTimeout(timeoutId);
};

/**
 * Sets a repeating interval timer.
 * @param {function()} func Called back each time the timer fires.
 * @param {number} timeoutMillis How long until the timer fires, in
 *     milliseconds.
 * @return {number} A timeout ID, which can be used to cancel the timer.
 */
WindowTimer.prototype.setInterval = function(func, timeoutMillis) {
  return window.setInterval(func, timeoutMillis);
};

/**
 * Clears a previously set interval timer.
 * @param {number} timeoutId The ID of the timer to clear.
 */
WindowTimer.prototype.clearInterval = function(timeoutId) {
  window.clearInterval(timeoutId);
};