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