| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_LINUX_MTP_READ_FILE_WORKER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_READ_FILE_WORKER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/files/file.h" | |
| 15 #include "base/macros.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class FilePath; | |
| 20 } | |
| 21 | |
| 22 class SnapshotFileDetails; | |
| 23 struct SnapshotRequestInfo; | |
| 24 | |
| 25 // Worker class to copy the contents of the media transfer protocol(MTP) device | |
| 26 // file to the given snapshot file. | |
| 27 class MTPReadFileWorker { | |
| 28 public: | |
| 29 explicit MTPReadFileWorker(const std::string& device_handle); | |
| 30 ~MTPReadFileWorker(); | |
| 31 | |
| 32 // Dispatches the request to MediaTransferProtocolManager to get the media | |
| 33 // file contents. | |
| 34 // | |
| 35 // |request_info| specifies the snapshot file request params. | |
| 36 // |snapshot_file_info| specifies the metadata of the snapshot file. | |
| 37 void WriteDataIntoSnapshotFile( | |
| 38 const SnapshotRequestInfo& request_info, | |
| 39 const base::File::Info& snapshot_file_info); | |
| 40 | |
| 41 private: | |
| 42 // Called when WriteDataIntoSnapshotFile() completes. | |
| 43 // | |
| 44 // |snapshot_file_details| contains the current state of the snapshot file | |
| 45 // (such as how many bytes written to the snapshot file, media device file | |
| 46 // path, snapshot file path, bytes remaining, etc). | |
| 47 // | |
| 48 // If there is an error, |snapshot_file_details.error_callback| is invoked on | |
| 49 // the IO thread to notify the caller about the failure. | |
| 50 // | |
| 51 // If there is no error, |snapshot_file_details.success_callback| is invoked | |
| 52 // on the IO thread to notify the caller about the success. | |
| 53 void OnDidWriteIntoSnapshotFile( | |
| 54 std::unique_ptr<SnapshotFileDetails> snapshot_file_details); | |
| 55 | |
| 56 // Dispatches the request to MediaTransferProtocolManager to get the device | |
| 57 // media file data chunk based on the parameters in |snapshot_file_details|. | |
| 58 void ReadDataChunkFromDeviceFile( | |
| 59 std::unique_ptr<SnapshotFileDetails> snapshot_file_details); | |
| 60 | |
| 61 // Called when ReadDataChunkFromDeviceFile() completes. | |
| 62 // | |
| 63 // If there is no error, |data| will contain the data chunk and |error| is | |
| 64 // set to false. | |
| 65 // | |
| 66 // If there is an error, |data| is empty and |error| is set to true. | |
| 67 void OnDidReadDataChunkFromDeviceFile( | |
| 68 std::unique_ptr<SnapshotFileDetails> snapshot_file_details, | |
| 69 const std::string& data, | |
| 70 bool error); | |
| 71 | |
| 72 // Called when the data chunk is written to the | |
| 73 // |snapshot_file_details_.snapshot_file_path|. | |
| 74 // | |
| 75 // If the write operation succeeds, |bytes_written| is set to a non-zero | |
| 76 // value. | |
| 77 // | |
| 78 // If the write operation fails, |bytes_written| is set to zero. | |
| 79 void OnDidWriteDataChunkIntoSnapshotFile( | |
| 80 std::unique_ptr<SnapshotFileDetails> snapshot_file_details, | |
| 81 uint32_t bytes_written); | |
| 82 | |
| 83 // The device unique identifier to query the device. | |
| 84 const std::string device_handle_; | |
| 85 | |
| 86 // For callbacks that may run after destruction. | |
| 87 base::WeakPtrFactory<MTPReadFileWorker> weak_ptr_factory_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(MTPReadFileWorker); | |
| 90 }; | |
| 91 | |
| 92 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_READ_FILE_WORKER_H_ | |
| OLD | NEW |