| 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 <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 16 #include "third_party/zlib/google/zip_internal.h" | 18 #include "third_party/zlib/google/zip_internal.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 389 |
| 388 if (!output_file.IsValid()) { | 390 if (!output_file.IsValid()) { |
| 389 DVLOG(1) << "Unzip failed: unable to create platform file at " | 391 DVLOG(1) << "Unzip failed: unable to create platform file at " |
| 390 << output_file_path.value(); | 392 << output_file_path.value(); |
| 391 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); | 393 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); |
| 392 return; | 394 return; |
| 393 } | 395 } |
| 394 | 396 |
| 395 base::MessageLoop::current()->PostTask( | 397 base::MessageLoop::current()->PostTask( |
| 396 FROM_HERE, | 398 FROM_HERE, |
| 397 base::Bind(&ZipReader::ExtractChunk, | 399 base::Bind(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), |
| 398 weak_ptr_factory_.GetWeakPtr(), | 400 Passed(std::move(output_file)), success_callback, |
| 399 Passed(output_file.Pass()), | 401 failure_callback, progress_callback, 0 /* initial offset */)); |
| 400 success_callback, | |
| 401 failure_callback, | |
| 402 progress_callback, | |
| 403 0 /* initial offset */)); | |
| 404 } | 402 } |
| 405 | 403 |
| 406 bool ZipReader::ExtractCurrentEntryIntoDirectory( | 404 bool ZipReader::ExtractCurrentEntryIntoDirectory( |
| 407 const base::FilePath& output_directory_path) const { | 405 const base::FilePath& output_directory_path) const { |
| 408 DCHECK(current_entry_info_.get()); | 406 DCHECK(current_entry_info_.get()); |
| 409 | 407 |
| 410 base::FilePath output_file_path = output_directory_path.Append( | 408 base::FilePath output_file_path = output_directory_path.Append( |
| 411 current_entry_info()->file_path()); | 409 current_entry_info()->file_path()); |
| 412 return ExtractCurrentEntryToFilePath(output_file_path); | 410 return ExtractCurrentEntryToFilePath(output_file_path); |
| 413 } | 411 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 failure_callback.Run(); | 496 failure_callback.Run(); |
| 499 return; | 497 return; |
| 500 } | 498 } |
| 501 | 499 |
| 502 int64_t current_progress = offset + num_bytes_read; | 500 int64_t current_progress = offset + num_bytes_read; |
| 503 | 501 |
| 504 progress_callback.Run(current_progress); | 502 progress_callback.Run(current_progress); |
| 505 | 503 |
| 506 base::MessageLoop::current()->PostTask( | 504 base::MessageLoop::current()->PostTask( |
| 507 FROM_HERE, | 505 FROM_HERE, |
| 508 base::Bind(&ZipReader::ExtractChunk, | 506 base::Bind(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), |
| 509 weak_ptr_factory_.GetWeakPtr(), | 507 Passed(std::move(output_file)), success_callback, |
| 510 Passed(output_file.Pass()), | 508 failure_callback, progress_callback, current_progress)); |
| 511 success_callback, | |
| 512 failure_callback, | |
| 513 progress_callback, | |
| 514 current_progress)); | |
| 515 | |
| 516 } | 509 } |
| 517 } | 510 } |
| 518 | 511 |
| 519 // FileWriterDelegate ---------------------------------------------------------- | 512 // FileWriterDelegate ---------------------------------------------------------- |
| 520 | 513 |
| 521 FileWriterDelegate::FileWriterDelegate(base::File* file) | 514 FileWriterDelegate::FileWriterDelegate(base::File* file) |
| 522 : file_(file), | 515 : file_(file), |
| 523 file_length_(0) { | 516 file_length_(0) { |
| 524 } | 517 } |
| 525 | 518 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 536 } | 529 } |
| 537 | 530 |
| 538 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { | 531 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { |
| 539 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); | 532 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); |
| 540 if (bytes_written > 0) | 533 if (bytes_written > 0) |
| 541 file_length_ += bytes_written; | 534 file_length_ += bytes_written; |
| 542 return bytes_written == num_bytes; | 535 return bytes_written == num_bytes; |
| 543 } | 536 } |
| 544 | 537 |
| 545 } // namespace zip | 538 } // namespace zip |
| OLD | NEW |