diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-14 05:15:53 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-14 05:15:53 +0000 |
commit | 397281fdb6003ab5b86ead542a46e3d82aa2be1f (patch) | |
tree | 6d7a2d27edfb8b3790dd4a199d2e32283206fcce /webkit/fileapi/file_system_operation.h | |
parent | c10878accf5f6c12c471d77d20b32ef3e84f5693 (diff) | |
download | chromium_src-397281fdb6003ab5b86ead542a46e3d82aa2be1f.zip chromium_src-397281fdb6003ab5b86ead542a46e3d82aa2be1f.tar.gz chromium_src-397281fdb6003ab5b86ead542a46e3d82aa2be1f.tar.bz2 |
Cleanup SandboxedFileSystem* and merge them into FileSystem* for simplicity.
Based on our rough discussion over emails, I just went ahead and did the cleanup.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6471018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_system_operation.h')
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 151 |
1 files changed, 86 insertions, 65 deletions
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index 1b52e22..6542806 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -15,6 +15,7 @@ #include "base/scoped_callback_factory.h" #include "base/scoped_ptr.h" #include "googleurl/src/gurl.h" +#include "webkit/fileapi/file_system_types.h" namespace base { class Time; @@ -30,6 +31,7 @@ class GURL; namespace fileapi { class FileSystemCallbackDispatcher; +class FileSystemContext; class FileWriterDelegate; // This class is designed to serve one-time file system operation per instance. @@ -42,74 +44,47 @@ class FileSystemOperation { public: // |dispatcher| will be owned by this class. FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, - scoped_refptr<base::MessageLoopProxy> proxy); + scoped_refptr<base::MessageLoopProxy> proxy, + FileSystemContext* file_system_context); virtual ~FileSystemOperation(); - virtual void CreateFile(const FilePath& path, - bool exclusive); - - virtual void CreateDirectory(const FilePath& path, - bool exclusive, - bool recursive); - - virtual void Copy(const FilePath& src_path, - const FilePath& dest_path); - - virtual void Move(const FilePath& src_path, - const FilePath& dest_path); - - virtual void DirectoryExists(const FilePath& path); - - virtual void FileExists(const FilePath& path); - - virtual void GetMetadata(const FilePath& path); - - virtual void ReadDirectory(const FilePath& path); - - virtual void Remove(const FilePath& path, bool recursive); - - virtual void Write(scoped_refptr<net::URLRequestContext> url_request_context, - const FilePath& path, - const GURL& blob_url, - int64 offset); - - virtual void Truncate(const FilePath& path, int64 length); - - virtual void TouchFile(const FilePath& path, - const base::Time& last_access_time, - const base::Time& last_modified_time); + void OpenFileSystem(const GURL& origin_url, + fileapi::FileSystemType type, + bool create); + void CreateFile(const FilePath& path, + bool exclusive); + void CreateDirectory(const FilePath& path, + bool exclusive, + bool recursive); + void Copy(const FilePath& src_path, + const FilePath& dest_path); + void Move(const FilePath& src_path, + const FilePath& dest_path); + void DirectoryExists(const FilePath& path); + void FileExists(const FilePath& path); + void GetMetadata(const FilePath& path); + void ReadDirectory(const FilePath& path); + void Remove(const FilePath& path, bool recursive); + void Write(scoped_refptr<net::URLRequestContext> url_request_context, + const FilePath& path, + const GURL& blob_url, + int64 offset); + void Truncate(const FilePath& path, int64 length); + void TouchFile(const FilePath& path, + const base::Time& last_access_time, + const base::Time& last_modified_time); // Try to cancel the current operation [we support cancelling write or // truncate only]. Report failure for the current operation, then tell the // passed-in operation to report success. - virtual void Cancel(FileSystemOperation* cancel_operation); - - protected: -#ifndef NDEBUG - enum OperationType { - kOperationNone, - kOperationCreateFile, - kOperationCreateDirectory, - kOperationCopy, - kOperationMove, - kOperationDirectoryExists, - kOperationFileExists, - kOperationGetMetadata, - kOperationReadDirectory, - kOperationRemove, - kOperationWrite, - kOperationTruncate, - kOperationTouchFile, - kOperationCancel, - }; - - // A flag to make sure we call operation only once per instance. - OperationType pending_operation_; -#endif - - FileSystemCallbackDispatcher* dispatcher() const { return dispatcher_.get(); } + void Cancel(FileSystemOperation* cancel_operation); private: + // A callback used for OpenFileSystem. + void DidGetRootPath(bool success, + const FilePath& path, + const std::string& name); + // Callback for CreateFile for |exclusive|=true cases. void DidEnsureFileExistsExclusive(base::PlatformFileError rv, bool created); @@ -123,22 +98,17 @@ class FileSystemOperation { void DidDirectoryExists(base::PlatformFileError rv, const base::PlatformFileInfo& file_info); - void DidFileExists(base::PlatformFileError rv, const base::PlatformFileInfo& file_info); - void DidGetMetadata(base::PlatformFileError rv, const base::PlatformFileInfo& file_info); - void DidReadDirectory( base::PlatformFileError rv, const std::vector<base::FileUtilProxy::Entry>& entries); - void DidWrite( base::PlatformFileError rv, int64 bytes, bool complete); - void DidTouchFile(base::PlatformFileError rv); // Helper for Write(). @@ -147,11 +117,62 @@ class FileSystemOperation { base::PassPlatformFile file, bool created); + // Checks the validity of a given |path| for reading. + // Returns true if the given |path| is a valid FileSystem path. + // Otherwise it calls dispatcher's DidFail method with + // PLATFORM_FILE_ERROR_SECURITY and returns false. + // (Note: this doesn't delete this when it calls DidFail and returns false; + // it's the caller's responsibility.) + bool VerifyFileSystemPathForRead(const FilePath& path); + + // Checks the validity of a given |path| for writing. + // Returns true if the given |path| is a valid FileSystem path, and + // its origin embedded in the path has the right to write as much as + // the given |growth|. + // Otherwise it fires dispatcher's DidFail method with + // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, + // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to + // increase the usage by |growth|. + // In either case it returns false after firing DidFail. + // If |create| flag is true this also checks if the |path| contains + // any restricted names and chars. If it does, the call fires dispatcher's + // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false. + // (Note: this doesn't delete this when it calls DidFail and returns false; + // it's the caller's responsibility.) + bool VerifyFileSystemPathForWrite(const FilePath& path, + bool create, + int64 growth); + +#ifndef NDEBUG + enum OperationType { + kOperationNone, + kOperationOpenFileSystem, + kOperationCreateFile, + kOperationCreateDirectory, + kOperationCopy, + kOperationMove, + kOperationDirectoryExists, + kOperationFileExists, + kOperationGetMetadata, + kOperationReadDirectory, + kOperationRemove, + kOperationWrite, + kOperationTruncate, + kOperationTouchFile, + kOperationCancel, + }; + + // A flag to make sure we call operation only once per instance. + OperationType pending_operation_; +#endif + // Proxy for calling file_util_proxy methods. scoped_refptr<base::MessageLoopProxy> proxy_; scoped_ptr<FileSystemCallbackDispatcher> dispatcher_; + scoped_refptr<FileSystemContext> file_system_context_; + base::ScopedCallbackFactory<FileSystemOperation> callback_factory_; // These are all used only by Write(). |