| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Type of a Files.app's instance launch. | 6 * Type of a Files.app's instance launch. |
| 7 * @enum {number} | 7 * @enum {number} |
| 8 */ | 8 */ |
| 9 var LaunchType = { | 9 var LaunchType = { |
| 10 ALWAYS_CREATE: 0, | 10 ALWAYS_CREATE: 0, |
| 11 FOCUS_ANY_OR_CREATE: 1, | 11 FOCUS_ANY_OR_CREATE: 1, |
| 12 FOCUS_SAME_OR_CREATE: 2 | 12 FOCUS_SAME_OR_CREATE: 2 |
| 13 }; | 13 }; |
| 14 Object.freeze(LaunchType); | 14 Object.freeze(LaunchType); |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Root class of the background page. | 17 * Root class of the background page. |
| 18 * @constructor | 18 * @constructor |
| 19 * @extends {BackgroundBase} | 19 * @extends {BackgroundBase} |
| 20 */ | 20 */ |
| 21 function FileBrowserBackground() { | 21 function FileBrowserBackground() { |
| 22 BackgroundBase.call(this); | 22 BackgroundBase.call(this); |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Map of all currently open file dialogs. The key is an app ID. | 25 * Map of all currently open file dialogs. The key is an app ID. |
| 26 * @type {Object.<string, Window>} | 26 * @type {!Object.<string, !Window>} |
| 27 */ | 27 */ |
| 28 this.dialogs = {}; | 28 this.dialogs = {}; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Synchronous queue for asynchronous calls. | 31 * Synchronous queue for asynchronous calls. |
| 32 * @type {AsyncUtil.Queue} | 32 * @type {!AsyncUtil.Queue} |
| 33 */ | 33 */ |
| 34 this.queue = new AsyncUtil.Queue(); | 34 this.queue = new AsyncUtil.Queue(); |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Progress center of the background page. | 37 * Progress center of the background page. |
| 38 * @type {ProgressCenter} | 38 * @type {!ProgressCenter} |
| 39 */ | 39 */ |
| 40 this.progressCenter = new ProgressCenter(); | 40 this.progressCenter = new ProgressCenter(); |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * File operation manager. | 43 * File operation manager. |
| 44 * @type {FileOperationManager} | 44 * @type {!FileOperationManager} |
| 45 */ | 45 */ |
| 46 this.fileOperationManager = new FileOperationManager(); | 46 this.fileOperationManager = new FileOperationManager(); |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Promise for the class that manages loading of import history | 49 * Promise for the class that manages loading of import history |
| 50 * necessary for decorating files in some views and integral to | 50 * necessary for decorating files in some views and integral to |
| 51 * local dedupling files during the cloud import process. | 51 * local dedupling files during the cloud import process. |
| 52 * | 52 * |
| 53 * @type {!Promise.<!importer.HistoryLoader>} | 53 * @type {!Promise.<!importer.HistoryLoader>} |
| 54 */ | 54 */ |
| 55 this.historyLoaderPromise = FileBrowserBackground.initHistoryLoader_(); | 55 this.historyLoaderPromise = FileBrowserBackground.initHistoryLoader_(); |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * Event handler for progress center. | 58 * Event handler for progress center. |
| 59 * @type {FileOperationHandler} | 59 * @private {!FileOperationHandler} |
| 60 * @private | |
| 61 */ | 60 */ |
| 62 this.fileOperationHandler_ = new FileOperationHandler(this); | 61 this.fileOperationHandler_ = new FileOperationHandler(this); |
| 63 | 62 |
| 64 /** | 63 /** |
| 65 * Event handler for C++ sides notifications. | 64 * Event handler for C++ sides notifications. |
| 66 * @type {DeviceHandler} | 65 * @private {!DeviceHandler} |
| 67 * @private | |
| 68 */ | 66 */ |
| 69 this.deviceHandler_ = new DeviceHandler(); | 67 this.deviceHandler_ = new DeviceHandler(); |
| 70 this.deviceHandler_.addEventListener( | 68 this.deviceHandler_.addEventListener( |
| 71 DeviceHandler.VOLUME_NAVIGATION_REQUESTED, | 69 DeviceHandler.VOLUME_NAVIGATION_REQUESTED, |
| 72 function(event) { | 70 function(event) { |
| 73 this.navigateToVolume_(event.devicePath, event.filePath); | 71 this.navigateToVolume_(event.devicePath, event.filePath); |
| 74 }.bind(this)); | 72 }.bind(this)); |
| 75 | 73 |
| 76 /** | 74 /** |
| 77 * Drive sync handler. | 75 * Drive sync handler. |
| 78 * @type {DriveSyncHandler} | 76 * @type {!DriveSyncHandler} |
| 79 */ | 77 */ |
| 80 this.driveSyncHandler = new DriveSyncHandler(this.progressCenter); | 78 this.driveSyncHandler = new DriveSyncHandler(this.progressCenter); |
| 81 this.driveSyncHandler.addEventListener( | 79 this.driveSyncHandler.addEventListener( |
| 82 DriveSyncHandler.COMPLETED_EVENT, | 80 DriveSyncHandler.COMPLETED_EVENT, |
| 83 function() { this.tryClose(); }.bind(this)); | 81 function() { this.tryClose(); }.bind(this)); |
| 84 | 82 |
| 85 /** | 83 /** |
| 84 * Handles importing of user media (e.g. photos, videos) from removable |
| 85 * devices. |
| 86 * @type {!importer.MediaImportHandler} |
| 87 */ |
| 88 this.mediaImportHandler = |
| 89 new importer.MediaImportHandler(this.fileOperationManager); |
| 90 |
| 91 /** |
| 86 * Promise of string data. | 92 * Promise of string data. |
| 87 * @type {Promise} | 93 * @type {!Promise} |
| 88 */ | 94 */ |
| 89 this.stringDataPromise = new Promise(function(fulfill) { | 95 this.stringDataPromise = new Promise(function(fulfill) { |
| 90 chrome.fileManagerPrivate.getStrings(fulfill); | 96 chrome.fileManagerPrivate.getStrings(fulfill); |
| 91 }); | 97 }); |
| 92 | 98 |
| 93 /** | 99 /** |
| 94 * String assets. | 100 * String assets. |
| 95 * @type {Object.<string, string>} | 101 * @type {Object<string, string>} |
| 96 */ | 102 */ |
| 97 this.stringData = null; | 103 this.stringData = null; |
| 98 | 104 |
| 99 /** | 105 /** |
| 100 * Callback list to be invoked after initialization. | 106 * Callback list to be invoked after initialization. |
| 101 * It turns to null after initialization. | 107 * It turns to null after initialization. |
| 102 * | 108 * |
| 103 * @type {Array.<function()>} | 109 * @private {!Array<function()>} |
| 104 * @private | |
| 105 */ | 110 */ |
| 106 this.initializeCallbacks_ = []; | 111 this.initializeCallbacks_ = []; |
| 107 | 112 |
| 108 /** | 113 /** |
| 109 * Last time when the background page can close. | 114 * Last time when the background page can close. |
| 110 * | 115 * |
| 111 * @type {?number} | 116 * @private {?number} |
| 112 * @private | |
| 113 */ | 117 */ |
| 114 this.lastTimeCanClose_ = null; | 118 this.lastTimeCanClose_ = null; |
| 115 | 119 |
| 116 // Seal self. | 120 // Seal self. |
| 117 Object.seal(this); | 121 Object.seal(this); |
| 118 | 122 |
| 119 // Initialize handlers. | 123 // Initialize handlers. |
| 120 chrome.fileBrowserHandler.onExecute.addListener(this.onExecute_.bind(this)); | 124 chrome.fileBrowserHandler.onExecute.addListener(this.onExecute_.bind(this)); |
| 121 chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this)); | 125 chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this)); |
| 122 chrome.app.runtime.onRestarted.addListener(this.onRestarted_.bind(this)); | 126 chrome.app.runtime.onRestarted.addListener(this.onRestarted_.bind(this)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 136 }.bind(this)).catch(function(error) { | 140 }.bind(this)).catch(function(error) { |
| 137 console.error(error.stack || error); | 141 console.error(error.stack || error); |
| 138 callback(); | 142 callback(); |
| 139 }); | 143 }); |
| 140 }.bind(this)); | 144 }.bind(this)); |
| 141 } | 145 } |
| 142 | 146 |
| 143 /** | 147 /** |
| 144 * A number of delay milliseconds from the first call of tryClose to the actual | 148 * A number of delay milliseconds from the first call of tryClose to the actual |
| 145 * close action. | 149 * close action. |
| 146 * @type {number} | 150 * @const {number} |
| 147 * @const | |
| 148 * @private | 151 * @private |
| 149 */ | 152 */ |
| 150 FileBrowserBackground.CLOSE_DELAY_MS_ = 5000; | 153 FileBrowserBackground.CLOSE_DELAY_MS_ = 5000; |
| 151 | 154 |
| 152 FileBrowserBackground.prototype = { | 155 FileBrowserBackground.prototype = { |
| 153 __proto__: BackgroundBase.prototype | 156 __proto__: BackgroundBase.prototype |
| 154 }; | 157 }; |
| 155 | 158 |
| 156 /** | 159 /** |
| 157 * Prepares the Cloud Import {@code HistoryLoader} to be used at runtime. | 160 * Prepares the Cloud Import {@code HistoryLoader} to be used at runtime. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (opt_callback) | 456 if (opt_callback) |
| 454 opt_callback(appId); | 457 opt_callback(appId); |
| 455 onTaskCompleted(); | 458 onTaskCompleted(); |
| 456 }); | 459 }); |
| 457 }); | 460 }); |
| 458 } | 461 } |
| 459 | 462 |
| 460 /** | 463 /** |
| 461 * Registers dialog window to the background page. | 464 * Registers dialog window to the background page. |
| 462 * | 465 * |
| 463 * @param {Window} dialogWindow Window of the dialog. | 466 * @param {!Window} dialogWindow Window of the dialog. |
| 464 */ | 467 */ |
| 465 function registerDialog(dialogWindow) { | 468 function registerDialog(dialogWindow) { |
| 466 var id = DIALOG_ID_PREFIX + (nextFileManagerDialogID++); | 469 var id = DIALOG_ID_PREFIX + (nextFileManagerDialogID++); |
| 467 window.background.dialogs[id] = dialogWindow; | 470 window.background.dialogs[id] = dialogWindow; |
| 468 dialogWindow.addEventListener('pagehide', function() { | 471 dialogWindow.addEventListener('pagehide', function() { |
| 469 delete window.background.dialogs[id]; | 472 delete window.background.dialogs[id]; |
| 470 }); | 473 }); |
| 471 } | 474 } |
| 472 | 475 |
| 473 /** | 476 /** |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 contexts: ['launcher'], | 594 contexts: ['launcher'], |
| 592 title: str('NEW_WINDOW_BUTTON_LABEL') | 595 title: str('NEW_WINDOW_BUTTON_LABEL') |
| 593 }); | 596 }); |
| 594 }; | 597 }; |
| 595 | 598 |
| 596 /** | 599 /** |
| 597 * Singleton instance of Background. | 600 * Singleton instance of Background. |
| 598 * @type {FileBrowserBackground} | 601 * @type {FileBrowserBackground} |
| 599 */ | 602 */ |
| 600 window.background = new FileBrowserBackground(); | 603 window.background = new FileBrowserBackground(); |
| OLD | NEW |