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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_WIN_SNAPSHOT_FILE_DETAILS_H_
      6 #define CHROME_BROWSER_MEDIA_GALLERIES_WIN_SNAPSHOT_FILE_DETAILS_H_
      7 
      8 #include "base/files/file.h"
      9 #include "base/files/file_path.h"
     10 #include "base/win/scoped_comptr.h"
     11 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
     12 
     13 // Structure used to represent snapshot file request params.
     14 struct SnapshotRequestInfo {
     15   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 
     22   // Device file path.
     23   base::FilePath device_file_path;
     24 
     25   // Local platform path of the snapshot file.
     26   base::FilePath snapshot_file_path;
     27 
     28   // A callback to be called when CreateSnapshotFile() succeeds.
     29   MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback
     30       success_callback;
     31 
     32   // A callback to be called when CreateSnapshotFile() fails.
     33   MTPDeviceAsyncDelegate::ErrorCallback error_callback;
     34 };
     35 
     36 // Provides the details for the the creation of snapshot file.
     37 class SnapshotFileDetails {
     38  public:
     39   explicit SnapshotFileDetails(const SnapshotRequestInfo& request_info);
     40   ~SnapshotFileDetails();
     41 
     42   void set_file_info(const base::File::Info& file_info);
     43   void set_device_file_stream(IStream* file_stream);
     44   void set_optimal_transfer_size(DWORD optimal_transfer_size);
     45 
     46   SnapshotRequestInfo request_info() const {
     47     return request_info_;
     48   }
     49 
     50   base::File::Info file_info() const {
     51     return file_info_;
     52   }
     53 
     54   IStream* device_file_stream() const {
     55     return file_stream_.get();
     56   }
     57 
     58   DWORD optimal_transfer_size() const {
     59     return optimal_transfer_size_;
     60   }
     61 
     62   // Returns true if the data contents of the device file is written to the
     63   // snapshot file.
     64   bool IsSnapshotFileWriteComplete() const;
     65 
     66   // Adds |bytes_written| to |bytes_written_|.
     67   // |bytes_written| specifies the total number of bytes transferred during
     68   // the last write operation.
     69   // If |bytes_written| is valid, returns true and adds |bytes_written| to
     70   // |bytes_written_|.
     71   // If |bytes_written| is invalid, returns false and does not add
     72   // |bytes_written| to |bytes_written_|.
     73   bool AddBytesWritten(DWORD bytes_written);
     74 
     75  private:
     76   // Snapshot file request params.
     77   SnapshotRequestInfo request_info_;
     78 
     79   // Metadata of the created snapshot file.
     80   base::File::Info file_info_;
     81 
     82   // Used to read the device file contents.
     83   base::win::ScopedComPtr<IStream> file_stream_;
     84 
     85   // The number of bytes of data to read from the |file_stream| object
     86   // during each IStream::Read() operation.
     87   DWORD optimal_transfer_size_;
     88 
     89   // Total number of bytes written into the snapshot file.
     90   DWORD bytes_written_;
     91 };
     92 
     93 #endif  // CHROME_BROWSER_MEDIA_GALLERIES_WIN_SNAPSHOT_FILE_DETAILS_H_
     94