diff options
author | Haibo Huang <hhb@google.com> | 2019-10-16 11:43:14 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-10-16 11:43:14 -0700 |
commit | f3b6ef05541f222e5bde9833f2a8c335df40a24f (patch) | |
tree | 04ab5506b6bffa180cf39a1f415cdd72d99899fa | |
parent | 084a9b55aa7b2fc1932d5b8f5a5f34c7c80d86cc (diff) | |
parent | b708c0f136b87e1406410dea9cda5f994b86783f (diff) | |
download | zlib-f3b6ef05541f222e5bde9833f2a8c335df40a24f.tar.gz |
Merge "Upgrade zlib to ddebad26cfadeb4ecdfe3da8beb396a85cf90c91" am: de51e42c11 am: 046b1c12db
am: b708c0f136
Change-Id: I5889c66bc8ecb86bf45ea3faa7bb2d9367c7c3f4
-rw-r--r-- | METADATA | 4 | ||||
-rw-r--r-- | google/BUILD.gn | 15 | ||||
-rw-r--r-- | google/zip.cc | 10 | ||||
-rw-r--r-- | google/zip.h | 6 | ||||
-rw-r--r-- | google/zip_reader.cc | 43 | ||||
-rw-r--r-- | google/zip_reader.h | 14 | ||||
-rw-r--r-- | google/zip_reader_unittest.cc | 22 |
7 files changed, 64 insertions, 50 deletions
@@ -5,11 +5,11 @@ third_party { type: GIT value: "https://chromium.googlesource.com/chromium/src/third_party/zlib/" } - version: "0044d0424c7f7d15436541ed1ecc89479b8bfda4" + version: "ddebad26cfadeb4ecdfe3da8beb396a85cf90c91" license_type: NOTICE last_upgrade_date { year: 2019 - month: 9 + month: 10 day: 9 } } diff --git a/google/BUILD.gn b/google/BUILD.gn index 0dee214..4024836 100644 --- a/google/BUILD.gn +++ b/google/BUILD.gn @@ -26,12 +26,23 @@ if (build_with_chromium) { sources = [ "compression_utils.cc", "compression_utils.h", - "compression_utils_portable.cc", - "compression_utils_portable.h", ] deps = [ + ":compression_utils_portable", "//base", "//third_party/zlib", ] } } + +# This allows other users of Chromium's zlib library, but don't use Chromium's +# //base, to reuse some boilerplate code. +static_library("compression_utils_portable") { + sources = [ + "compression_utils_portable.cc", + "compression_utils_portable.h", + ] + deps = [ + "//third_party/zlib", + ] +} diff --git a/google/zip.cc b/google/zip.cc index 4127471..907e5da 100644 --- a/google/zip.cc +++ b/google/zip.cc @@ -173,8 +173,8 @@ bool Zip(const ZipParams& params) { } bool Unzip(const base::FilePath& src_file, const base::FilePath& dest_dir) { - return UnzipWithFilterCallback(src_file, dest_dir, - base::Bind(&ExcludeNoFilesFilter), true); + return UnzipWithFilterCallback( + src_file, dest_dir, base::BindRepeating(&ExcludeNoFilesFilter), true); } bool UnzipWithFilterCallback(const base::FilePath& src_file, @@ -249,11 +249,11 @@ bool ZipWithFilterCallback(const base::FilePath& src_dir, bool Zip(const base::FilePath& src_dir, const base::FilePath& dest_file, bool include_hidden_files) { if (include_hidden_files) { - return ZipWithFilterCallback( - src_dir, dest_file, base::Bind(&ExcludeNoFilesFilter)); + return ZipWithFilterCallback(src_dir, dest_file, + base::BindRepeating(&ExcludeNoFilesFilter)); } else { return ZipWithFilterCallback( - src_dir, dest_file, base::Bind(&ExcludeHiddenFilesFilter)); + src_dir, dest_file, base::BindRepeating(&ExcludeHiddenFilesFilter)); } } diff --git a/google/zip.h b/google/zip.h index 7458be0..4f64a8a 100644 --- a/google/zip.h +++ b/google/zip.h @@ -71,7 +71,7 @@ class ZipParams { } const std::vector<base::FilePath>& files_to_zip() const { return src_files_; } - using FilterCallback = base::Callback<bool(const base::FilePath&)>; + using FilterCallback = base::RepeatingCallback<bool(const base::FilePath&)>; void set_filter_callback(FilterCallback filter_callback) { filter_callback_ = filter_callback; } @@ -125,7 +125,7 @@ bool Zip(const ZipParams& params); // of src_dir will be at the root level of the created zip. For each file in // src_dir, include it only if the callback |filter_cb| returns true. Otherwise // omit it. -typedef base::Callback<bool(const base::FilePath&)> FilterCallback; +using FilterCallback = base::RepeatingCallback<bool(const base::FilePath&)>; bool ZipWithFilterCallback(const base::FilePath& src_dir, const base::FilePath& dest_file, const FilterCallback& filter_cb); @@ -152,7 +152,7 @@ bool ZipFiles(const base::FilePath& src_dir, // returns true. Otherwise omit it. // If |log_skipped_files| is true, files skipped during extraction are printed // to debug log. -typedef base::Callback<bool(const base::FilePath&)> FilterCallback; +using FilterCallback = base::RepeatingCallback<bool(const base::FilePath&)>; bool UnzipWithFilterCallback(const base::FilePath& zip_file, const base::FilePath& dest_dir, const FilterCallback& filter_cb, diff --git a/google/zip_reader.cc b/google/zip_reader.cc index 6bba0cf..8b4bb4a 100644 --- a/google/zip_reader.cc +++ b/google/zip_reader.cc @@ -287,8 +287,8 @@ bool ZipReader::ExtractCurrentEntry(WriterDelegate* delegate, void ZipReader::ExtractCurrentEntryToFilePathAsync( const base::FilePath& output_file_path, - const SuccessCallback& success_callback, - const FailureCallback& failure_callback, + SuccessCallback success_callback, + FailureCallback failure_callback, const ProgressCallback& progress_callback) { DCHECK(zip_file_); DCHECK(current_entry_info_.get()); @@ -296,24 +296,28 @@ void ZipReader::ExtractCurrentEntryToFilePathAsync( // If this is a directory, just create it and return. if (current_entry_info()->is_directory()) { if (base::CreateDirectory(output_file_path)) { - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, success_callback); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, std::move(success_callback)); } else { DVLOG(1) << "Unzip failed: unable to create directory."; - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, std::move(failure_callback)); } return; } if (unzOpenCurrentFile(zip_file_) != UNZ_OK) { DVLOG(1) << "Unzip failed: unable to open current zip entry."; - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, + std::move(failure_callback)); return; } base::FilePath output_dir_path = output_file_path.DirName(); if (!base::CreateDirectory(output_dir_path)) { DVLOG(1) << "Unzip failed: unable to create containing directory."; - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, + std::move(failure_callback)); return; } @@ -323,15 +327,17 @@ void ZipReader::ExtractCurrentEntryToFilePathAsync( if (!output_file.IsValid()) { DVLOG(1) << "Unzip failed: unable to create platform file at " << output_file_path.value(); - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, failure_callback); + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, + std::move(failure_callback)); return; } base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), - Passed(std::move(output_file)), success_callback, - failure_callback, progress_callback, 0 /* initial offset */)); + base::BindOnce(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), + Passed(std::move(output_file)), + std::move(success_callback), std::move(failure_callback), + progress_callback, 0 /* initial offset */)); } bool ZipReader::ExtractCurrentEntryToString(uint64_t max_read_bytes, @@ -400,8 +406,8 @@ void ZipReader::Reset() { } void ZipReader::ExtractChunk(base::File output_file, - const SuccessCallback& success_callback, - const FailureCallback& failure_callback, + SuccessCallback success_callback, + FailureCallback failure_callback, const ProgressCallback& progress_callback, const int64_t offset) { char buffer[internal::kZipBufSize]; @@ -412,15 +418,15 @@ void ZipReader::ExtractChunk(base::File output_file, if (num_bytes_read == 0) { unzCloseCurrentFile(zip_file_); - success_callback.Run(); + std::move(success_callback).Run(); } else if (num_bytes_read < 0) { DVLOG(1) << "Unzip failed: error while reading zipfile " << "(" << num_bytes_read << ")"; - failure_callback.Run(); + std::move(failure_callback).Run(); } else { if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) { DVLOG(1) << "Unzip failed: unable to write all bytes to target."; - failure_callback.Run(); + std::move(failure_callback).Run(); return; } @@ -430,9 +436,10 @@ void ZipReader::ExtractChunk(base::File output_file, base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), - Passed(std::move(output_file)), success_callback, - failure_callback, progress_callback, current_progress)); + base::BindOnce(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(), + Passed(std::move(output_file)), + std::move(success_callback), std::move(failure_callback), + progress_callback, current_progress)); } } diff --git a/google/zip_reader.h b/google/zip_reader.h index 7a43d3a..d442d42 100644 --- a/google/zip_reader.h +++ b/google/zip_reader.h @@ -65,12 +65,12 @@ class WriterDelegate { class ZipReader { public: // A callback that is called when the operation is successful. - typedef base::Closure SuccessCallback; + using SuccessCallback = base::OnceClosure; // A callback that is called when the operation fails. - typedef base::Closure FailureCallback; + using FailureCallback = base::OnceClosure; // A callback that is called periodically during the operation with the number // of bytes that have been processed so far. - typedef base::Callback<void(int64_t)> ProgressCallback; + using ProgressCallback = base::RepeatingCallback<void(int64_t)>; // This class represents information of an entry (file or directory) in // a zip file. @@ -175,8 +175,8 @@ class ZipReader { // Callbacks will be posted to the current MessageLoop in-order. void ExtractCurrentEntryToFilePathAsync( const base::FilePath& output_file_path, - const SuccessCallback& success_callback, - const FailureCallback& failure_callback, + SuccessCallback success_callback, + FailureCallback failure_callback, const ProgressCallback& progress_callback); // Extracts the current entry into memory. If the current entry is a @@ -214,8 +214,8 @@ class ZipReader { // Extracts a chunk of the file to the target. Will post a task for the next // chunk and success/failure/progress callbacks as necessary. void ExtractChunk(base::File target_file, - const SuccessCallback& success_callback, - const FailureCallback& failure_callback, + SuccessCallback success_callback, + FailureCallback failure_callback, const ProgressCallback& progress_callback, const int64_t offset); diff --git a/google/zip_reader_unittest.cc b/google/zip_reader_unittest.cc index aa20185..87190c7 100644 --- a/google/zip_reader_unittest.cc +++ b/google/zip_reader_unittest.cc @@ -214,7 +214,7 @@ class ZipReaderTest : public PlatformTest { base::ScopedTempDir temp_dir_; - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; }; TEST_F(ZipReaderTest, Open_ValidZipFile) { @@ -428,12 +428,10 @@ TEST_F(ZipReaderTest, ExtractToFileAsync_RegularFile) { ASSERT_TRUE(LocateAndOpenEntry(&reader, target_path)); reader.ExtractCurrentEntryToFilePathAsync( target_file, - base::Bind(&MockUnzipListener::OnUnzipSuccess, - listener.AsWeakPtr()), - base::Bind(&MockUnzipListener::OnUnzipFailure, - listener.AsWeakPtr()), - base::Bind(&MockUnzipListener::OnUnzipProgress, - listener.AsWeakPtr())); + base::BindOnce(&MockUnzipListener::OnUnzipSuccess, listener.AsWeakPtr()), + base::BindOnce(&MockUnzipListener::OnUnzipFailure, listener.AsWeakPtr()), + base::BindRepeating(&MockUnzipListener::OnUnzipProgress, + listener.AsWeakPtr())); EXPECT_EQ(0, listener.success_calls()); EXPECT_EQ(0, listener.failure_calls()); @@ -468,12 +466,10 @@ TEST_F(ZipReaderTest, ExtractToFileAsync_Directory) { ASSERT_TRUE(LocateAndOpenEntry(&reader, target_path)); reader.ExtractCurrentEntryToFilePathAsync( target_file, - base::Bind(&MockUnzipListener::OnUnzipSuccess, - listener.AsWeakPtr()), - base::Bind(&MockUnzipListener::OnUnzipFailure, - listener.AsWeakPtr()), - base::Bind(&MockUnzipListener::OnUnzipProgress, - listener.AsWeakPtr())); + base::BindOnce(&MockUnzipListener::OnUnzipSuccess, listener.AsWeakPtr()), + base::BindOnce(&MockUnzipListener::OnUnzipFailure, listener.AsWeakPtr()), + base::BindRepeating(&MockUnzipListener::OnUnzipProgress, + listener.AsWeakPtr())); EXPECT_EQ(0, listener.success_calls()); EXPECT_EQ(0, listener.failure_calls()); |