Commit 27a51353 authored by serya@chromium.org's avatar serya@chromium.org

[FileBrowser] Progress of copying file to/from gdata.

Progress shows uploaded and downloaded bytes, but not copyed (so it 'in sync' with the sync indicator; current API restrics from more percise status update).
So for pinned or previusly copied gdata files progress still jumps in big chuncks.

BUG=134600
TEST=Manual test.


Review URL: https://chromiumcodereview.appspot.com/10697098

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146101 0039d316-1c4b-4281-b951-d872f2087c98
parent fba85d2e
...@@ -196,10 +196,6 @@ FileCopyManager.prototype.getStatus = function() { ...@@ -196,10 +196,6 @@ FileCopyManager.prototype.getStatus = function() {
completedFiles: 0, completedFiles: 0,
completedDirectories: 0, completedDirectories: 0,
completedBytes: 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++) { for (var i = 0; i < this.copyTasks_.length; i++) {
...@@ -211,8 +207,6 @@ FileCopyManager.prototype.getStatus = function() { ...@@ -211,8 +207,6 @@ FileCopyManager.prototype.getStatus = function() {
rv.completedFiles += task.completedFiles.length; rv.completedFiles += task.completedFiles.length;
rv.completedDirectories += task.completedDirectories.length; rv.completedDirectories += task.completedDirectories.length;
rv.completedBytes += task.completedBytes; rv.completedBytes += task.completedBytes;
if (task.sourceOnGData || task.targetOnGData)
rv.useBytesForPercentage = false;
} }
rv.pendingItems = rv.pendingFiles + rv.pendingDirectories; rv.pendingItems = rv.pendingFiles + rv.pendingDirectories;
rv.completedItems = rv.completedFiles + rv.completedDirectories; rv.completedItems = rv.completedFiles + rv.completedDirectories;
...@@ -234,18 +228,7 @@ FileCopyManager.prototype.getStatus = function() { ...@@ -234,18 +228,7 @@ FileCopyManager.prototype.getStatus = function() {
FileCopyManager.prototype.getProgress = function() { FileCopyManager.prototype.getProgress = function() {
var status = this.getStatus(); var status = this.getStatus();
// TODO(tbarzic): We can't use completedBytes and totalBytes to estimate var percentage = status.completedBytes / status.totalBytes;
// 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);
return { return {
percentage: percentage, percentage: percentage,
...@@ -765,9 +748,24 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function( ...@@ -765,9 +748,24 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function(
var sourceFileUrl = sourceEntry.toURL(); var sourceFileUrl = sourceEntry.toURL();
var targetFileUrl = targetDirEntry.toURL() + '/' + var targetFileUrl = targetDirEntry.toURL() + '/' +
encodeURIComponent(targetRelativePath); 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( chrome.fileBrowserPrivate.transferFile(
sourceFileUrl, targetFileUrl, sourceFileUrl, targetFileUrl,
function() { function() {
chrome.fileBrowserPrivate.onFileTransfersUpdated.removeListener(
onFileTransfersUpdated);
if (chrome.extension.lastError) { if (chrome.extension.lastError) {
console.log( console.log(
'Error copying ' + sourceFileUrl + ' to ' + targetFileUrl); 'Error copying ' + sourceFileUrl + ' to ' + targetFileUrl);
...@@ -778,7 +776,14 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function( ...@@ -778,7 +776,14 @@ FileCopyManager.prototype.serviceNextTaskEntry_ = function(
}); });
} else { } else {
targetDirEntry.getFile(targetRelativePath, {}, 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); onFilesystemError);
} }
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment