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_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_INTERFACE_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_INTERFACE_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "chrome/browser/chromeos/gdata/drive_cache.h" | |
13 #include "chrome/browser/chromeos/gdata/drive_resource_metadata.h" | |
14 #include "chrome/browser/chromeos/gdata/gdata_operations.h" | |
15 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" | |
16 | |
17 namespace gdata { | |
18 | |
19 class DocumentEntry; | |
20 class DriveEntryProto; | |
21 | |
22 typedef std::vector<DriveEntryProto> DriveEntryProtoVector; | |
23 | |
24 // Information about search result returned by Search Async callback. | |
25 // This is data needed to create a file system entry that will be used by file | |
26 // browser. | |
27 struct SearchResultInfo { | |
28 SearchResultInfo(const FilePath& in_path, bool in_is_directory) | |
29 : path(in_path), | |
30 is_directory(in_is_directory) { | |
31 } | |
32 | |
33 FilePath path; | |
34 bool is_directory; | |
35 }; | |
36 | |
37 // Used to get files from the file system. | |
38 typedef base::Callback<void(DriveFileError error, | |
39 const FilePath& file_path, | |
40 const std::string& mime_type, | |
41 DriveFileType file_type)> GetFileCallback; | |
42 | |
43 // Used to read a directory from the file system. | |
44 // Similar to ReadDirectoryCallback but this one provides | |
45 // |hide_hosted_documents| | |
46 // If |error| is not DRIVE_FILE_OK, |entries| is set to NULL. | |
47 // |entries| are contents, both files and directories, of the directory. | |
48 typedef base::Callback<void(DriveFileError error, | |
49 bool hide_hosted_documents, | |
50 scoped_ptr<DriveEntryProtoVector> entries)> | |
51 ReadDirectoryWithSettingCallback; | |
52 | |
53 // Used to get drive content search results. | |
54 // If |error| is not DRIVE_FILE_OK, |result_paths| is empty. | |
55 typedef base::Callback<void( | |
56 DriveFileError error, | |
57 const GURL& next_feed, | |
58 scoped_ptr<std::vector<SearchResultInfo> > result_paths)> SearchCallback; | |
59 | |
60 // Used to open files from the file system. |file_path| is the path on the local | |
61 // file system for the opened file. | |
62 typedef base::Callback<void(DriveFileError error, | |
63 const FilePath& file_path)> OpenFileCallback; | |
64 | |
65 // Used to get available space for the account from GData. | |
66 typedef base::Callback<void(DriveFileError error, | |
67 int64 bytes_total, | |
68 int64 bytes_used)> GetAvailableSpaceCallback; | |
69 | |
70 // GData file system abstraction layer. | |
71 // The interface is defined to make GDataFileSystem mockable. | |
72 class GDataFileSystemInterface { | |
73 public: | |
74 virtual ~GDataFileSystemInterface() {} | |
75 | |
76 // Used to notify events on the file system. | |
77 // All events are notified on UI thread. | |
78 class Observer { | |
79 public: | |
80 // Triggered when a content of a directory has been changed. | |
81 // |directory_path| is a virtual directory path (/gdata/...) representing | |
82 // changed directory. | |
83 virtual void OnDirectoryChanged(const FilePath& directory_path) {} | |
84 | |
85 // Triggered when the file system is initially loaded. | |
86 virtual void OnInitialLoadFinished() {} | |
87 | |
88 // Triggered when a document feed is fetched. |num_accumulated_entries| | |
89 // tells the number of entries fetched so far. | |
90 virtual void OnDocumentFeedFetched(int num_accumulated_entries) {} | |
91 | |
92 // Triggered when the feed from the server is loaded. | |
93 virtual void OnFeedFromServerLoaded() {} | |
94 | |
95 // Triggered when the file system is mounted. | |
96 virtual void OnFileSystemMounted() {} | |
97 // Triggered when the file system is being unmounted. | |
98 virtual void OnFileSystemBeingUnmounted() {} | |
99 | |
100 protected: | |
101 virtual ~Observer() {} | |
102 }; | |
103 | |
104 // Initializes the object. This function should be called before any | |
105 // other functions. | |
106 virtual void Initialize() = 0; | |
107 | |
108 // Adds and removes the observer. | |
109 virtual void AddObserver(Observer* observer) = 0; | |
110 virtual void RemoveObserver(Observer* observer) = 0; | |
111 | |
112 // Starts and stops periodic updates. | |
113 virtual void StartUpdates() = 0; | |
114 virtual void StopUpdates() = 0; | |
115 | |
116 // Notifies the file system was just mounted. | |
117 virtual void NotifyFileSystemMounted() = 0; | |
118 | |
119 // Notifies the file system is going to be unmounted. | |
120 virtual void NotifyFileSystemToBeUnmounted() = 0; | |
121 | |
122 // Checks for updates on the server. | |
123 virtual void CheckForUpdates() = 0; | |
124 | |
125 // Finds an entry (file or directory) by using |resource_id|. This call | |
126 // does not initiate content refreshing. | |
127 // | |
128 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
129 // |callback| must not be null. | |
130 virtual void GetEntryInfoByResourceId( | |
131 const std::string& resource_id, | |
132 const GetEntryInfoWithFilePathCallback& callback) = 0; | |
133 | |
134 // Initiates transfer of |remote_src_file_path| to |local_dest_file_path|. | |
135 // |remote_src_file_path| is the virtual source path on the gdata file system. | |
136 // |local_dest_file_path| is the destination path on the local file system. | |
137 // | |
138 // Must be called from *UI* thread. |callback| is run on the calling thread. | |
139 // |callback| must not be null. | |
140 virtual void TransferFileFromRemoteToLocal( | |
141 const FilePath& remote_src_file_path, | |
142 const FilePath& local_dest_file_path, | |
143 const FileOperationCallback& callback) = 0; | |
144 | |
145 // Initiates transfer of |local_src_file_path| to |remote_dest_file_path|. | |
146 // |local_src_file_path| must be a file from the local file system. | |
147 // |remote_dest_file_path| is the virtual destination path within gdata file | |
148 // system. | |
149 // | |
150 // Must be called from *UI* thread. |callback| is run on the calling thread. | |
151 // |callback| must not be null. | |
152 virtual void TransferFileFromLocalToRemote( | |
153 const FilePath& local_src_file_path, | |
154 const FilePath& remote_dest_file_path, | |
155 const FileOperationCallback& callback) = 0; | |
156 | |
157 // Retrieves a file at the virtual path |file_path| on the gdata file system | |
158 // onto the cache, and mark it dirty. The local path to the cache file is | |
159 // returned to |callback|. After opening the file, both read and write | |
160 // on the file can be done with normal local file operations. | |
161 // | |
162 // |CloseFile| must be called when the modification to the cache is done. | |
163 // Otherwise, GData file system does not pick up the file for uploading. | |
164 // | |
165 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
166 virtual void OpenFile(const FilePath& file_path, | |
167 const OpenFileCallback& callback) = 0; | |
168 | |
169 // Closes a file at the virtual path |file_path| on the gdata file system, | |
170 // which is opened via OpenFile(). It commits the dirty flag on the cache. | |
171 // | |
172 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
173 // |callback| must not be null. | |
174 virtual void CloseFile(const FilePath& file_path, | |
175 const FileOperationCallback& callback) = 0; | |
176 | |
177 // Copies |src_file_path| to |dest_file_path| on the file system. | |
178 // |src_file_path| can be a hosted document (see limitations below). | |
179 // |dest_file_path| is expected to be of the same type of |src_file_path| | |
180 // (i.e. if |src_file_path| is a file, |dest_file_path| will be created as | |
181 // a file). | |
182 // | |
183 // This method also has the following assumptions/limitations that may be | |
184 // relaxed or addressed later: | |
185 // - |src_file_path| cannot be a regular file (i.e. non-hosted document) | |
186 // or a directory. | |
187 // - |dest_file_path| must not exist. | |
188 // - The parent of |dest_file_path| must already exist. | |
189 // | |
190 // The file entries represented by |src_file_path| and the parent directory | |
191 // of |dest_file_path| need to be present in the in-memory representation | |
192 // of the file system. | |
193 // | |
194 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
195 // |callback| must not be null. | |
196 virtual void Copy(const FilePath& src_file_path, | |
197 const FilePath& dest_file_path, | |
198 const FileOperationCallback& callback) = 0; | |
199 | |
200 // Moves |src_file_path| to |dest_file_path| on the file system. | |
201 // |src_file_path| can be a file (regular or hosted document) or a directory. | |
202 // |dest_file_path| is expected to be of the same type of |src_file_path| | |
203 // (i.e. if |src_file_path| is a file, |dest_file_path| will be created as | |
204 // a file). | |
205 // | |
206 // This method also has the following assumptions/limitations that may be | |
207 // relaxed or addressed later: | |
208 // - |dest_file_path| must not exist. | |
209 // - The parent of |dest_file_path| must already exist. | |
210 // | |
211 // The file entries represented by |src_file_path| and the parent directory | |
212 // of |dest_file_path| need to be present in the in-memory representation | |
213 // of the file system. | |
214 // | |
215 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
216 // |callback| must not be null. | |
217 virtual void Move(const FilePath& src_file_path, | |
218 const FilePath& dest_file_path, | |
219 const FileOperationCallback& callback) = 0; | |
220 | |
221 // Removes |file_path| from the file system. If |is_recursive| is set and | |
222 // |file_path| represents a directory, we will also delete all of its | |
223 // contained children elements. The file entry represented by |file_path| | |
224 // needs to be present in in-memory representation of the file system that | |
225 // in order to be removed. | |
226 // | |
227 // TODO(satorux): is_recursive is not supported yet. crbug.com/138282 | |
228 // | |
229 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
230 virtual void Remove(const FilePath& file_path, | |
231 bool is_recursive, | |
232 const FileOperationCallback& callback) = 0; | |
233 | |
234 // Creates new directory under |directory_path|. If |is_exclusive| is true, | |
235 // an error is raised in case a directory is already present at the | |
236 // |directory_path|. If |is_recursive| is true, the call creates parent | |
237 // directories as needed just like mkdir -p does. | |
238 // | |
239 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
240 virtual void CreateDirectory(const FilePath& directory_path, | |
241 bool is_exclusive, | |
242 bool is_recursive, | |
243 const FileOperationCallback& callback) = 0; | |
244 | |
245 // Creates a file at |file_path|. If the flag |is_exclusive| is true, an | |
246 // error is raised when a file already exists at the path. It is | |
247 // an error if a directory or a hosted document is already present at the | |
248 // path, or the parent directory of the path is not present yet. | |
249 // | |
250 // Can be called from UI/IO thread. |callback| is run on the calling thread | |
251 // |callback| must not be null. | |
252 virtual void CreateFile(const FilePath& file_path, | |
253 bool is_exclusive, | |
254 const FileOperationCallback& callback) = 0; | |
255 | |
256 // Gets |file_path| from the file system. The file entry represented by | |
257 // |file_path| needs to be present in in-memory representation of the file | |
258 // system in order to be retrieved. If the file is not cached, the file | |
259 // will be downloaded through gdata api. | |
260 // | |
261 // Can be called from UI/IO thread. |get_file_callback| and | |
262 // |get_content_callback| are run on the calling thread. | |
263 virtual void GetFileByPath( | |
264 const FilePath& file_path, | |
265 const GetFileCallback& get_file_callback, | |
266 const GetContentCallback& get_content_callback) = 0; | |
267 | |
268 // Gets a file by the given |resource_id| from the gdata server. Used for | |
269 // fetching pinned-but-not-fetched files. | |
270 // | |
271 // Can be called from UI/IO thread. |get_file_callback| and | |
272 // |get_content_callback| are run on the calling thread. | |
273 virtual void GetFileByResourceId( | |
274 const std::string& resource_id, | |
275 const GetFileCallback& get_file_callback, | |
276 const GetContentCallback& get_content_callback) = 0; | |
277 | |
278 // Updates a file by the given |resource_id| on the gdata server by | |
279 // uploading an updated version. Used for uploading dirty files. The file | |
280 // should already be present in the cache. | |
281 // | |
282 // TODO(satorux): As of now, the function only handles files with the dirty | |
283 // bit committed. We should eliminate the restriction. crbug.com/134558. | |
284 // | |
285 // Can be called from UI/IO thread. |callback| and is run on the calling | |
286 // thread. |callback| must not be null. | |
287 virtual void UpdateFileByResourceId( | |
288 const std::string& resource_id, | |
289 const FileOperationCallback& callback) = 0; | |
290 | |
291 // Finds an entry (a file or a directory) by |file_path|. This call will also | |
292 // retrieve and refresh file system content from server and disk cache. | |
293 // | |
294 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
295 // |callback| must not be null. | |
296 virtual void GetEntryInfoByPath(const FilePath& file_path, | |
297 const GetEntryInfoCallback& callback) = 0; | |
298 | |
299 // Finds and reads a directory by |file_path|. This call will also retrieve | |
300 // and refresh file system content from server and disk cache. | |
301 // | |
302 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
303 // |callback| must not be null. | |
304 virtual void ReadDirectoryByPath( | |
305 const FilePath& file_path, | |
306 const ReadDirectoryWithSettingCallback& callback) = 0; | |
307 | |
308 // Requests a refresh of the directory pointed by |file_path| (i.e. fetches | |
309 // the latest metadata of files in the target directory). | |
310 // | |
311 // In particular, this function is used to get the latest thumbnail | |
312 // URLs. Thumbnail URLs change periodically even if contents of files are | |
313 // not changed, hence we should get the new thumbnail URLs manually if we | |
314 // detect that the existing thumbnail URLs are stale. | |
315 // | |
316 // Upon success, the metadata of files in the target directory is updated, | |
317 // and the change is notified via Observer::OnDirectoryChanged(). Note that | |
318 // this function ignores changes in directories in the target | |
319 // directory. Changes in directories are handled via the delta feeds. | |
320 // | |
321 // Can be called from UI/IO thread. | |
322 virtual void RequestDirectoryRefresh(const FilePath& file_path) = 0; | |
323 | |
324 // Does server side content search for |search_query|. | |
325 // If |next_feed| is set, this is the feed url that will be fetched. | |
326 // Search results will be returned as a list of results' |SearchResultInfo| | |
327 // structs, which contains file's path and is_directory flag. | |
328 // | |
329 // Can be called from UI/IO thread. |callback| is run on the calling thread. | |
330 virtual void Search(const std::string& search_query, | |
331 const GURL& next_feed, | |
332 const SearchCallback& callback) = 0; | |
333 | |
334 // Fetches the user's Account Metadata to find out current quota information | |
335 // and returns it to the callback. | |
336 virtual void GetAvailableSpace(const GetAvailableSpaceCallback& callback) = 0; | |
337 | |
338 // Adds a file entry from |entry| under |virtual_dir_path|, and modifies | |
339 // the cache state. | |
340 // | |
341 // When uploading a new file, adds a new file entry, and store its content | |
342 // from |file_content_path| into the cache. | |
343 // | |
344 // When uploading an existing file, replaces the file entry with a new one, | |
345 // and clears the dirty bit in the cache. | |
346 // | |
347 // |callback| will be called on the UI thread upon completion of operation. | |
348 virtual void AddUploadedFile(UploadMode upload_mode, | |
349 const FilePath& virtual_dir_path, | |
350 scoped_ptr<DocumentEntry> entry, | |
351 const FilePath& file_content_path, | |
352 DriveCache::FileOperationType cache_operation, | |
353 const base::Closure& callback) = 0; | |
354 | |
355 // Updates the data associated with the file referenced by |resource_id| and | |
356 // |md5|. The data is copied from |file_content_path|. | |
357 // | |
358 // |callback| will be called on the UI thread upon completion of operation. | |
359 virtual void UpdateEntryData(const std::string& resource_id, | |
360 const std::string& md5, | |
361 scoped_ptr<DocumentEntry> entry, | |
362 const FilePath& file_content_path, | |
363 const base::Closure& callback) = 0; | |
364 }; | |
365 | |
366 } // namespace gdata | |
367 | |
368 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_INTERFACE_H_ | |
OLD | NEW |