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

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

Issue 12258003: [Cleanup] Files.app: Adds missing JSdoc annotations in file_manager/*.js. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 7 years, 10 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 | chrome/browser/resources/file_manager/js/file_selection.js » ('j') | 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 if (chrome.extension) { 5 if (chrome.extension) {
6 var getContentWindows = function() { 6 var getContentWindows = function() {
7 return chrome.extension.getViews(); 7 return chrome.extension.getViews();
8 }; 8 };
9 } 9 }
10 10
11 /** 11 /**
12 * @param {DirectoryEntry} root Root directory entry.
12 * @constructor 13 * @constructor
13 * @param {DirectoryEntry} root Root directory entry.
14 */ 14 */
15 function FileCopyManager(root) { 15 function FileCopyManager(root) {
16 this.copyTasks_ = []; 16 this.copyTasks_ = [];
17 this.deleteTasks_ = []; 17 this.deleteTasks_ = [];
18 this.lastDeleteId_ = 0; 18 this.lastDeleteId_ = 0;
19 this.cancelObservers_ = []; 19 this.cancelObservers_ = [];
20 this.cancelRequested_ = false; 20 this.cancelRequested_ = false;
21 this.cancelCallback_ = null; 21 this.cancelCallback_ = null;
22 this.root_ = root; 22 this.root_ = root;
23 this.unloadTimeout_ = null; 23 this.unloadTimeout_ = null;
24 24
25 window.addEventListener('error', function(e) { 25 window.addEventListener('error', function(e) {
26 this.log_('Unhandled error: ', e.message, e.filename + ':' + e.lineno); 26 this.log_('Unhandled error: ', e.message, e.filename + ':' + e.lineno);
27 }.bind(this)); 27 }.bind(this));
28 } 28 }
29 29
30 var fileCopyManagerInstance = null; 30 var fileCopyManagerInstance = null;
31 31
32 /** 32 /**
33 * Get FileCopyManager instance. In case is hasn't been initialized, a new 33 * Get FileCopyManager instance. In case is hasn't been initialized, a new
34 * instance is created. 34 * instance is created.
35 *
35 * @param {DirectoryEntry} root Root entry. 36 * @param {DirectoryEntry} root Root entry.
36 * @return {FileCopyManager} A FileCopyManager instance. 37 * @return {FileCopyManager} A FileCopyManager instance.
37 */ 38 */
38 FileCopyManager.getInstance = function(root) { 39 FileCopyManager.getInstance = function(root) {
39 if (fileCopyManagerInstance === null) { 40 if (fileCopyManagerInstance === null) {
40 fileCopyManagerInstance = new FileCopyManager(root); 41 fileCopyManagerInstance = new FileCopyManager(root);
41 } 42 }
42 return fileCopyManagerInstance; 43 return fileCopyManagerInstance;
43 }; 44 };
44 45
45 /** 46 /**
46 * A record of a queued copy operation. 47 * A record of a queued copy operation.
47 * 48 *
48 * Multiple copy operations may be queued at any given time. Additional 49 * Multiple copy operations may be queued at any given time. Additional
49 * Tasks may be added while the queue is being serviced. Though a 50 * Tasks may be added while the queue is being serviced. Though a
50 * cancel operation cancels everything in the queue. 51 * cancel operation cancels everything in the queue.
51 * 52 *
52 * @param {DirectoryEntry} sourceDirEntry Source directory. 53 * @param {DirectoryEntry} sourceDirEntry Source directory.
53 * @param {DirectoryEntry} targetDirEntry Target directory. 54 * @param {DirectoryEntry} targetDirEntry Target directory.
55 * @constructor
54 */ 56 */
55 FileCopyManager.Task = function(sourceDirEntry, targetDirEntry) { 57 FileCopyManager.Task = function(sourceDirEntry, targetDirEntry) {
56 this.sourceDirEntry = sourceDirEntry; 58 this.sourceDirEntry = sourceDirEntry;
57 this.targetDirEntry = targetDirEntry; 59 this.targetDirEntry = targetDirEntry;
58 this.originalEntries = null; 60 this.originalEntries = null;
59 61
60 this.pendingDirectories = []; 62 this.pendingDirectories = [];
61 this.pendingFiles = []; 63 this.pendingFiles = [];
62 this.pendingBytes = 0; 64 this.pendingBytes = 0;
63 65
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 var rename = this.renamedDirectories_[index]; 181 var rename = this.renamedDirectories_[index];
180 if (path.indexOf(rename.from) == 0) { 182 if (path.indexOf(rename.from) == 0) {
181 path = rename.to + path.substr(rename.from.length); 183 path = rename.to + path.substr(rename.from.length);
182 } 184 }
183 } 185 }
184 return path; 186 return path;
185 }; 187 };
186 188
187 /** 189 /**
188 * Error class used to report problems with a copy operation. 190 * Error class used to report problems with a copy operation.
189 * @constructor 191 *
190 * @param {string} reason Error type. 192 * @param {string} reason Error type.
191 * @param {Object} data Additional data. 193 * @param {Object} data Additional data.
194 * @constructor
192 */ 195 */
193 FileCopyManager.Error = function(reason, data) { 196 FileCopyManager.Error = function(reason, data) {
194 this.reason = reason; 197 this.reason = reason;
195 this.code = FileCopyManager.Error[reason]; 198 this.code = FileCopyManager.Error[reason];
196 this.data = data; 199 this.data = data;
197 }; 200 };
198 201
199 /** @const */ 202 /** @const */
200 FileCopyManager.Error.CANCELLED = 0; 203 FileCopyManager.Error.CANCELLED = 0;
201 /** @const */ 204 /** @const */
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 283
281 rv.percentage = rv.completedBytes / rv.totalBytes; 284 rv.percentage = rv.completedBytes / rv.totalBytes;
282 if (rv.pendingItems === 1) 285 if (rv.pendingItems === 1)
283 rv.filename = pendingFile.name; 286 rv.filename = pendingFile.name;
284 287
285 return rv; 288 return rv;
286 }; 289 };
287 290
288 /** 291 /**
289 * Send an event to all the FileManager windows. 292 * Send an event to all the FileManager windows.
293 *
290 * @private 294 * @private
291 * @param {string} eventName Event name. 295 * @param {string} eventName Event name.
292 * @param {Object} eventArgs An object with arbitrary event parameters. 296 * @param {Object} eventArgs An object with arbitrary event parameters.
293 */ 297 */
294 FileCopyManager.prototype.sendEvent_ = function(eventName, eventArgs) { 298 FileCopyManager.prototype.sendEvent_ = function(eventName, eventArgs) {
295 if (this.cancelRequested_) 299 if (this.cancelRequested_)
296 return; // Swallow events until cancellation complete. 300 return; // Swallow events until cancellation complete.
297 301
298 eventArgs.status = this.getStatus(); 302 eventArgs.status = this.getStatus();
299 303
300 var windows = getContentWindows(); 304 var windows = getContentWindows();
301 for (var i = 0; i < windows.length; i++) { 305 for (var i = 0; i < windows.length; i++) {
302 var w = windows[i]; 306 var w = windows[i];
303 if (w.fileCopyManagerWrapper) 307 if (w.fileCopyManagerWrapper)
304 w.fileCopyManagerWrapper.onEvent(eventName, eventArgs); 308 w.fileCopyManagerWrapper.onEvent(eventName, eventArgs);
305 } 309 }
306 }; 310 };
307 311
308 /** 312 /**
309 * Unloads the host page in 5 secs of idleing. Need to be called 313 * Unloads the host page in 5 secs of idleing. Need to be called
310 * each time this.copyTasks_.length or this.deleteTasks_.length 314 * each time this.copyTasks_.length or this.deleteTasks_.length
311 * changed. 315 * changed.
316 *
312 * @private 317 * @private
313 */ 318 */
314 FileCopyManager.prototype.maybeScheduleCloseBackgroundPage_ = function() { 319 FileCopyManager.prototype.maybeScheduleCloseBackgroundPage_ = function() {
315 if (this.copyTasks_.length === 0 && this.deleteTasks_.length === 0) { 320 if (this.copyTasks_.length === 0 && this.deleteTasks_.length === 0) {
316 if (this.unloadTimeout_ === null) 321 if (this.unloadTimeout_ === null)
317 this.unloadTimeout_ = setTimeout(close, 5000); 322 this.unloadTimeout_ = setTimeout(close, 5000);
318 } else if (this.unloadTimeout_) { 323 } else if (this.unloadTimeout_) {
319 clearTimeout(this.unloadTimeout_); 324 clearTimeout(this.unloadTimeout_);
320 this.unloadTimeout_ = null; 325 this.unloadTimeout_ = null;
321 } 326 }
322 }; 327 };
323 328
324 /** 329 /**
325 * Write to console.log on all the active FileManager windows. 330 * Write to console.log on all the active FileManager windows.
331 *
326 * @private 332 * @private
327 */ 333 */
328 FileCopyManager.prototype.log_ = function() { 334 FileCopyManager.prototype.log_ = function() {
329 var windows = getContentWindows(); 335 var windows = getContentWindows();
330 for (var i = 0; i < windows.length; i++) { 336 for (var i = 0; i < windows.length; i++) {
331 windows[i].console.log.apply(windows[i].console, arguments); 337 windows[i].console.log.apply(windows[i].console, arguments);
332 } 338 }
333 }; 339 };
334 340
335 /** 341 /**
336 * Dispatch a simple copy-progress event with reason and optional err data. 342 * Dispatch a simple copy-progress event with reason and optional err data.
343 *
337 * @private 344 * @private
338 * @param {string} reason Event type. 345 * @param {string} reason Event type.
339 * @param {FileCopyManager.Error} opt_err Error. 346 * @param {FileCopyManager.Error} opt_err Error.
340 */ 347 */
341 FileCopyManager.prototype.sendProgressEvent_ = function(reason, opt_err) { 348 FileCopyManager.prototype.sendProgressEvent_ = function(reason, opt_err) {
342 var event = {}; 349 var event = {};
343 event.reason = reason; 350 event.reason = reason;
344 if (opt_err) 351 if (opt_err)
345 event.error = opt_err; 352 event.error = opt_err;
346 this.sendEvent_('copy-progress', event); 353 this.sendEvent_('copy-progress', event);
347 }; 354 };
348 355
349 /** 356 /**
350 * Dispatch an event of file operation completion (allows to update the UI). 357 * Dispatch an event of file operation completion (allows to update the UI).
358 *
351 * @private 359 * @private
mtomasz 2013/02/14 07:40:10 Sorry, missed this. Should @private be the last on
yoshiki 2013/02/14 08:46:11 Ok, let's put '@private' after '@param' in the fut
352 * @param {string} reason Completed file operation: 'movied|copied|deleted'. 360 * @param {string} reason Completed file operation: 'movied|copied|deleted'.
353 * @param {Array.<Entry>} affectedEntries deleted ot created entries. 361 * @param {Array.<Entry>} affectedEntries deleted ot created entries.
354 */ 362 */
355 FileCopyManager.prototype.sendOperationEvent_ = function(reason, 363 FileCopyManager.prototype.sendOperationEvent_ = function(reason,
356 affectedEntries) { 364 affectedEntries) {
357 var event = {}; 365 var event = {};
358 event.reason = reason; 366 event.reason = reason;
359 event.affectedEntries = affectedEntries; 367 event.affectedEntries = affectedEntries;
360 this.sendEvent_('copy-operation-complete', event); 368 this.sendEvent_('copy-operation-complete', event);
361 }; 369 };
362 370
363 /** 371 /**
364 * Completely clear out the copy queue, either because we encountered an error 372 * Completely clear out the copy queue, either because we encountered an error
365 * or completed successfully. 373 * or completed successfully.
374 *
366 * @private 375 * @private
367 */ 376 */
368 FileCopyManager.prototype.resetQueue_ = function() { 377 FileCopyManager.prototype.resetQueue_ = function() {
369 for (var i = 0; i < this.cancelObservers_.length; i++) 378 for (var i = 0; i < this.cancelObservers_.length; i++)
370 this.cancelObservers_[i](); 379 this.cancelObservers_[i]();
371 380
372 this.copyTasks_ = []; 381 this.copyTasks_ = [];
373 this.cancelObservers_ = []; 382 this.cancelObservers_ = [];
374 this.maybeScheduleCloseBackgroundPage_(); 383 this.maybeScheduleCloseBackgroundPage_();
375 }; 384 };
376 385
377 /** 386 /**
378 * Request that the current copy queue be abandoned. 387 * Request that the current copy queue be abandoned.
388 *
379 * @param {Function} opt_callback On cancel. 389 * @param {Function} opt_callback On cancel.
380 */ 390 */
381 FileCopyManager.prototype.requestCancel = function(opt_callback) { 391 FileCopyManager.prototype.requestCancel = function(opt_callback) {
382 this.cancelRequested_ = true; 392 this.cancelRequested_ = true;
383 if (this.cancelCallback_) 393 if (this.cancelCallback_)
384 this.cancelCallback_(); 394 this.cancelCallback_();
385 if (opt_callback) 395 if (opt_callback)
386 this.cancelObservers_.push(opt_callback); 396 this.cancelObservers_.push(opt_callback);
387 397
388 // If there is any active task it will eventually call maybeCancel_. 398 // If there is any active task it will eventually call maybeCancel_.
389 // Otherwise call it right now. 399 // Otherwise call it right now.
390 if (this.copyTasks_.length == 0) 400 if (this.copyTasks_.length == 0)
391 this.doCancel_(); 401 this.doCancel_();
392 }; 402 };
393 403
394 /** 404 /**
395 * Perform the bookkeeping required to cancel. 405 * Perform the bookkeeping required to cancel.
406 *
396 * @private 407 * @private
397 */ 408 */
398 FileCopyManager.prototype.doCancel_ = function() { 409 FileCopyManager.prototype.doCancel_ = function() {
399 this.resetQueue_(); 410 this.resetQueue_();
400 this.cancelRequested_ = false; 411 this.cancelRequested_ = false;
401 this.sendProgressEvent_('CANCELLED'); 412 this.sendProgressEvent_('CANCELLED');
402 }; 413 };
403 414
404 /** 415 /**
405 * Used internally to check if a cancel has been requested, and handle 416 * Used internally to check if a cancel has been requested, and handle
406 * it if so. 417 * it if so.
418 *
407 * @private 419 * @private
408 * @return {boolean} If canceled. 420 * @return {boolean} If canceled.
409 */ 421 */
410 FileCopyManager.prototype.maybeCancel_ = function() { 422 FileCopyManager.prototype.maybeCancel_ = function() {
411 if (!this.cancelRequested_) 423 if (!this.cancelRequested_)
412 return false; 424 return false;
413 425
414 this.doCancel_(); 426 this.doCancel_();
415 return true; 427 return true;
416 }; 428 };
417 429
418 /** 430 /**
419 * Convert string in clipboard to entries and kick off pasting. 431 * Convert string in clipboard to entries and kick off pasting.
432 *
420 * @param {Object} clipboard Clipboard contents. 433 * @param {Object} clipboard Clipboard contents.
421 * @param {string} targetPath Target path. 434 * @param {string} targetPath Target path.
422 * @param {boolean} targetOnDrive If target is on Drive. 435 * @param {boolean} targetOnDrive If target is on Drive.
423 */ 436 */
424 FileCopyManager.prototype.paste = function(clipboard, targetPath, 437 FileCopyManager.prototype.paste = function(clipboard, targetPath,
425 targetOnDrive) { 438 targetOnDrive) {
426 var self = this; 439 var self = this;
427 var results = { 440 var results = {
428 sourceDirEntry: null, 441 sourceDirEntry: null,
429 entries: [], 442 entries: [],
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 */ 520 */
508 FileCopyManager.prototype.isOnSameRoot = function(sourceEntry, 521 FileCopyManager.prototype.isOnSameRoot = function(sourceEntry,
509 targetDirEntry, 522 targetDirEntry,
510 targetOnDrive) { 523 targetOnDrive) {
511 return PathUtil.getRootPath(sourceEntry.fullPath) == 524 return PathUtil.getRootPath(sourceEntry.fullPath) ==
512 PathUtil.getRootPath(targetDirEntry.fullPath); 525 PathUtil.getRootPath(targetDirEntry.fullPath);
513 }; 526 };
514 527
515 /** 528 /**
516 * Initiate a file copy. 529 * Initiate a file copy.
530 *
517 * @param {DirectoryEntry} sourceDirEntry Source directory. 531 * @param {DirectoryEntry} sourceDirEntry Source directory.
518 * @param {DirectoryEntry} targetDirEntry Target directory. 532 * @param {DirectoryEntry} targetDirEntry Target directory.
519 * @param {Array.<Entry>} entries Entries to copy. 533 * @param {Array.<Entry>} entries Entries to copy.
520 * @param {boolean} deleteAfterCopy In case of move. 534 * @param {boolean} deleteAfterCopy In case of move.
521 * @param {boolean} sourceOnDrive Source directory on Drive. 535 * @param {boolean} sourceOnDrive Source directory on Drive.
522 * @param {boolean} targetOnDrive Target directory on Drive. 536 * @param {boolean} targetOnDrive Target directory on Drive.
523 * @return {FileCopyManager.Task} Copy task. 537 * @return {FileCopyManager.Task} Copy task.
524 */ 538 */
525 FileCopyManager.prototype.queueCopy = function(sourceDirEntry, 539 FileCopyManager.prototype.queueCopy = function(sourceDirEntry,
526 targetDirEntry, 540 targetDirEntry,
(...skipping 27 matching lines...) Expand all
554 self.sendProgressEvent_('PROGRESS'); 568 self.sendProgressEvent_('PROGRESS');
555 } 569 }
556 }); 570 });
557 571
558 return copyTask; 572 return copyTask;
559 }; 573 };
560 574
561 /** 575 /**
562 * Service all pending tasks, as well as any that might appear during the 576 * Service all pending tasks, as well as any that might appear during the
563 * copy. 577 * copy.
578 *
564 * @private 579 * @private
565 */ 580 */
566 FileCopyManager.prototype.serviceAllTasks_ = function() { 581 FileCopyManager.prototype.serviceAllTasks_ = function() {
567 var self = this; 582 var self = this;
568 583
569 var onTaskError = function(err) { 584 var onTaskError = function(err) {
570 if (self.maybeCancel_()) 585 if (self.maybeCancel_())
571 return; 586 return;
572 self.sendProgressEvent_('ERROR', err); 587 self.sendProgressEvent_('ERROR', err);
573 self.resetQueue_(); 588 self.resetQueue_();
(...skipping 20 matching lines...) Expand all
594 609
595 // If the queue size is 1 after pushing our task, it was empty before, 610 // If the queue size is 1 after pushing our task, it was empty before,
596 // so we need to kick off queue processing and dispatch BEGIN event. 611 // so we need to kick off queue processing and dispatch BEGIN event.
597 612
598 this.sendProgressEvent_('BEGIN'); 613 this.sendProgressEvent_('BEGIN');
599 this.serviceNextTask_(onTaskSuccess, onTaskError); 614 this.serviceNextTask_(onTaskSuccess, onTaskError);
600 }; 615 };
601 616
602 /** 617 /**
603 * Service all entries in the next copy task. 618 * Service all entries in the next copy task.
619 *
604 * @private 620 * @private
mtomasz 2013/02/14 07:40:10 Last?
605 * @param {Function} successCallback On success. 621 * @param {Function} successCallback On success.
606 * @param {Function} errorCallback On error. 622 * @param {Function} errorCallback On error.
607 */ 623 */
608 FileCopyManager.prototype.serviceNextTask_ = function( 624 FileCopyManager.prototype.serviceNextTask_ = function(
609 successCallback, errorCallback) { 625 successCallback, errorCallback) {
610 var self = this; 626 var self = this;
611 var task = this.copyTasks_[0]; 627 var task = this.copyTasks_[0];
612 628
613 var onFilesystemError = function(err) { 629 var onFilesystemError = function(err) {
614 errorCallback(new FileCopyManager.Error('FILESYSTEM_ERROR', err)); 630 errorCallback(new FileCopyManager.Error('FILESYSTEM_ERROR', err));
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 sourceEntry.file(onSourceFileFound, errorCallback); 1145 sourceEntry.file(onSourceFileFound, errorCallback);
1130 }; 1146 };
1131 1147
1132 /** 1148 /**
1133 * Timeout before files are really deleted (to allow undo). 1149 * Timeout before files are really deleted (to allow undo).
1134 */ 1150 */
1135 FileCopyManager.DELETE_TIMEOUT = 30 * 1000; 1151 FileCopyManager.DELETE_TIMEOUT = 30 * 1000;
1136 1152
1137 /** 1153 /**
1138 * Schedules the files deletion. 1154 * Schedules the files deletion.
1155 *
1139 * @param {Array.<Entry>} entries The entries. 1156 * @param {Array.<Entry>} entries The entries.
1140 * @param {function(number)} callback Callback gets the scheduled task id. 1157 * @param {function(number)} callback Callback gets the scheduled task id.
1141 */ 1158 */
1142 FileCopyManager.prototype.deleteEntries = function(entries, callback) { 1159 FileCopyManager.prototype.deleteEntries = function(entries, callback) {
1143 var id = ++this.lastDeleteId_; 1160 var id = ++this.lastDeleteId_;
1144 var task = { 1161 var task = {
1145 entries: entries, 1162 entries: entries,
1146 id: id, 1163 id: id,
1147 timeout: setTimeout(this.forceDeleteTask.bind(this, id), 1164 timeout: setTimeout(this.forceDeleteTask.bind(this, id),
1148 FileCopyManager.DELETE_TIMEOUT) 1165 FileCopyManager.DELETE_TIMEOUT)
1149 }; 1166 };
1150 this.deleteTasks_.push(task); 1167 this.deleteTasks_.push(task);
1151 this.maybeScheduleCloseBackgroundPage_(); 1168 this.maybeScheduleCloseBackgroundPage_();
1152 callback(id); 1169 callback(id);
1153 this.sendDeleteEvent_(task, 'SCHEDULED'); 1170 this.sendDeleteEvent_(task, 'SCHEDULED');
1154 }; 1171 };
1155 1172
1156 /** 1173 /**
1157 * Creates a zip file for the selection of files. 1174 * Creates a zip file for the selection of files.
1175 *
1158 * @param {Entry} dirEntry the directory containing the selection. 1176 * @param {Entry} dirEntry the directory containing the selection.
1159 * @param {boolean} isOnDrive If directory is on Drive. 1177 * @param {boolean} isOnDrive If directory is on Drive.
1160 * @param {Array.<Entry>} selectionEntries the selected entries. 1178 * @param {Array.<Entry>} selectionEntries the selected entries.
1161 */ 1179 */
1162 FileCopyManager.prototype.zipSelection = function(dirEntry, isOnDrive, 1180 FileCopyManager.prototype.zipSelection = function(dirEntry, isOnDrive,
1163 selectionEntries) { 1181 selectionEntries) {
1164 var self = this; 1182 var self = this;
1165 var zipTask = new FileCopyManager.Task(dirEntry, dirEntry); 1183 var zipTask = new FileCopyManager.Task(dirEntry, dirEntry);
1166 zipTask.zip = true; 1184 zipTask.zip = true;
1167 zipTask.sourceOnDrive = isOnDrive; 1185 zipTask.sourceOnDrive = isOnDrive;
(...skipping 10 matching lines...) Expand all
1178 } else { 1196 } else {
1179 // Force to update the progress of butter bar when there are new tasks 1197 // Force to update the progress of butter bar when there are new tasks
1180 // coming while servicing current task. 1198 // coming while servicing current task.
1181 self.sendProgressEvent_('PROGRESS'); 1199 self.sendProgressEvent_('PROGRESS');
1182 } 1200 }
1183 }); 1201 });
1184 }; 1202 };
1185 1203
1186 /** 1204 /**
1187 * Force deletion before timeout runs out. 1205 * Force deletion before timeout runs out.
1206 *
1188 * @param {number} id The delete task id (as returned by deleteEntries). 1207 * @param {number} id The delete task id (as returned by deleteEntries).
1189 */ 1208 */
1190 FileCopyManager.prototype.forceDeleteTask = function(id) { 1209 FileCopyManager.prototype.forceDeleteTask = function(id) {
1191 var task = this.findDeleteTaskAndCancelTimeout_(id); 1210 var task = this.findDeleteTaskAndCancelTimeout_(id);
1192 if (task) this.serviceDeleteTask_(task); 1211 if (task) this.serviceDeleteTask_(task);
1193 }; 1212 };
1194 1213
1195 /** 1214 /**
1196 * Cancels the scheduled deletion. 1215 * Cancels the scheduled deletion.
1216 *
1197 * @param {number} id The delete task id (as returned by deleteEntries). 1217 * @param {number} id The delete task id (as returned by deleteEntries).
1198 */ 1218 */
1199 FileCopyManager.prototype.cancelDeleteTask = function(id) { 1219 FileCopyManager.prototype.cancelDeleteTask = function(id) {
1200 var task = this.findDeleteTaskAndCancelTimeout_(id); 1220 var task = this.findDeleteTaskAndCancelTimeout_(id);
1201 if (task) this.sendDeleteEvent_(task, 'CANCELLED'); 1221 if (task) this.sendDeleteEvent_(task, 'CANCELLED');
1202 }; 1222 };
1203 1223
1204 /** 1224 /**
1205 * Finds the delete task, removes it from list and cancels the timeout. 1225 * Finds the delete task, removes it from list and cancels the timeout.
1226 *
1206 * @param {number} id The delete task id (as returned by deleteEntries). 1227 * @param {number} id The delete task id (as returned by deleteEntries).
1207 * @return {object} The delete task. 1228 * @return {object} The delete task.
1208 * @private 1229 * @private
1209 */ 1230 */
1210 FileCopyManager.prototype.findDeleteTaskAndCancelTimeout_ = function(id) { 1231 FileCopyManager.prototype.findDeleteTaskAndCancelTimeout_ = function(id) {
1211 for (var index = 0; index < this.deleteTasks_.length; index++) { 1232 for (var index = 0; index < this.deleteTasks_.length; index++) {
1212 var task = this.deleteTasks_[index]; 1233 var task = this.deleteTasks_[index];
1213 if (task.id == id) { 1234 if (task.id == id) {
1214 this.deleteTasks_.splice(index, 1); 1235 this.deleteTasks_.splice(index, 1);
1215 this.maybeScheduleCloseBackgroundPage_(); 1236 this.maybeScheduleCloseBackgroundPage_();
1216 if (task.timeout) { 1237 if (task.timeout) {
1217 clearTimeout(task.timeout); 1238 clearTimeout(task.timeout);
1218 task.timeout = null; 1239 task.timeout = null;
1219 } 1240 }
1220 return task; 1241 return task;
1221 } 1242 }
1222 } 1243 }
1223 return null; 1244 return null;
1224 }; 1245 };
1225 1246
1226 /** 1247 /**
1227 * Performs the deletion. 1248 * Performs the deletion.
1249 *
1228 * @param {object} task The delete task (see deleteEntries function). 1250 * @param {object} task The delete task (see deleteEntries function).
1229 * @private 1251 * @private
mtomasz 2013/02/14 07:40:10 Here we have as the last one. That's why my concer
1230 */ 1252 */
1231 FileCopyManager.prototype.serviceDeleteTask_ = function(task) { 1253 FileCopyManager.prototype.serviceDeleteTask_ = function(task) {
1232 var downcount = task.entries.length + 1; 1254 var downcount = task.entries.length + 1;
1233 1255
1234 var onComplete = function() { 1256 var onComplete = function() {
1235 if (--downcount == 0) 1257 if (--downcount == 0)
1236 this.sendDeleteEvent_(task, 'SUCCESS'); 1258 this.sendDeleteEvent_(task, 'SUCCESS');
1237 }.bind(this); 1259 }.bind(this);
1238 1260
1239 for (var i = 0; i < task.entries.length; i++) { 1261 for (var i = 0; i < task.entries.length; i++) {
1240 var entry = task.entries[i]; 1262 var entry = task.entries[i];
1241 util.removeFileOrDirectory( 1263 util.removeFileOrDirectory(
1242 entry, 1264 entry,
1243 onComplete, 1265 onComplete,
1244 onComplete); // We ignore error, because we can't do anything here. 1266 onComplete); // We ignore error, because we can't do anything here.
1245 } 1267 }
1246 onComplete(); 1268 onComplete();
1247 }; 1269 };
1248 1270
1249 /** 1271 /**
1250 * Send a 'delete' event to listeners. 1272 * Send a 'delete' event to listeners.
1273 *
1251 * @param {Object} task The delete task (see deleteEntries function). 1274 * @param {Object} task The delete task (see deleteEntries function).
1252 * @param {string} reason Event reason. 1275 * @param {string} reason Event reason.
1253 * @private 1276 * @private
1254 */ 1277 */
1255 FileCopyManager.prototype.sendDeleteEvent_ = function(task, reason) { 1278 FileCopyManager.prototype.sendDeleteEvent_ = function(task, reason) {
1256 this.sendEvent_('delete', { 1279 this.sendEvent_('delete', {
1257 reason: reason, 1280 reason: reason,
1258 id: task.id, 1281 id: task.id,
1259 urls: task.entries.map(function(e) { 1282 urls: task.entries.map(function(e) {
1260 return util.makeFilesystemUrl(e.fullPath); 1283 return util.makeFilesystemUrl(e.fullPath);
1261 }) 1284 })
1262 }); 1285 });
1263 }; 1286 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_selection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698