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

Side by Side Diff: chrome/browser/resources/file_manager/background/js/file_operation_manager.js

Issue 152513002: Files.app: Fix the number of remaining files and processed bytes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make it simpler Created 6 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 | « chrome/browser/resources/file_manager/background/js/file_operation_handler.js ('k') | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 * Utilities for FileOperationManager. 8 * Utilities for FileOperationManager.
9 */ 9 */
10 var fileOperationUtil = {}; 10 var fileOperationUtil = {};
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 */ 405 */
406 this.totalBytes = 0; 406 this.totalBytes = 0;
407 407
408 /** 408 /**
409 * Total number of already processed bytes. Updated periodically. 409 * Total number of already processed bytes. Updated periodically.
410 * @type {number} 410 * @type {number}
411 */ 411 */
412 this.processedBytes = 0; 412 this.processedBytes = 0;
413 413
414 /** 414 /**
415 * Index of the progressing entry in sourceEntries.
416 * @type {number}
417 * @private
418 */
419 this.processingSourceIndex_ = 0;
420
421 /**
415 * Set to true when cancel is requested. 422 * Set to true when cancel is requested.
416 * @private {boolean} 423 * @private {boolean}
417 */ 424 */
418 this.cancelRequested_ = false; 425 this.cancelRequested_ = false;
419 426
420 /** 427 /**
421 * Callback to cancel the running process. 428 * Callback to cancel the running process.
422 * @private {function()} 429 * @private {function()}
423 */ 430 */
424 this.cancelCallback_ = null; 431 this.cancelCallback_ = null;
425 432
426 // TODO(hidehiko): After we support recursive copy, we don't need this. 433 // TODO(hidehiko): After we support recursive copy, we don't need this.
427 // If directory already exists, we try to make a copy named 'dir (X)', 434 // If directory already exists, we try to make a copy named 'dir (X)',
428 // where X is a number. When we do this, all subsequent copies from 435 // where X is a number. When we do this, all subsequent copies from
429 // inside the subtree should be mapped to the new directory name. 436 // inside the subtree should be mapped to the new directory name.
430 // For example, if 'dir' was copied as 'dir (1)', then 'dir\file.txt' should 437 // For example, if 'dir' was copied as 'dir (1)', then 'dir\file.txt' should
431 // become 'dir (1)\file.txt'. 438 // become 'dir (1)\file.txt'.
432 this.renamedDirectories_ = []; 439 this.renamedDirectories_ = [];
433 }; 440 };
434 441
435 /** 442 /**
436 * @param {function()} callback When entries resolved. 443 * @param {function()} callback When entries resolved.
437 */ 444 */
438 FileOperationManager.Task.prototype.initialize = function(callback) { 445 FileOperationManager.Task.prototype.initialize = function(callback) {
439 }; 446 };
440 447
441 /** 448 /**
442 * Updates copy progress status for the entry.
443 *
444 * @param {number} size Number of bytes that has been copied since last update.
445 */
446 FileOperationManager.Task.prototype.updateFileCopyProgress = function(size) {
447 this.completedBytes += size;
448 };
449
450 /**
451 * Requests cancellation of this task. 449 * Requests cancellation of this task.
452 * When the cancellation is done, it is notified via callbacks of run(). 450 * When the cancellation is done, it is notified via callbacks of run().
453 */ 451 */
454 FileOperationManager.Task.prototype.requestCancel = function() { 452 FileOperationManager.Task.prototype.requestCancel = function() {
455 this.cancelRequested_ = true; 453 this.cancelRequested_ = true;
456 if (this.cancelCallback_) { 454 if (this.cancelCallback_) {
457 this.cancelCallback_(); 455 this.cancelCallback_();
458 this.cancelCallback_ = null; 456 this.cancelCallback_ = null;
459 } 457 }
460 }; 458 };
(...skipping 12 matching lines...) Expand all
473 FileOperationManager.Task.prototype.run = function( 471 FileOperationManager.Task.prototype.run = function(
474 entryChangedCallback, progressCallback, successCallback, errorCallback) { 472 entryChangedCallback, progressCallback, successCallback, errorCallback) {
475 }; 473 };
476 474
477 /** 475 /**
478 * Get states of the task. 476 * Get states of the task.
479 * TOOD(hirono): Removes this method and sets a task to progress events. 477 * TOOD(hirono): Removes this method and sets a task to progress events.
480 * @return {object} Status object. 478 * @return {object} Status object.
481 */ 479 */
482 FileOperationManager.Task.prototype.getStatus = function() { 480 FileOperationManager.Task.prototype.getStatus = function() {
483 var numRemainingItems = this.countRemainingItems(); 481 var processingEntry = this.sourceEntries[this.processingSourceIndex_];
484 return { 482 return {
485 operationType: this.operationType, 483 operationType: this.operationType,
yoshiki 2014/02/03 09:51:03 nit: 4 space indent
hirono 2014/02/03 10:40:18 It seems that we shuold use 2 space indenet for ob
486 numRemainingItems: numRemainingItems, 484 numRemainingItems: this.sourceEntries.length - this.processingSourceIndex_,
487 totalBytes: this.totalBytes, 485 totalBytes: this.totalBytes,
488 processedBytes: this.processedBytes, 486 processedBytes: this.processedBytes,
489 processingEntry: this.getSingleEntry() 487 processingEntryName: processingEntry ? processingEntry.name : ''
490 }; 488 };
491 }; 489 };
492 490
493 /** 491 /**
494 * Counts the number of remaining items. 492 * Obtains the number of total processed bytes.
495 * @return {number} Number of remaining items. 493 * @return {number} Number of total processed bytes.
494 * @private
496 */ 495 */
497 FileOperationManager.Task.prototype.countRemainingItems = function() { 496 FileOperationManager.Task.prototype.calcProcessedBytes_ = function() {
498 var count = 0; 497 var bytes = 0;
499 for (var i = 0; i < this.processingEntries.length; i++) { 498 for (var i = 0; i < this.processingSourceIndex_; i++) {
500 for (var entryURL in this.processingEntries[i]) { 499 var processedEntries = this.processingEntries[i];
501 count++; 500 for (var name in processedEntries) {
501 bytes += processedEntries[name].size;
502 } 502 }
503 } 503 }
504 return count; 504 var processingEntries = this.processingEntries[this.processingSourceIndex_];
yoshiki 2014/02/03 09:51:03 Can't you combine L504-510 into the loop at L498?
hirono 2014/02/03 10:40:18 Done.
505 if (processingEntries) {
506 for (var name in processingEntries) {
507 bytes += processingEntries[name].processedBytes;
508 }
509 }
510 return bytes;
505 }; 511 };
506 512
507 /** 513 /**
508 * Obtains the single processing entry. If there are multiple processing
509 * entries, it returns null.
510 * @return {Entry} First entry.
511 */
512 FileOperationManager.Task.prototype.getSingleEntry = function() {
513 if (this.countRemainingItems() !== 1)
514 return null;
515 for (var i = 0; i < this.processingEntries.length; i++) {
516 var entryMap = this.processingEntries[i];
517 for (var name in entryMap)
518 return entryMap[name];
519 }
520 return null;
521 };
522
523 /**
524 * Task to copy entries. 514 * Task to copy entries.
525 * 515 *
526 * @param {Array.<Entry>} sourceEntries Array of source entries. 516 * @param {Array.<Entry>} sourceEntries Array of source entries.
527 * @param {DirectoryEntry} targetDirEntry Target directory. 517 * @param {DirectoryEntry} targetDirEntry Target directory.
528 * @param {boolean} deleteAfterCopy Whether the delete original files after 518 * @param {boolean} deleteAfterCopy Whether the delete original files after
529 * copy. 519 * copy.
530 * @constructor 520 * @constructor
531 * @extends {FileOperationManager.Task} 521 * @extends {FileOperationManager.Task}
532 */ 522 */
533 FileOperationManager.CopyTask = function(sourceEntries, 523 FileOperationManager.CopyTask = function(sourceEntries,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 return; 636 return;
647 } 637 }
648 progressCallback(); 638 progressCallback();
649 this.processEntry_( 639 this.processEntry_(
650 entry, this.targetDirEntry, 640 entry, this.targetDirEntry,
651 function(sourceEntry, destinationEntry) { 641 function(sourceEntry, destinationEntry) {
652 // Finalize the entry's progress state. 642 // Finalize the entry's progress state.
653 var sourceEntryURL = sourceEntry.toURL(); 643 var sourceEntryURL = sourceEntry.toURL();
654 var processedEntry = 644 var processedEntry =
655 this.processingEntries[index][sourceEntryURL]; 645 this.processingEntries[index][sourceEntryURL];
656 if (processedEntry) { 646
657 this.processedBytes += 647 // Update current source index.
658 processedEntry.size - processedEntry.processedBytes; 648 this.processingSourceIndex_ = index + 1;
659 progressCallback(); 649 this.processedBytes = this.calcProcessedBytes_();
660 delete this.processingEntries[index][sourceEntryURL];
661 }
662 650
663 // The destination entry may be null, if the copied file got 651 // The destination entry may be null, if the copied file got
664 // deleted just after copying. 652 // deleted just after copying.
665 if (destinationEntry) { 653 if (destinationEntry) {
666 entryChangedCallback( 654 entryChangedCallback(
667 util.EntryChangedKind.CREATED, destinationEntry); 655 util.EntryChangedKind.CREATED, destinationEntry);
668 } 656 }
669 }.bind(this), 657 }.bind(this),
670 function(sourceEntry, size) { 658 function(sourceEntry, size) {
671 var sourceEntryURL = sourceEntry.toURL(); 659 var sourceEntryURL = sourceEntry.toURL();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (this.cancelRequested_) { 795 if (this.cancelRequested_) {
808 errorCallback(new FileOperationManager.Error( 796 errorCallback(new FileOperationManager.Error(
809 util.FileOperationErrorType.FILESYSTEM_ERROR, 797 util.FileOperationErrorType.FILESYSTEM_ERROR,
810 util.createDOMError(util.FileError.ABORT_ERR))); 798 util.createDOMError(util.FileError.ABORT_ERR)));
811 return; 799 return;
812 } 800 }
813 progressCallback(); 801 progressCallback();
814 FileOperationManager.MoveTask.processEntry_( 802 FileOperationManager.MoveTask.processEntry_(
815 entry, this.targetDirEntry, entryChangedCallback, 803 entry, this.targetDirEntry, entryChangedCallback,
816 function() { 804 function() {
817 // Erase the processing entry. 805 // Update current source index.
818 this.processingEntries[index] = {}; 806 this.processingSourceIndex_ = index + 1;
819 this.processedBytes++; 807 this.processedBytes = this.calcProcessedBytes_();
820 callback(); 808 callback();
821 }.bind(this), 809 }.bind(this),
822 errorCallback); 810 errorCallback);
823 }, 811 },
824 function() { 812 function() {
825 successCallback(); 813 successCallback();
826 }.bind(this), 814 }.bind(this),
827 this); 815 this);
828 }; 816 };
829 817
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 1348
1361 /** 1349 /**
1362 * Generates new task ID. 1350 * Generates new task ID.
1363 * 1351 *
1364 * @return {string} New task ID. 1352 * @return {string} New task ID.
1365 * @private 1353 * @private
1366 */ 1354 */
1367 FileOperationManager.prototype.generateTaskId_ = function() { 1355 FileOperationManager.prototype.generateTaskId_ = function() {
1368 return 'file-operation-' + this.taskIdCounter_++; 1356 return 'file-operation-' + this.taskIdCounter_++;
1369 }; 1357 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/background/js/file_operation_handler.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698