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

Unified Diff: chrome/browser/resources/file_manager/js/file_copy_manager.js

Issue 10697098: [FileBrowser] Progress of copying file to/from gdata. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/file_copy_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_copy_manager.js b/chrome/browser/resources/file_manager/js/file_copy_manager.js
index 550401259d71ae4750b9e840c52a7d1ffbda3d3d..48716112d41849999ccaf1b860c2b6bbd7afdc7d 100644
--- a/chrome/browser/resources/file_manager/js/file_copy_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_copy_manager.js
@@ -196,10 +196,6 @@ FileCopyManager.prototype.getStatus = function() {
completedFiles: 0,
completedDirectories: 0,
completedBytes: 0,
-
- // If source or target are on gdata we can't use completed bytes to track
- // progress.
- useBytesForPercentage: true
};
for (var i = 0; i < this.copyTasks_.length; i++) {
@@ -211,8 +207,6 @@ FileCopyManager.prototype.getStatus = function() {
rv.completedFiles += task.completedFiles.length;
rv.completedDirectories += task.completedDirectories.length;
rv.completedBytes += task.completedBytes;
- if (task.sourceOnGData || task.targetOnGData)
- rv.useBytesForPercentage = false;
}
rv.pendingItems = rv.pendingFiles + rv.pendingDirectories;
rv.completedItems = rv.completedFiles + rv.completedDirectories;
@@ -234,18 +228,7 @@ FileCopyManager.prototype.getStatus = function() {
FileCopyManager.prototype.getProgress = function() {
var status = this.getStatus();
- // TODO(tbarzic): We can't use completedBytes and totalBytes to estimate
- // progress if the file is transferred from/to drive for two reasons:
- // 1' completedBytes don't get updated for drive files.
- // 2' There is no way to get completed bytes in real time. If completed bytes
- // are updated when each item finished and if there is a large item to be
- // copied, the progress bar would stop moving until the item is finished
- // and then jump a large portion of the bar.
- //
- // Obviously 2' > 1'.
- var percentage = status.useBytesForPercentage ?
- (status.completedBytes / status.totalBytes) :
- ((status.completedItems + 0.5) / status.totalItems);
+ var percentage = status.completedBytes / status.totalBytes;
return {
percentage: percentage,
@@ -765,9 +748,24 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function(
var sourceFileUrl = sourceEntry.toURL();
var targetFileUrl = targetDirEntry.toURL() + '/' +
encodeURIComponent(targetRelativePath);
+ var transferedBytes = 0;
+ function onFileTransfersUpdated(statusList) {
+ for (var i = 0; i < statusList.length; i++) {
+ var s = statusList[i];
+ if ((s.fileUrl == sourceFileUrl || s.fileUrl == targetFileUrl) &&
+ s.processed > transferedBytes) {
+ onCopyProgress(sourceEntry, s.processed - transferedBytes);
+ transferedBytes = s.processed;
+ }
+ }
+ }
+ chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener(
+ onFileTransfersUpdated);
chrome.fileBrowserPrivate.transferFile(
sourceFileUrl, targetFileUrl,
function() {
+ chrome.fileBrowserPrivate.onFileTransfersUpdated.removeListener(
+ onFileTransfersUpdated);
if (chrome.extension.lastError) {
console.log(
'Error copying ' + sourceFileUrl + ' to ' + targetFileUrl);
@@ -778,7 +776,14 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function(
});
} else {
targetDirEntry.getFile(targetRelativePath, {},
- onFilesystemCopyComplete.bind(self, sourceEntry),
+ function(targetEntry) {
+ targetEntry.getMetadata(function(metadata) {
+ if (metadata.size > transferedBytes)
+ onCopyProgress(sourceEntry,
+ metadata.size - transferedBytes);
+ onFilesystemCopyComplete(sourceEntry, targetEntry);
+ });
+ },
onFilesystemError);
}
});
« 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