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. |
| 129 // |src_file_path| can be a hosted document (see limitations below). |
| 130 // |dest_file_path| is expected to be of the same type of |src_file_path| |
| 131 // (i.e. if |src_file_path| is a file, |dest_file_path| will be created as |
| 132 // a file). |
| 133 // |
| 134 // This method also has the following assumptions/limitations that may be |
| 135 // relaxed or addressed later: |
| 136 // - |src_file_path| cannot be a regular file (i.e. non-hosted document) |
| 137 // or a directory. |
| 138 // - |dest_file_path| must not exist. |
| 139 // - The parent of |dest_file_path| must already exist. |
| 140 // |
| 141 // The file entries represented by |src_file_path| and the parent directory |
| 142 // of |dest_file_path| need to be present in the in-memory representation |
| 143 // of the file system. |
| 144 // |
| 145 // Can be called from any thread. |
| 146 void Copy(const FilePath& src_file_path, |
| 147 const FilePath& dest_file_path, |
| 148 const FileOperationCallback& callback); |
| 149 |
| 150 // Moves |src_file_path| to |dest_file_path| on the file system. |
| 151 // |src_file_path| can be a file (regular or hosted document) or a directory. |
| 152 // |dest_file_path| is expected to be of the same type of |src_file_path| |
| 153 // (i.e. if |src_file_path| is a file, |dest_file_path| will be created as |
| 154 // a file). |
| 155 // |
| 156 // This method also has the following assumptions/limitations that may be |
| 157 // relaxed or addressed later: |
| 158 // - |dest_file_path| must not exist. |
| 159 // - The parent of |dest_file_path| must already exist. |
| 160 // |
| 161 // The file entries represented by |src_file_path| and the parent directory |
| 162 // of |dest_file_path| need to be present in the in-memory representation |
| 163 // of the file system. |
| 164 // |
| 165 // Can be called from any thread. |
| 166 void Move(const FilePath& src_file_path, |
| 167 const FilePath& dest_file_path, |
| 168 const FileOperationCallback& callback); |
| 169 |
127 // Removes |file_path| from the file system. If |is_recursive| is set and | 170 // 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 | 171 // |file_path| represents a directory, we will also delete all of its |
129 // contained children elements. The file entry represented by |file_path| | 172 // contained children elements. The file entry represented by |file_path| |
130 // needs to be present in in-memory representation of the file system that | 173 // needs to be present in in-memory representation of the file system that |
131 // in order to be removed. | 174 // in order to be removed. |
132 // | 175 // |
133 // TODO(zelidrag): Wire |is_recursive| through gdata api | 176 // TODO(zelidrag): Wire |is_recursive| through gdata api |
134 // (find appropriate calls for it). | 177 // (find appropriate calls for it). |
135 // | 178 // |
136 // Can be called from any thread. |callback| is run on the calling thread. | 179 // Can be called from any thread. |callback| is run on the calling thread. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 const bool is_exclusive; | 254 const bool is_exclusive; |
212 const bool is_recursive; | 255 const bool is_recursive; |
213 FileOperationCallback callback; | 256 FileOperationCallback callback; |
214 }; | 257 }; |
215 | 258 |
216 enum CacheType { // This indexes into |cache_paths_| vector. | 259 enum CacheType { // This indexes into |cache_paths_| vector. |
217 CACHE_TYPE_BLOBS = 0, | 260 CACHE_TYPE_BLOBS = 0, |
218 CACHE_TYPE_META, | 261 CACHE_TYPE_META, |
219 }; | 262 }; |
220 | 263 |
221 explicit GDataFileSystem(Profile* profile, | 264 // Callback similar to FileOperationCallback but with a given |
222 DocumentsServiceInterface* documents_service); | 265 // |file_path|. |
| 266 typedef base::Callback<void(base::PlatformFileError error, |
| 267 const FilePath& file_path)> |
| 268 FilePathUpdateCallback; |
| 269 |
| 270 GDataFileSystem(Profile* profile, |
| 271 DocumentsServiceInterface* documents_service); |
223 virtual ~GDataFileSystem(); | 272 virtual ~GDataFileSystem(); |
224 | 273 |
225 // Initiates upload operation of file defined with |file_name|, | 274 // Initiates upload operation of file defined with |file_name|, |
226 // |content_type| and |content_length|. The operation will place the newly | 275 // |content_type| and |content_length|. The operation will place the newly |
227 // created file entity into |destination_directory|. | 276 // created file entity into |destination_directory|. |
228 // | 277 // |
229 // Can be called from any thread. |callback| is run on the calling thread. | 278 // Can be called from any thread. |callback| is run on the calling thread. |
230 void InitiateUpload(const std::string& file_name, | 279 void InitiateUpload(const std::string& file_name, |
231 const std::string& content_type, | 280 const std::string& content_type, |
232 int64 content_length, | 281 int64 content_length, |
(...skipping 16 matching lines...) Expand all Loading... |
249 // DocumentsService. | 298 // DocumentsService. |
250 void ContinueDirectoryRefresh(const FindFileParams& params, | 299 void ContinueDirectoryRefresh(const FindFileParams& params, |
251 scoped_ptr<base::ListValue> feed_list); | 300 scoped_ptr<base::ListValue> feed_list); |
252 | 301 |
253 // Converts document feed from gdata service into DirectoryInfo. On failure, | 302 // Converts document feed from gdata service into DirectoryInfo. On failure, |
254 // returns NULL and fills in |error| with an appropriate value. | 303 // returns NULL and fills in |error| with an appropriate value. |
255 GDataDirectory* ParseGDataFeed(GDataErrorCode status, | 304 GDataDirectory* ParseGDataFeed(GDataErrorCode status, |
256 base::Value* data, | 305 base::Value* data, |
257 base::PlatformFileError *error); | 306 base::PlatformFileError *error); |
258 | 307 |
| 308 // Renames a file or directory at |file_path| to |new_name|. |
| 309 void Rename(const FilePath& file_path, |
| 310 const FilePath::StringType& new_name, |
| 311 const FilePathUpdateCallback& callback); |
| 312 |
| 313 // Adds a file or directory at |file_path| to the directory at |dir_path|. |
| 314 void AddFileToDirectory(const FilePath& dir_path, |
| 315 const FileOperationCallback& callback, |
| 316 base::PlatformFileError error, |
| 317 const FilePath& file_path); |
| 318 |
| 319 // Removes a file or directory at |file_path| from the directory at |
| 320 // |dir_path| and moves it to the root directory. |
| 321 void RemoveFileFromDirectory(const FilePath& dir_path, |
| 322 const FilePathUpdateCallback& callback, |
| 323 base::PlatformFileError error, |
| 324 const FilePath& file_path); |
| 325 |
259 // Callback for handling feed content fetching while searching for file info. | 326 // Callback for handling feed content fetching while searching for file info. |
260 // This callback is invoked after async feed fetch operation that was | 327 // This callback is invoked after async feed fetch operation that was |
261 // invoked by StartDirectoryRefresh() completes. This callback will update | 328 // invoked by StartDirectoryRefresh() completes. This callback will update |
262 // the content of the refreshed directory object and continue initially | 329 // the content of the refreshed directory object and continue initially |
263 // started FindFileByPath() request. | 330 // started FindFileByPath() request. |
264 void OnGetDocuments(const FindFileParams& params, | 331 void OnGetDocuments(const FindFileParams& params, |
265 scoped_ptr<base::ListValue> feed_list, | 332 scoped_ptr<base::ListValue> feed_list, |
266 GDataErrorCode status, | 333 GDataErrorCode status, |
267 scoped_ptr<base::Value> data); | 334 scoped_ptr<base::Value> data); |
268 | 335 |
| 336 // A pass-through callback used for bridging from |
| 337 // FilePathUpdateCallback to FileOperationCallback. |
| 338 void OnFilePathUpdated(const FileOperationCallback& cllback, |
| 339 base::PlatformFileError error, |
| 340 const FilePath& file_path); |
| 341 |
| 342 // Callback for handling resource rename attempt. |
| 343 void OnRenameResourceCompleted(const FilePath& file_path, |
| 344 const FilePath::StringType& new_name, |
| 345 const FilePathUpdateCallback& callback, |
| 346 GDataErrorCode status, |
| 347 const GURL& document_url); |
| 348 |
| 349 // Callback for handling document copy attempt. |
| 350 void OnCopyDocumentCompleted(const FilePathUpdateCallback& callback, |
| 351 GDataErrorCode status, |
| 352 scoped_ptr<base::Value> data); |
| 353 |
| 354 // Callback for handling an attempt to add a file or directory to another |
| 355 // directory. |
| 356 void OnAddFileToDirectoryCompleted(const FileOperationCallback& callback, |
| 357 const FilePath& file_path, |
| 358 const FilePath& dir_path, |
| 359 GDataErrorCode status, |
| 360 const GURL& document_url); |
| 361 |
| 362 // Callback for handling an attempt to remove a file or directory from |
| 363 // another directory. |
| 364 void OnRemoveFileFromDirectoryCompleted( |
| 365 const FilePathUpdateCallback& callback, |
| 366 const FilePath& file_path, |
| 367 const FilePath& dir_path, |
| 368 GDataErrorCode status, |
| 369 const GURL& document_url); |
| 370 |
269 // Callback for handling document remove attempt. | 371 // Callback for handling document remove attempt. |
270 void OnRemovedDocument( | 372 void OnRemovedDocument( |
271 const FileOperationCallback& callback, | 373 const FileOperationCallback& callback, |
272 const FilePath& file_path, | 374 const FilePath& file_path, |
273 GDataErrorCode status, | 375 GDataErrorCode status, |
274 const GURL& document_url); | 376 const GURL& document_url); |
275 | 377 |
276 // Callback for handling directory create requests. | 378 // Callback for handling directory create requests. |
277 void OnCreateDirectoryCompleted( | 379 void OnCreateDirectoryCompleted( |
278 const CreateDirectoryParams& params, | 380 const CreateDirectoryParams& params, |
(...skipping 15 matching lines...) Expand all Loading... |
294 const GURL& upload_location); | 396 const GURL& upload_location); |
295 | 397 |
296 // Callback for handling file upload resume requests. | 398 // Callback for handling file upload resume requests. |
297 void OnResumeUpload( | 399 void OnResumeUpload( |
298 const ResumeUploadOperationCallback& callback, | 400 const ResumeUploadOperationCallback& callback, |
299 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 401 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
300 GDataErrorCode code, | 402 GDataErrorCode code, |
301 int64 start_range_received, | 403 int64 start_range_received, |
302 int64 end_range_received); | 404 int64 end_range_received); |
303 | 405 |
| 406 // Renames a file or directory at |file_path| on in-memory snapshot |
| 407 // of the file system. Returns PLATFORM_FILE_OK if successful. |
| 408 base::PlatformFileError RenameFileOnFilesystem( |
| 409 const FilePath& file_path, const FilePath::StringType& new_name, |
| 410 FilePath* updated_file_path); |
| 411 |
| 412 // Adds a file or directory at |file_path| to another directory at |
| 413 // |dir_path| on in-memory snapshot of the file system. |
| 414 // Returns PLATFORM_FILE_OK if successful. |
| 415 base::PlatformFileError AddFileToDirectoryOnFilesystem( |
| 416 const FilePath& file_path, const FilePath& dir_path); |
| 417 |
| 418 // Removes a file or directory at |file_path| from another directory at |
| 419 // |dir_path| on in-memory snapshot of the file system. |
| 420 // Returns PLATFORM_FILE_OK if successful. |
| 421 base::PlatformFileError RemoveFileFromDirectoryOnFilesystem( |
| 422 const FilePath& file_path, const FilePath& dir_path, |
| 423 FilePath* updated_file_path); |
| 424 |
304 // Removes file under |file_path| from in-memory snapshot of the file system. | 425 // Removes file under |file_path| from in-memory snapshot of the file system. |
305 // Return PLATFORM_FILE_OK if successful. | 426 // Return PLATFORM_FILE_OK if successful. |
306 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); | 427 base::PlatformFileError RemoveFileFromFileSystem(const FilePath& file_path); |
307 | 428 |
308 // Parses the content of |feed_data| and returns DocumentFeed instance | 429 // Parses the content of |feed_data| and returns DocumentFeed instance |
309 // represeting it. | 430 // represeting it. |
310 DocumentFeed* ParseDocumentFeed(base::Value* feed_data); | 431 DocumentFeed* ParseDocumentFeed(base::Value* feed_data); |
311 | 432 |
312 // Updates content of the directory identified with |directory_path| with | 433 // Updates content of the directory identified with |directory_path| with |
313 // feeds collected in |feed_list|. | 434 // feeds collected in |feed_list|. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 GDataDirectory*) OVERRIDE; | 668 GDataDirectory*) OVERRIDE; |
548 virtual void OnError(base::PlatformFileError) OVERRIDE; | 669 virtual void OnError(base::PlatformFileError) OVERRIDE; |
549 | 670 |
550 // File entry that was found. | 671 // File entry that was found. |
551 GDataFileBase* file_; | 672 GDataFileBase* file_; |
552 }; | 673 }; |
553 | 674 |
554 } // namespace gdata | 675 } // namespace gdata |
555 | 676 |
556 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ | 677 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILE_SYSTEM_H_ |
OLD | NEW |