Commit 4a530823 authored by iseki's avatar iseki Committed by Commit bot

Make onFileTransferUpdated single value from list.

* SendDriveFileTransferEvent and onFileTransfersUpdated are not
  necessay to recieve list because this event is always single.

BUG=408482
TEST=manually
1. Copy the local file to drive.
2. Confirm sync status is updated correctly.

Review URL: https://codereview.chromium.org/542573002

Cr-Commit-Position: refs/heads/master@{#293619}
parent 54ab6c56
......@@ -671,25 +671,18 @@ void EventRouter::SendDriveFileTransferEvent() {
if (!drive_job_info_for_scheduled_event_)
return;
// Convert the drive_job_info_for_scheduled_event_ to IDL type.
std::vector<linked_ptr<file_browser_private::FileTransferStatus> >
status_list;
linked_ptr<file_browser_private::FileTransferStatus> status(
new file_browser_private::FileTransferStatus());
file_browser_private::FileTransferStatus status;
JobInfoToTransferStatus(profile_,
kFileManagerAppId,
drive_job_info_for_scheduled_event_->status,
drive_job_info_for_scheduled_event_->job_info,
status.get());
status_list.push_back(status);
&status);
drive_job_info_for_scheduled_event_.reset();
BroadcastEvent(
profile_,
file_browser_private::OnFileTransfersUpdated::kEventName,
file_browser_private::OnFileTransfersUpdated::Create(status_list));
BroadcastEvent(profile_,
file_browser_private::OnFileTransfersUpdated::kEventName,
file_browser_private::OnFileTransfersUpdated::Create(status));
}
void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) {
......
......@@ -808,7 +808,7 @@ interface Functions {
interface Events {
static void onMountCompleted(MountCompletedEvent event);
static void onFileTransfersUpdated(FileTransferStatus[] event);
static void onFileTransfersUpdated(FileTransferStatus event);
static void onCopyProgress(long copyId, CopyProgressStatus status);
......
......@@ -84,25 +84,21 @@ DriveSyncHandler.prototype = {
* @param {Array.<FileTransferStatus>} statusList List of drive status.
* @private
*/
DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(statusList) {
var completed = false;
for (var i = 0; i < statusList.length; i++) {
var status = statusList[i];
switch (status.transferState) {
case 'added':
case 'in_progress':
case 'started':
this.updateItem_(status);
break;
case 'completed':
case 'failed':
if (status.num_total_jobs === 1)
this.removeItem_(status);
break;
default:
throw new Error(
'Invalid transfer state: ' + status.transferState + '.');
}
DriveSyncHandler.prototype.onFileTransfersUpdated_ = function(status) {
switch (status.transferState) {
case 'added':
case 'in_progress':
case 'started':
this.updateItem_(status);
break;
case 'completed':
case 'failed':
if (status.num_total_jobs === 1)
this.removeItem_(status);
break;
default:
throw new Error(
'Invalid transfer state: ' + status.transferState + '.');
}
};
......
......@@ -3026,23 +3026,17 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
var bytesTotal = 0;
var bytesDone = 0;
var onFileTransfersUpdated = function(statusList) {
for (var index = 0; index < statusList.length; index++) {
var status = statusList[index];
var escaped = encodeURI(status.fileUrl);
if (!(escaped in progressMap)) continue;
if (status.total == -1) continue;
var old = progressMap[escaped];
if (old == -1) {
// -1 means we don't know file size yet.
bytesTotal += status.total;
filesStarted++;
old = 0;
}
bytesDone += status.processed - old;
progressMap[escaped] = status.processed;
var onFileTransfersUpdated = function(status) {
var escaped = encodeURI(status.fileUrl);
var old = progressMap[escaped];
if (old == -1) {
// -1 means we don't know file size yet.
bytesTotal += status.total;
filesStarted++;
old = 0;
}
bytesDone += status.processed - old;
progressMap[escaped] = status.processed;
var percent = bytesTotal == 0 ? 0 : bytesDone / bytesTotal;
// For files we don't have information about, assume the progress is zero.
......
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