Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/resources/local_ntp/local_ntp_util.js

Issue 412073002: Local NTP: prevent tiles from reloading on resize by moving them into single <div>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding local_ntp_utils.js and moving Barrier there. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5
6 /**
7 * @fileoverview Utilities for local_ntp.js.
8 */
9
10
11 /**
12 * A counter with a callback that gets executed on the 1-to-0 transition.
James Hawkins 2014/07/28 17:43:35 Please add a test for this.
huangs 2014/07/29 19:43:45 Maybe in a different CL? LocalNTPJavascriptTest i
Mathieu 2014/07/29 21:36:08 Assigned the crbug to you. Thanks! :)
13 *
14 * @param {Function} callback The callback to be executed.
Jered 2014/07/28 18:32:51 nit: !Function or function() here and below
huangs 2014/07/29 19:43:46 Done, using {function()}
15 * @constructor
16 */
17 function Barrier(callback) {
18 /** @private {Function} */
19 this.callback_ = callback;
20
21 /** @private {number} */
22 this.count_ = 0;
23 }
24
25
26 /**
27 * Increments count of the Barrier.
28 */
29 Barrier.prototype.add = function() {
30 ++this.count_;
31 };
32
33
34 /**
35 * Decrements count of the Barrier, and executes callback on 1-to-0 transition.
36 */
37 Barrier.prototype.remove = function() {
38 if (this.count_ === 0) // Guards against underflow.
39 return;
40 --this.count_;
41 if (this.count_ === 0)
42 this.callback_();
43 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698