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.
7 * @fileoverview Utilities for local_ntp.js.
12 * A counter with a callback that gets executed on the 1-to-0 transition.
14 * @param {function()} callback The callback to be executed.
17 function Barrier(callback
) {
18 /** @private {function()} */
19 this.callback_
= callback
;
21 /** @private {number} */
24 /** @private {boolean} */
25 this.isCancelled_
= false;
30 * Increments count of the Barrier.
32 Barrier
.prototype.add = function() {
38 * Decrements count of the Barrier, and executes callback on 1-to-0 transition.
40 Barrier
.prototype.remove = function() {
41 if (this.count_
=== 0) // Guards against underflow.
44 if (!this.isCancelled_
&& this.count_
=== 0)
50 * Deactivates the Barrier; the callback will never be executed.
52 Barrier
.prototype.cancel = function() {
53 this.isCancelled_
= true;