| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/media_galleries/win/snapshot_file_details.h" | 5 #include "chrome/browser/media_galleries/win/snapshot_file_details.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const SnapshotRequestInfo& request_info) | 38 const SnapshotRequestInfo& request_info) |
| 39 : request_info_(request_info), | 39 : request_info_(request_info), |
| 40 optimal_transfer_size_(0), | 40 optimal_transfer_size_(0), |
| 41 bytes_written_(0) { | 41 bytes_written_(0) { |
| 42 } | 42 } |
| 43 | 43 |
| 44 SnapshotFileDetails::SnapshotFileDetails(const SnapshotFileDetails& other) = | 44 SnapshotFileDetails::SnapshotFileDetails(const SnapshotFileDetails& other) = |
| 45 default; | 45 default; |
| 46 | 46 |
| 47 SnapshotFileDetails::~SnapshotFileDetails() { | 47 SnapshotFileDetails::~SnapshotFileDetails() { |
| 48 file_stream_.Release(); | 48 file_stream_.Reset(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void SnapshotFileDetails::set_file_info(const base::File::Info& file_info) { | 51 void SnapshotFileDetails::set_file_info(const base::File::Info& file_info) { |
| 52 file_info_ = file_info; | 52 file_info_ = file_info; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SnapshotFileDetails::set_device_file_stream( | 55 void SnapshotFileDetails::set_device_file_stream( |
| 56 IStream* file_stream) { | 56 IStream* file_stream) { |
| 57 file_stream_ = file_stream; | 57 file_stream_ = file_stream; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void SnapshotFileDetails::set_optimal_transfer_size( | 60 void SnapshotFileDetails::set_optimal_transfer_size( |
| 61 DWORD optimal_transfer_size) { | 61 DWORD optimal_transfer_size) { |
| 62 optimal_transfer_size_ = optimal_transfer_size; | 62 optimal_transfer_size_ = optimal_transfer_size; |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool SnapshotFileDetails::IsSnapshotFileWriteComplete() const { | 65 bool SnapshotFileDetails::IsSnapshotFileWriteComplete() const { |
| 66 return bytes_written_ == file_info_.size; | 66 return bytes_written_ == file_info_.size; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool SnapshotFileDetails::AddBytesWritten(DWORD bytes_written) { | 69 bool SnapshotFileDetails::AddBytesWritten(DWORD bytes_written) { |
| 70 if ((bytes_written == 0) || | 70 if ((bytes_written == 0) || |
| 71 (bytes_written_ > std::numeric_limits<uint64_t>::max() - bytes_written) || | 71 (bytes_written_ > std::numeric_limits<uint64_t>::max() - bytes_written) || |
| 72 (bytes_written_ + bytes_written > file_info_.size)) | 72 (bytes_written_ + bytes_written > file_info_.size)) |
| 73 return false; | 73 return false; |
| 74 | 74 |
| 75 bytes_written_ += bytes_written; | 75 bytes_written_ += bytes_written; |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| OLD | NEW |