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

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

Issue 805533003: Hook up import history to media scanner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert manifest.json. Created 6 years 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 | « no previous file | ui/file_manager/file_manager/background/js/media_scanner.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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}
*/
« no previous file with comments | « no previous file | ui/file_manager/file_manager/background/js/media_scanner.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698