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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/media_galleries/win/snapshot_file_details.h" 6 7 #include "base/basictypes.h" 8 9 namespace chrome { 10 11 /////////////////////////////////////////////////////////////////////////////// 12 // SnapshotRequestInfo // 13 /////////////////////////////////////////////////////////////////////////////// 14 15 SnapshotRequestInfo::SnapshotRequestInfo( 16 const base::FilePath& device_file_path, 17 const base::FilePath& snapshot_file_path, 18 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback& 19 success_callback, 20 const MTPDeviceAsyncDelegate::ErrorCallback& error_callback) 21 : device_file_path(device_file_path), 22 snapshot_file_path(snapshot_file_path), 23 success_callback(success_callback), 24 error_callback(error_callback) { 25 } 26 27 /////////////////////////////////////////////////////////////////////////////// 28 // SnapshotFileDetails // 29 /////////////////////////////////////////////////////////////////////////////// 30 31 SnapshotFileDetails::SnapshotFileDetails( 32 const SnapshotRequestInfo& request_info) 33 : request_info_(request_info), 34 optimal_transfer_size_(0), 35 bytes_written_(0) { 36 } 37 38 SnapshotFileDetails::~SnapshotFileDetails() { 39 file_stream_.Release(); 40 } 41 42 void SnapshotFileDetails::set_file_info( 43 const base::PlatformFileInfo& file_info) { 44 file_info_ = file_info; 45 } 46 47 void SnapshotFileDetails::set_device_file_stream( 48 IStream* file_stream) { 49 file_stream_ = file_stream; 50 } 51 52 void SnapshotFileDetails::set_optimal_transfer_size( 53 DWORD optimal_transfer_size) { 54 optimal_transfer_size_ = optimal_transfer_size; 55 } 56 57 bool SnapshotFileDetails::IsSnapshotFileWriteComplete() const { 58 return bytes_written_ == file_info_.size; 59 } 60 61 bool SnapshotFileDetails::AddBytesWritten(DWORD bytes_written) { 62 if ((bytes_written == 0) || 63 (bytes_written_ > kuint64max - bytes_written) || 64 (bytes_written_ + bytes_written > file_info_.size)) 65 return false; 66 67 bytes_written_ += bytes_written; 68 return true; 69 } 70 71 } // namespace chrome 72