OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * This object encapsulates everything related to tasks execution. | 6 * This object encapsulates everything related to tasks execution. |
7 * @param {FileManager} fileManager FileManager instance. | 7 * @param {FileManager} fileManager FileManager instance. |
8 * @param {Array.<string>} urls List of file urls. | 8 * @param {Array.<string>} urls List of file urls. |
9 */ | 9 */ |
10 function FileTasks(fileManager, urls) { | 10 function FileTasks(fileManager, urls) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 this.pendingInvocations_ = []; | 48 this.pendingInvocations_ = []; |
49 }; | 49 }; |
50 | 50 |
51 /** | 51 /** |
52 * Processes internal tasks. | 52 * Processes internal tasks. |
53 * @param {Array.<Object>} tasks The tasks. | 53 * @param {Array.<Object>} tasks The tasks. |
54 * @private | 54 * @private |
55 */ | 55 */ |
56 FileTasks.prototype.processTasks_ = function(tasks) { | 56 FileTasks.prototype.processTasks_ = function(tasks) { |
57 this.tasks_ = []; | 57 this.tasks_ = []; |
58 var id = this.fileManager_.getExtensionId(); | 58 var id = util.getExtensionId(); |
59 var is_on_drive = false; | 59 var is_on_drive = false; |
60 for (var index = 0; index < this.urls_.length; ++index) { | 60 for (var index = 0; index < this.urls_.length; ++index) { |
61 if (FileType.isOnGDrive(this.urls_[index])) { | 61 if (FileType.isOnGDrive(this.urls_[index])) { |
62 is_on_drive = true; | 62 is_on_drive = true; |
63 break; | 63 break; |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 for (var i = 0; i < tasks.length; i++) { | 67 for (var i = 0; i < tasks.length; i++) { |
68 var task = tasks[i]; | 68 var task = tasks[i]; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 * @param {string} taskId Task identifier. | 155 * @param {string} taskId Task identifier. |
156 * @param {Array.<string>=} opt_urls Urls to execute on instead of |this.urls_|. | 156 * @param {Array.<string>=} opt_urls Urls to execute on instead of |this.urls_|. |
157 * @private | 157 * @private |
158 */ | 158 */ |
159 FileTasks.prototype.execute_ = function(taskId, opt_urls) { | 159 FileTasks.prototype.execute_ = function(taskId, opt_urls) { |
160 var urls = opt_urls || this.urls_; | 160 var urls = opt_urls || this.urls_; |
161 this.checkAvailability_(function() { | 161 this.checkAvailability_(function() { |
162 chrome.fileBrowserPrivate.executeTask(taskId, urls); | 162 chrome.fileBrowserPrivate.executeTask(taskId, urls); |
163 | 163 |
164 var task_parts = taskId.split('|'); | 164 var task_parts = taskId.split('|'); |
165 if (task_parts[0] == this.fileManager_.getExtensionId()) { | 165 if (task_parts[0] == util.getExtensionId()) { |
166 // For internal tasks we do not listen to the event to avoid | 166 // For internal tasks we do not listen to the event to avoid |
167 // handling the same task instance from multiple tabs. | 167 // handling the same task instance from multiple tabs. |
168 // So, we manually execute the task. | 168 // So, we manually execute the task. |
169 this.executeInternalTask_(task_parts[1], urls); | 169 this.executeInternalTask_(task_parts[1], urls); |
170 } | 170 } |
171 }.bind(this)); | 171 }.bind(this)); |
172 }; | 172 }; |
173 | 173 |
174 /** | 174 /** |
175 * Checks whether the remote files are available right now. | 175 * Checks whether the remote files are available right now. |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 this.fileManager_.setDefaultActionMenuItem(this.defaultTask_); | 458 this.fileManager_.setDefaultActionMenuItem(this.defaultTask_); |
459 }; | 459 }; |
460 | 460 |
461 /** | 461 /** |
462 * Returns a list of external tasks (i.e. not defined in file manager). | 462 * Returns a list of external tasks (i.e. not defined in file manager). |
463 * @param {function(Array.<Object>)} callback The callback. | 463 * @param {function(Array.<Object>)} callback The callback. |
464 * @private | 464 * @private |
465 */ | 465 */ |
466 FileTasks.prototype.getExternals_ = function(callback) { | 466 FileTasks.prototype.getExternals_ = function(callback) { |
467 var externals = []; | 467 var externals = []; |
468 var id = this.fileManager_.getExtensionId(); | 468 var id = util.getExtensionId(); |
469 for (var index = 0; index < this.tasks_.length; index++) { | 469 for (var index = 0; index < this.tasks_.length; index++) { |
470 var task = this.tasks_[index]; | 470 var task = this.tasks_[index]; |
471 var task_parts = task.taskId.split('|'); | 471 var task_parts = task.taskId.split('|'); |
472 if (task_parts[0] != id) { | 472 if (task_parts[0] != id) { |
473 // Add callback, so gallery can execute the task. | 473 // Add callback, so gallery can execute the task. |
474 task.execute = this.execute_.bind(this, task.taskId); | 474 task.execute = this.execute_.bind(this, task.taskId); |
475 externals.push(task); | 475 externals.push(task); |
476 } | 476 } |
477 } | 477 } |
478 callback(externals); | 478 callback(externals); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 return this; | 512 return this; |
513 }; | 513 }; |
514 }; | 514 }; |
515 | 515 |
516 FileTasks.decorate('display'); | 516 FileTasks.decorate('display'); |
517 FileTasks.decorate('updateMenuItem'); | 517 FileTasks.decorate('updateMenuItem'); |
518 FileTasks.decorate('execute'); | 518 FileTasks.decorate('execute'); |
519 FileTasks.decorate('executeDefault'); | 519 FileTasks.decorate('executeDefault'); |
520 FileTasks.decorate('getExternals'); | 520 FileTasks.decorate('getExternals'); |
521 | 521 |
OLD | NEW |