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

Unified Diff: ui/file_manager/gallery/js/background.js

Issue 291893006: Gallery.app: Remove old Gallery files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « ui/file_manager/file_manager_resources.grd ('k') | ui/file_manager/gallery/manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/gallery/js/background.js
diff --git a/ui/file_manager/gallery/js/background.js b/ui/file_manager/gallery/js/background.js
index 61ea019d2f1723588bc96580eeea76886ec7484a..4c5d2582339c57ffbe9390652f5bf01a7c7dec34 100644
--- a/ui/file_manager/gallery/js/background.js
+++ b/ui/file_manager/gallery/js/background.js
@@ -93,9 +93,15 @@ function getChildren(entry) {
/**
* Promise to be fulfilled with single application window.
- * @param {AppWindow}
+ * @type {Promise}
+ */
+var appWindowPromise = Promise.resolve(null);
+
+/**
+ * Promise to be fulfilled with the current window is closed.
+ * @type {Promise}
*/
-var appWindowPromise = null;
+var closingPromise = Promise.resolve(null);
chrome.app.runtime.onLaunched.addListener(function(launchData) {
// Skip if files are not selected.
@@ -136,19 +142,16 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
});
});
- // Close previous window.
- var closePromise;
- if (appWindowPromise) {
- closePromise = appWindowPromise.then(function(appWindow) {
- return new Promise(function(fulfill) {
- appWindow.close();
- appWindow.onClosed.addListener(fulfill);
- });
- });
- } else {
- closePromise = Promise.resolve();
- }
- var createdWindowPromise = closePromise.then(function() {
+ // If there is the previous window, close the window.
+ appWindowPromise = appWindowPromise.then(function(appWindow) {
+ if (appWindow) {
+ appWindow.close();
+ return closingPromise;
+ }
+ });
+
+ // Create a new window.
+ appWindowPromise = appWindowPromise.then(function() {
return new Promise(function(fulfill) {
chrome.app.window.create(
'gallery.html',
@@ -161,11 +164,16 @@ chrome.app.runtime.onLaunched.addListener(function(launchData) {
function(appWindow) {
appWindow.contentWindow.addEventListener(
'load', fulfill.bind(null, appWindow));
+ closingPromise = new Promise(function(fulfill) {
+ appWindow.onClosed.addListener(fulfill);
+ });
});
});
});
+
+ // Initialize the window document.
appWindowPromise = Promise.all([
- createdWindowPromise,
+ appWindowPromise,
backgroundComponentsPromise,
]).then(function(args) {
args[0].contentWindow.initialize(args[1]);
« no previous file with comments | « ui/file_manager/file_manager_resources.grd ('k') | ui/file_manager/gallery/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698