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

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

Issue 2292873003: Divide volume_manager.js into files for each classes and extract interfaces from them. (Closed)
Patch Set: Address comments. Created 4 years, 3 months 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
Index: ui/file_manager/file_manager/background/js/volume_manager_factory.js
diff --git a/ui/file_manager/file_manager/background/js/volume_manager_factory.js b/ui/file_manager/file_manager/background/js/volume_manager_factory.js
new file mode 100644
index 0000000000000000000000000000000000000000..013de01b94c9dc72a17c523e6d08a524eadf15ed
--- /dev/null
+++ b/ui/file_manager/file_manager/background/js/volume_manager_factory.js
@@ -0,0 +1,64 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var volumeManagerFactory = (function() {
+ /**
+ * The singleton instance of VolumeManager. Initialized by the first
+ * invocation of getInstance().
+ * @type {VolumeManager}
+ */
+ var instance = null;
+
+ /**
+ * @type {Promise}
+ */
+ var instancePromise = null;
+
+ /**
+ * Returns the VolumeManager instance asynchronously. If it has not been
+ * created or is under initialization, it will waits for the finish of the
+ * initialization.
+ * @param {function(VolumeManager)=} opt_callback Called with the
+ * VolumeManager instance. TODO(hirono): Remove the callback and use
+ * Promise instead.
+ * @return {Promise} Promise to be fulfilled with the volume manager.
+ */
+ function getInstance(opt_callback) {
+ if (!instancePromise) {
+ instance = new VolumeManagerImpl();
+ instancePromise = new Promise(function(fulfill) {
+ instance.initialize_(function() {
+ return fulfill(instance);
+ });
+ });
+ }
+ if (opt_callback)
+ instancePromise.then(opt_callback);
+ return instancePromise;
+ };
+
+ /**
+ * Returns instance of VolumeManager for debug purpose.
+ * This method returns VolumeManager.instance which may not be initialized.
+ *
+ * @return {VolumeManager} Volume manager.
+ */
+ function getInstanceForDebug() {
+ return instance;
+ };
+
+ /**
+ * Revokes the singleton instance for testing.
+ */
+ function revokeInstanceForTesting() {
+ instancePromise = null;
+ instance = null;
+ };
+
+ return {
+ getInstance: getInstance,
+ getInstanceForDebug: getInstanceForDebug,
+ revokeInstanceForTesting: revokeInstanceForTesting
+ };
+}());

Powered by Google App Engine
This is Rietveld 408576698