| 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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_SNAPSHOT_FILE_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_SNAPSHOT_FILE_DETAILS_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_SNAPSHOT_FILE_DETAILS_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_SNAPSHOT_FILE_DETAILS_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" | 15 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" |
| 15 | 16 |
| 16 // Used to represent snapshot file request params. | 17 // Used to represent snapshot file request params. |
| 17 struct SnapshotRequestInfo { | 18 struct SnapshotRequestInfo { |
| 18 SnapshotRequestInfo( | 19 SnapshotRequestInfo( |
| 19 uint32 file_id, | 20 uint32_t file_id, |
| 20 const base::FilePath& snapshot_file_path, | 21 const base::FilePath& snapshot_file_path, |
| 21 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback& | 22 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback& |
| 22 success_callback, | 23 success_callback, |
| 23 const MTPDeviceAsyncDelegate::ErrorCallback& error_callback); | 24 const MTPDeviceAsyncDelegate::ErrorCallback& error_callback); |
| 24 ~SnapshotRequestInfo(); | 25 ~SnapshotRequestInfo(); |
| 25 | 26 |
| 26 // MTP device file id. | 27 // MTP device file id. |
| 27 const uint32 file_id; | 28 const uint32_t file_id; |
| 28 | 29 |
| 29 // Local platform path of the snapshot file. | 30 // Local platform path of the snapshot file. |
| 30 const base::FilePath snapshot_file_path; | 31 const base::FilePath snapshot_file_path; |
| 31 | 32 |
| 32 // A callback to be called when CreateSnapshotFile() succeeds. | 33 // A callback to be called when CreateSnapshotFile() succeeds. |
| 33 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback | 34 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback |
| 34 success_callback; | 35 success_callback; |
| 35 | 36 |
| 36 // A callback to be called when CreateSnapshotFile() fails. | 37 // A callback to be called when CreateSnapshotFile() fails. |
| 37 const MTPDeviceAsyncDelegate::ErrorCallback error_callback; | 38 const MTPDeviceAsyncDelegate::ErrorCallback error_callback; |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // SnapshotFileDetails tracks the current state of the snapshot file (e.g how | 41 // SnapshotFileDetails tracks the current state of the snapshot file (e.g how |
| 41 // many bytes written to the snapshot file, source file details, snapshot file | 42 // many bytes written to the snapshot file, source file details, snapshot file |
| 42 // metadata information, etc). | 43 // metadata information, etc). |
| 43 class SnapshotFileDetails { | 44 class SnapshotFileDetails { |
| 44 public: | 45 public: |
| 45 SnapshotFileDetails(const SnapshotRequestInfo& request_info, | 46 SnapshotFileDetails(const SnapshotRequestInfo& request_info, |
| 46 const base::File::Info& file_info); | 47 const base::File::Info& file_info); |
| 47 | 48 |
| 48 ~SnapshotFileDetails(); | 49 ~SnapshotFileDetails(); |
| 49 | 50 |
| 50 uint32 file_id() const { | 51 uint32_t file_id() const { return request_info_.file_id; } |
| 51 return request_info_.file_id; | |
| 52 } | |
| 53 | 52 |
| 54 base::FilePath snapshot_file_path() const { | 53 base::FilePath snapshot_file_path() const { |
| 55 return request_info_.snapshot_file_path; | 54 return request_info_.snapshot_file_path; |
| 56 } | 55 } |
| 57 | 56 |
| 58 uint32 bytes_written() const { | 57 uint32_t bytes_written() const { return bytes_written_; } |
| 59 return bytes_written_; | |
| 60 } | |
| 61 | 58 |
| 62 const base::File::Info& file_info() const { | 59 const base::File::Info& file_info() const { |
| 63 return file_info_; | 60 return file_info_; |
| 64 } | 61 } |
| 65 | 62 |
| 66 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback | 63 const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback |
| 67 success_callback() const { | 64 success_callback() const { |
| 68 return request_info_.success_callback; | 65 return request_info_.success_callback; |
| 69 } | 66 } |
| 70 | 67 |
| 71 const MTPDeviceAsyncDelegate::ErrorCallback error_callback() const { | 68 const MTPDeviceAsyncDelegate::ErrorCallback error_callback() const { |
| 72 return request_info_.error_callback; | 69 return request_info_.error_callback; |
| 73 } | 70 } |
| 74 | 71 |
| 75 bool error_occurred() const { | 72 bool error_occurred() const { |
| 76 return error_occurred_; | 73 return error_occurred_; |
| 77 } | 74 } |
| 78 | 75 |
| 79 void set_error_occurred(bool error); | 76 void set_error_occurred(bool error); |
| 80 | 77 |
| 81 // Adds |bytes_written| to |bytes_written_|. | 78 // Adds |bytes_written| to |bytes_written_|. |
| 82 // |bytes_written| specifies the total number of bytes transferred during the | 79 // |bytes_written| specifies the total number of bytes transferred during the |
| 83 // last write operation. | 80 // last write operation. |
| 84 // If |bytes_written| is valid, returns true and adds |bytes_written| to | 81 // If |bytes_written| is valid, returns true and adds |bytes_written| to |
| 85 // |bytes_written_|. | 82 // |bytes_written_|. |
| 86 // If |bytes_written| is invalid, returns false and does not add | 83 // If |bytes_written| is invalid, returns false and does not add |
| 87 // |bytes_written| to |bytes_written_|. | 84 // |bytes_written| to |bytes_written_|. |
| 88 bool AddBytesWritten(uint32 bytes_written); | 85 bool AddBytesWritten(uint32_t bytes_written); |
| 89 | 86 |
| 90 // Returns true if the snapshot file is created successfully (no more write | 87 // Returns true if the snapshot file is created successfully (no more write |
| 91 // operation is required to complete the snapshot file). | 88 // operation is required to complete the snapshot file). |
| 92 bool IsSnapshotFileWriteComplete() const; | 89 bool IsSnapshotFileWriteComplete() const; |
| 93 | 90 |
| 94 uint32 BytesToRead() const; | 91 uint32_t BytesToRead() const; |
| 95 | 92 |
| 96 private: | 93 private: |
| 97 // Snapshot file request params. | 94 // Snapshot file request params. |
| 98 const SnapshotRequestInfo request_info_; | 95 const SnapshotRequestInfo request_info_; |
| 99 | 96 |
| 100 // Metadata of the snapshot file (such as name, size, type, etc). | 97 // Metadata of the snapshot file (such as name, size, type, etc). |
| 101 const base::File::Info file_info_; | 98 const base::File::Info file_info_; |
| 102 | 99 |
| 103 // Number of bytes written into the snapshot file. | 100 // Number of bytes written into the snapshot file. |
| 104 uint32 bytes_written_; | 101 uint32_t bytes_written_; |
| 105 | 102 |
| 106 // Whether an error occurred during file transfer. | 103 // Whether an error occurred during file transfer. |
| 107 bool error_occurred_; | 104 bool error_occurred_; |
| 108 | 105 |
| 109 DISALLOW_COPY_AND_ASSIGN(SnapshotFileDetails); | 106 DISALLOW_COPY_AND_ASSIGN(SnapshotFileDetails); |
| 110 }; | 107 }; |
| 111 | 108 |
| 112 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_SNAPSHOT_FILE_DETAILS_H_ | 109 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_SNAPSHOT_FILE_DETAILS_H_ |
| OLD | NEW |