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

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

Issue 166573007: Remove some PlatformFile uses from zlib (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yet another rebase Created 6 years, 9 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 | « third_party/zlib/google/zip_reader.h ('k') | third_party/zlib/google/zip_reader_unittest.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 "third_party/zlib/google/zip_reader.h" 5 #include "third_party/zlib/google/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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return; 268 return;
269 } 269 }
270 270
271 base::FilePath output_dir_path = output_file_path.DirName(); 271 base::FilePath output_dir_path = output_file_path.DirName();
272 if (!base::CreateDirectory(output_dir_path)) { 272 if (!base::CreateDirectory(output_dir_path)) {
273 DVLOG(1) << "Unzip failed: unable to create containing directory."; 273 DVLOG(1) << "Unzip failed: unable to create containing directory.";
274 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); 274 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback);
275 return; 275 return;
276 } 276 }
277 277
278 const int flags = (base::PLATFORM_FILE_CREATE_ALWAYS | 278 const int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
279 base::PLATFORM_FILE_WRITE); 279 base::File output_file(output_file_path, flags);
280 bool created = false;
281 base::PlatformFileError platform_file_error;
282 base::PlatformFile output_file = CreatePlatformFile(output_file_path,
283 flags,
284 &created,
285 &platform_file_error);
286 280
287 if (platform_file_error != base::PLATFORM_FILE_OK) { 281 if (!output_file.IsValid()) {
288 DVLOG(1) << "Unzip failed: unable to create platform file at " 282 DVLOG(1) << "Unzip failed: unable to create platform file at "
289 << output_file_path.value(); 283 << output_file_path.value();
290 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback); 284 base::MessageLoopProxy::current()->PostTask(FROM_HERE, failure_callback);
291 return; 285 return;
292 } 286 }
293 287
294 base::MessageLoop::current()->PostTask( 288 base::MessageLoop::current()->PostTask(
295 FROM_HERE, 289 FROM_HERE,
296 base::Bind(&ZipReader::ExtractChunk, 290 base::Bind(&ZipReader::ExtractChunk,
297 weak_ptr_factory_.GetWeakPtr(), 291 weak_ptr_factory_.GetWeakPtr(),
298 output_file, 292 Passed(output_file.Pass()),
299 success_callback, 293 success_callback,
300 failure_callback, 294 failure_callback,
301 progress_callback, 295 progress_callback,
302 0 /* initial offset */)); 296 0 /* initial offset */));
303 } 297 }
304 298
305 bool ZipReader::ExtractCurrentEntryIntoDirectory( 299 bool ZipReader::ExtractCurrentEntryIntoDirectory(
306 const base::FilePath& output_directory_path) { 300 const base::FilePath& output_directory_path) {
307 DCHECK(current_entry_info_.get()); 301 DCHECK(current_entry_info_.get());
308 302
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return true; 361 return true;
368 } 362 }
369 363
370 void ZipReader::Reset() { 364 void ZipReader::Reset() {
371 zip_file_ = NULL; 365 zip_file_ = NULL;
372 num_entries_ = 0; 366 num_entries_ = 0;
373 reached_end_ = false; 367 reached_end_ = false;
374 current_entry_info_.reset(); 368 current_entry_info_.reset();
375 } 369 }
376 370
377 void ZipReader::ExtractChunk(base::PlatformFile output_file, 371 void ZipReader::ExtractChunk(base::File output_file,
378 const SuccessCallback& success_callback, 372 const SuccessCallback& success_callback,
379 const FailureCallback& failure_callback, 373 const FailureCallback& failure_callback,
380 const ProgressCallback& progress_callback, 374 const ProgressCallback& progress_callback,
381 const int64 offset) { 375 const int64 offset) {
382 char buffer[internal::kZipBufSize]; 376 char buffer[internal::kZipBufSize];
383 377
384 const int num_bytes_read = unzReadCurrentFile(zip_file_, 378 const int num_bytes_read = unzReadCurrentFile(zip_file_,
385 buffer, 379 buffer,
386 internal::kZipBufSize); 380 internal::kZipBufSize);
387 381
388 if (num_bytes_read == 0) { 382 if (num_bytes_read == 0) {
389 unzCloseCurrentFile(zip_file_); 383 unzCloseCurrentFile(zip_file_);
390 base::ClosePlatformFile(output_file);
391 success_callback.Run(); 384 success_callback.Run();
392 } else if (num_bytes_read < 0) { 385 } else if (num_bytes_read < 0) {
393 DVLOG(1) << "Unzip failed: error while reading zipfile " 386 DVLOG(1) << "Unzip failed: error while reading zipfile "
394 << "(" << num_bytes_read << ")"; 387 << "(" << num_bytes_read << ")";
395 base::ClosePlatformFile(output_file);
396 failure_callback.Run(); 388 failure_callback.Run();
397 } else { 389 } else {
398 if (num_bytes_read != base::WritePlatformFile(output_file, 390 if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) {
399 offset,
400 buffer,
401 num_bytes_read)) {
402 DVLOG(1) << "Unzip failed: unable to write all bytes to target."; 391 DVLOG(1) << "Unzip failed: unable to write all bytes to target.";
403 base::ClosePlatformFile(output_file);
404 failure_callback.Run(); 392 failure_callback.Run();
405 return; 393 return;
406 } 394 }
407 395
408 int64 current_progress = offset + num_bytes_read; 396 int64 current_progress = offset + num_bytes_read;
409 397
410 progress_callback.Run(current_progress); 398 progress_callback.Run(current_progress);
411 399
412 base::MessageLoop::current()->PostTask( 400 base::MessageLoop::current()->PostTask(
413 FROM_HERE, 401 FROM_HERE,
414 base::Bind(&ZipReader::ExtractChunk, 402 base::Bind(&ZipReader::ExtractChunk,
415 weak_ptr_factory_.GetWeakPtr(), 403 weak_ptr_factory_.GetWeakPtr(),
416 output_file, 404 Passed(output_file.Pass()),
417 success_callback, 405 success_callback,
418 failure_callback, 406 failure_callback,
419 progress_callback, 407 progress_callback,
420 current_progress)); 408 current_progress));
421 409
422 } 410 }
423 } 411 }
424 412
425 413
426 } // namespace zip 414 } // namespace zip
OLDNEW
« no previous file with comments | « third_party/zlib/google/zip_reader.h ('k') | third_party/zlib/google/zip_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698