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

Side by Side Diff: chrome/common/zip_reader.cc

Issue 9349005: net: Rename FileStream::Open/Close with OpenSync/CloseSync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/zip.cc ('k') | content/browser/download/base_file.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 "chrome/common/zip_reader.h" 5 #include "chrome/common/zip_reader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 // We can't rely on parent directory entries being specified in the 187 // We can't rely on parent directory entries being specified in the
188 // zip, so we make sure they are created. 188 // zip, so we make sure they are created.
189 FilePath output_dir_path = output_file_path.DirName(); 189 FilePath output_dir_path = output_file_path.DirName();
190 if (!file_util::CreateDirectory(output_dir_path)) 190 if (!file_util::CreateDirectory(output_dir_path))
191 return false; 191 return false;
192 192
193 net::FileStream stream(NULL); 193 net::FileStream stream(NULL);
194 const int flags = (base::PLATFORM_FILE_CREATE_ALWAYS | 194 const int flags = (base::PLATFORM_FILE_CREATE_ALWAYS |
195 base::PLATFORM_FILE_WRITE); 195 base::PLATFORM_FILE_WRITE);
196 if (stream.Open(output_file_path, flags) != 0) 196 if (stream.OpenSync(output_file_path, flags) != 0)
197 return false; 197 return false;
198 198
199 bool success = true; // This becomes false when something bad happens. 199 bool success = true; // This becomes false when something bad happens.
200 while (true) { 200 while (true) {
201 char buf[internal::kZipBufSize]; 201 char buf[internal::kZipBufSize];
202 const int num_bytes_read = unzReadCurrentFile(zip_file_, buf, 202 const int num_bytes_read = unzReadCurrentFile(zip_file_, buf,
203 internal::kZipBufSize); 203 internal::kZipBufSize);
204 if (num_bytes_read == 0) { 204 if (num_bytes_read == 0) {
205 // Reached the end of the file. 205 // Reached the end of the file.
206 break; 206 break;
207 } else if (num_bytes_read < 0) { 207 } else if (num_bytes_read < 0) {
208 // If num_bytes_read < 0, then it's a specific UNZ_* error code. 208 // If num_bytes_read < 0, then it's a specific UNZ_* error code.
209 success = false; 209 success = false;
210 break; 210 break;
211 } else if (num_bytes_read > 0) { 211 } else if (num_bytes_read > 0) {
212 // Some data is read. Write it to the output file. 212 // Some data is read. Write it to the output file.
213 if (num_bytes_read != stream.Write(buf, num_bytes_read, 213 if (num_bytes_read != stream.Write(buf, num_bytes_read,
214 net::CompletionCallback())) { 214 net::CompletionCallback())) {
215 success = false; 215 success = false;
216 break; 216 break;
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 stream.Close(); 221 stream.CloseSync();
222 unzCloseCurrentFile(zip_file_); 222 unzCloseCurrentFile(zip_file_);
223 return success; 223 return success;
224 } 224 }
225 225
226 bool ZipReader::ExtractCurrentEntryIntoDirectory( 226 bool ZipReader::ExtractCurrentEntryIntoDirectory(
227 const FilePath& output_directory_path) { 227 const FilePath& output_directory_path) {
228 DCHECK(current_entry_info_.get()); 228 DCHECK(current_entry_info_.get());
229 229
230 FilePath output_file_path = output_directory_path.Append( 230 FilePath output_file_path = output_directory_path.Append(
231 current_entry_info()->file_path()); 231 current_entry_info()->file_path());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 289 }
290 290
291 void ZipReader::Reset() { 291 void ZipReader::Reset() {
292 zip_file_ = NULL; 292 zip_file_ = NULL;
293 num_entries_ = 0; 293 num_entries_ = 0;
294 reached_end_ = false; 294 reached_end_ = false;
295 current_entry_info_.reset(); 295 current_entry_info_.reset();
296 } 296 }
297 297
298 } // namespace zip 298 } // namespace zip
OLDNEW
« no previous file with comments | « chrome/common/zip.cc ('k') | content/browser/download/base_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698