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