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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Scanner of the entries. | 8 * Scanner of the entries. |
9 * @constructor | 9 * @constructor |
10 */ | 10 */ |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 */ | 559 */ |
560 DirectoryContents.prototype.cancelScan = function() { | 560 DirectoryContents.prototype.cancelScan = function() { |
561 if (this.scanCancelled_) | 561 if (this.scanCancelled_) |
562 return; | 562 return; |
563 this.scanCancelled_ = true; | 563 this.scanCancelled_ = true; |
564 if (this.scanner_) | 564 if (this.scanner_) |
565 this.scanner_.cancel(); | 565 this.scanner_.cancel(); |
566 | 566 |
567 this.onScanFinished_(); | 567 this.onScanFinished_(); |
568 | 568 |
569 // Cancels the current prefetchMetadata queue and replaces it with new one. | |
569 this.prefetchMetadataQueue_.cancel(); | 570 this.prefetchMetadataQueue_.cancel(); |
571 this.prefetchMetadataQueue_ = new AsyncUtil.Queue(); | |
hirono
2014/05/26 09:19:42
Does it really need to reassign a new queue?
It lo
yoshiki
2014/05/26 09:36:33
That's right. Removed.
| |
572 | |
570 cr.dispatchSimpleEvent(this, 'scan-cancelled'); | 573 cr.dispatchSimpleEvent(this, 'scan-cancelled'); |
571 }; | 574 }; |
572 | 575 |
573 /** | 576 /** |
574 * Called when the scanning by scanner_ is done, even when the scanning is | 577 * Called when the scanning by scanner_ is done, even when the scanning is |
575 * succeeded or failed. This is called before completion (or error) callback. | 578 * succeeded or failed. This is called before completion (or error) callback. |
576 * | 579 * |
577 * @private | 580 * @private |
578 */ | 581 */ |
579 DirectoryContents.prototype.onScanFinished_ = function() { | 582 DirectoryContents.prototype.onScanFinished_ = function() { |
580 this.scanner_ = null; | 583 this.scanner_ = null; |
581 | 584 |
582 this.prefetchMetadataQueue_.run(function(callback) { | 585 this.prefetchMetadataQueue_.run(function(callback, cancelled) { |
586 if (cancelled) | |
587 return callback(); | |
588 | |
583 // TODO(yoshiki): Here we should fire the update event of changed | 589 // TODO(yoshiki): Here we should fire the update event of changed |
584 // items. Currently we have a method this.fileList_.updateIndex() to | 590 // items. Currently we have a method this.fileList_.updateIndex() to |
585 // fire an event, but this method takes only 1 argument and invokes sort | 591 // fire an event, but this method takes only 1 argument and invokes sort |
586 // one by one. It is obviously time wasting. Instead, we call sort | 592 // one by one. It is obviously time wasting. Instead, we call sort |
587 // directory. | 593 // directory. |
588 // In future, we should implement a good method like updateIndexes and | 594 // In future, we should implement a good method like updateIndexes and |
589 // use it here. | 595 // use it here. |
590 var status = this.fileList_.sortStatus; | 596 var status = this.fileList_.sortStatus; |
591 if (status) | 597 if (status) |
592 this.fileList_.sort(status.field, status.direction); | 598 this.fileList_.sort(status.field, status.direction); |
593 | 599 |
594 callback(); | 600 callback(); |
595 }.bind(this)); | 601 }.bind(this)); |
596 }; | 602 }; |
597 | 603 |
598 /** | 604 /** |
599 * Called when the scanning by scanner_ is succeeded. | 605 * Called when the scanning by scanner_ is succeeded. |
600 * @private | 606 * @private |
601 */ | 607 */ |
602 DirectoryContents.prototype.onScanCompleted_ = function() { | 608 DirectoryContents.prototype.onScanCompleted_ = function() { |
603 if (this.scanCancelled_) | 609 if (this.scanCancelled_) |
604 return; | 610 return; |
605 | 611 |
606 this.prefetchMetadataQueue_.run(function(callback) { | 612 this.prefetchMetadataQueue_.run(function(callback, cancelled) { |
hirono
2014/05/26 09:19:42
What is difference between this.scanCancelled_ and
yoshiki
2014/05/26 09:36:33
In this case, they are same. But in general, the c
hirono
2014/05/26 09:41:04
How about removing this.scanCancelled_ and using t
| |
607 // Call callback first, so isScanning() returns false in the event handlers. | 613 // Call callback first, so isScanning() returns false in the event handlers. |
608 callback(); | 614 callback(); |
609 | 615 |
610 cr.dispatchSimpleEvent(this, 'scan-completed'); | 616 if (!cancelled) |
617 cr.dispatchSimpleEvent(this, 'scan-completed'); | |
611 }.bind(this)); | 618 }.bind(this)); |
612 }; | 619 }; |
613 | 620 |
614 /** | 621 /** |
615 * Called in case scan has failed. Should send the event. | 622 * Called in case scan has failed. Should send the event. |
616 * @private | 623 * @private |
617 */ | 624 */ |
618 DirectoryContents.prototype.onScanError_ = function() { | 625 DirectoryContents.prototype.onScanError_ = function() { |
619 if (this.scanCancelled_) | 626 if (this.scanCancelled_) |
620 return; | 627 return; |
621 | 628 |
622 this.prefetchMetadataQueue_.run(function(callback) { | 629 this.prefetchMetadataQueue_.run(function(callback, cancelled) { |
623 // Call callback first, so isScanning() returns false in the event handlers. | 630 // Call callback first, so isScanning() returns false in the event handlers. |
624 callback(); | 631 callback(); |
625 cr.dispatchSimpleEvent(this, 'scan-failed'); | 632 |
633 if (!cancelled) | |
634 cr.dispatchSimpleEvent(this, 'scan-failed'); | |
626 }.bind(this)); | 635 }.bind(this)); |
627 }; | 636 }; |
628 | 637 |
629 /** | 638 /** |
630 * Called when some chunk of entries are read by scanner. | 639 * Called when some chunk of entries are read by scanner. |
631 * @param {Array.<Entry>} entries The list of the scanned entries. | 640 * @param {Array.<Entry>} entries The list of the scanned entries. |
632 * @private | 641 * @private |
633 */ | 642 */ |
634 DirectoryContents.prototype.onNewEntries_ = function(entries) { | 643 DirectoryContents.prototype.onNewEntries_ = function(entries) { |
635 if (this.scanCancelled_) | 644 if (this.scanCancelled_) |
(...skipping 12 matching lines...) Expand all Loading... | |
648 cr.dispatchSimpleEvent(this, 'scan-updated'); | 657 cr.dispatchSimpleEvent(this, 'scan-updated'); |
649 | 658 |
650 this.context_.metadataCache.setCacheSize(this.fileList_.length); | 659 this.context_.metadataCache.setCacheSize(this.fileList_.length); |
651 | 660 |
652 // Because the prefetchMetadata can be slow, throttling by splitting entries | 661 // Because the prefetchMetadata can be slow, throttling by splitting entries |
653 // into smaller chunks to reduce UI latency. | 662 // into smaller chunks to reduce UI latency. |
654 // TODO(hidehiko,mtomasz): This should be handled in MetadataCache. | 663 // TODO(hidehiko,mtomasz): This should be handled in MetadataCache. |
655 var MAX_CHUNK_SIZE = 50; | 664 var MAX_CHUNK_SIZE = 50; |
656 for (var i = 0; i < entriesFiltered.length; i += MAX_CHUNK_SIZE) { | 665 for (var i = 0; i < entriesFiltered.length; i += MAX_CHUNK_SIZE) { |
657 var chunk = entriesFiltered.slice(i, i + MAX_CHUNK_SIZE); | 666 var chunk = entriesFiltered.slice(i, i + MAX_CHUNK_SIZE); |
658 this.prefetchMetadataQueue_.run(function(chunk, callback) { | 667 this.prefetchMetadataQueue_.run(function(chunk, callback, cancelled) { |
668 if (cancelled) | |
669 return callback(); | |
hirono
2014/05/26 09:19:42
Maybe "callback(); return;" is more free from misr
yoshiki
2014/05/26 09:36:33
Done.
| |
670 | |
659 this.prefetchMetadata(chunk, function() { | 671 this.prefetchMetadata(chunk, function() { |
660 if (this.scanCancelled_) { | 672 if (this.scanCancelled_) { |
661 // Do nothing if the scanning is cancelled. | 673 // Do nothing if the scanning is cancelled. |
662 callback(); | 674 callback(); |
663 return; | 675 return; |
664 } | 676 } |
665 | 677 |
666 cr.dispatchSimpleEvent(this, 'scan-updated'); | 678 cr.dispatchSimpleEvent(this, 'scan-updated'); |
667 callback(); | 679 callback(); |
668 }.bind(this)); | 680 }.bind(this)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 DirectoryContents.createForDriveMetadataSearch = function( | 763 DirectoryContents.createForDriveMetadataSearch = function( |
752 context, fakeDirectoryEntry, searchType) { | 764 context, fakeDirectoryEntry, searchType) { |
753 return new DirectoryContents( | 765 return new DirectoryContents( |
754 context, | 766 context, |
755 true, // Search | 767 true, // Search |
756 fakeDirectoryEntry, | 768 fakeDirectoryEntry, |
757 function() { | 769 function() { |
758 return new DriveMetadataSearchContentScanner(searchType); | 770 return new DriveMetadataSearchContentScanner(searchType); |
759 }); | 771 }); |
760 }; | 772 }; |
OLD | NEW |