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

Unified 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: Fixing comments; improving renderTiles(). 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/local_ntp/local_ntp_util.js
diff --git a/chrome/browser/resources/local_ntp/local_ntp_util.js b/chrome/browser/resources/local_ntp/local_ntp_util.js
new file mode 100644
index 0000000000000000000000000000000000000000..7312a1f72189b29bafc69d45b3c7a87e4e5dd540
--- /dev/null
+++ b/chrome/browser/resources/local_ntp/local_ntp_util.js
@@ -0,0 +1,43 @@
+// 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 Utilities for local_ntp.js.
+ */
+
+
+/**
+ * A counter with a callback that gets executed on the 1-to-0 transition.
+ *
+ * @param {function()} callback The callback to be executed.
+ * @constructor
+ */
+function Barrier(callback) {
+ /** @private {function()} */
+ this.callback_ = callback;
+
+ /** @private {number} */
+ this.count_ = 0;
+}
+
+
+/**
+ * Increments count of the Barrier.
+ */
+Barrier.prototype.add = function() {
+ ++this.count_;
+};
+
+
+/**
+ * Decrements count of the Barrier, and executes callback on 1-to-0 transition.
+ */
+Barrier.prototype.remove = function() {
+ if (this.count_ === 0) // Guards against underflow.
+ return;
+ --this.count_;
+ if (this.count_ === 0)
+ this.callback_();
+};

Powered by Google App Engine
This is Rietveld 408576698