Commit c0de9cda authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: Remove callback from launcher.launchFileManager()

Given that this function is async, we can remove callback and the caller
sites can use then() or "await" to chain additional work. This
simplifies the logic inside launchFileManager() method.

Bug: 1067478
Change-Id: I203370d5ff9dbb351df8bcd68696bae39630e5fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147438Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759533}
parent d23785c0
...@@ -334,7 +334,7 @@ class FileBrowserBackgroundImpl extends BackgroundBase { ...@@ -334,7 +334,7 @@ class FileBrowserBackgroundImpl extends BackgroundBase {
appState.selectionURL = urls[0]; appState.selectionURL = urls[0];
launchType = LaunchType.FOCUS_SAME_OR_CREATE; launchType = LaunchType.FOCUS_SAME_OR_CREATE;
} }
launcher.launchFileManager(appState, undefined, launchType, () => { launcher.launchFileManager(appState, undefined, launchType).then(() => {
metrics.recordInterval('Load.BackgroundLaunch'); metrics.recordInterval('Load.BackgroundLaunch');
}); });
}); });
...@@ -368,7 +368,7 @@ class FileBrowserBackgroundImpl extends BackgroundBase { ...@@ -368,7 +368,7 @@ class FileBrowserBackgroundImpl extends BackgroundBase {
const id = Number(match[1]); const id = Number(match[1]);
try { try {
const appState = /** @type {Object} */ (JSON.parse(items[key])); const appState = /** @type {Object} */ (JSON.parse(items[key]));
launcher.launchFileManager(appState, id, undefined, () => { launcher.launchFileManager(appState, id, undefined).then(() => {
metrics.recordInterval('Load.BackgroundRestart'); metrics.recordInterval('Load.BackgroundRestart');
}); });
} catch (e) { } catch (e) {
......
...@@ -69,10 +69,10 @@ launcher.setInitializationPromise = (promise) => { ...@@ -69,10 +69,10 @@ launcher.setInitializationPromise = (promise) => {
* @param {Object=} opt_appState App state. * @param {Object=} opt_appState App state.
* @param {number=} opt_id Window id. * @param {number=} opt_id Window id.
* @param {LaunchType=} opt_type Launch type. Default: ALWAYS_CREATE. * @param {LaunchType=} opt_type Launch type. Default: ALWAYS_CREATE.
* @param {function(?string)=} opt_callback Completion callback with the App ID. * @return {!Promise<chrome.app.window.AppWindow|string>} Resolved with the App
* ID.
*/ */
launcher.launchFileManager = launcher.launchFileManager = async (opt_appState, opt_id, opt_type) => {
async (opt_appState, opt_id, opt_type, opt_callback) => {
const type = opt_type || LaunchType.ALWAYS_CREATE; const type = opt_type || LaunchType.ALWAYS_CREATE;
opt_appState = opt_appState =
/** /**
...@@ -113,9 +113,6 @@ launcher.launchFileManager = ...@@ -113,9 +113,6 @@ launcher.launchFileManager =
continue; continue;
} }
window.appWindows[key].focus(); window.appWindows[key].focus();
if (opt_callback) {
opt_callback(key);
}
return Promise.resolve(key); return Promise.resolve(key);
} }
} }
...@@ -132,9 +129,6 @@ launcher.launchFileManager = ...@@ -132,9 +129,6 @@ launcher.launchFileManager =
// the Files app's failed on some error, wrap it with try catch. // the Files app's failed on some error, wrap it with try catch.
try { try {
if (window.appWindows[key].contentWindow.isFocused()) { if (window.appWindows[key].contentWindow.isFocused()) {
if (opt_callback) {
opt_callback(key);
}
return Promise.resolve(key); return Promise.resolve(key);
} }
} catch (e) { } catch (e) {
...@@ -149,9 +143,6 @@ launcher.launchFileManager = ...@@ -149,9 +143,6 @@ launcher.launchFileManager =
if (!window.appWindows[key].isMinimized()) { if (!window.appWindows[key].isMinimized()) {
window.appWindows[key].focus(); window.appWindows[key].focus();
if (opt_callback) {
opt_callback(key);
}
return Promise.resolve(key); return Promise.resolve(key);
} }
} }
...@@ -162,9 +153,6 @@ launcher.launchFileManager = ...@@ -162,9 +153,6 @@ launcher.launchFileManager =
} }
window.appWindows[key].focus(); window.appWindows[key].focus();
if (opt_callback) {
opt_callback(key);
}
return Promise.resolve(key); return Promise.resolve(key);
} }
} }
...@@ -183,16 +171,11 @@ launcher.launchFileManager = ...@@ -183,16 +171,11 @@ launcher.launchFileManager =
const appWindow = new AppWindowWrapper( const appWindow = new AppWindowWrapper(
'main.html', appId, FILE_MANAGER_WINDOW_CREATE_OPTIONS); 'main.html', appId, FILE_MANAGER_WINDOW_CREATE_OPTIONS);
appWindow.launch(opt_appState || {}, false).then(() => { await appWindow.launch(opt_appState || {}, false);
if (!appWindow.rawAppWindow) { if (!appWindow.rawAppWindow) {
opt_callback && opt_callback(null); return null;
return Promise.resolve(null); }
}
appWindow.rawAppWindow.focus(); appWindow.rawAppWindow.focus();
if (opt_callback) { return appId;
opt_callback(appId);
}
return Promise.resolve(appId);
});
}; };
...@@ -10,11 +10,13 @@ ...@@ -10,11 +10,13 @@
* App ID. * App ID.
*/ */
test.util.async.openMainWindow = (appState, callback) => { test.util.async.openMainWindow = (appState, callback) => {
launcher.launchFileManager( launcher
appState, .launchFileManager(
undefined, // opt_type appState,
undefined, // opt_id undefined, // opt_type
callback); undefined, // opt_id
)
.then(callback);
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment