Chromium Code Reviews| Index: chrome/browser/extensions/api/image_writer_private/operation.cc |
| diff --git a/chrome/browser/extensions/api/image_writer_private/operation.cc b/chrome/browser/extensions/api/image_writer_private/operation.cc |
| index a37c81c4e6755c4b553f9f820b04bd53e9d103da..a6361c8fa4fcd5aceccedaf314e78d0b1bbaf0fc 100644 |
| --- a/chrome/browser/extensions/api/image_writer_private/operation.cc |
| +++ b/chrome/browser/extensions/api/image_writer_private/operation.cc |
| @@ -36,14 +36,11 @@ Operation::Operation(base::WeakPtr<OperationManager> manager, |
| progress_(0) { |
| } |
| -Operation::~Operation() { |
| -} |
| +Operation::~Operation() {} |
| void Operation::Cancel() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| - DVLOG(1) << "Cancelling image writing operation for ext: " << extension_id_; |
| - |
| stage_ = image_writer_api::STAGE_NONE; |
| CleanUp(); |
| @@ -97,16 +94,17 @@ void Operation::SetProgress(int progress) { |
| return; |
| } |
| - progress_ = progress; |
| + if (progress > progress_) { |
| + progress_ = progress; |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, |
| - FROM_HERE, |
| - base::Bind(&OperationManager::OnProgress, |
| - manager_, |
| - extension_id_, |
| - stage_, |
| - progress_)); |
| + BrowserThread::PostTask(BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&OperationManager::OnProgress, |
| + manager_, |
| + extension_id_, |
| + stage_, |
| + progress_)); |
| + } |
| } |
| void Operation::SetStage(image_writer_api::Stage stage) { |
| @@ -144,7 +142,6 @@ void Operation::Finish() { |
| base::Bind(&Operation::Finish, this)); |
| return; |
| } |
| - DVLOG(1) << "Write operation complete."; |
| CleanUp(); |
| @@ -178,13 +175,41 @@ void Operation::CleanUp() { |
| cleanup_functions_.clear(); |
| } |
| -void Operation::UnzipStart(scoped_ptr<base::FilePath> zip_path) { |
| +void Operation::StartImageWriterClient() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + if (!image_writer_client_) { |
| + image_writer_client_ = new ImageWriterClient(); |
| + |
| + AddCleanUpFunction(base::Bind(&Operation::StopImageWriterClient, this)); |
| + } |
| +} |
| + |
| +void Operation::StopImageWriterClient() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&ImageWriterClient::Shutdown, image_writer_client_)); |
| +} |
| + |
| +void Operation::WriteImageProgress(int64 total_bytes, int64 curr_bytes) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| if (IsCancelled()) { |
| return; |
| } |
| - DVLOG(1) << "Starting unzip stage for " << zip_path->value(); |
| + int progress = kProgressComplete * curr_bytes / total_bytes; |
|
Lei Zhang
2014/02/15 00:26:59
Can this overflow? Same with line 338.
Drew Haven
2014/02/15 01:23:58
My understanding is that kProgressComplete * curr_
Lei Zhang
2014/02/15 01:41:50
Do you trust the utility process to send you a val
Jorge Lucangeli Obes
2014/02/15 01:43:19
I would add CHECKS for both values to be positive,
|
| + |
| + if (progress > GetProgress()) { |
| + SetProgress(progress); |
| + } |
| +} |
| + |
| +void Operation::UnzipStart(scoped_ptr<base::FilePath> zip_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + if (IsCancelled()) { |
| + return; |
| + } |
| SetStage(image_writer_api::STAGE_UNZIP); |
| @@ -335,7 +360,7 @@ void Operation::OnUnzipFailure() { |
| void Operation::OnUnzipProgress(int64 total_bytes, int64 progress_bytes) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| - int progress_percent = 100 * progress_bytes / total_bytes; |
| + int progress_percent = kProgressComplete * progress_bytes / total_bytes; |
| SetProgress(progress_percent); |
| } |