OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
7 | 7 |
8 #include <sys/stat.h> | |
9 | |
8 #include <map> | 10 #include <map> |
9 #include <string> | 11 #include <string> |
10 #include <sys/stat.h> | |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "chrome/browser/chromeos/gdata/gdata.h" | 20 #include "chrome/browser/chromeos/gdata/gdata.h" |
20 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 118 |
118 // Finds file info by using virtual |file_path|. If |require_content| is set, | 119 // Finds file info by using virtual |file_path|. If |require_content| is set, |
119 // the found directory will be pre-populated before passed back to the | 120 // the found directory will be pre-populated before passed back to the |
120 // |delegate|. If |allow_refresh| is not set, directories' content | 121 // |delegate|. If |allow_refresh| is not set, directories' content |
121 // won't be performed. | 122 // won't be performed. |
122 // | 123 // |
123 // Can be called from any thread. | 124 // Can be called from any thread. |
124 void FindFileByPath(const FilePath& file_path, | 125 void FindFileByPath(const FilePath& file_path, |
125 scoped_refptr<FindFileDelegate> delegate); | 126 scoped_refptr<FindFileDelegate> delegate); |
126 | 127 |
128 // Copies |src_file_path| to |dest_file_path| on the file system. | |
satorux1
2012/03/12 17:48:24
Please document that if this allows copy of direct
Ben Chan
2012/03/13 00:29:21
Done.
| |
129 // The file entries represented by |src_file_path| and the parent directory | |
130 // of |dest_file_path| need to be present in the in-memory representation | |
satorux1
2012/03/12 17:48:24
Please also document if |dest_file_path| can be a
Ben Chan
2012/03/13 00:29:21
Done.
| |
131 // of the file system. | |
satorux1
2012/03/12 17:48:24
//
// Can be called from any thread.
?
Ben Chan
2012/03/13 00:29:21
Done.
| |
132 void Copy(const FilePath& src_file_path, | |
133 const FilePath& dest_file_path, | |
134 const FileOperationCallback& callback); | |
135 | |
136 // Moves |src_file_path| to |dest_file_path| on the file system. | |
137 // The file entries represented by |src_file_path| and the parent directory | |
138 // of |dest_file_path| need to be present in the in-memory representation | |
139 // of the file system. | |
satorux1
2012/03/12 17:48:24
ditto.
Ben Chan
2012/03/13 00:29:21
Done.
| |
140 void Move(const FilePath& src_file_path, | |
141 const FilePath& dest_file_path, | |
142 const FileOperationCallback& callback); | |
143 | |
127 // Removes |file_path| from the file system. If |is_recursive| is set and | 144 // Removes |file_path| from the file system. If |is_recursive| is set and |
128 // |file_path| represents a directory, we will also delete all of its | 145 // |file_path| represents a directory, we will also delete all of its |
129 // contained children elements. The file entry represented by |file_path| | 146 // contained children elements. The file entry represented by |file_path| |
130 // needs to be present in in-memory representation of the file system that | 147 // needs to be present in in-memory representation of the file system that |
131 // in order to be removed. | 148 // in order to be removed. |
132 // | 149 // |
133 // TODO(zelidrag): Wire |is_recursive| through gdata api | 150 // TODO(zelidrag): Wire |is_recursive| through gdata api |
134 // (find appropriate calls for it). | 151 // (find appropriate calls for it). |
135 // | 152 // |
136 // Can be called from any thread. |callback| is run on the calling thread. | 153 // Can be called from any thread. |callback| is run on the calling thread. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // Finds file object by |file_path| and returns the file info. | 186 // Finds file object by |file_path| and returns the file info. |
170 // Returns NULL if it does not find the file. | 187 // Returns NULL if it does not find the file. |
171 GDataFileBase* GetGDataFileInfoFromPath(const FilePath& file_path); | 188 GDataFileBase* GetGDataFileInfoFromPath(const FilePath& file_path); |
172 | 189 |
173 private: | 190 private: |
174 friend class GDataUploader; | 191 friend class GDataUploader; |
175 friend class GDataFileSystemFactory; | 192 friend class GDataFileSystemFactory; |
176 friend class GDataFileSystemTestBase; | 193 friend class GDataFileSystemTestBase; |
177 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, | 194 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, |
178 FindFirstMissingParentDirectory); | 195 FindFirstMissingParentDirectory); |
196 FRIEND_TEST_ALL_PREFIXES(GDataFileSystemTest, GetCopyMoveFileParams); | |
179 | 197 |
180 // Defines possible search results of FindFirstMissingParentDirectory(). | 198 // Defines possible search results of FindFirstMissingParentDirectory(). |
181 enum FindMissingDirectoryResult { | 199 enum FindMissingDirectoryResult { |
182 // Target directory found, it's not a directory. | 200 // Target directory found, it's not a directory. |
183 FOUND_INVALID, | 201 FOUND_INVALID, |
184 // Found missing directory segment while searching for given directory. | 202 // Found missing directory segment while searching for given directory. |
185 FOUND_MISSING, | 203 FOUND_MISSING, |
186 // Found target directory, it already exists. | 204 // Found target directory, it already exists. |
187 DIRECTORY_ALREADY_PRESENT, | 205 DIRECTORY_ALREADY_PRESENT, |
188 }; | 206 }; |
189 | 207 |
190 // Defines set of parameters passes to intermediate callbacks during | 208 // Defines set of parameters passes to intermediate callbacks during |
191 // execution of CreateDirectory() method. | 209 // execution of CreateDirectory() method. |
192 struct CreateDirectoryParams { | 210 struct CreateDirectoryParams { |
193 CreateDirectoryParams(const FilePath& created_directory_path, | 211 CreateDirectoryParams(const FilePath& created_directory_path, |
194 const FilePath& target_directory_path, | 212 const FilePath& target_directory_path, |
195 bool is_exclusive, | 213 bool is_exclusive, |
196 bool is_recursive, | 214 bool is_recursive, |
197 const FileOperationCallback& callback); | 215 const FileOperationCallback& callback); |
198 ~CreateDirectoryParams(); | 216 ~CreateDirectoryParams(); |
199 | 217 |
200 const FilePath created_directory_path; | 218 const FilePath created_directory_path; |
201 const FilePath target_directory_path; | 219 const FilePath target_directory_path; |
202 const bool is_exclusive; | 220 const bool is_exclusive; |
203 const bool is_recursive; | 221 const bool is_recursive; |
204 FileOperationCallback callback; | 222 FileOperationCallback callback; |
205 }; | 223 }; |
206 | 224 |
225 // Defines set of parameters of a file/directory that is needed for | |
226 // copy/move related operations. | |
227 struct CopyMoveFileParams { | |
228 CopyMoveFileParams(); | |
229 ~CopyMoveFileParams(); | |
230 | |
231 GURL self_url; | |
232 GURL content_url; | |
233 bool is_directory; | |
234 bool is_root_directory; | |
235 bool is_hosted_document; | |
236 std::string resource_id; | |
237 std::string document_extension; | |
238 }; | |
239 | |
207 enum CacheType { // This indexes into |cache_paths_| vector. | 240 enum CacheType { // This indexes into |cache_paths_| vector. |
208 CACHE_TYPE_BLOBS = 0, | 241 CACHE_TYPE_BLOBS = 0, |
209 CACHE_TYPE_META, | 242 CACHE_TYPE_META, |
210 }; | 243 }; |
211 | 244 |
212 explicit GDataFileSystem(Profile* profile, | 245 // Callback similar to FileOperationCallback but with a given |
213 DocumentsServiceInterface* documents_service); | 246 // |file_path|. |
247 typedef base::Callback<void(base::PlatformFileError error, | |
248 const FilePath& file_path)> | |
249 FilePathUpdateCallback; | |
250 | |
251 GDataFileSystem(Profile* profile, | |
252 DocumentsServiceInterface* documents_service); | |
214 virtual ~GDataFileSystem(); | 253 virtual ~GDataFileSystem(); |
215 | 254 |
216 // Initiates upload operation of file defined with |file_name|, | 255 // Initiates upload operation of file defined with |file_name|, |
217 // |content_type| and |content_length|. The operation will place the newly | 256 // |content_type| and |content_length|. The operation will place the newly |
218 // created file entity into |destination_directory|. | 257 // created file entity into |destination_directory|. |
219 // | 258 // |
220 // Can be called from any thread. |callback| is run on the calling thread. | 259 // Can be called from any thread. |callback| is run on the calling thread. |
221 void InitiateUpload(const std::string& file_name, | 260 void InitiateUpload(const std::string& file_name, |
222 const std::string& content_type, | 261 const std::string& content_type, |
223 int64 content_length, | 262 int64 content_length, |
(...skipping 16 matching lines...) Expand all Loading... | |
240 // DocumentsService. | 279 // DocumentsService. |
241 void ContinueDirectoryRefresh(const FindFileParams& params, | 280 void ContinueDirectoryRefresh(const FindFileParams& params, |
242 scoped_ptr<base::ListValue> feed_list); | 281 scoped_ptr<base::ListValue> feed_list); |
243 | 282 |
244 // Converts document feed from gdata service into DirectoryInfo. On failure, | 283 // Converts document feed from gdata service into DirectoryInfo. On failure, |
245 // returns NULL and fills in |error| with an appropriate value. | 284 // returns NULL and fills in |error| with an appropriate value. |
246 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 285 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
247 base::Value* data, | 286 base::Value* data, |
248 base::PlatformFileError *error); | 287 base::PlatformFileError *error); |
249 | 288 |
289 // Gets the parameters of a file or directory at |file_path| for copy/move | |
290 // related operations. Returns false if |file_path| is not found. | |
291 bool GetCopyMoveFileParams(const FilePath& file_path, | |
292 CopyMoveFileParams* params); | |
293 | |
294 // Renames a file or directory at |file_path| to |new_name|. | |
295 void Rename(const FilePath& file_path, | |
296 const FilePath::StringType& new_name, | |
297 const FilePathUpdateCallback& callback); | |
298 | |
299 // Adds a file or directory at |file_path| to the directory at |dir_path|. | |
300 void AddFileToDirectory(const FilePath& dir_path, | |
301 const FileOperationCallback& callback, | |
302 base::PlatformFileError error, | |
303 const FilePath& file_path); | |
304 | |
305 // Removes a file or directory at |file_path| from the directory at | |
306 // |dir_path| and moves it to the root directory. | |
307 void RemoveFileFromDirectory(const FilePath& dir_path, | |
308 const FilePathUpdateCallback& callback, | |
309 base::PlatformFileError error, | |
310 const FilePath& file_path); | |
311 | |
250 // Callback for handling feed content fetching while searching for file info. | 312 // Callback for handling feed content fetching while searching for file info. |
251 // This callback is invoked after async feed fetch operation that was | 313 // This callback is invoked after async feed fetch operation that was |
252 // invoked by StartDirectoryRefresh() completes. This callback will update | 314 // invoked by StartDirectoryRefresh() completes. This callback will update |
253 // the content of the refreshed directory object and continue initially | 315 // the content of the refreshed directory object and continue initially |
254 // started FindFileByPath() request. | 316 // started FindFileByPath() request. |
255 void OnGetDocuments(const FindFileParams& params, | 317 void OnGetDocuments(const FindFileParams& params, |
256 scoped_ptr<base::ListValue> feed_list, | 318 scoped_ptr<base::ListValue> feed_list, |
257 GDataErrorCode status, | 319 GDataErrorCode status, |
258 scoped_ptr<base::Value> data); | 320 scoped_ptr<base::Value> data); |
259 | 321 |
322 // A pass-through callback used for bridging from | |
323 // FilePathUpdateCallback to FileOperationCallback. | |
324 void OnFilePathUpdated(const FileOperationCallback& cllback, | |
325 base::PlatformFileError error, | |
326 const FilePath& file_path); | |
327 | |
328 // Callback for handling resource rename attempt. | |
329 void OnRenameResourceCompleted(const FilePath& file_path, | |
330 const FilePath::StringType& new_name, | |
331 const FilePathUpdateCallback& callback, | |
332 GDataErrorCode status, | |
333 const GURL& document_url); | |
334 | |
335 // Callback for handling document copy attempt. | |
336 void OnCopyDocumentCompleted(const FilePathUpdateCallback& callback, | |
337 GDataErrorCode status, | |
338 scoped_ptr<base::Value> data); | |
339 | |
340 // Callback for handling an attempt to add a file or directory to another | |
341 // directory. | |
342 void OnAddFileToDirectoryCompleted(const FileOperationCallback& callback, | |
343 const FilePath& file_path, | |
344 const FilePath& dir_path, | |
345 GDataErrorCode status, | |
346 const GURL& document_url); | |
347 | |
348 // Callback for handling an attempt to remove a file or directory from | |
349 // another directory. | |
350 void OnRemoveFileFromDirectoryCompleted( | |
351 const FilePathUpdateCallback& callback, | |
352 const FilePath& file_path, | |
353 const FilePath& dir_path, | |
354 GDataErrorCode status, | |
355 const GURL& document_url); | |
356 | |
260 // Callback for handling document remove attempt. | 357 // Callback for handling document remove attempt. |
261 void OnRemovedDocument( | 358 void OnRemovedDocument( |
262 const FileOperationCallback& callback, | 359 const FileOperationCallback& callback, |
263 const FilePath& file_path, | 360 const FilePath& file_path, |
264 GDataErrorCode status, | 361 GDataErrorCode status, |
265 const GURL& document_url); | 362 const GURL& document_url); |
266 | 363 |
267 // Callback for handling directory create requests. | 364 // Callback for handling directory create requests. |
268 void OnCreateDirectoryCompleted( | 365 void OnCreateDirectoryCompleted( |
269 const CreateDirectoryParams& params, | 366 const CreateDirectoryParams& params, |
(...skipping 15 matching lines...) Expand all Loading... | |
285 const GURL& upload_location); | 382 const GURL& upload_location); |
286 | 383 |
287 // Callback for handling file upload resume requests. | 384 // Callback for handling file upload resume requests. |
288 void OnResumeUpload( | 385 void OnResumeUpload( |
289 const ResumeUploadOperationCallback& callback, | 386 const ResumeUploadOperationCallback& callback, |
290 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 387 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
291 GDataErrorCode code, | 388 GDataErrorCode code, |
292 int64 start_range_received, | 389 int64 start_range_received, |
293 int64 end_range_received); | 390 int64 end_range_received); |
294 | 391 |
392 // Renames a file or directory at |file_path| on in-memory snapshot | |
393 // of the file system. Returns PLATFORM_FILE_OK if successful. | |
394 base::PlatformFileError RenameFileOnFilesystem( | |
395 const FilePath& file_path, const FilePath::StringType& new_name, | |
396 FilePath* updated_file_path); | |
397 | |
398 // Adds a file or directory at |file_path| to another directory at | |
399 // |dir_path| on in-memory snapshot of the file system. | |
400 // Returns PLATFORM_FILE_OK if successful. | |
401 base::PlatformFileError AddFileToDirectoryOnFilesystem( | |
402 const FilePath& file_path, const FilePath& dir_path); | |
403 | |
404 // Removes a file or directory at |file_path| from another directory at | |
405 // |dir_path| on in-memory snapshot of the file system. | |
406 // Returns PLATFORM_FILE_OK if successful. | |
407 base::PlatformFileError RemoveFileFromDirectoryOnFilesystem( | |
408 const FilePath& file_path, const FilePath& dir_path, | |
409 FilePath* updated_file_path); | |
410 | |
295 // Removes file under |file_path| from in-memory snapshot of the file system. | 411 // Removes file under |file_path| from in-memory snapshot of the file system. |
296 // Return PLATFORM_FILE_OK if successful. | 412 // Return PLATFORM_FILE_OK if successful. |
297 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); | 413 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); |
298 | 414 |
299 // Parses the content of |feed_data| and returns DocumentFeed instance | 415 // Parses the content of |feed_data| and returns DocumentFeed instance |
300 // represeting it. | 416 // represeting it. |
301 DocumentFeed* ParseDocumentFeed(base::Value* feed_data); | 417 DocumentFeed* ParseDocumentFeed(base::Value* feed_data); |
302 | 418 |
303 // Updates content of the directory identified with |directory_path| with | 419 // Updates content of the directory identified with |directory_path| with |
304 // feeds collected in |feed_list|. | 420 // feeds collected in |feed_list|. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 GDataDirectory*) OVERRIDE; | 657 GDataDirectory*) OVERRIDE; |
542 virtual void OnError(base::PlatformFileError) OVERRIDE; | 658 virtual void OnError(base::PlatformFileError) OVERRIDE; |
543 | 659 |
544 // File entry that was found. | 660 // File entry that was found. |
545 GDataFileBase* file_; | 661 GDataFileBase* file_; |
546 }; | 662 }; |
547 | 663 |
548 } // namespace gdata | 664 } // namespace gdata |
549 | 665 |
550 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 666 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |