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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_selection.js

Issue 14367009: Fix Javascript errors occuring when a file is deleted during calculating it's size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * The current selection object. 8 * The current selection object.
9 * 9 *
10 * @param {FileManager} fileManager FileManager instance. 10 * @param {FileManager} fileManager FileManager instance.
11 * @param {Array.<number>} indexes Selected indexes. 11 * @param {Array.<number>} indexes Selected indexes.
12 * @constructor 12 * @constructor
13 */ 13 */
14 function FileSelection(fileManager, indexes) { 14 function FileSelection(fileManager, indexes) {
15 this.fileManager_ = fileManager; 15 this.fileManager_ = fileManager;
16 this.sequenceIndex_ = 0;
satorux1 2013/04/19 07:52:18 sequenceIndex_ may sound too general as this is on
mtomasz 2013/04/19 09:13:16 Done.
16 this.indexes = indexes; 17 this.indexes = indexes;
17 this.entries = []; 18 this.entries = [];
18 this.urls = []; 19 this.urls = [];
19 this.totalCount = 0; 20 this.totalCount = 0;
20 this.fileCount = 0; 21 this.fileCount = 0;
21 this.directoryCount = 0; 22 this.directoryCount = 0;
22 this.bytes = 0; 23 this.bytes = 0;
23 this.showBytes = false; 24 this.showBytes = false;
24 this.allDriveFilesPresent = false, 25 this.allDriveFilesPresent = false,
25 this.iconType = null; 26 this.iconType = null;
26 this.cancelled_ = false;
27 this.bytesKnown = false; 27 this.bytesKnown = false;
28 28
29 // Synchronously compute what we can. 29 // Synchronously compute what we can.
30 for (var i = 0; i < this.indexes.length; i++) { 30 for (var i = 0; i < this.indexes.length; i++) {
31 var entry = fileManager.getFileList().item(this.indexes[i]); 31 var entry = fileManager.getFileList().item(this.indexes[i]);
32 if (!entry) 32 if (!entry)
33 continue; 33 continue;
34 34
35 this.entries.push(entry); 35 this.entries.push(entry);
36 this.urls.push(entry.toURL()); 36 this.urls.push(entry.toURL());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 }); 76 });
77 77
78 this.tasks.init(this.urls, this.mimeTypes); 78 this.tasks.init(this.urls, this.mimeTypes);
79 callback(); 79 callback();
80 }.bind(this)); 80 }.bind(this));
81 }; 81 };
82 82
83 /** 83 /**
84 * Computes the total size of selected files. 84 * Computes the total size of selected files.
85 * 85 *
86 * @param {function} callback The callback. 86 * @param {function} callback Completion callback. Not called when cancelled,
87 * or a new call has been invoked in the meantime.
87 */ 88 */
88 FileSelection.prototype.computeBytes = function(callback) { 89 FileSelection.prototype.computeBytes = function(callback) {
89 if (this.entries.length == 0) { 90 if (this.entries.length == 0) {
90 this.bytesKnown = true; 91 this.bytesKnown = true;
91 this.bytes = 0; 92 this.bytes = 0;
92 return; 93 return;
93 } 94 }
94 95
95 var countdown = this.entries.length; 96 var sequenceIndex = ++this.sequenceIndex_;
96 var pendingMetadataCount = 0; 97 var pendingMetadataCount = 0;
97 98
98 var maybeDone = function() { 99 var maybeDone = function() {
99 if (countdown == 0 && pendingMetadataCount == 0 && !this.cancelled_) { 100 if (pendingMetadataCount == 0) {
100 this.bytesKnown = true; 101 this.bytesKnown = true;
101 callback(); 102 callback();
102 } 103 }
103 }.bind(this); 104 }.bind(this);
104 105
105 var onProps = function(filesystem) { 106 var onProps = function(filesystem) {
satorux1 2013/04/19 07:52:18 The parameter looks like a misnomer. We are gettin
mtomasz 2013/04/19 09:13:16 This fetches the 'filesystem' metadata. Done.
106 this.bytes += filesystem.size; 107 // Ignore if the call got cancelled, or there is another new one fired.
108 if (sequenceIndex != this.sequenceIndex_)
109 return;
110
111 // It may happen that the metadata is not available because a file has been
112 // deleted in the meantime.
113 if (filesystem)
114 this.bytes += filesystem.size;
107 pendingMetadataCount--; 115 pendingMetadataCount--;
108 maybeDone(); 116 maybeDone();
109 }.bind(this); 117 }.bind(this);
110 118
111 for (var index = 0; index < this.entries.length; index++) { 119 for (var index = 0; index < this.entries.length; index++) {
112 if (this.cancelled_)
113 break;
114
115 var entry = this.entries[index]; 120 var entry = this.entries[index];
116 if (entry.isFile) { 121 if (entry.isFile) {
117 this.showBytes |= !FileType.isHosted(entry); 122 this.showBytes |= !FileType.isHosted(entry);
118 pendingMetadataCount++; 123 pendingMetadataCount++;
119 this.fileManager_.metadataCache_.get(entry, 'filesystem', onProps); 124 this.fileManager_.metadataCache_.get(entry, 'filesystem', onProps);
120 } else if (entry.isDirectory) { 125 } else if (entry.isDirectory) {
121 // Don't compute the directory size as it's expensive. 126 // Don't compute the directory size as it's expensive.
122 // crbug.com/179073. 127 // crbug.com/179073.
123 this.showBytes = false; 128 this.showBytes = false;
124 countdown = 0;
125 break; 129 break;
126 } 130 }
127 countdown--;
128 } 131 }
129 maybeDone(); 132 maybeDone();
130 }; 133 };
131 134
132 /** 135 /**
133 * Cancels any async computation. 136 * Cancels any async computation.
134 * 137 *
135 * @private 138 * @private
136 */ 139 */
137 FileSelection.prototype.cancelComputing_ = function() { 140 FileSelection.prototype.cancelComputing_ = function() {
138 this.cancelled_ = true; 141 this.sequenceIndex_++;
satorux1 2013/04/19 07:52:18 Maybe add some comment? This will invalidate the
mtomasz 2013/04/19 09:13:16 Done.
139 }; 142 };
140 143
141 /** 144 /**
142 * This object encapsulates everything related to current selection. 145 * This object encapsulates everything related to current selection.
143 * 146 *
144 * @param {FileManager} fileManager File manager instance. 147 * @param {FileManager} fileManager File manager instance.
145 * @constructor 148 * @constructor
146 */ 149 */
147 function FileSelectionHandler(fileManager) { 150 function FileSelectionHandler(fileManager) {
148 this.fileManager_ = fileManager; 151 this.fileManager_ = fileManager;
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 style.left = (boxWidth - imageWidth) / 2 + 'px'; 695 style.left = (boxWidth - imageWidth) / 2 + 'px';
693 style.top = (boxHeight - imageHeight) / 2 + 'px'; 696 style.top = (boxHeight - imageHeight) / 2 + 'px';
694 style.position = 'relative'; 697 style.position = 'relative';
695 698
696 util.applyTransform(largeImage, transform); 699 util.applyTransform(largeImage, transform);
697 700
698 largeImageBox.appendChild(largeImage); 701 largeImageBox.appendChild(largeImage);
699 largeImageBox.style.zIndex = 1000; 702 largeImageBox.style.zIndex = 1000;
700 return true; 703 return true;
701 }; 704 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698