summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Degros <fdegros@chromium.org>2022-02-22 08:05:54 +0000
committerCopybara-Service <copybara-worker@google.com>2022-02-22 00:20:24 -0800
commitfb9ea7fd319d87fcb373cc80c2cc00ece06791ad (patch)
tree34eeeeecee6ab982976dfc19e39c85484c737eca
parentf8d70d13465e79ff7513aafe3a0f4374271fbade (diff)
downloadzlib-fb9ea7fd319d87fcb373cc80c2cc00ece06791ad.tar.gz
[zip] Move progress callback in ZipReader
Pass the ProgressCallback by value to ZipReader's ExtractCurrentEntryToFilePathAsync() and ExtractChunk() and move it. This is an optimization. BUG=chromium:1295127 TEST=autoninja -C out/Default zlib_unittests && out/Default/zlib_unittests Change-Id: I3214c0ea9d897dc53a1999b92b364f9673120edc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3478940 Reviewed-by: Noel Gordon <noel@chromium.org> Commit-Queue: François Degros <fdegros@chromium.org> Cr-Commit-Position: refs/heads/main@{#973640} NOKEYCHECK=True GitOrigin-RevId: b6044c6f242889d31da099d7a6413dd41b1b793b
-rw-r--r--google/zip_reader.cc9
-rw-r--r--google/zip_reader.h13
2 files changed, 12 insertions, 10 deletions
diff --git a/google/zip_reader.cc b/google/zip_reader.cc
index ab4476b..e28e5d4 100644
--- a/google/zip_reader.cc
+++ b/google/zip_reader.cc
@@ -337,7 +337,7 @@ void ZipReader::ExtractCurrentEntryToFilePathAsync(
const base::FilePath& output_file_path,
SuccessCallback success_callback,
FailureCallback failure_callback,
- const ProgressCallback& progress_callback) {
+ ProgressCallback progress_callback) {
DCHECK(zip_file_);
DCHECK_LT(0, next_index_);
DCHECK(ok_);
@@ -391,7 +391,7 @@ void ZipReader::ExtractCurrentEntryToFilePathAsync(
FROM_HERE,
base::BindOnce(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(),
std::move(output_file), std::move(success_callback),
- std::move(failure_callback), progress_callback,
+ std::move(failure_callback), std::move(progress_callback),
0 /* initial offset */));
}
@@ -449,7 +449,7 @@ void ZipReader::Reset() {
void ZipReader::ExtractChunk(base::File output_file,
SuccessCallback success_callback,
FailureCallback failure_callback,
- const ProgressCallback& progress_callback,
+ ProgressCallback progress_callback,
int64_t offset) {
char buffer[internal::kZipBufSize];
@@ -489,7 +489,8 @@ void ZipReader::ExtractChunk(base::File output_file,
FROM_HERE,
base::BindOnce(&ZipReader::ExtractChunk, weak_ptr_factory_.GetWeakPtr(),
std::move(output_file), std::move(success_callback),
- std::move(failure_callback), progress_callback, offset));
+ std::move(failure_callback), std::move(progress_callback),
+ offset));
}
// FileWriterDelegate ----------------------------------------------------------
diff --git a/google/zip_reader.h b/google/zip_reader.h
index 67cea3c..ff1d3ec 100644
--- a/google/zip_reader.h
+++ b/google/zip_reader.h
@@ -188,8 +188,9 @@ class ZipReader {
bool ok() const { return ok_; }
// Extracts |num_bytes_to_extract| bytes of the current entry to |delegate|,
- // starting from the beginning of the entry. Return value specifies whether
- // the entire file was extracted.
+ // starting from the beginning of the entry.
+ //
+ // Returns true if the entire file was extracted without error.
//
// Precondition: Next() returned a non-null Entry.
bool ExtractCurrentEntry(WriterDelegate* delegate,
@@ -200,8 +201,8 @@ class ZipReader {
// the current entry is a directory it just creates the directory
// synchronously instead.
//
- // success_callback will be called on success and failure_callback will be
- // called on failure. progress_callback will be called at least once.
+ // |success_callback| will be called on success and |failure_callback| will be
+ // called on failure. |progress_callback| will be called at least once.
// Callbacks will be posted to the current MessageLoop in-order.
//
// Precondition: Next() returned a non-null Entry.
@@ -209,7 +210,7 @@ class ZipReader {
const base::FilePath& output_file_path,
SuccessCallback success_callback,
FailureCallback failure_callback,
- const ProgressCallback& progress_callback);
+ ProgressCallback progress_callback);
// Extracts the current entry into memory. If the current entry is a
// directory, |*output| is set to the empty string. If the current entry is a
@@ -258,7 +259,7 @@ class ZipReader {
void ExtractChunk(base::File target_file,
SuccessCallback success_callback,
FailureCallback failure_callback,
- const ProgressCallback& progress_callback,
+ ProgressCallback progress_callback,
const int64_t offset);
std::string encoding_;