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

Unified Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10692090: Move FileCopyManager to background page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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: chrome/browser/resources/file_manager/js/file_manager.js
===================================================================
--- chrome/browser/resources/file_manager/js/file_manager.js (revision 146973)
+++ chrome/browser/resources/file_manager/js/file_manager.js (working copy)
@@ -539,7 +539,8 @@
};
FileManager.prototype.initDataTransferOperations_ = function() {
- this.copyManager_ = new FileCopyManager(this.filesystem_.root);
+ this.copyManager_ = FileCopyManagerWrapper.getInstance(
+ this.filesystem_.root);
this.copyManager_.addEventListener('copy-progress',
this.onCopyProgress_.bind(this));
this.copyManager_.addEventListener('copy-operation-complete',
@@ -4643,3 +4644,60 @@
}.bind(this));
}
})();
+
+var fileCopyManagerWrapper = null;
+
+/**
+ * @constructor
+ * @param {DirectoryEntry} root Root directory entry.
+ */
+function FileCopyManagerWrapper(root) {
+ var copyManagerPrototype =
+ chrome.extension.getBackgroundPage().FileCopyManager.prototype;
+
+ for (var property in copyManagerPrototype) {
+ if (this[property] === undefined &&
+ typeof copyManagerPrototype[property] === 'function') {
+ this[property] = (function(p) {
+ return function() {
+ var cmInstance =
+ chrome.extension.getBackgroundPage().FileCopyManager.getInstance(
+ root);
+ return cmInstance[p].apply(cmInstance, arguments);
+ }
+ })(property);
+ }
+ }
+}
+
+/**
+ * Extending cr.EventTarget
dgozman 2012/07/17 16:10:53 full stop
Oleg Eterevsky 2012/07/17 16:44:13 Done.
+ */
+FileCopyManagerWrapper.prototype.__proto__ = cr.EventTarget.prototype;
+
+/**
+ * Create a new instance or get existing instance of FCMW.
+ * @param {DirectoryEntry} root Root directory entry.
+ * @return {FileCopyManagerWrapper} A FileCopyManagerWrapper instance.
+ */
+FileCopyManagerWrapper.getInstance = function(root) {
+ if (fileCopyManagerWrapper === null) {
+ fileCopyManagerWrapper = new FileCopyManagerWrapper(root);
+ }
+ return fileCopyManagerWrapper;
+};
+
+/**
+ * Called be FileCopyManager to raise an event in this instance of FileManager.
+ * @param {string} eventName Event name.
+ * @param {Object} eventArgs Arbitratry field written to event object.
+ */
+FileCopyManagerWrapper.prototype.onEvent = function(eventName, eventArgs) {
+ var event = new cr.Event(eventName);
+ for (var arg in eventArgs)
+ if (eventArgs.hasOwnProperty(arg))
+ event[arg] = eventArgs[arg];
+
+ this.dispatchEvent(event);
+};
+

Powered by Google App Engine
This is Rietveld 408576698