1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview Provides an implementation of the SystemTimer interface based
7 * on window's timer methods.
12 * Creates an implementation of the SystemTimer interface based on window's
15 * @implements {SystemTimer}
17 function WindowTimer() {
21 * Sets a single-shot timer.
22 * @param {function()} func Called back when the timer expires.
23 * @param {number} timeoutMillis How long until the timer fires, in
25 * @return {number} A timeout ID, which can be used to cancel the timer.
27 WindowTimer.prototype.setTimeout = function(func, timeoutMillis) {
28 return window.setTimeout(func, timeoutMillis);
32 * Clears a previously set timer.
33 * @param {number} timeoutId The ID of the timer to clear.
35 WindowTimer.prototype.clearTimeout = function(timeoutId) {
36 window.clearTimeout(timeoutId);
40 * Sets a repeating interval timer.
41 * @param {function()} func Called back each time the timer fires.
42 * @param {number} timeoutMillis How long until the timer fires, in
44 * @return {number} A timeout ID, which can be used to cancel the timer.
46 WindowTimer.prototype.setInterval = function(func, timeoutMillis) {
47 return window.setInterval(func, timeoutMillis);
51 * Clears a previously set interval timer.
52 * @param {number} timeoutId The ID of the timer to clear.
54 WindowTimer.prototype.clearInterval = function(timeoutId) {
55 window.clearInterval(timeoutId);