| 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 dcd147f4ecf03340fc5f8f8e9f1405b114ccafff..92a091fa559d12b711d104e169a84c7b6d061734 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 @@
|
| +//
|
| // 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 {
|
| @@ -168,59 +168,46 @@ 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 (!file_util::CreateTemporaryDirInDir(zip_file->DirName(),
|
| - FILE_PATH_LITERAL("image_writer"),
|
| + if (!file_util::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 (!file_util::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_,
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
|
| + this);
|
| }
|
|
|
| void Operation::GetMD5SumOfFile(
|
| @@ -316,5 +303,26 @@ void Operation::MD5Chunk(
|
| }
|
| }
|
|
|
| +void Operation::OnUnzipProgress(int progress) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| + SetProgress(progress);
|
| +}
|
| +
|
| +void Operation::OnUnzipFailed() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| + Error(error::kUnzip);
|
| +}
|
| +
|
| +void Operation::OnUnzipSuccess() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| + SetProgress(kProgressComplete);
|
| +
|
| + if (zip_reader_.HasMore()) {
|
| + Error(error::kMultiFileZip);
|
| + } else {
|
| + WriteStart();
|
| + }
|
| +}
|
| +
|
| } // namespace image_writer
|
| } // namespace extensions
|
|
|