OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 // Namespace | 5 // Namespace |
6 var importer = importer || {}; | 6 var importer = importer || {}; |
7 | 7 |
8 /** @private @enum {string} */ | 8 /** @private @enum {string} */ |
9 importer.ActivityState = { | 9 importer.ActivityState = { |
10 READY: 'ready', | 10 READY: 'ready', |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 73 |
74 var listener = this.onScanEvent_.bind(this); | 74 var listener = this.onScanEvent_.bind(this); |
75 this.scanner_.addObserver(listener); | 75 this.scanner_.addObserver(listener); |
76 // Remove the observer when the foreground window is closed. | 76 // Remove the observer when the foreground window is closed. |
77 window.addEventListener( | 77 window.addEventListener( |
78 'pagehide', | 78 'pagehide', |
79 function() { | 79 function() { |
80 this.scanner_.removeObserver(listener); | 80 this.scanner_.removeObserver(listener); |
81 }.bind(this)); | 81 }.bind(this)); |
82 | 82 |
83 this.environment_.addWindowCloseListener( | |
84 this.onWindowClosing_.bind(this)); | |
85 | |
83 this.environment_.addVolumeUnmountListener( | 86 this.environment_.addVolumeUnmountListener( |
84 this.onVolumeUnmounted_.bind(this)); | 87 this.onVolumeUnmounted_.bind(this)); |
85 | 88 |
86 this.environment_.addDirectoryChangedListener( | 89 this.environment_.addDirectoryChangedListener( |
87 this.onDirectoryChanged_.bind(this)); | 90 this.onDirectoryChanged_.bind(this)); |
88 | 91 |
89 this.environment_.addSelectionChangedListener( | 92 this.environment_.addSelectionChangedListener( |
90 this.onSelectionChanged_.bind(this)); | 93 this.onSelectionChanged_.bind(this)); |
91 | 94 |
92 this.commandWidget_.addClickListener( | 95 this.commandWidget_.addClickListener( |
(...skipping 28 matching lines...) Expand all Loading... | |
121 * | 124 * |
122 * @private | 125 * @private |
123 */ | 126 */ |
124 importer.ImportController.prototype.onScanEvent_ = function(event, scan) { | 127 importer.ImportController.prototype.onScanEvent_ = function(event, scan) { |
125 if (!this.scanManager_.isActiveScan(scan)) { | 128 if (!this.scanManager_.isActiveScan(scan)) { |
126 return; | 129 return; |
127 } | 130 } |
128 | 131 |
129 switch (event) { | 132 switch (event) { |
130 case importer.ScanEvent.INVALIDATED: | 133 case importer.ScanEvent.INVALIDATED: |
131 this.scanManager_.reset(); | 134 this.onScanInvalidated_(); |
132 case importer.ScanEvent.FINALIZED: | 135 case importer.ScanEvent.FINALIZED: |
133 case importer.ScanEvent.UPDATED: | 136 case importer.ScanEvent.UPDATED: |
134 this.checkState_(scan); | 137 this.checkState_(scan); |
135 break; | 138 break; |
136 } | 139 } |
137 }; | 140 }; |
138 | 141 |
142 /** @private */ | |
143 importer.ImportController.prototype.onWindowClosing_ = function() { | |
144 this.scanManager_.reset(); // Will cancel any active scans. | |
145 }; | |
146 | |
139 /** | 147 /** |
140 * @param {string} volumeId | 148 * @param {string} volumeId |
141 * @private | 149 * @private |
142 */ | 150 */ |
143 importer.ImportController.prototype.onVolumeUnmounted_ = function(volumeId) { | 151 importer.ImportController.prototype.onVolumeUnmounted_ = function(volumeId) { |
144 if (this.activeImport_) { | 152 if (this.activeImport_) { |
145 this.activeImport_.task.requestCancel(); | 153 this.activeImport_.task.requestCancel(); |
146 this.finalizeActiveImport_(); | 154 this.finalizeActiveImport_(); |
147 this.tracker_.send(metrics.ImportEvents.DEVICE_YANKED); | 155 this.tracker_.send(metrics.ImportEvents.DEVICE_YANKED); |
148 } | 156 } |
149 this.scanManager_.reset(); | 157 this.scanManager_.reset(); |
150 this.checkState_(); | 158 this.checkState_(); |
151 }; | 159 }; |
152 | 160 |
153 /** | 161 /** |
154 * @param {!Event} event | 162 * @param {!Event} event |
155 * @private | 163 * @private |
156 */ | 164 */ |
157 importer.ImportController.prototype.onDirectoryChanged_ = function(event) { | 165 importer.ImportController.prototype.onDirectoryChanged_ = function(event) { |
158 if (!event.previousDirEntry && | 166 if (!event.previousDirEntry && |
159 event.newDirEntry && | 167 event.newDirEntry && |
160 importer.isMediaDirectory(event.newDirEntry, this.environment_)) { | 168 importer.isMediaDirectory(event.newDirEntry, this.environment_)) { |
161 this.commandWidget_.setDetailsVisible(true); | 169 this.commandWidget_.setDetailsVisible(true); |
162 } | 170 } |
163 this.scanManager_.clearSelectionScan(); | 171 |
172 this.scanManager_.reset(); | |
164 if (this.isCurrentDirectoryScannable_()) { | 173 if (this.isCurrentDirectoryScannable_()) { |
165 this.checkState_( | 174 this.checkState_( |
166 this.scanManager_.getCurrentDirectoryScan()); | 175 this.scanManager_.getDirectoryScan()); |
167 } else { | 176 } else { |
168 this.checkState_(); | 177 this.checkState_(); |
169 } | 178 } |
170 }; | 179 }; |
171 | 180 |
172 /** @private */ | 181 /** @private */ |
173 importer.ImportController.prototype.onSelectionChanged_ = function() { | 182 importer.ImportController.prototype.onSelectionChanged_ = function() { |
183 // NOTE: Empty selection changed events can and will fire for a directory | |
184 // before we receive the the corresponding directory changed event | |
185 // and when the selection is empty. These are spurios events | |
186 // and we ignore them. | |
187 if (!this.scanManager_.hasSelectionScan() && | |
188 this.environment_.getSelection().length === 0) { | |
189 return; | |
190 } | |
191 | |
174 // NOTE: We clear the scan here, but don't immediately initiate | 192 // NOTE: We clear the scan here, but don't immediately initiate |
175 // a new scan. checkState will attempt to initialize the scan | 193 // a new scan. checkState will attempt to initialize the scan |
176 // during normal processing. | 194 // during normal processing. |
177 // Also, in the case the selection is transitioning to empty, | 195 // Also, in the case the selection is transitioning to empty, |
178 // we want to reinstate the underlying directory scan (if | 196 // we want to reinstate the underlying directory scan (if |
179 // in fact, one is possible). | 197 // in fact, one is possible). |
180 this.scanManager_.clearSelectionScan(); | 198 this.scanManager_.clearSelectionScan(); |
181 if (this.environment_.getSelection().length === 0 && | 199 if (this.environment_.getSelection().length === 0 && |
182 this.isCurrentDirectoryScannable_()) { | 200 this.isCurrentDirectoryScannable_()) { |
183 this.checkState_( | 201 this.checkState_( |
184 this.scanManager_.getCurrentDirectoryScan()); | 202 this.scanManager_.getDirectoryScan()); |
185 } else { | 203 } else { |
186 this.checkState_(); | 204 this.checkState_(); |
187 } | 205 } |
188 }; | 206 }; |
189 | 207 |
190 /** | 208 /** |
191 * @param {!importer.MediaImportHandler.ImportTask} task | 209 * @param {!importer.MediaImportHandler.ImportTask} task |
192 * @private | 210 * @private |
193 */ | 211 */ |
194 importer.ImportController.prototype.onImportFinished_ = function(task) { | 212 importer.ImportController.prototype.onImportFinished_ = function(task) { |
195 this.finalizeActiveImport_(); | 213 this.finalizeActiveImport_(); |
196 this.scanManager_.reset(); | 214 this.scanManager_.reset(); |
197 this.storage_.set(importer.Setting.HAS_COMPLETED_IMPORT, true); | 215 this.storage_.set(importer.Setting.HAS_COMPLETED_IMPORT, true); |
198 this.commandWidget_.setDetailsBannerVisible(false); | 216 this.commandWidget_.setDetailsBannerVisible(false); |
199 this.checkState_(); | 217 this.checkState_(); |
200 }; | 218 }; |
201 | 219 |
220 /** @private */ | |
221 importer.ImportController.prototype.onScanInvalidated_ = function() { | |
222 this.scanManager_.reset(); | |
223 if (this.environment_.getSelection().length === 0 && | |
224 this.isCurrentDirectoryScannable_()) { | |
225 this.checkState_( | |
226 this.scanManager_.getDirectoryScan()); | |
227 } else { | |
228 this.checkState_(); | |
229 } | |
230 }; | |
231 | |
232 /** | |
233 * @param {!importer.ScanResult} scan | |
234 * @private | |
235 */ | |
236 importer.ImportController.prototype.onScanCanceled_ = function(scan) { | |
mtomasz
2015/04/01 02:31:09
Is this method used?
Steve McKay
2015/04/01 03:52:53
Nope. Removed.
| |
237 this.scanManager_.reset(); | |
238 this.checkState_(); | |
239 }; | |
240 | |
202 /** | 241 /** |
203 * Does book keeping necessary to finalize the active task. | 242 * Does book keeping necessary to finalize the active task. |
204 * @private | 243 * @private |
205 */ | 244 */ |
206 importer.ImportController.prototype.finalizeActiveImport_ = function() { | 245 importer.ImportController.prototype.finalizeActiveImport_ = function() { |
207 console.assert(!!this.activeImport_, | 246 console.assert(!!this.activeImport_, |
208 'Cannot finish import when none is running.'); | 247 'Cannot finish import when none is running.'); |
209 this.previousImport_ = this.activeImport_; | 248 this.previousImport_ = this.activeImport_; |
210 this.activeImport_ = null; | 249 this.activeImport_ = null; |
211 }; | 250 }; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 var taskFinished = this.onImportFinished_.bind(this, importTask); | 314 var taskFinished = this.onImportFinished_.bind(this, importTask); |
276 importTask.whenFinished.then(taskFinished).catch(taskFinished); | 315 importTask.whenFinished.then(taskFinished).catch(taskFinished); |
277 this.checkState_(); | 316 this.checkState_(); |
278 }; | 317 }; |
279 | 318 |
280 /** | 319 /** |
281 * Cancels the active task. | 320 * Cancels the active task. |
282 * @private | 321 * @private |
283 */ | 322 */ |
284 importer.ImportController.prototype.cancel_ = function() { | 323 importer.ImportController.prototype.cancel_ = function() { |
285 this.activeImport_.task.requestCancel(); | 324 if (this.activeImport_) { |
286 this.finalizeActiveImport_(); | 325 this.activeImport_.task.requestCancel(); |
287 this.tracker_.send(metrics.ImportEvents.IMPORT_CANCELLED); | 326 this.finalizeActiveImport_(); |
327 this.tracker_.send(metrics.ImportEvents.IMPORT_CANCELLED); | |
328 } | |
288 | 329 |
289 this.scanManager_.reset(); | 330 this.scanManager_.reset(); |
290 this.checkState_(); | 331 this.checkState_(); |
291 }; | 332 }; |
292 | 333 |
293 /** | 334 /** |
294 * Checks the environment and updates UI as needed. | 335 * Checks the environment and updates UI as needed. |
295 * @param {importer.ScanResult=} opt_scan If supplied, | 336 * @param {importer.ScanResult=} opt_scan If supplied, |
296 * @private | 337 * @private |
297 */ | 338 */ |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 445 |
405 /** | 446 /** |
406 * Attempts to scan the current context. | 447 * Attempts to scan the current context. |
407 * | 448 * |
408 * @return {importer.ScanResult} A scan object, | 449 * @return {importer.ScanResult} A scan object, |
409 * or null if scan is not possible in current context. | 450 * or null if scan is not possible in current context. |
410 * @private | 451 * @private |
411 */ | 452 */ |
412 importer.ImportController.prototype.tryScan_ = function() { | 453 importer.ImportController.prototype.tryScan_ = function() { |
413 var entries = this.environment_.getSelection(); | 454 var entries = this.environment_.getSelection(); |
414 | |
415 if (entries.length) { | 455 if (entries.length) { |
416 if (entries.every( | 456 if (entries.every( |
417 importer.isEligibleEntry.bind(null, this.environment_))) { | 457 importer.isEligibleEntry.bind(null, this.environment_))) { |
418 return this.scanManager_.getSelectionScan(entries); | 458 return this.scanManager_.getSelectionScan(entries); |
419 } | 459 } |
420 } else if (this.isCurrentDirectoryScannable_()) { | 460 } else if (this.isCurrentDirectoryScannable_()) { |
421 return this.scanManager_.getCurrentDirectoryScan(); | 461 return this.scanManager_.getDirectoryScan(); |
422 } | 462 } |
423 | 463 |
424 return null; | 464 return null; |
425 }; | 465 }; |
426 | 466 |
427 /** | 467 /** |
428 * Class that adapts from the new non-command button to the old | 468 * Class that adapts from the new non-command button to the old |
429 * command style interface. | 469 * command style interface. |
430 * | 470 * |
431 * @interface | 471 * @interface |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 */ | 835 */ |
796 importer.ScanManager = function(environment, scanner) { | 836 importer.ScanManager = function(environment, scanner) { |
797 | 837 |
798 /** @private {!importer.ControllerEnvironment} */ | 838 /** @private {!importer.ControllerEnvironment} */ |
799 this.environment_ = environment; | 839 this.environment_ = environment; |
800 | 840 |
801 /** @private {!importer.MediaScanner} */ | 841 /** @private {!importer.MediaScanner} */ |
802 this.scanner_ = scanner; | 842 this.scanner_ = scanner; |
803 | 843 |
804 /** | 844 /** |
805 * A cache of selection scans by directory (url). | 845 * The active files scan, if any. |
806 * | 846 * |
807 * @private {importer.ScanResult} | 847 * @private {importer.ScanResult} |
808 */ | 848 */ |
809 this.selectionScan_ = null; | 849 this.selectionScan_ = null; |
810 | 850 |
811 /** | 851 /** |
812 * A cache of scans by directory (url). | 852 * The active directory scan, if any. |
813 * | 853 * |
814 * @private {!Object.<string, !importer.ScanResult>} | 854 * @private {importer.ScanResult} |
815 */ | 855 */ |
816 this.directoryScans_ = {}; | 856 this.directoryScan_ = null; |
817 }; | 857 }; |
818 | 858 |
819 /** | 859 /** |
820 * Forgets all scans. | 860 * Cancels and forgets all scans. |
821 */ | 861 */ |
822 importer.ScanManager.prototype.reset = function() { | 862 importer.ScanManager.prototype.reset = function() { |
823 this.clearSelectionScan(); | 863 this.clearSelectionScan(); |
824 this.clearDirectoryScans(); | 864 this.clearDirectoryScan(); |
825 }; | 865 }; |
826 | 866 |
827 /** | 867 /** |
828 * Forgets the selection scans for the current directory. | 868 * @return {boolean} True if we have an existing selection scan. |
869 */ | |
870 importer.ScanManager.prototype.hasSelectionScan = function() { | |
871 return !!this.selectionScan_; | |
872 }; | |
873 | |
874 /** | |
875 * Cancels and forgets the current selection scan, if any. | |
829 */ | 876 */ |
830 importer.ScanManager.prototype.clearSelectionScan = function() { | 877 importer.ScanManager.prototype.clearSelectionScan = function() { |
878 if (this.selectionScan_) { | |
879 this.selectionScan_.cancel(); | |
880 } | |
831 this.selectionScan_ = null; | 881 this.selectionScan_ = null; |
832 }; | 882 }; |
833 | 883 |
834 /** | 884 /** |
835 * Forgets directory scans. | 885 * Cancels and forgets the current directory scan, if any. |
836 */ | 886 */ |
837 importer.ScanManager.prototype.clearDirectoryScans = function() { | 887 importer.ScanManager.prototype.clearDirectoryScan = function() { |
838 this.directoryScans_ = {}; | 888 if (this.directoryScan_) { |
889 this.directoryScan_.cancel(); | |
890 } | |
891 this.directoryScan_ = null; | |
839 }; | 892 }; |
840 | 893 |
841 /** | 894 /** |
842 * @return {importer.ScanResult} Current active scan, or null | 895 * @return {importer.ScanResult} Current active scan, or null |
843 * if none. | 896 * if none. |
844 */ | 897 */ |
845 importer.ScanManager.prototype.getActiveScan = function() { | 898 importer.ScanManager.prototype.getActiveScan = function() { |
846 if (!!this.selectionScan_) { | 899 return this.selectionScan_ || this.directoryScan_; |
847 return this.selectionScan_; | |
848 } | |
849 var directory = this.environment_.getCurrentDirectory(); | |
850 if (directory) { | |
851 return this.directoryScans_[directory.toURL()]; | |
852 } | |
853 return null; | |
854 }; | 900 }; |
855 | 901 |
856 /** | 902 /** |
857 * @param {importer.ScanResult} scan | 903 * @param {importer.ScanResult} scan |
858 * @return {boolean} True if scan is the active scan...meaning the current | 904 * @return {boolean} True if scan is the active scan...meaning the current |
859 * selection scan or the scan for the current directory. | 905 * selection scan or the scan for the current directory. |
860 */ | 906 */ |
861 importer.ScanManager.prototype.isActiveScan = function(scan) { | 907 importer.ScanManager.prototype.isActiveScan = function(scan) { |
862 if (scan === this.selectionScan_) { | 908 return scan === this.selectionScan_ || scan === this.directoryScan_; |
863 return true; | |
864 } | |
865 | |
866 var directory = this.environment_.getCurrentDirectory(); | |
867 return !!directory && | |
868 scan === this.directoryScans_[directory.toURL()]; | |
869 }; | 909 }; |
870 | 910 |
871 /** | 911 /** |
872 * Returns the existing selection scan or a new one for the supplied | 912 * Returns the existing selection scan or a new one for the supplied |
873 * selection. | 913 * selection. |
874 * | 914 * |
875 * @param {!Array.<!FileEntry>} entries | 915 * @param {!Array.<!FileEntry>} entries |
876 * | 916 * |
877 * @return {!importer.ScanResult} | 917 * @return {!importer.ScanResult} |
878 */ | 918 */ |
879 importer.ScanManager.prototype.getSelectionScan = function(entries) { | 919 importer.ScanManager.prototype.getSelectionScan = function(entries) { |
880 console.assert(!this.selectionScan_, | 920 console.assert(!this.selectionScan_, |
881 'Cannot create new selection scan with another in the cache.'); | 921 'Cannot create new selection scan with another in the cache.'); |
882 this.selectionScan_ = this.scanner_.scanFiles(entries); | 922 this.selectionScan_ = this.scanner_.scanFiles(entries); |
883 return this.selectionScan_; | 923 return this.selectionScan_; |
884 }; | 924 }; |
885 | 925 |
886 /** | 926 /** |
887 * Returns a scan for the directory. | 927 * Returns a scan for the directory. |
888 * | 928 * |
889 * @return {importer.ScanResult} | 929 * @return {importer.ScanResult} |
890 */ | 930 */ |
891 importer.ScanManager.prototype.getCurrentDirectoryScan = function() { | 931 importer.ScanManager.prototype.getDirectoryScan = function() { |
892 var directory = this.environment_.getCurrentDirectory(); | 932 if (!this.directoryScan_) { |
893 if (!directory) { | 933 var directory = this.environment_.getCurrentDirectory(); |
894 return null; | 934 if (directory) { |
935 this.directoryScan_ = this.scanner_.scanDirectory( | |
936 /** @type {!DirectoryEntry} */ (directory)); | |
mtomasz
2015/04/01 02:31:09
nit: indent
Steve McKay
2015/04/01 03:52:53
Done.
| |
937 } | |
895 } | 938 } |
896 | 939 return this.directoryScan_; |
897 var url = directory.toURL(); | |
898 var scan = this.directoryScans_[url]; | |
899 if (!scan) { | |
900 scan = this.scanner_.scanDirectory( | |
901 /** @type {!DirectoryEntry} */ (directory)); | |
902 this.directoryScans_[url] = scan; | |
903 } | |
904 | |
905 return scan; | |
906 }; | 940 }; |
907 | 941 |
908 /** | 942 /** |
909 * Interface abstracting away the concrete file manager available | 943 * Interface abstracting away the concrete file manager available |
910 * to commands. By hiding file manager we make it easy to test | 944 * to commands. By hiding file manager we make it easy to test |
911 * ImportController. | 945 * ImportController. |
912 * | 946 * |
913 * @interface | 947 * @interface |
914 * @extends {VolumeManagerCommon.VolumeInfoProvider} | 948 * @extends {VolumeManagerCommon.VolumeInfoProvider} |
915 */ | 949 */ |
(...skipping 22 matching lines...) Expand all Loading... | |
938 */ | 972 */ |
939 importer.ControllerEnvironment.prototype.isGoogleDriveMounted; | 973 importer.ControllerEnvironment.prototype.isGoogleDriveMounted; |
940 | 974 |
941 /** | 975 /** |
942 * Returns the available space for the local volume in bytes. | 976 * Returns the available space for the local volume in bytes. |
943 * @return {!Promise<number>} | 977 * @return {!Promise<number>} |
944 */ | 978 */ |
945 importer.ControllerEnvironment.prototype.getFreeStorageSpace; | 979 importer.ControllerEnvironment.prototype.getFreeStorageSpace; |
946 | 980 |
947 /** | 981 /** |
982 * Installs a 'window closed' listener. Listener is called just | |
983 * just before the window is closed. Any business must be | |
984 * done synchronously. | |
985 * @param {function()} listener | |
986 */ | |
987 importer.ControllerEnvironment.prototype.addWindowCloseListener; | |
988 | |
989 /** | |
948 * Installs an 'unmount' listener. Listener is called with | 990 * Installs an 'unmount' listener. Listener is called with |
949 * the corresponding volume id when a volume is unmounted. | 991 * the corresponding volume id when a volume is unmounted. |
950 * @param {function(string)} listener | 992 * @param {function(string)} listener |
951 */ | 993 */ |
952 importer.ControllerEnvironment.prototype.addVolumeUnmountListener; | 994 importer.ControllerEnvironment.prototype.addVolumeUnmountListener; |
953 | 995 |
954 /** | 996 /** |
955 * Installs an 'directory-changed' listener. Listener is called when | 997 * Installs an 'directory-changed' listener. Listener is called when |
956 * the directory changed. | 998 * the directory changed. |
957 * @param {function(!Event)} listener | 999 * @param {function(!Event)} listener |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1042 | 1084 |
1043 /** @override */ | 1085 /** @override */ |
1044 importer.RuntimeControllerEnvironment.prototype.isGoogleDriveMounted = | 1086 importer.RuntimeControllerEnvironment.prototype.isGoogleDriveMounted = |
1045 function() { | 1087 function() { |
1046 var drive = this.fileManager_.volumeManager.getCurrentProfileVolumeInfo( | 1088 var drive = this.fileManager_.volumeManager.getCurrentProfileVolumeInfo( |
1047 VolumeManagerCommon.VolumeType.DRIVE); | 1089 VolumeManagerCommon.VolumeType.DRIVE); |
1048 return !!drive; | 1090 return !!drive; |
1049 }; | 1091 }; |
1050 | 1092 |
1051 /** @override */ | 1093 /** @override */ |
1052 importer.RuntimeControllerEnvironment.prototype.addVolumeUnmountListener = | |
1053 function(listener) { | |
1054 // TODO(smckay): remove listeners when the page is torn down. | |
1055 chrome.fileManagerPrivate.onMountCompleted.addListener( | |
1056 /** | |
1057 * @param {!MountCompletedEvent} event | |
1058 * @this {importer.RuntimeControllerEnvironment} | |
1059 */ | |
1060 function(event) { | |
1061 if (event.eventType === 'unmount') { | |
1062 listener(event.volumeMetadata.volumeId); | |
1063 } | |
1064 }); | |
1065 }; | |
1066 | |
1067 /** @override */ | |
1068 importer.RuntimeControllerEnvironment.prototype.getFreeStorageSpace = | 1094 importer.RuntimeControllerEnvironment.prototype.getFreeStorageSpace = |
1069 function() { | 1095 function() { |
1070 // Checking DOWNLOADS returns the amount of available local storage space. | 1096 // Checking DOWNLOADS returns the amount of available local storage space. |
1071 var localVolumeInfo = | 1097 var localVolumeInfo = |
1072 this.fileManager_.volumeManager.getCurrentProfileVolumeInfo( | 1098 this.fileManager_.volumeManager.getCurrentProfileVolumeInfo( |
1073 VolumeManagerCommon.VolumeType.DOWNLOADS); | 1099 VolumeManagerCommon.VolumeType.DOWNLOADS); |
1074 return new Promise( | 1100 return new Promise( |
1075 function(resolve, reject) { | 1101 function(resolve, reject) { |
1076 chrome.fileManagerPrivate.getSizeStats( | 1102 chrome.fileManagerPrivate.getSizeStats( |
1077 localVolumeInfo.volumeId, | 1103 localVolumeInfo.volumeId, |
1078 /** @param {Object} stats */ | 1104 /** @param {Object} stats */ |
1079 function(stats) { | 1105 function(stats) { |
1080 if (stats && !chrome.runtime.lastError) { | 1106 if (stats && !chrome.runtime.lastError) { |
1081 resolve(stats.remainingSize); | 1107 resolve(stats.remainingSize); |
1082 } else { | 1108 } else { |
1083 reject('Failed to ascertain available free space: ' + | 1109 reject('Failed to ascertain available free space: ' + |
1084 chrome.runtime.lastError.message || | 1110 chrome.runtime.lastError.message || |
1085 chrome.runtime.lastError); | 1111 chrome.runtime.lastError); |
1086 } | 1112 } |
1087 }); | 1113 }); |
1088 }); | 1114 }); |
1089 }; | 1115 }; |
1090 | 1116 |
1091 /** @override */ | 1117 /** @override */ |
1118 importer.RuntimeControllerEnvironment.prototype.addWindowCloseListener = | |
1119 function(listener) { | |
1120 window.addEventListener('pagehide', listener); | |
mtomasz
2015/04/01 03:19:47
nit: indent
Steve McKay
2015/04/01 03:52:53
Done.
| |
1121 }; | |
1122 | |
1123 /** @override */ | |
1124 importer.RuntimeControllerEnvironment.prototype.addVolumeUnmountListener = | |
1125 function(listener) { | |
1126 // TODO(smckay): remove listeners when the page is torn down. | |
1127 chrome.fileManagerPrivate.onMountCompleted.addListener( | |
1128 /** | |
1129 * @param {!MountCompletedEvent} event | |
1130 * @this {importer.RuntimeControllerEnvironment} | |
1131 */ | |
1132 function(event) { | |
1133 if (event.eventType === 'unmount') { | |
1134 listener(event.volumeMetadata.volumeId); | |
1135 } | |
1136 }); | |
1137 }; | |
1138 | |
1139 /** @override */ | |
1092 importer.RuntimeControllerEnvironment.prototype.addDirectoryChangedListener = | 1140 importer.RuntimeControllerEnvironment.prototype.addDirectoryChangedListener = |
1093 function(listener) { | 1141 function(listener) { |
1094 // TODO(smckay): remove listeners when the page is torn down. | 1142 // TODO(smckay): remove listeners when the page is torn down. |
1095 this.fileManager_.directoryModel.addEventListener( | 1143 this.fileManager_.directoryModel.addEventListener( |
1096 'directory-changed', | 1144 'directory-changed', |
1097 listener); | 1145 listener); |
1098 }; | 1146 }; |
1099 | 1147 |
1100 /** @override */ | 1148 /** @override */ |
1101 importer.RuntimeControllerEnvironment.prototype.addSelectionChangedListener = | 1149 importer.RuntimeControllerEnvironment.prototype.addSelectionChangedListener = |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 .catch(importer.getLogger().catcher('import-destination-provision')); | 1217 .catch(importer.getLogger().catcher('import-destination-provision')); |
1170 }; | 1218 }; |
1171 | 1219 |
1172 /** @override */ | 1220 /** @override */ |
1173 importer.RuntimeControllerEnvironment.prototype.showImportDestination = | 1221 importer.RuntimeControllerEnvironment.prototype.showImportDestination = |
1174 function(date) { | 1222 function(date) { |
1175 return this.getImportDestination(date) | 1223 return this.getImportDestination(date) |
1176 .then(this.revealDirectory_.bind(this)) | 1224 .then(this.revealDirectory_.bind(this)) |
1177 .catch(importer.getLogger().catcher('import-destination-reveal')); | 1225 .catch(importer.getLogger().catcher('import-destination-reveal')); |
1178 }; | 1226 }; |
OLD | NEW |