media: Remove kRAConsentGranted pref.
[chromium-blink-merge.git] / device / media_transfer_protocol / media_transfer_protocol_manager.h
blob90acd5e09d292f980bc5a848b85061339a9fec63
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 OpenStorage.
33 // The first argument is the returned handle.
34 // The second argument is true if there was an error.
35 typedef base::Callback<void(const std::string& handle,
36 bool error)> OpenStorageCallback;
38 // A callback to handle the result of CloseStorage.
39 // The argument is true if there was an error.
40 typedef base::Callback<void(bool error)> CloseStorageCallback;
42 // A callback to handle the result of CreateDirectory.
43 // The first argument is true if there was an error.
44 typedef base::Callback<void(bool error)> CreateDirectoryCallback;
46 // A callback to handle the result of ReadDirectory.
47 // The first argument is a vector of file entries.
48 // The second argument is true if there are more file entries.
49 // The third argument is true if there was an error.
50 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries,
51 bool has_more,
52 bool error)> ReadDirectoryCallback;
54 // A callback to handle the result of ReadFileChunk.
55 // The first argument is a string containing the file data.
56 // The second argument is true if there was an error.
57 typedef base::Callback<void(const std::string& data,
58 bool error)> ReadFileCallback;
60 // A callback to handle the result of GetFileInfo.
61 // The first argument is a file entry.
62 // The second argument is true if there was an error.
63 typedef base::Callback<void(const MtpFileEntry& file_entry,
64 bool error)> GetFileInfoCallback;
66 // A callback to handle the result of RenameObject.
67 // The first argument is true if there was an error.
68 typedef base::Callback<void(bool error)> RenameObjectCallback;
70 // A callback to handle the result of CopyFileFromLocal.
71 // The first argument is true if there was an error.
72 typedef base::Callback<void(bool error)> CopyFileFromLocalCallback;
74 // A callback to handle the result of DeleteObject.
75 // The first argument is true if there was an error.
76 typedef base::Callback<void(bool error)> DeleteObjectCallback;
78 // Implement this interface to be notified about MTP storage
79 // attachment / detachment events.
80 class Observer {
81 public:
82 virtual ~Observer() {}
84 // A function called after a MTP storage has been attached / detached.
85 virtual void StorageChanged(bool is_attached,
86 const std::string& storage_name) = 0;
89 virtual ~MediaTransferProtocolManager() {}
91 // Adds an observer.
92 virtual void AddObserver(Observer* observer) = 0;
94 // Removes an observer.
95 virtual void RemoveObserver(Observer* observer) = 0;
97 // Returns a vector of available MTP storages.
98 virtual const std::vector<std::string> GetStorages() const = 0;
100 // On success, returns the the metadata for |storage_name|.
101 // Otherwise returns NULL.
102 virtual const MtpStorageInfo* GetStorageInfo(
103 const std::string& storage_name) const = 0;
105 // Opens |storage_name| in |mode| and runs |callback|.
106 virtual void OpenStorage(const std::string& storage_name,
107 const std::string& mode,
108 const OpenStorageCallback& callback) = 0;
110 // Close |storage_handle| and runs |callback|.
111 virtual void CloseStorage(const std::string& storage_handle,
112 const CloseStorageCallback& callback) = 0;
114 // Creates |directory_name| in |parent_id|.
115 virtual void CreateDirectory(const std::string& storage_handle,
116 const uint32 parent_id,
117 const std::string& directory_name,
118 const CreateDirectoryCallback& callback) = 0;
120 // Reads directory entries from |file_id| on |storage_handle| and runs
121 // |callback|. |max_size| is a maximum number of files to be read.
122 virtual void ReadDirectory(const std::string& storage_handle,
123 const uint32 file_id,
124 const size_t max_size,
125 const ReadDirectoryCallback& callback) = 0;
127 // Reads file data from |file_id| on |storage_handle| and runs |callback|.
128 // Reads |count| bytes of data starting at |offset|.
129 virtual void ReadFileChunk(const std::string& storage_handle,
130 uint32 file_id,
131 uint32 offset,
132 uint32 count,
133 const ReadFileCallback& callback) = 0;
135 // Gets the file metadata for |file_id| on |storage_handle| and runs
136 // |callback|.
137 virtual void GetFileInfo(const std::string& storage_handle,
138 uint32 file_id,
139 const GetFileInfoCallback& callback) = 0;
141 // Renames |object_id| to |new_name|.
142 virtual void RenameObject(const std::string& storage_handle,
143 const uint32 object_id,
144 const std::string& new_name,
145 const RenameObjectCallback& callback) = 0;
147 // Copies the file from |source_file_descriptor| to |file_name| on
148 // |parent_id|.
149 virtual void CopyFileFromLocal(const std::string& storage_handle,
150 const int source_file_descriptor,
151 const uint32 parent_id,
152 const std::string& file_name,
153 const CopyFileFromLocalCallback& callback) = 0;
155 // Deletes |object_id|.
156 virtual void DeleteObject(const std::string& storage_handle,
157 const uint32 object_id,
158 const DeleteObjectCallback& callback) = 0;
160 // Creates and returns the global MediaTransferProtocolManager instance.
161 // On Linux, |task_runner| specifies the task runner to process asynchronous
162 // operations.
163 // On ChromeOS, |task_runner| should just be set to NULL because ChromeOS
164 // already has a dedicated message loop proxy.
165 static MediaTransferProtocolManager* Initialize(
166 scoped_refptr<base::SequencedTaskRunner> task_runner);
169 } // namespace device
171 #endif // DEVICE_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H_