Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_interface.h

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

Powered by Google App Engine
This is Rietveld 408576698