Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Side by Side Diff: third_party/zlib/google/zip_reader.cc

Issue 1552513002: Switch to standard integer types in third_party/zlib/google/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/zlib/google/zip_reader.h ('k') | third_party/zlib/google/zip_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "build/build_config.h"
14 #include "third_party/zlib/google/zip_internal.h" 16 #include "third_party/zlib/google/zip_internal.h"
15 17
16 #if defined(USE_SYSTEM_MINIZIP) 18 #if defined(USE_SYSTEM_MINIZIP)
17 #include <minizip/unzip.h> 19 #include <minizip/unzip.h>
18 #else 20 #else
19 #include "third_party/zlib/contrib/minizip/unzip.h" 21 #include "third_party/zlib/contrib/minizip/unzip.h"
20 #if defined(OS_WIN) 22 #if defined(OS_WIN)
21 #include "third_party/zlib/contrib/minizip/iowin32.h" 23 #include "third_party/zlib/contrib/minizip/iowin32.h"
22 #endif // defined(OS_WIN) 24 #endif // defined(OS_WIN)
23 #endif // defined(USE_SYSTEM_MINIZIP) 25 #endif // defined(USE_SYSTEM_MINIZIP)
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (current_entry_info()->is_directory()) { 433 if (current_entry_info()->is_directory()) {
432 output->clear(); 434 output->clear();
433 return true; 435 return true;
434 } 436 }
435 437
436 // The original_size() is the best hint for the real size, so it saves 438 // The original_size() is the best hint for the real size, so it saves
437 // doing reallocations for the common case when the uncompressed size is 439 // doing reallocations for the common case when the uncompressed size is
438 // correct. However, we need to assume that the uncompressed size could be 440 // correct. However, we need to assume that the uncompressed size could be
439 // incorrect therefore this function needs to read as much data as possible. 441 // incorrect therefore this function needs to read as much data as possible.
440 std::string contents; 442 std::string contents;
441 contents.reserve(static_cast<size_t>(std::min( 443 contents.reserve(
442 static_cast<int64>(max_read_bytes), 444 static_cast<size_t>(std::min(static_cast<int64_t>(max_read_bytes),
443 current_entry_info()->original_size()))); 445 current_entry_info()->original_size())));
444 446
445 StringWriterDelegate writer(max_read_bytes, &contents); 447 StringWriterDelegate writer(max_read_bytes, &contents);
446 if (!ExtractCurrentEntry(&writer)) 448 if (!ExtractCurrentEntry(&writer))
447 return false; 449 return false;
448 output->swap(contents); 450 output->swap(contents);
449 return true; 451 return true;
450 } 452 }
451 453
452 bool ZipReader::OpenInternal() { 454 bool ZipReader::OpenInternal() {
453 DCHECK(zip_file_); 455 DCHECK(zip_file_);
(...skipping 15 matching lines...) Expand all
469 zip_file_ = NULL; 471 zip_file_ = NULL;
470 num_entries_ = 0; 472 num_entries_ = 0;
471 reached_end_ = false; 473 reached_end_ = false;
472 current_entry_info_.reset(); 474 current_entry_info_.reset();
473 } 475 }
474 476
475 void ZipReader::ExtractChunk(base::File output_file, 477 void ZipReader::ExtractChunk(base::File output_file,
476 const SuccessCallback& success_callback, 478 const SuccessCallback& success_callback,
477 const FailureCallback& failure_callback, 479 const FailureCallback& failure_callback,
478 const ProgressCallback& progress_callback, 480 const ProgressCallback& progress_callback,
479 const int64 offset) { 481 const int64_t offset) {
480 char buffer[internal::kZipBufSize]; 482 char buffer[internal::kZipBufSize];
481 483
482 const int num_bytes_read = unzReadCurrentFile(zip_file_, 484 const int num_bytes_read = unzReadCurrentFile(zip_file_,
483 buffer, 485 buffer,
484 internal::kZipBufSize); 486 internal::kZipBufSize);
485 487
486 if (num_bytes_read == 0) { 488 if (num_bytes_read == 0) {
487 unzCloseCurrentFile(zip_file_); 489 unzCloseCurrentFile(zip_file_);
488 success_callback.Run(); 490 success_callback.Run();
489 } else if (num_bytes_read < 0) { 491 } else if (num_bytes_read < 0) {
490 DVLOG(1) << "Unzip failed: error while reading zipfile " 492 DVLOG(1) << "Unzip failed: error while reading zipfile "
491 << "(" << num_bytes_read << ")"; 493 << "(" << num_bytes_read << ")";
492 failure_callback.Run(); 494 failure_callback.Run();
493 } else { 495 } else {
494 if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) { 496 if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) {
495 DVLOG(1) << "Unzip failed: unable to write all bytes to target."; 497 DVLOG(1) << "Unzip failed: unable to write all bytes to target.";
496 failure_callback.Run(); 498 failure_callback.Run();
497 return; 499 return;
498 } 500 }
499 501
500 int64 current_progress = offset + num_bytes_read; 502 int64_t current_progress = offset + num_bytes_read;
501 503
502 progress_callback.Run(current_progress); 504 progress_callback.Run(current_progress);
503 505
504 base::MessageLoop::current()->PostTask( 506 base::MessageLoop::current()->PostTask(
505 FROM_HERE, 507 FROM_HERE,
506 base::Bind(&ZipReader::ExtractChunk, 508 base::Bind(&ZipReader::ExtractChunk,
507 weak_ptr_factory_.GetWeakPtr(), 509 weak_ptr_factory_.GetWeakPtr(),
508 Passed(output_file.Pass()), 510 Passed(output_file.Pass()),
509 success_callback, 511 success_callback,
510 failure_callback, 512 failure_callback,
(...skipping 23 matching lines...) Expand all
534 } 536 }
535 537
536 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { 538 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) {
537 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); 539 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes);
538 if (bytes_written > 0) 540 if (bytes_written > 0)
539 file_length_ += bytes_written; 541 file_length_ += bytes_written;
540 return bytes_written == num_bytes; 542 return bytes_written == num_bytes;
541 } 543 }
542 544
543 } // namespace zip 545 } // namespace zip
OLDNEW
« no previous file with comments | « third_party/zlib/google/zip_reader.h ('k') | third_party/zlib/google/zip_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698