OLD | NEW |
---|---|
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 bool LocateAndOpenEntry(const base::FilePath& path_in_zip); | 123 bool LocateAndOpenEntry(const base::FilePath& path_in_zip); |
124 | 124 |
125 // Extracts the current entry to the given output file path. If the | 125 // Extracts the current entry to the given output file path. If the |
126 // current file is a directory, just creates a directory | 126 // current file is a directory, just creates a directory |
127 // instead. Returns true on success. OpenCurrentEntryInZip() must be | 127 // instead. Returns true on success. OpenCurrentEntryInZip() must be |
128 // called beforehand. | 128 // called beforehand. |
129 // | 129 // |
130 // This function does not preserve the timestamp of the original entry. | 130 // This function does not preserve the timestamp of the original entry. |
131 bool ExtractCurrentEntryToFilePath(const base::FilePath& output_file_path); | 131 bool ExtractCurrentEntryToFilePath(const base::FilePath& output_file_path); |
132 | 132 |
133 // Asynchronously extracts the current entry to the given output file path. | |
134 // If the current entry is a directory it just creates the directory | |
135 // synchronously instead. OpenCurrentEntryInZip() must be called beforehand. | |
satorux1
2013/12/11 06:45:11
Please document callback parameters.
Drew Haven
2013/12/11 18:20:53
I ended up with split documentation between the ty
| |
136 void ExtractCurrentEntryToFilePathAsync( | |
137 const base::FilePath& output_file_path, | |
138 base::Closure success_callback, | |
139 base::Closure failure_Callback, | |
satorux1
2013/12/11 06:45:11
failure_callback
Drew Haven
2013/12/11 18:20:53
Done.
| |
140 base::Callback<void(int64)> progress_callback); | |
satorux1
2013/12/11 06:45:11
Let's typedef this:
typedef base::Callback<void(i
Drew Haven
2013/12/11 18:20:53
Done.
| |
141 | |
133 // Extracts the current entry to the given output directory path using | 142 // Extracts the current entry to the given output directory path using |
134 // ExtractCurrentEntryToFilePath(). Sub directories are created as needed | 143 // ExtractCurrentEntryToFilePath(). Sub directories are created as needed |
135 // based on the file path of the current entry. For example, if the file | 144 // 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", | 145 // path in zip is "foo/bar.txt", and the output directory is "output", |
137 // "output/foo/bar.txt" will be created. | 146 // "output/foo/bar.txt" will be created. |
138 // | 147 // |
139 // Returns true on success. OpenCurrentEntryInZip() must be called | 148 // Returns true on success. OpenCurrentEntryInZip() must be called |
140 // beforehand. | 149 // beforehand. |
141 bool ExtractCurrentEntryIntoDirectory( | 150 bool ExtractCurrentEntryIntoDirectory( |
142 const base::FilePath& output_directory_path); | 151 const base::FilePath& output_directory_path); |
(...skipping 14 matching lines...) Expand all Loading... | |
157 // Open() must be called beforehand. | 166 // Open() must be called beforehand. |
158 int num_entries() const { return num_entries_; } | 167 int num_entries() const { return num_entries_; } |
159 | 168 |
160 private: | 169 private: |
161 // Common code used both in Open and OpenFromFd. | 170 // Common code used both in Open and OpenFromFd. |
162 bool OpenInternal(); | 171 bool OpenInternal(); |
163 | 172 |
164 // Resets the internal state. | 173 // Resets the internal state. |
165 void Reset(); | 174 void Reset(); |
166 | 175 |
176 // Unzip loop for asynchronous code. | |
satorux1
2013/12/11 06:45:11
Function comments should usually start from a verb
Drew Haven
2013/12/11 18:20:53
Done.
| |
177 void ExtractChunk(base::PlatformFile target_file, | |
178 base::Closure success_callback, | |
179 base::Closure failure_callback, | |
180 base::Callback<void(int64)> progress_callback, | |
181 const int64 offset); | |
182 | |
167 unzFile zip_file_; | 183 unzFile zip_file_; |
168 int num_entries_; | 184 int num_entries_; |
169 bool reached_end_; | 185 bool reached_end_; |
170 scoped_ptr<EntryInfo> current_entry_info_; | 186 scoped_ptr<EntryInfo> current_entry_info_; |
171 | 187 |
188 base::WeakPtrFactory<ZipReader> weak_factory_; | |
satorux1
2013/12/11 06:45:11
nit: weak_ptr_factory_
Drew Haven
2013/12/11 18:20:53
I thought that was weird too. But it happens to b
| |
189 | |
172 DISALLOW_COPY_AND_ASSIGN(ZipReader); | 190 DISALLOW_COPY_AND_ASSIGN(ZipReader); |
173 }; | 191 }; |
174 | 192 |
175 } // namespace zip | 193 } // namespace zip |
176 | 194 |
177 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 195 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
OLD | NEW |