| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "third_party/zlib/google/zip_reader.h" | 5 #include "third_party/zlib/google/zip_reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "third_party/zlib/google/zip_internal.h" | 14 #include "third_party/zlib/google/zip_internal.h" |
| 14 | 15 |
| 15 #if defined(USE_SYSTEM_MINIZIP) | 16 #if defined(USE_SYSTEM_MINIZIP) |
| 16 #include <minizip/unzip.h> | 17 #include <minizip/unzip.h> |
| 17 #else | 18 #else |
| 18 #include "third_party/zlib/contrib/minizip/unzip.h" | 19 #include "third_party/zlib/contrib/minizip/unzip.h" |
| 19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 20 #include "third_party/zlib/contrib/minizip/iowin32.h" | 21 #include "third_party/zlib/contrib/minizip/iowin32.h" |
| 21 #endif // defined(OS_WIN) | 22 #endif // defined(OS_WIN) |
| 22 #endif // defined(USE_SYSTEM_MINIZIP) | 23 #endif // defined(USE_SYSTEM_MINIZIP) |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 const base::FilePath& output_file_path, | 349 const base::FilePath& output_file_path, |
| 349 const SuccessCallback& success_callback, | 350 const SuccessCallback& success_callback, |
| 350 const FailureCallback& failure_callback, | 351 const FailureCallback& failure_callback, |
| 351 const ProgressCallback& progress_callback) { | 352 const ProgressCallback& progress_callback) { |
| 352 DCHECK(zip_file_); | 353 DCHECK(zip_file_); |
| 353 DCHECK(current_entry_info_.get()); | 354 DCHECK(current_entry_info_.get()); |
| 354 | 355 |
| 355 // If this is a directory, just create it and return. | 356 // If this is a directory, just create it and return. |
| 356 if (current_entry_info()->is_directory()) { | 357 if (current_entry_info()->is_directory()) { |
| 357 if (base::CreateDirectory(output_file_path)) { | 358 if (base::CreateDirectory(output_file_path)) { |
| 358 base::MessageLoopProxy::current()->PostTask(FROM_HERE, success_callback); | 359 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, success_callback)
; |
| 359 } else { | 360 } else { |
| 360 DVLOG(1) << "Unzip failed: unable to create directory."; | 361 DVLOG(1) << "Unzip failed: unable to create directory."; |
| 361 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); | 362 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback)
; |
| 362 } | 363 } |
| 363 return; | 364 return; |
| 364 } | 365 } |
| 365 | 366 |
| 366 if (unzOpenCurrentFile(zip_file_) != UNZ_OK) { | 367 if (unzOpenCurrentFile(zip_file_) != UNZ_OK) { |
| 367 DVLOG(1) << "Unzip failed: unable to open current zip entry."; | 368 DVLOG(1) << "Unzip failed: unable to open current zip entry."; |
| 368 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); | 369 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); |
| 369 return; | 370 return; |
| 370 } | 371 } |
| 371 | 372 |
| 372 base::FilePath output_dir_path = output_file_path.DirName(); | 373 base::FilePath output_dir_path = output_file_path.DirName(); |
| 373 if (!base::CreateDirectory(output_dir_path)) { | 374 if (!base::CreateDirectory(output_dir_path)) { |
| 374 DVLOG(1) << "Unzip failed: unable to create containing directory."; | 375 DVLOG(1) << "Unzip failed: unable to create containing directory."; |
| 375 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); | 376 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); |
| 376 return; | 377 return; |
| 377 } | 378 } |
| 378 | 379 |
| 379 const int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE; | 380 const int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE; |
| 380 base::File output_file(output_file_path, flags); | 381 base::File output_file(output_file_path, flags); |
| 381 | 382 |
| 382 if (!output_file.IsValid()) { | 383 if (!output_file.IsValid()) { |
| 383 DVLOG(1) << "Unzip failed: unable to create platform file at " | 384 DVLOG(1) << "Unzip failed: unable to create platform file at " |
| 384 << output_file_path.value(); | 385 << output_file_path.value(); |
| 385 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); | 386 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); |
| 386 return; | 387 return; |
| 387 } | 388 } |
| 388 | 389 |
| 389 base::MessageLoop::current()->PostTask( | 390 base::MessageLoop::current()->PostTask( |
| 390 FROM_HERE, | 391 FROM_HERE, |
| 391 base::Bind(&ZipReader::ExtractChunk, | 392 base::Bind(&ZipReader::ExtractChunk, |
| 392 weak_ptr_factory_.GetWeakPtr(), | 393 weak_ptr_factory_.GetWeakPtr(), |
| 393 Passed(output_file.Pass()), | 394 Passed(output_file.Pass()), |
| 394 success_callback, | 395 success_callback, |
| 395 failure_callback, | 396 failure_callback, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 531 } |
| 531 | 532 |
| 532 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { | 533 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { |
| 533 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); | 534 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); |
| 534 if (bytes_written > 0) | 535 if (bytes_written > 0) |
| 535 file_length_ += bytes_written; | 536 file_length_ += bytes_written; |
| 536 return bytes_written == num_bytes; | 537 return bytes_written == num_bytes; |
| 537 } | 538 } |
| 538 | 539 |
| 539 } // namespace zip | 540 } // namespace zip |
| OLD | NEW |