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..93d377435ac54fc8c44f821ce3a44bb277c294d2 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::StartUtilityClient() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ if (!image_writer_client_) { |
+ image_writer_client_ = new ImageWriterUtilityClient(); |
+ |
+ AddCleanUpFunction(base::Bind(&Operation::StopUtilityClient, this)); |
+ } |
+} |
+ |
+void Operation::StopUtilityClient() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&ImageWriterUtilityClient::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; |
+ |
+ 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); |
} |