| 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 WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/platform_file.h" | |
| 14 #include "base/process/process.h" | 13 #include "base/process/process.h" |
| 15 #include "webkit/browser/fileapi/file_system_operation_context.h" | 14 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 16 #include "webkit/browser/webkit_storage_browser_export.h" | 15 #include "webkit/browser/webkit_storage_browser_export.h" |
| 17 #include "webkit/common/fileapi/directory_entry.h" | 16 #include "webkit/common/fileapi/directory_entry.h" |
| 18 | 17 |
| 19 namespace base { | 18 namespace base { |
| 20 class Time; | 19 class Time; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace net { | 22 namespace net { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 67 |
| 69 // Used for CreateFile(), etc. |result| is the return code of the operation. | 68 // Used for CreateFile(), etc. |result| is the return code of the operation. |
| 70 typedef base::Callback<void(base::File::Error result)> StatusCallback; | 69 typedef base::Callback<void(base::File::Error result)> StatusCallback; |
| 71 | 70 |
| 72 // Used for GetMetadata(). |result| is the return code of the operation, | 71 // Used for GetMetadata(). |result| is the return code of the operation, |
| 73 // |file_info| is the obtained file info. | 72 // |file_info| is the obtained file info. |
| 74 typedef base::Callback< | 73 typedef base::Callback< |
| 75 void(base::File::Error result, | 74 void(base::File::Error result, |
| 76 const base::File::Info& file_info)> GetMetadataCallback; | 75 const base::File::Info& file_info)> GetMetadataCallback; |
| 77 | 76 |
| 78 // Used for OpenFile(). |result| is the return code of the operation. | 77 // Used for OpenFile(). |on_close_callback| will be called after the file is |
| 79 // |on_close_callback| will be called after the file is closed in the child | 78 // closed in the child process. It can be null, if no operation is needed on |
| 80 // process. It can be null, if no operation is needed on closing a file. | 79 // closing a file. |
| 81 typedef base::Callback< | 80 typedef base::Callback< |
| 82 void(base::File::Error result, | 81 void(base::File file, |
| 83 base::PlatformFile file, | |
| 84 const base::Closure& on_close_callback)> OpenFileCallback; | 82 const base::Closure& on_close_callback)> OpenFileCallback; |
| 85 | 83 |
| 86 // Used for ReadDirectoryCallback. | 84 // Used for ReadDirectoryCallback. |
| 87 typedef std::vector<DirectoryEntry> FileEntryList; | 85 typedef std::vector<DirectoryEntry> FileEntryList; |
| 88 | 86 |
| 89 // Used for ReadDirectory(). |result| is the return code of the operation, | 87 // Used for ReadDirectory(). |result| is the return code of the operation, |
| 90 // |file_list| is the list of files read, and |has_more| is true if some files | 88 // |file_list| is the list of files read, and |has_more| is true if some files |
| 91 // are yet to be read. | 89 // are yet to be read. |
| 92 typedef base::Callback< | 90 typedef base::Callback< |
| 93 void(base::File::Error result, | 91 void(base::File::Error result, |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // | 321 // |
| 324 // E.g. a typical cancel implementation would look like: | 322 // E.g. a typical cancel implementation would look like: |
| 325 // | 323 // |
| 326 // virtual void SomeOperationImpl::Cancel( | 324 // virtual void SomeOperationImpl::Cancel( |
| 327 // const StatusCallback& cancel_callback) { | 325 // const StatusCallback& cancel_callback) { |
| 328 // // Abort the current inflight operation first. | 326 // // Abort the current inflight operation first. |
| 329 // ... | 327 // ... |
| 330 // | 328 // |
| 331 // // Dispatch ABORT error for the current operation by invoking | 329 // // Dispatch ABORT error for the current operation by invoking |
| 332 // // the callback function for the ongoing operation, | 330 // // the callback function for the ongoing operation, |
| 333 // operation_callback.Run(base::PLATFORM_FILE_ERROR_ABORT, ...); | 331 // operation_callback.Run(base::File::FILE_ERROR_ABORT, ...); |
| 334 // | 332 // |
| 335 // // Dispatch 'success' for the cancel (or dispatch appropriate | 333 // // Dispatch 'success' for the cancel (or dispatch appropriate |
| 336 // // error code with DidFail() if the cancel has somehow failed). | 334 // // error code with DidFail() if the cancel has somehow failed). |
| 337 // cancel_callback.Run(base::PLATFORM_FILE_OK); | 335 // cancel_callback.Run(base::File::FILE_OK); |
| 338 // } | 336 // } |
| 339 // | 337 // |
| 340 // Note that, for reporting failure, the callback function passed to a | 338 // Note that, for reporting failure, the callback function passed to a |
| 341 // cancellable operations are kept around with the operation instance | 339 // cancellable operations are kept around with the operation instance |
| 342 // (as |operation_callback_| in the code example). | 340 // (as |operation_callback_| in the code example). |
| 343 virtual void Cancel(const StatusCallback& cancel_callback) = 0; | 341 virtual void Cancel(const StatusCallback& cancel_callback) = 0; |
| 344 | 342 |
| 345 // Modifies timestamps of a file or directory at |path| with | 343 // Modifies timestamps of a file or directory at |path| with |
| 346 // |last_access_time| and |last_modified_time|. The function DOES NOT | 344 // |last_access_time| and |last_modified_time|. The function DOES NOT |
| 347 // create a file unlike 'touch' command on Linux. | 345 // create a file unlike 'touch' command on Linux. |
| 348 // | 346 // |
| 349 // This function is used only by Pepper as of writing. | 347 // This function is used only by Pepper as of writing. |
| 350 virtual void TouchFile(const FileSystemURL& path, | 348 virtual void TouchFile(const FileSystemURL& path, |
| 351 const base::Time& last_access_time, | 349 const base::Time& last_access_time, |
| 352 const base::Time& last_modified_time, | 350 const base::Time& last_modified_time, |
| 353 const StatusCallback& callback) = 0; | 351 const StatusCallback& callback) = 0; |
| 354 | 352 |
| 355 // Opens a file at |path| with |file_flags|, where flags are OR'ed | 353 // Opens a file at |path| with |file_flags|, where flags are OR'ed |
| 356 // values of base::PlatformFileFlags. | 354 // values of base::File::Flags. |
| 357 // | 355 // |
| 358 // This function is used only by Pepper as of writing. | 356 // This function is used only by Pepper as of writing. |
| 359 virtual void OpenFile(const FileSystemURL& path, | 357 virtual void OpenFile(const FileSystemURL& path, |
| 360 int file_flags, | 358 int file_flags, |
| 361 const OpenFileCallback& callback) = 0; | 359 const OpenFileCallback& callback) = 0; |
| 362 | 360 |
| 363 // Creates a local snapshot file for a given |path| and returns the | 361 // Creates a local snapshot file for a given |path| and returns the |
| 364 // metadata and platform path of the snapshot file via |callback|. | 362 // metadata and platform path of the snapshot file via |callback|. |
| 365 // In local filesystem cases the implementation may simply return | 363 // In local filesystem cases the implementation may simply return |
| 366 // the metadata of the file itself (as well as GetMetadata does), | 364 // the metadata of the file itself (as well as GetMetadata does), |
| 367 // while in remote filesystem case the backend may want to download the file | 365 // while in remote filesystem case the backend may want to download the file |
| 368 // into a temporary snapshot file and return the metadata of the | 366 // into a temporary snapshot file and return the metadata of the |
| 369 // temporary file. Or if the implementaiton already has the local cache | 367 // temporary file. Or if the implementaiton already has the local cache |
| 370 // data for |path| it can simply return the path to the cache. | 368 // data for |path| it can simply return the path to the cache. |
| 371 virtual void CreateSnapshotFile(const FileSystemURL& path, | 369 virtual void CreateSnapshotFile(const FileSystemURL& path, |
| 372 const SnapshotFileCallback& callback) = 0; | 370 const SnapshotFileCallback& callback) = 0; |
| 373 | 371 |
| 374 // Copies in a single file from a different filesystem. | 372 // Copies in a single file from a different filesystem. |
| 375 // | 373 // |
| 376 // This returns: | 374 // This returns: |
| 377 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path| | 375 // - File::FILE_ERROR_NOT_FOUND if |src_file_path| |
| 378 // or the parent directory of |dest_url| does not exist. | 376 // or the parent directory of |dest_url| does not exist. |
| 379 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 377 // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 380 // is not a file. | 378 // is not a file. |
| 381 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 379 // - File::FILE_ERROR_FAILED if |dest_url| does not exist and |
| 382 // its parent path is a file. | 380 // its parent path is a file. |
| 383 // | 381 // |
| 384 virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path, | 382 virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path, |
| 385 const FileSystemURL& dest_url, | 383 const FileSystemURL& dest_url, |
| 386 const StatusCallback& callback) = 0; | 384 const StatusCallback& callback) = 0; |
| 387 | 385 |
| 388 // Removes a single file. | 386 // Removes a single file. |
| 389 // | 387 // |
| 390 // This returns: | 388 // This returns: |
| 391 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 389 // - File::FILE_ERROR_NOT_FOUND if |url| does not exist. |
| 392 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file. | 390 // - File::FILE_ERROR_NOT_A_FILE if |url| is not a file. |
| 393 // | 391 // |
| 394 virtual void RemoveFile(const FileSystemURL& url, | 392 virtual void RemoveFile(const FileSystemURL& url, |
| 395 const StatusCallback& callback) = 0; | 393 const StatusCallback& callback) = 0; |
| 396 | 394 |
| 397 // Removes a single empty directory. | 395 // Removes a single empty directory. |
| 398 // | 396 // |
| 399 // This returns: | 397 // This returns: |
| 400 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 398 // - File::FILE_ERROR_NOT_FOUND if |url| does not exist. |
| 401 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. | 399 // - File::FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. |
| 402 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. | 400 // - File::FILE_ERROR_NOT_EMPTY if |url| is not empty. |
| 403 // | 401 // |
| 404 virtual void RemoveDirectory(const FileSystemURL& url, | 402 virtual void RemoveDirectory(const FileSystemURL& url, |
| 405 const StatusCallback& callback) = 0; | 403 const StatusCallback& callback) = 0; |
| 406 | 404 |
| 407 // Copies a file from |src_url| to |dest_url|. | 405 // Copies a file from |src_url| to |dest_url|. |
| 408 // This must be called for files that belong to the same filesystem | 406 // This must be called for files that belong to the same filesystem |
| 409 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). | 407 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
| 410 // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's | 408 // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's |
| 411 // comment for details. | 409 // comment for details. |
| 412 // |progress_callback| is periodically called to report the progress | 410 // |progress_callback| is periodically called to report the progress |
| 413 // update. See also the comment of CopyFileProgressCallback. This callback is | 411 // update. See also the comment of CopyFileProgressCallback. This callback is |
| 414 // optional. | 412 // optional. |
| 415 // | 413 // |
| 416 // This returns: | 414 // This returns: |
| 417 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 415 // - File::FILE_ERROR_NOT_FOUND if |src_url| |
| 418 // or the parent directory of |dest_url| does not exist. | 416 // or the parent directory of |dest_url| does not exist. |
| 419 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 417 // - File::FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 420 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 418 // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 421 // is not a file. | 419 // is not a file. |
| 422 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 420 // - File::FILE_ERROR_FAILED if |dest_url| does not exist and |
| 423 // its parent path is a file. | 421 // its parent path is a file. |
| 424 // | 422 // |
| 425 virtual void CopyFileLocal(const FileSystemURL& src_url, | 423 virtual void CopyFileLocal(const FileSystemURL& src_url, |
| 426 const FileSystemURL& dest_url, | 424 const FileSystemURL& dest_url, |
| 427 CopyOrMoveOption option, | 425 CopyOrMoveOption option, |
| 428 const CopyFileProgressCallback& progress_callback, | 426 const CopyFileProgressCallback& progress_callback, |
| 429 const StatusCallback& callback) = 0; | 427 const StatusCallback& callback) = 0; |
| 430 | 428 |
| 431 // Moves a local file from |src_url| to |dest_url|. | 429 // Moves a local file from |src_url| to |dest_url|. |
| 432 // This must be called for files that belong to the same filesystem | 430 // This must be called for files that belong to the same filesystem |
| 433 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). | 431 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
| 434 // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's | 432 // |option| specifies the minor behavior of Copy(). See CopyOrMoveOption's |
| 435 // comment for details. | 433 // comment for details. |
| 436 // | 434 // |
| 437 // This returns: | 435 // This returns: |
| 438 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 436 // - File::FILE_ERROR_NOT_FOUND if |src_url| |
| 439 // or the parent directory of |dest_url| does not exist. | 437 // or the parent directory of |dest_url| does not exist. |
| 440 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 438 // - File::FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 441 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 439 // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 442 // is not a file. | 440 // is not a file. |
| 443 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 441 // - File::FILE_ERROR_FAILED if |dest_url| does not exist and |
| 444 // its parent path is a file. | 442 // its parent path is a file. |
| 445 // | 443 // |
| 446 virtual void MoveFileLocal(const FileSystemURL& src_url, | 444 virtual void MoveFileLocal(const FileSystemURL& src_url, |
| 447 const FileSystemURL& dest_url, | 445 const FileSystemURL& dest_url, |
| 448 CopyOrMoveOption option, | 446 CopyOrMoveOption option, |
| 449 const StatusCallback& callback) = 0; | 447 const StatusCallback& callback) = 0; |
| 450 | 448 |
| 451 // Synchronously gets the platform path for the given |url|. | 449 // Synchronously gets the platform path for the given |url|. |
| 452 // This may fail if the given |url|'s filesystem type is neither | 450 // This may fail if the given |url|'s filesystem type is neither |
| 453 // temporary nor persistent. | 451 // temporary nor persistent. |
| 454 // In such a case, base::PLATFORM_FILE_ERROR_INVALID_OPERATION will be | 452 // In such a case, base::File::FILE_ERROR_INVALID_OPERATION will be |
| 455 // returned. | 453 // returned. |
| 456 virtual base::File::Error SyncGetPlatformPath( | 454 virtual base::File::Error SyncGetPlatformPath( |
| 457 const FileSystemURL& url, | 455 const FileSystemURL& url, |
| 458 base::FilePath* platform_path) = 0; | 456 base::FilePath* platform_path) = 0; |
| 459 | 457 |
| 460 protected: | 458 protected: |
| 461 // Used only for internal assertions. | 459 // Used only for internal assertions. |
| 462 enum OperationType { | 460 enum OperationType { |
| 463 kOperationNone, | 461 kOperationNone, |
| 464 kOperationCreateFile, | 462 kOperationCreateFile, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 478 kOperationOpenFile, | 476 kOperationOpenFile, |
| 479 kOperationCloseFile, | 477 kOperationCloseFile, |
| 480 kOperationGetLocalPath, | 478 kOperationGetLocalPath, |
| 481 kOperationCancel, | 479 kOperationCancel, |
| 482 }; | 480 }; |
| 483 }; | 481 }; |
| 484 | 482 |
| 485 } // namespace fileapi | 483 } // namespace fileapi |
| 486 | 484 |
| 487 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 485 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
| OLD | NEW |