ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / provided_file_system_interface.h
blob7d50fb558c53d33e783c6d649472174959519fce
1 // Copyright 2014 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_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERFACE_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERFACE_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/files/file.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "chrome/browser/chromeos/file_system_provider/abort_callback.h"
18 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h"
19 #include "chrome/browser/chromeos/file_system_provider/watcher.h"
20 #include "storage/browser/fileapi/async_file_util.h"
21 #include "storage/browser/fileapi/watcher_manager.h"
22 #include "url/gurl.h"
24 class EventRouter;
26 namespace base {
27 class Time;
28 } // namespace base
30 namespace net {
31 class IOBuffer;
32 } // namespace net
34 namespace chromeos {
35 namespace file_system_provider {
37 class ProvidedFileSystemInfo;
38 class RequestManager;
40 // Represents metadata for either a file or a directory.
41 struct EntryMetadata {
42 EntryMetadata();
43 ~EntryMetadata();
45 bool is_directory;
46 std::string name;
47 int64 size;
48 base::Time modification_time;
49 std::string mime_type;
50 std::string thumbnail;
52 private:
53 DISALLOW_COPY_AND_ASSIGN(EntryMetadata);
56 // Mode of opening a file. Used by OpenFile().
57 enum OpenFileMode { OPEN_FILE_MODE_READ, OPEN_FILE_MODE_WRITE };
59 // Contains information about an opened file.
60 struct OpenedFile {
61 OpenedFile(const base::FilePath& file_path, OpenFileMode& mode);
62 OpenedFile();
63 ~OpenedFile();
65 base::FilePath file_path;
66 OpenFileMode mode;
69 // Map from a file handle to an OpenedFile struct.
70 typedef std::map<int, OpenedFile> OpenedFiles;
72 // Interface for a provided file system. Acts as a proxy between providers
73 // and clients. All of the request methods return an abort callback in order to
74 // terminate it while running. They must be called on the same thread as the
75 // request methods. The cancellation callback may be null if the operation
76 // fails synchronously. It must not be called once the operation is completed
77 // with either a success or an error.
78 class ProvidedFileSystemInterface {
79 public:
80 // Extra fields to be fetched with metadata.
81 enum MetadataField {
82 METADATA_FIELD_DEFAULT = 0,
83 METADATA_FIELD_THUMBNAIL = 1 << 0
86 typedef base::Callback<void(int file_handle, base::File::Error result)>
87 OpenFileCallback;
89 typedef base::Callback<
90 void(int chunk_length, bool has_more, base::File::Error result)>
91 ReadChunkReceivedCallback;
93 typedef base::Callback<void(scoped_ptr<EntryMetadata> entry_metadata,
94 base::File::Error result)> GetMetadataCallback;
96 // Mask of fields requested from the GetMetadata() call.
97 typedef int MetadataFieldMask;
99 virtual ~ProvidedFileSystemInterface() {}
101 // Requests unmounting of the file system. The callback is called when the
102 // request is accepted or rejected, with an error code.
103 virtual AbortCallback RequestUnmount(
104 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
106 // Requests metadata of the passed |entry_path|. It can be either a file
107 // or a directory. All |fields| will be returned if supported. Note, that
108 // default fields are always returned.
109 virtual AbortCallback GetMetadata(const base::FilePath& entry_path,
110 MetadataFieldMask fields,
111 const GetMetadataCallback& callback) = 0;
113 // Requests enumerating entries from the passed |directory_path|. The callback
114 // can be called multiple times until |has_more| is set to false.
115 virtual AbortCallback ReadDirectory(
116 const base::FilePath& directory_path,
117 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) = 0;
119 // Requests opening a file at |file_path|. If the file doesn't exist, then the
120 // operation will fail.
121 virtual AbortCallback OpenFile(const base::FilePath& file_path,
122 OpenFileMode mode,
123 const OpenFileCallback& callback) = 0;
125 // Requests closing a file, previously opened with OpenFile() as a file with
126 // |file_handle|. For either succes or error |callback| must be called.
127 virtual AbortCallback CloseFile(
128 int file_handle,
129 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
131 // Requests reading a file previously opened with |file_handle|. The callback
132 // can be called multiple times until |has_more| is set to false. On success
133 // it should return |length| bytes starting from |offset| in total. It can
134 // return less only in case EOF is encountered.
135 virtual AbortCallback ReadFile(int file_handle,
136 net::IOBuffer* buffer,
137 int64 offset,
138 int length,
139 const ReadChunkReceivedCallback& callback) = 0;
141 // Requests creating a directory. If |recursive| is passed, then all non
142 // existing directories on the path will be created. The operation will fail
143 // if the target directory already exists.
144 virtual AbortCallback CreateDirectory(
145 const base::FilePath& directory_path,
146 bool recursive,
147 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
149 // Requests creating a file. If the entry already exists, then the
150 // FILE_ERROR_EXISTS error must be returned.
151 virtual AbortCallback CreateFile(
152 const base::FilePath& file_path,
153 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
155 // Requests deleting a directory. If |recursive| is passed and the entry is
156 // a directory, then all contents of it (recursively) will be deleted too.
157 virtual AbortCallback DeleteEntry(
158 const base::FilePath& entry_path,
159 bool recursive,
160 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
162 // Requests copying an entry (recursively in case of a directory) within the
163 // same file system.
164 virtual AbortCallback CopyEntry(
165 const base::FilePath& source_path,
166 const base::FilePath& target_path,
167 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
169 // Requests moving an entry (recursively in case of a directory) within the
170 // same file system.
171 virtual AbortCallback MoveEntry(
172 const base::FilePath& source_path,
173 const base::FilePath& target_path,
174 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
176 // Requests truncating a file to the desired length.
177 virtual AbortCallback Truncate(
178 const base::FilePath& file_path,
179 int64 length,
180 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
182 // Requests writing to a file previously opened with |file_handle|.
183 virtual AbortCallback WriteFile(
184 int file_handle,
185 net::IOBuffer* buffer,
186 int64 offset,
187 int length,
188 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
190 // Requests adding a watcher on an entry. |recursive| must not be true for
191 // files. |callback| is optional, but it can't be used for persistent
192 // watchers.
193 virtual AbortCallback AddWatcher(
194 const GURL& origin,
195 const base::FilePath& entry_path,
196 bool recursive,
197 bool persistent,
198 const storage::AsyncFileUtil::StatusCallback& callback,
199 const storage::WatcherManager::NotificationCallback&
200 notification_callback) = 0;
202 // Requests removing a watcher, which is immediately deleted from the internal
203 // list, hence the operation is not abortable.
204 virtual void RemoveWatcher(
205 const GURL& origin,
206 const base::FilePath& entry_path,
207 bool recursive,
208 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
210 // Notifies about changes related to the watcher within the file system.
211 // Invoked by the file system implementation. Returns an error code via the
212 // callback if the notification arguments are malformed or the entry is not
213 // watched anymore. On success, returns base::File::FILE_OK.
214 // TODO(mtomasz): Replace [entry_path, recursive] with a watcher id.
215 virtual void Notify(
216 const base::FilePath& entry_path,
217 bool recursive,
218 storage::WatcherManager::ChangeType change_type,
219 scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
220 const std::string& tag,
221 const storage::AsyncFileUtil::StatusCallback& callback) = 0;
223 // Returns a provided file system info for this file system.
224 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0;
226 // Returns a mutable list of watchers.
227 virtual Watchers* GetWatchers() = 0;
229 // Returns a list of opened files.
230 virtual const OpenedFiles& GetOpenedFiles() const = 0;
232 // Returns a request manager for the file system.
233 virtual RequestManager* GetRequestManager() = 0;
235 // Adds an observer on the file system.
236 virtual void AddObserver(ProvidedFileSystemObserver* observer) = 0;
238 // Removes an observer.
239 virtual void RemoveObserver(ProvidedFileSystemObserver* observer) = 0;
241 // Returns a weak pointer to this object.
242 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() = 0;
245 } // namespace file_system_provider
246 } // namespace chromeos
248 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_PROVIDED_FILE_SYSTEM_INTERFACE_H_