Index: ui/file_manager/file_manager/background/js/background.js |
diff --git a/ui/file_manager/file_manager/background/js/background.js b/ui/file_manager/file_manager/background/js/background.js |
index 2b72823baaf203ab757a848a714d2e9128aa9572..43825d69e987776aa4a927eba478f3ba3cfed690 100644 |
--- a/ui/file_manager/file_manager/background/js/background.js |
+++ b/ui/file_manager/file_manager/background/js/background.js |
@@ -50,9 +50,9 @@ function FileBrowserBackground() { |
* necessary for decorating files in some views and integral to |
* local dedupling files during the cloud import process. |
* |
- * @type {!Promise.<!importer.HistoryLoader>} |
+ * @type {!importer.HistoryLoader} |
*/ |
- this.historyLoaderPromise = FileBrowserBackground.initHistoryLoader_(); |
+ this.historyLoader = new FileBrowserBackground.HistoryLoader(); |
/** |
* Event handler for progress center. |
@@ -88,7 +88,7 @@ function FileBrowserBackground() { |
this.mediaImportHandler = |
new importer.MediaImportHandler( |
this.fileOperationManager, |
- new importer.DefaultMediaScanner()); |
+ new importer.DefaultMediaScanner(this.historyLoader)); |
/** |
* Promise of string data. |
@@ -159,26 +159,6 @@ FileBrowserBackground.prototype = { |
}; |
/** |
- * Prepares the Cloud Import {@code HistoryLoader} to be used at runtime. |
- * |
- * @return {!Promise.<!importer.HistoryLoader>} |
- */ |
-FileBrowserBackground.initHistoryLoader_ = function() { |
- return importer.importEnabled() |
- .then( |
- /** |
- * @param {boolean} enabled |
- * @this {!FileBrowserBackground} |
- */ |
- function(enabled) { |
- return enabled ? |
- new importer.SynchronizedHistoryLoader( |
- new importer.ChromeSyncFileEntryProvider()) : |
- new importer.DummyImportHistory(false); |
- }); |
-}; |
- |
-/** |
* Register callback to be invoked after initialization. |
* If the initialization is already done, the callback is invoked immediately. |
* |
@@ -599,6 +579,42 @@ FileBrowserBackground.prototype.initContextMenu_ = function() { |
}; |
/** |
+ * History loader that provides an ImportHistorty appropriate |
+ * to user settings (if import history is enabled/disabled). |
+ * |
+ * TODO(smckay): Use SynchronizedHistoryLoader directly |
+ * once cloud-import feature is enabled by default. |
+ * |
+ * @constructor |
+ * @implements {importer.HistoryLoader} |
+ */ |
+FileBrowserBackground.HistoryLoader = function() { |
+ /** @private {Promise.<!importer.ImportHistory>} */ |
+ this.historyPromise_ = null; |
+}; |
+ |
+/** @override */ |
+FileBrowserBackground.HistoryLoader.prototype.getHistory = function() { |
+ return this.historyPromise_ ? |
+ this.historyPromise_ : |
+ importer.importEnabled() |
+ .then(this.initHistoryPromise_.bind(this)) |
+ .then( |
+ function() { |
+ return this.historyPromise_; |
+ }.bind(this)); |
+}; |
+ |
+/** @param {boolean} featureEnabled */ |
+FileBrowserBackground.HistoryLoader.prototype.initHistoryPromise_ = |
+ function(featureEnabled) { |
+ this.historyPromise_ = featureEnabled ? |
+ new importer.SynchronizedHistoryLoader( |
+ new importer.ChromeSyncFileEntryProvider()).getHistory() : |
+ new importer.DummyImportHistory(false).getHistory(); |
+}; |
+ |
+/** |
* Singleton instance of Background. |
* @type {FileBrowserBackground} |
*/ |