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

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

Issue 92873003: Adds asynchronous unzip functions to ZipReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes up commenting and minor style issues. Created 7 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ 4 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_
6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ 5 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_
7 6
8 #include <string> 7 #include <string>
9 8
10 #include "base/basictypes.h" 9 #include "base/basictypes.h"
11 #include "base/file_util.h" 10 #include "base/file_util.h"
12 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/platform_file.h" 14 #include "base/platform_file.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 16
17 #if defined(USE_SYSTEM_MINIZIP) 17 #if defined(USE_SYSTEM_MINIZIP)
18 #include <minizip/unzip.h> 18 #include <minizip/unzip.h>
19 #else 19 #else
20 #include "third_party/zlib/contrib/minizip/unzip.h" 20 #include "third_party/zlib/contrib/minizip/unzip.h"
21 #endif 21 #endif
22 22
23 namespace zip { 23 namespace zip {
(...skipping 11 matching lines...) Expand all
35 // } 35 // }
36 // 36 //
37 // For simplicty, error checking is omitted in the example code above. The 37 // For simplicty, error checking is omitted in the example code above. The
38 // production code should check return values from all of these functions. 38 // production code should check return values from all of these functions.
39 // 39 //
40 // This calls can also be used for random access of contents in a zip file 40 // This calls can also be used for random access of contents in a zip file
41 // using LocateAndOpenEntry(). 41 // using LocateAndOpenEntry().
42 // 42 //
43 class ZipReader { 43 class ZipReader {
44 public: 44 public:
45 // A callback that is called when the operation is successful.
46 typedef base::Closure SuccessCallback;
47 // A callback that is called when the operation fails.
48 typedef base::Closure FailureCallback;
49 // A callback that is called periodically during the operation with the number
50 // of bytes that have been processed so far.
51 typedef base::Callback<void(int64)> ProgressCallback;
52
45 // This class represents information of an entry (file or directory) in 53 // This class represents information of an entry (file or directory) in
46 // a zip file. 54 // a zip file.
47 class EntryInfo { 55 class EntryInfo {
48 public: 56 public:
49 EntryInfo(const std::string& filename_in_zip, 57 EntryInfo(const std::string& filename_in_zip,
50 const unz_file_info& raw_file_info); 58 const unz_file_info& raw_file_info);
51 59
52 // Returns the file path. The path is usually relative like 60 // Returns the file path. The path is usually relative like
53 // "foo/bar.txt", but if it's absolute, is_unsafe() returns true. 61 // "foo/bar.txt", but if it's absolute, is_unsafe() returns true.
54 const base::FilePath& file_path() const { return file_path_; } 62 const base::FilePath& file_path() const { return file_path_; }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 bool LocateAndOpenEntry(const base::FilePath& path_in_zip); 131 bool LocateAndOpenEntry(const base::FilePath& path_in_zip);
124 132
125 // Extracts the current entry to the given output file path. If the 133 // Extracts the current entry to the given output file path. If the
126 // current file is a directory, just creates a directory 134 // current file is a directory, just creates a directory
127 // instead. Returns true on success. OpenCurrentEntryInZip() must be 135 // instead. Returns true on success. OpenCurrentEntryInZip() must be
128 // called beforehand. 136 // called beforehand.
129 // 137 //
130 // This function does not preserve the timestamp of the original entry. 138 // This function does not preserve the timestamp of the original entry.
131 bool ExtractCurrentEntryToFilePath(const base::FilePath& output_file_path); 139 bool ExtractCurrentEntryToFilePath(const base::FilePath& output_file_path);
132 140
141 // Asynchronously extracts the current entry to the given output file path.
142 // If the current entry is a directory it just creates the directory
143 // synchronously instead. OpenCurrentEntryInZip() must be called beforehand.
144 // success_callback will be called on success and failure_callback will be
145 // called on failure. progress_callback will be called at least once.
146 // Callbacks will be posted to the current MessageLoop in-order.
147 void ExtractCurrentEntryToFilePathAsync(
148 const base::FilePath& output_file_path,
149 SuccessCallback success_callback,
satorux1 2013/12/12 08:13:01 Please make it const SuccessCallback& and change o
Drew Haven 2013/12/12 22:06:17 Done.
150 FailureCallback failure_callback,
151 ProgressCallback progress_callback);
152
133 // Extracts the current entry to the given output directory path using 153 // Extracts the current entry to the given output directory path using
134 // ExtractCurrentEntryToFilePath(). Sub directories are created as needed 154 // ExtractCurrentEntryToFilePath(). Sub directories are created as needed
135 // based on the file path of the current entry. For example, if the file 155 // based on the file path of the current entry. For example, if the file
136 // path in zip is "foo/bar.txt", and the output directory is "output", 156 // path in zip is "foo/bar.txt", and the output directory is "output",
137 // "output/foo/bar.txt" will be created. 157 // "output/foo/bar.txt" will be created.
138 // 158 //
139 // Returns true on success. OpenCurrentEntryInZip() must be called 159 // Returns true on success. OpenCurrentEntryInZip() must be called
140 // beforehand. 160 // beforehand.
141 bool ExtractCurrentEntryIntoDirectory( 161 bool ExtractCurrentEntryIntoDirectory(
142 const base::FilePath& output_directory_path); 162 const base::FilePath& output_directory_path);
(...skipping 14 matching lines...) Expand all
157 // Open() must be called beforehand. 177 // Open() must be called beforehand.
158 int num_entries() const { return num_entries_; } 178 int num_entries() const { return num_entries_; }
159 179
160 private: 180 private:
161 // Common code used both in Open and OpenFromFd. 181 // Common code used both in Open and OpenFromFd.
162 bool OpenInternal(); 182 bool OpenInternal();
163 183
164 // Resets the internal state. 184 // Resets the internal state.
165 void Reset(); 185 void Reset();
166 186
187 // Extracts a chunk of the file to the target. Will post a task for the next
188 // chunk and success/failure/progress callbacks as necessary.
189 void ExtractChunk(base::PlatformFile target_file,
190 SuccessCallback success_callback,
satorux1 2013/12/12 08:13:01 ditto
Drew Haven 2013/12/12 22:06:17 Done.
191 FailureCallback failure_callback,
192 ProgressCallback progress_callback,
193 const int64 offset);
194
167 unzFile zip_file_; 195 unzFile zip_file_;
168 int num_entries_; 196 int num_entries_;
169 bool reached_end_; 197 bool reached_end_;
170 scoped_ptr<EntryInfo> current_entry_info_; 198 scoped_ptr<EntryInfo> current_entry_info_;
171 199
200 base::WeakPtrFactory<ZipReader> weak_ptr_factory_;
201
172 DISALLOW_COPY_AND_ASSIGN(ZipReader); 202 DISALLOW_COPY_AND_ASSIGN(ZipReader);
173 }; 203 };
174 204
175 } // namespace zip 205 } // namespace zip
176 206
177 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ 207 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698