Home | History | Annotate | Download | only in win
      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 ///////////////////////////////////////////////////////////////////////////////
     10 //                       SnapshotRequestInfo                                 //
     11 ///////////////////////////////////////////////////////////////////////////////
     12 
     13 SnapshotRequestInfo::SnapshotRequestInfo(
     14     const base::FilePath& device_file_path,
     15     const base::FilePath& snapshot_file_path,
     16     const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback&
     17         success_callback,
     18     const MTPDeviceAsyncDelegate::ErrorCallback& error_callback)
     19     : device_file_path(device_file_path),
     20       snapshot_file_path(snapshot_file_path),
     21       success_callback(success_callback),
     22       error_callback(error_callback) {
     23 }
     24 
     25 ///////////////////////////////////////////////////////////////////////////////
     26 //                       SnapshotFileDetails                                 //
     27 ///////////////////////////////////////////////////////////////////////////////
     28 
     29 SnapshotFileDetails::SnapshotFileDetails(
     30     const SnapshotRequestInfo& request_info)
     31     : request_info_(request_info),
     32       optimal_transfer_size_(0),
     33       bytes_written_(0) {
     34 }
     35 
     36 SnapshotFileDetails::~SnapshotFileDetails() {
     37   file_stream_.Release();
     38 }
     39 
     40 void SnapshotFileDetails::set_file_info(const base::File::Info& file_info) {
     41   file_info_ = file_info;
     42 }
     43 
     44 void SnapshotFileDetails::set_device_file_stream(
     45     IStream* file_stream) {
     46   file_stream_ = file_stream;
     47 }
     48 
     49 void SnapshotFileDetails::set_optimal_transfer_size(
     50     DWORD optimal_transfer_size) {
     51   optimal_transfer_size_ = optimal_transfer_size;
     52 }
     53 
     54 bool SnapshotFileDetails::IsSnapshotFileWriteComplete() const {
     55   return bytes_written_ == file_info_.size;
     56 }
     57 
     58 bool SnapshotFileDetails::AddBytesWritten(DWORD bytes_written) {
     59   if ((bytes_written == 0) ||
     60       (bytes_written_ > kuint64max - bytes_written) ||
     61       (bytes_written_ + bytes_written > file_info_.size))
     62     return false;
     63 
     64   bytes_written_ += bytes_written;
     65   return true;
     66 }
     67