diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-16 11:31:43 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-16 11:31:43 +0000 |
commit | 7546c9e9d9c3955f133db24daaf2982d7a7304d0 (patch) | |
tree | df5656a063b48b3ac4ae5c5dc9cac3ea9dfb2451 /webkit | |
parent | 15b6387e8dafd9cc91e86acf118e282a72603b76 (diff) | |
download | chromium_src-7546c9e9d9c3955f133db24daaf2982d7a7304d0.zip chromium_src-7546c9e9d9c3955f133db24daaf2982d7a7304d0.tar.gz chromium_src-7546c9e9d9c3955f133db24daaf2982d7a7304d0.tar.bz2 |
Introduce FileSystemOperationInterface.
This is in preparation for implementing FileSystemOperation for
non-local file systems.
BUG=chromium-os:23316
TEST=test_shell_tests
Review URL: http://codereview.chromium.org/8956010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114792 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 67 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation_interface.h | 132 | ||||
-rw-r--r-- | webkit/fileapi/webkit_fileapi.gypi | 1 |
4 files changed, 167 insertions, 35 deletions
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index e4c9593..62b21f0 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -346,7 +346,7 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive) { } void FileSystemOperation::Write( - scoped_refptr<net::URLRequestContext> url_request_context, + const net::URLRequestContext* url_request_context, const GURL& path, const GURL& blob_url, int64 offset) { diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index ea38357..f1b948f 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -19,6 +19,7 @@ #include "base/process.h" #include "googleurl/src/gurl.h" #include "webkit/fileapi/file_system_operation_context.h" +#include "webkit/fileapi/file_system_operation_interface.h" #include "webkit/fileapi/file_system_types.h" #include "webkit/quota/quota_manager.h" @@ -40,13 +41,8 @@ class FileSystemContext; class FileWriterDelegate; class FileSystemOperationTest; -// This class is designed to serve one-time file system operation per instance. -// Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, -// GetMetadata, ReadDirectory and Remove) may be called during the lifetime of -// this object and it should be called no more than once. -// This class is self-destructed, or get deleted via base::Owned() fater the -// operation finishes and completion callback is called. -class FileSystemOperation { +// FileSystemOperation implementation for local file systems. +class FileSystemOperation : public FileSystemOperationInterface { public: // |dispatcher| will be owned by this class. FileSystemOperation(FileSystemCallbackDispatcher* dispatcher, @@ -54,35 +50,38 @@ class FileSystemOperation { FileSystemContext* file_system_context); virtual ~FileSystemOperation(); - void OpenFileSystem(const GURL& origin_url, - fileapi::FileSystemType type, - bool create); - void CreateFile(const GURL& path, - bool exclusive); - void CreateDirectory(const GURL& path, - bool exclusive, - bool recursive); - void Copy(const GURL& src_path, - const GURL& dest_path); - void Move(const GURL& src_path, - const GURL& dest_path); - void DirectoryExists(const GURL& path); - void FileExists(const GURL& path); - void GetMetadata(const GURL& path); - void ReadDirectory(const GURL& path); - void Remove(const GURL& path, bool recursive); - void Write(scoped_refptr<net::URLRequestContext> url_request_context, - const GURL& path, - const GURL& blob_url, - int64 offset); - void Truncate(const GURL& path, int64 length); - void TouchFile(const GURL& path, - const base::Time& last_access_time, - const base::Time& last_modified_time); - void OpenFile( + // FileSystemOperation overrides. + virtual void OpenFileSystem(const GURL& origin_url, + fileapi::FileSystemType type, + bool create) OVERRIDE; + virtual void CreateFile(const GURL& path, + bool exclusive) OVERRIDE; + virtual void CreateDirectory(const GURL& path, + bool exclusive, + bool recursive) OVERRIDE; + virtual void Copy(const GURL& src_path, + const GURL& dest_path) OVERRIDE; + virtual void Move(const GURL& src_path, + const GURL& dest_path) OVERRIDE; + virtual void DirectoryExists(const GURL& path) OVERRIDE; + virtual void FileExists(const GURL& path) OVERRIDE; + virtual void GetMetadata(const GURL& path) OVERRIDE; + virtual void ReadDirectory(const GURL& path) OVERRIDE; + virtual void Remove(const GURL& path, bool recursive) OVERRIDE; + virtual void Write(const net::URLRequestContext* url_request_context, + const GURL& path, + const GURL& blob_url, + int64 offset) OVERRIDE; + virtual void Truncate(const GURL& path, int64 length) OVERRIDE; + virtual void TouchFile(const GURL& path, + const base::Time& last_access_time, + const base::Time& last_modified_time) OVERRIDE; + virtual void OpenFile( const GURL& path, int file_flags, - base::ProcessHandle peer_handle); + base::ProcessHandle peer_handle) OVERRIDE; + + // Synchronously gets the platform path for the given |path|. void SyncGetPlatformPath(const GURL& path, FilePath* platform_path); // Try to cancel the current operation [we support cancelling write or diff --git a/webkit/fileapi/file_system_operation_interface.h b/webkit/fileapi/file_system_operation_interface.h new file mode 100644 index 0000000..033abea --- /dev/null +++ b/webkit/fileapi/file_system_operation_interface.h @@ -0,0 +1,132 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_ +#define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_ + +#include "base/process.h" + +namespace base { +class Time; +} // namespace base + +namespace net { +class URLRequest; +class URLRequestContext; +} // namespace net + +class GURL; + +namespace fileapi { + +// The interface class for FileSystemOperation implementations. +// +// This interface defines file system operations required to implement +// "File API: Directories and System" +// http://www.w3.org/TR/file-system-api/ +// +// DESIGN NOTES +// +// This class is designed to +// +// 1) Serve one-time file system operation per instance. Only one +// method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, +// GetMetadata, ReadDirectory and Remove) may be called during the +// lifetime of this object and it should be called no more than once. +// +// 2) Be self-destructed, or get deleted via base::Owned() after the +// operation finishes and completion callback is called. +// +// 3) Deliver the results of operations to the client via +// FileSystemCallbackDispatcher. +// TODO(kinuko): Change the functions to take callbacks instead. +// +class FileSystemOperationInterface { + public: + virtual ~FileSystemOperationInterface() {} + + // Opens a file system at |origin_url| of the |type|. Creates a new file + // system if |create| is true. + virtual void OpenFileSystem(const GURL& origin_url, + fileapi::FileSystemType type, + bool create) = 0; + + // Creates a file at |path|. If |exclusive| is true, an error is raised + // in case a file is already present at the URL. + virtual void CreateFile(const GURL& path, + bool exclusive) = 0; + + // Creates a directory at |path|. If |exclusive| is true, an error is + // raised in case a directory is already present at the URL. If + // |recursive| is true, create parent directories as needed just like + // mkdir -p does. + virtual void CreateDirectory(const GURL& path, + bool exclusive, + bool recursive) = 0; + + // Copes a file or directory from |src_path| to |dest_path|. If + // |src_path| is a directory, the contents of |src_path| are copied to + // |dest_path| recursively. A new file or directory is created at + // |dest_path| as needed. + virtual void Copy(const GURL& src_path, + const GURL& dest_path) = 0; + + // Moves a file or directory from |src_path| to |dest_path|. A new file + // or directory is created at |dest_path| as needed. + virtual void Move(const GURL& src_path, + const GURL& dest_path) = 0; + + // Checks if a directory is present at |path|. + virtual void DirectoryExists(const GURL& path) = 0; + + // Checks if a file is present at |path|. + virtual void FileExists(const GURL& path) = 0; + + // Gets the metadata of a file or directory at |path|. + virtual void GetMetadata(const GURL& path) = 0; + + // Reads contents of a directory at |path|. + virtual void ReadDirectory(const GURL& path) = 0; + + // Removes a file or directory at |path|. If |recursive| is true, remove + // all files and directories under the directory at |path| recursively. + virtual void Remove(const GURL& path, bool recursive) = 0; + + // Writes contents of |blob_url| to |path| at |offset|. + // |url_request_context| is used to read contents in |blob_url|. + virtual void Write(const net::URLRequestContext* url_request_context, + const GURL& path, + const GURL& blob_url, + int64 offset) = 0; + + // Truncates a file at |path| to |length|. If |length| is larger than + // the original file size, the file will be extended, and the extended + // part is filled with null bytes. + virtual void Truncate(const GURL& path, int64 length) = 0; + + // Modifies timestamps of a file or directory at |path| with + // |last_access_time| and |last_modified_time|. The function DOES NOT + // create a file unlike 'touch' command on Linux. + // + // This function is used only by Pepper as of writing. + virtual void TouchFile(const GURL& path, + const base::Time& last_access_time, + const base::Time& last_modified_time) = 0; + + // Opens a file at |path| with |file_flags|, where flags are OR'ed + // values of base::PlatformFileFlags. + // + // |peer_handle| is the process handle of a pepper plugin process, which + // is necessary for underlying IPC calls with Pepper plugins. + // + // This function is used only by Pepper as of writing. + virtual void OpenFile( + const GURL& path, + int file_flags, + base::ProcessHandle peer_handle) = 0; +}; + +} // namespace fileapi + +#endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_INTERFACE_H_ diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi index 5ae71e4..a07c467 100644 --- a/webkit/fileapi/webkit_fileapi.gypi +++ b/webkit/fileapi/webkit_fileapi.gypi @@ -32,6 +32,7 @@ 'file_system_operation.h', 'file_system_operation_context.cc', 'file_system_operation_context.h', + 'file_system_operation_interface.h', 'file_system_origin_database.cc', 'file_system_origin_database.h', 'file_system_path_manager.cc', |