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

Side by Side Diff: ui/file_manager/file_manager/foreground/js/file_tasks.js

Issue 2833413003: Reuse FileTasks when entries are not changed. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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 * Represents a collection of available tasks to execute for a specific list 6 * Represents a collection of available tasks to execute for a specific list
7 * of entries. 7 * of entries.
8 * 8 *
9 * @param {!VolumeManagerWrapper} volumeManager 9 * @param {!VolumeManagerWrapper} volumeManager
10 * @param {!MetadataModel} metadataModel 10 * @param {!MetadataModel} metadataModel
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 taskDialog.showDefaultTaskDialog( 792 taskDialog.showDefaultTaskDialog(
793 title, 793 title,
794 message, 794 message,
795 items, defaultIdx, 795 items, defaultIdx,
796 function(item) { 796 function(item) {
797 onSuccess(item.task); 797 onSuccess(item.task);
798 }); 798 });
799 }; 799 };
800 800
801 /** 801 /**
802 * Compares if the given file entry set and the file entry set for this
fukino 2017/04/25 09:06:10 You compare two entry lists as sets, but if previo
tetsui2 2017/04/26 01:58:04 Done.
803 * FileTasks are same.
804 *
805 * @param {!Array<!Entry>} newEntries
806 * @return {boolean} return true if they are same.
807 */
808 FileTasks.prototype.areEntriesSame =
fukino 2017/04/25 09:06:10 nit: "are" is not common for boolean getters. If
tetsui2 2017/04/26 01:58:04 Done.
809 function(newEntries) {
810 // If the length of the entries is different, they are not same.
811 if (this.entries_.length !== newEntries.length) {
812 return false;
813 }
814 // Create set of new entry URLs.
815 var newEntryUrlSet = {};
816 for (var i = 0; i < newEntries.length; i++) {
817 newEntryUrlSet[newEntries[i].toURL()] = true;
818 }
819 // False if one of previous entries is not in the new set.
820 for (var i = 0; i < this.entries_.length; i++) {
821 if (!(this.entries_[i].toURL() in newEntryUrlSet)) {
822 return false;
823 }
824 }
825 return true;
826 };
827
828 /**
802 * Gets the default task from tasks. In case there is no such task (i.e. all 829 * Gets the default task from tasks. In case there is no such task (i.e. all
803 * tasks are generic file handlers), then return opt_taskToUseIfNoDefault or 830 * tasks are generic file handlers), then return opt_taskToUseIfNoDefault or
804 * null. 831 * null.
805 * 832 *
806 * @param {!Array<!Object>} tasks The list of tasks from where to choose the 833 * @param {!Array<!Object>} tasks The list of tasks from where to choose the
807 * default task. 834 * default task.
808 * @param {!Object=} opt_taskToUseIfNoDefault The task to return in case there 835 * @param {!Object=} opt_taskToUseIfNoDefault The task to return in case there
809 * is no default task available in tasks. 836 * is no default task available in tasks.
810 * @return {Object} opt_taskToUseIfNoDefault or null in case 837 * @return {Object} opt_taskToUseIfNoDefault or null in case
811 * opt_taskToUseIfNoDefault is undefined. 838 * opt_taskToUseIfNoDefault is undefined.
812 */ 839 */
813 FileTasks.getDefaultTask = function(tasks, opt_taskToUseIfNoDefault) { 840 FileTasks.getDefaultTask = function(tasks, opt_taskToUseIfNoDefault) {
814 for (var i = 0; i < tasks.length; i++) { 841 for (var i = 0; i < tasks.length; i++) {
815 if (tasks[i].isDefault) { 842 if (tasks[i].isDefault) {
816 return tasks[i]; 843 return tasks[i];
817 } 844 }
818 } 845 }
819 // If we haven't picked a default task yet, then just pick the first one 846 // If we haven't picked a default task yet, then just pick the first one
820 // which is not generic file handler. 847 // which is not generic file handler.
821 for (var i = 0; i < tasks.length; i++) { 848 for (var i = 0; i < tasks.length; i++) {
822 if (!tasks[i].isGenericFileHandler) { 849 if (!tasks[i].isGenericFileHandler) {
823 return tasks[i]; 850 return tasks[i];
824 } 851 }
825 } 852 }
826 return opt_taskToUseIfNoDefault || null; 853 return opt_taskToUseIfNoDefault || null;
827 }; 854 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698