| OLD | NEW |
| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 507 } |
| 508 | 508 |
| 509 // FileWriterDelegate ---------------------------------------------------------- | 509 // FileWriterDelegate ---------------------------------------------------------- |
| 510 | 510 |
| 511 FileWriterDelegate::FileWriterDelegate(base::File* file) | 511 FileWriterDelegate::FileWriterDelegate(base::File* file) |
| 512 : file_(file), | 512 : file_(file), |
| 513 file_length_(0) { | 513 file_length_(0) { |
| 514 } | 514 } |
| 515 | 515 |
| 516 FileWriterDelegate::~FileWriterDelegate() { | 516 FileWriterDelegate::~FileWriterDelegate() { |
| 517 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 517 if (!file_->SetLength(file_length_)) { |
| 518 const bool success = | 518 DPLOG(ERROR) << "Failed updating length of written file"; |
| 519 #endif | 519 } |
| 520 file_->SetLength(file_length_); | |
| 521 DPLOG_IF(ERROR, !success) << "Failed updating length of written file"; | |
| 522 } | 520 } |
| 523 | 521 |
| 524 bool FileWriterDelegate::PrepareOutput() { | 522 bool FileWriterDelegate::PrepareOutput() { |
| 525 return file_->Seek(base::File::FROM_BEGIN, 0) >= 0; | 523 return file_->Seek(base::File::FROM_BEGIN, 0) >= 0; |
| 526 } | 524 } |
| 527 | 525 |
| 528 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { | 526 bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) { |
| 529 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); | 527 int bytes_written = file_->WriteAtCurrentPos(data, num_bytes); |
| 530 if (bytes_written > 0) | 528 if (bytes_written > 0) |
| 531 file_length_ += bytes_written; | 529 file_length_ += bytes_written; |
| 532 return bytes_written == num_bytes; | 530 return bytes_written == num_bytes; |
| 533 } | 531 } |
| 534 | 532 |
| 535 } // namespace zip | 533 } // namespace zip |
| OLD | NEW |