Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / device / media_transfer_protocol / media_transfer_protocol_manager.h
blob048e75bf3a705358b89b9c0565a72f9ee2198935
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 DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_
6 #define DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "build/build_config.h"
15 #if !defined(OS_LINUX)
16 #error "Only used on Linux and ChromeOS"
17 #endif
19 class MtpFileEntry;
20 class MtpStorageInfo;
22 namespace base {
23 class SequencedTaskRunner;
26 namespace device {
28 // This class handles the interaction with mtpd.
29 // Other classes can add themselves as observers.
30 class MediaTransferProtocolManager {
31 public:
32 // A callback to handle the result of GetStorageInfoFromDevice.
33 // The first argument is the returned storage info.
34 // The second argument is true if there was an error.
35 typedef base::Callback<void(const MtpStorageInfo& storage_info,
36 const bool error)>
37 GetStorageInfoFromDeviceCallback;
39 // A callback to handle the result of OpenStorage.
40 // The first argument is the returned handle.
41 // The second argument is true if there was an error.
42 typedef base::Callback<void(const std::string& handle,
43 bool error)> OpenStorageCallback;
45 // A callback to handle the result of CloseStorage.
46 // The argument is true if there was an error.
47 typedef base::Callback<void(bool error)> CloseStorageCallback;
49 // A callback to handle the result of CreateDirectory.
50 // The first argument is true if there was an error.
51 typedef base::Callback<void(bool error)> CreateDirectoryCallback;
53 // A callback to handle the result of ReadDirectory.
54 // The first argument is a vector of file entries.
55 // The second argument is true if there are more file entries.
56 // The third argument is true if there was an error.
57 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries,
58 bool has_more,
59 bool error)> ReadDirectoryCallback;
61 // A callback to handle the result of ReadFileChunk.
62 // The first argument is a string containing the file data.
63 // The second argument is true if there was an error.
64 typedef base::Callback<void(const std::string& data,
65 bool error)> ReadFileCallback;
67 // A callback to handle the result of GetFileInfo.
68 // The first argument is a file entry.
69 // The second argument is true if there was an error.
70 typedef base::Callback<void(const MtpFileEntry& file_entry,
71 bool error)> GetFileInfoCallback;
73 // A callback to handle the result of RenameObject.
74 // The first argument is true if there was an error.
75 typedef base::Callback<void(bool error)> RenameObjectCallback;
77 // A callback to handle the result of CopyFileFromLocal.
78 // The first argument is true if there was an error.
79 typedef base::Callback<void(bool error)> CopyFileFromLocalCallback;
81 // A callback to handle the result of DeleteObject.
82 // The first argument is true if there was an error.
83 typedef base::Callback<void(bool error)> DeleteObjectCallback;
85 // Implement this interface to be notified about MTP storage
86 // attachment / detachment events.
87 class Observer {
88 public:
89 virtual ~Observer() {}
91 // A function called after a MTP storage has been attached / detached.
92 virtual void StorageChanged(bool is_attached,
93 const std::string& storage_name) = 0;
96 virtual ~MediaTransferProtocolManager() {}
98 // Adds an observer.
99 virtual void AddObserver(Observer* observer) = 0;
101 // Removes an observer.
102 virtual void RemoveObserver(Observer* observer) = 0;
104 // Returns a vector of available MTP storages.
105 virtual const std::vector<std::string> GetStorages() const = 0;
107 // On success, returns the metadata for |storage_name|.
108 // Otherwise returns NULL.
109 virtual const MtpStorageInfo* GetStorageInfo(
110 const std::string& storage_name) const = 0;
112 // Read the metadata of |storage_name| from device and runs |callback|.
113 virtual void GetStorageInfoFromDevice(
114 const std::string& storage_name,
115 const GetStorageInfoFromDeviceCallback& callback) = 0;
117 // Opens |storage_name| in |mode| and runs |callback|.
118 virtual void OpenStorage(const std::string& storage_name,
119 const std::string& mode,
120 const OpenStorageCallback& callback) = 0;
122 // Close |storage_handle| and runs |callback|.
123 virtual void CloseStorage(const std::string& storage_handle,
124 const CloseStorageCallback& callback) = 0;
126 // Creates |directory_name| in |parent_id|.
127 virtual void CreateDirectory(const std::string& storage_handle,
128 const uint32 parent_id,
129 const std::string& directory_name,
130 const CreateDirectoryCallback& callback) = 0;
132 // Reads directory entries from |file_id| on |storage_handle| and runs
133 // |callback|. |max_size| is a maximum number of files to be read.
134 virtual void ReadDirectory(const std::string& storage_handle,
135 const uint32 file_id,
136 const size_t max_size,
137 const ReadDirectoryCallback& callback) = 0;
139 // Reads file data from |file_id| on |storage_handle| and runs |callback|.
140 // Reads |count| bytes of data starting at |offset|.
141 virtual void ReadFileChunk(const std::string& storage_handle,
142 uint32 file_id,
143 uint32 offset,
144 uint32 count,
145 const ReadFileCallback& callback) = 0;
147 // Gets the file metadata for |file_id| on |storage_handle| and runs
148 // |callback|.
149 virtual void GetFileInfo(const std::string& storage_handle,
150 uint32 file_id,
151 const GetFileInfoCallback& callback) = 0;
153 // Renames |object_id| to |new_name|.
154 virtual void RenameObject(const std::string& storage_handle,
155 const uint32 object_id,
156 const std::string& new_name,
157 const RenameObjectCallback& callback) = 0;
159 // Copies the file from |source_file_descriptor| to |file_name| on
160 // |parent_id|.
161 virtual void CopyFileFromLocal(const std::string& storage_handle,
162 const int source_file_descriptor,
163 const uint32 parent_id,
164 const std::string& file_name,
165 const CopyFileFromLocalCallback& callback) = 0;
167 // Deletes |object_id|.
168 virtual void DeleteObject(const std::string& storage_handle,
169 const uint32 object_id,
170 const DeleteObjectCallback& callback) = 0;
172 // Creates and returns the global MediaTransferProtocolManager instance.
173 // On Linux, |task_runner| specifies the task runner to process asynchronous
174 // operations.
175 // On ChromeOS, |task_runner| should just be set to NULL because ChromeOS
176 // already has a dedicated message loop proxy.
177 static MediaTransferProtocolManager* Initialize(
178 scoped_refptr<base::SequencedTaskRunner> task_runner);
181 } // namespace device
183 #endif // DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_