Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / linux / mtp_read_file_worker.h
blobd330d19434bc58999543e918efce18438f14c4a0
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.
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_READ_FILE_WORKER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_READ_FILE_WORKER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h"
15 namespace base {
16 class FilePath;
19 class SnapshotFileDetails;
20 struct SnapshotRequestInfo;
22 // Worker class to copy the contents of the media transfer protocol(MTP) device
23 // file to the given snapshot file.
24 class MTPReadFileWorker {
25 public:
26 explicit MTPReadFileWorker(const std::string& device_handle);
27 ~MTPReadFileWorker();
29 // Dispatches the request to MediaTransferProtocolManager to get the media
30 // file contents.
32 // |request_info| specifies the snapshot file request params.
33 // |snapshot_file_info| specifies the metadata of the snapshot file.
34 void WriteDataIntoSnapshotFile(
35 const SnapshotRequestInfo& request_info,
36 const base::PlatformFileInfo& snapshot_file_info);
38 private:
39 // Called when WriteDataIntoSnapshotFile() completes.
41 // |snapshot_file_details| contains the current state of the snapshot file
42 // (such as how many bytes written to the snapshot file, media device file
43 // path, snapshot file path, bytes remaining, etc).
45 // If there is an error, |snapshot_file_details.error_callback| is invoked on
46 // the IO thread to notify the caller about the failure.
48 // If there is no error, |snapshot_file_details.success_callback| is invoked
49 // on the IO thread to notify the caller about the success.
50 void OnDidWriteIntoSnapshotFile(
51 scoped_ptr<SnapshotFileDetails> snapshot_file_details);
53 // Dispatches the request to MediaTransferProtocolManager to get the device
54 // media file data chunk based on the parameters in |snapshot_file_details|.
55 void ReadDataChunkFromDeviceFile(
56 scoped_ptr<SnapshotFileDetails> snapshot_file_details);
58 // Called when ReadDataChunkFromDeviceFile() completes.
60 // If there is no error, |data| will contain the data chunk and |error| is
61 // set to false.
63 // If there is an error, |data| is empty and |error| is set to true.
64 void OnDidReadDataChunkFromDeviceFile(
65 scoped_ptr<SnapshotFileDetails> snapshot_file_details,
66 const std::string& data,
67 bool error);
69 // Called when the data chunk is written to the
70 // |snapshot_file_details_.snapshot_file_path|.
72 // If the write operation succeeds, |bytes_written| is set to a non-zero
73 // value.
75 // If the write operation fails, |bytes_written| is set to zero.
76 void OnDidWriteDataChunkIntoSnapshotFile(
77 scoped_ptr<SnapshotFileDetails> snapshot_file_details,
78 uint32 bytes_written);
80 // The device unique identifier to query the device.
81 const std::string device_handle_;
83 // For callbacks that may run after destruction.
84 base::WeakPtrFactory<MTPReadFileWorker> weak_ptr_factory_;
86 DISALLOW_COPY_AND_ASSIGN(MTPReadFileWorker);
89 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_READ_FILE_WORKER_H_