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 6170949cceedf092547755f30f48f5c752786ad2..6a7580637bafdb4f44808a7da689b7cebd451fef 100644 |
| --- a/chrome/browser/extensions/api/image_writer_private/operation.cc |
| +++ b/chrome/browser/extensions/api/image_writer_private/operation.cc |
| @@ -1,3 +1,4 @@ |
| +// |
|
satorux1
2013/12/13 07:55:09
remove this
Drew Haven
2013/12/13 18:36:11
Done.
|
| // Copyright 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -9,7 +10,6 @@ |
| #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
| #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "third_party/zlib/google/zip.h" |
| namespace extensions { |
| namespace image_writer { |
| @@ -178,59 +178,49 @@ void Operation::CleanUp() { |
| cleanup_functions_.clear(); |
| } |
| -void Operation::UnzipStart(scoped_ptr<base::FilePath> zip_file) { |
| +void Operation::UnzipStart(scoped_ptr<base::FilePath> zip_path) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| if (IsCancelled()) { |
| return; |
| } |
| - DVLOG(1) << "Starting unzip stage for " << zip_file->value(); |
| + DVLOG(1) << "Starting unzip stage for " << zip_path->value(); |
| SetStage(image_writer_api::STAGE_UNZIP); |
| base::FilePath tmp_dir; |
| - if (!base::CreateTemporaryDirInDir(zip_file->DirName(), |
| + if (!base::CreateTemporaryDirInDir(zip_path->DirName(), |
| FILE_PATH_LITERAL("image_writer"), |
| &tmp_dir)) { |
| + DLOG(ERROR) << "Failed to create temporary directory."; |
| Error(error::kTempDir); |
| return; |
| } |
| AddCleanUpFunction(base::Bind(&RemoveTempDirectory, tmp_dir)); |
| - if (!zip::Unzip(*zip_file, tmp_dir)) { |
| - Error(error::kUnzip); |
| - return; |
| - } |
| - |
| - base::FileEnumerator file_enumerator(tmp_dir, |
| - false, |
| - base::FileEnumerator::FILES); |
| - |
| - scoped_ptr<base::FilePath> unzipped_file( |
| - new base::FilePath(file_enumerator.Next())); |
| - |
| - if (unzipped_file->empty()) { |
| - Error(error::kEmptyUnzip); |
| + if (!base::CreateTemporaryFileInDir(tmp_dir, &image_path_)) { |
| + DLOG(ERROR) << "Failed create temporary unzip target in " |
| + << tmp_dir.value(); |
| + Error(error::kTempDir); |
| return; |
| } |
| - if (!file_enumerator.Next().empty()) { |
| - Error(error::kMultiFileZip); |
| + if (!(zip_reader_.Open(*zip_path) && |
| + zip_reader_.AdvanceToNextEntry() && |
| + zip_reader_.OpenCurrentEntryInZip())) { |
| + DLOG(ERROR) << "Failed to open zip file."; |
| + Error(error::kUnzip); |
| return; |
| } |
| - DVLOG(1) << "Successfully unzipped as " << unzipped_file->value(); |
| - |
| - SetProgress(kProgressComplete); |
| - |
| - image_path_ = *unzipped_file; |
| - |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, |
| - FROM_HERE, |
| - base::Bind(&Operation::WriteStart, |
| - this)); |
| + zip_reader_.ExtractCurrentEntryToFilePathAsync( |
| + image_path_, |
| + base::Bind(&Operation::OnUnzipSuccess, this), |
| + base::Bind(&Operation::OnUnzipFailure, this), |
| + base::Bind(&Operation::OnUnzipProgress, |
| + this, |
| + zip_reader_.current_entry_info()->original_size())); |
| } |
| void Operation::GetMD5SumOfFile( |
| @@ -326,5 +316,28 @@ void Operation::MD5Chunk( |
| } |
| } |
| +void Operation::OnUnzipSuccess() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + SetProgress(kProgressComplete); |
| + |
| + if (zip_reader_.HasMore()) { |
| + Error(error::kMultiFileZip); |
| + } else { |
| + WriteStart(); |
| + } |
| +} |
| + |
| +void Operation::OnUnzipFailure() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + Error(error::kUnzip); |
| +} |
| + |
| +void Operation::OnUnzipProgress(int64 total_bytes, int64 progress_bytes) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + |
| + int progress_percent = 100 * progress_bytes / total_bytes; |
| + SetProgress(progress_percent); |
| +} |
| + |
| } // namespace image_writer |
| } // namespace extensions |