Index: webkit/fileapi/file_system_file_util.h |
diff --git a/webkit/fileapi/file_system_file_util.h b/webkit/fileapi/file_system_file_util.h |
index 8a46fbdb6d5974369ce2d8e7b12bc76663879425..4c9f62e1be9980de7cf0aca011a75735662e4f3f 100644 |
--- a/webkit/fileapi/file_system_file_util.h |
+++ b/webkit/fileapi/file_system_file_util.h |
@@ -2,21 +2,14 @@ |
// 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_FILE_UTIL_H_ |
-#define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
+#ifndef WEBKIT_FILEAPI_FILE_UTIL_H_ |
+#define WEBKIT_FILEAPI_FILE_UTIL_H_ |
-#include "base/callback.h" |
#include "base/file_path.h" |
-#include "base/file_util.h" |
#include "base/file_util_proxy.h" |
-#include "base/memory/ref_counted.h" |
#include "base/platform_file.h" |
-#include "base/tracked_objects.h" |
-#include "webkit/fileapi/file_system_types.h" |
namespace base { |
-struct PlatformFileInfo; |
-class MessageLoopProxy; |
class Time; |
} |
@@ -46,84 +39,27 @@ class FileSystemOperationContext; |
// PerformCommonCheckAndPreparationForMoveAndCopy and CopyOrMoveDirectory. |
class FileSystemFileUtil { |
public: |
- FileSystemFileUtil() {} |
- virtual ~FileSystemFileUtil() {} |
- |
- // Creates or opens a file with the given flags. It is invalid to pass NULL |
- // for the callback. |
- // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
- // a new file at the given |file_path| and calls back with |
- // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
- virtual PlatformFileError CreateOrOpen( |
- FileSystemOperationContext* context, |
- const FilePath& file_path, |
- int file_flags, |
- PlatformFile* file_handle, |
- bool* created); |
- |
- // Close the given file handle. |
- virtual PlatformFileError Close( |
- FileSystemOperationContext* context, |
- PlatformFile); |
- |
- // Ensures that the given |file_path| exist. This creates a empty new file |
- // at |file_path| if the |file_path| does not exist. |
- // If a new file han not existed and is created at the |file_path|, |
- // |created| of the callback argument is set true and |error code| |
- // is set PLATFORM_FILE_OK. |
- // If the file already exists, |created| is set false and |error code| |
- // is set PLATFORM_FILE_OK. |
- // If the file hasn't existed but it couldn't be created for some other |
- // reasons, |created| is set false and |error code| indicates the error. |
- virtual PlatformFileError EnsureFileExists( |
- FileSystemOperationContext* context, |
- const FilePath& file_path, bool* created); |
+ // It will be implemented by each subclass such as FileSystemFileEnumerator. |
+ class AbstractFileEnumerator { |
+ public: |
+ virtual ~AbstractFileEnumerator() {} |
- // Maps |virtual_path| given |context| into |local_path| which represents |
- // physical file location on the host OS. This may not always make sense for |
- // all subclasses. |
- virtual PlatformFileError GetLocalFilePath( |
- FileSystemOperationContext* context, |
- const FilePath& virtual_path, |
- FilePath* local_path); |
+ // Returns an empty string if there are no more results. |
+ virtual FilePath Next() = 0; |
- // Retrieves the information about a file. It is invalid to pass NULL for the |
- // callback. |
- virtual PlatformFileError GetFileInfo( |
- FileSystemOperationContext* context, |
- const FilePath& file_, |
- base::PlatformFileInfo* file_info, |
- FilePath* platform_path); |
+ virtual bool IsDirectory() = 0; |
+ }; |
- // Reads the filenames in |file_path|. |
- virtual PlatformFileError ReadDirectory( |
- FileSystemOperationContext* context, |
- const FilePath& file_path, |
- std::vector<base::FileUtilProxy::Entry>* entries); |
+ class EmptyFileEnumerator : public AbstractFileEnumerator { |
+ virtual FilePath Next() { return FilePath(); } |
+ virtual bool IsDirectory() { return false; } |
+ }; |
- // Creates directory at given path. It's an error to create |
- // if |exclusive| is true and dir already exists. |
- virtual PlatformFileError CreateDirectory( |
- FileSystemOperationContext* context, |
- const FilePath& file_path, |
- bool exclusive, |
- bool recursive); |
+ FileSystemFileUtil(); |
+ explicit FileSystemFileUtil(FileSystemFileUtil* underlying_file_util); |
+ virtual ~FileSystemFileUtil(); |
// Copies or moves a single file. |
- virtual PlatformFileError CopyOrMoveFile( |
- FileSystemOperationContext* context, |
- const FilePath& src_file_path, |
- const FilePath& dest_file_path, |
- bool copy); |
- |
- // Copies in a single file from a different filesystem. The src_file_path is |
- // a true local platform path, regardless of which subclass of |
- // FileSystemFileUtil is being invoked. |
- virtual PlatformFileError CopyInForeignFile( |
- FileSystemOperationContext* context, |
- const FilePath& src_file_path, |
- const FilePath& dest_file_path); |
- |
// Copies a file or a directory from |src_file_path| to |dest_file_path|. |
// |
// Error cases: |
@@ -169,23 +105,73 @@ class FileSystemFileUtil { |
const FilePath& file_path, |
bool recursive); |
- // Deletes a single file. |
- // It assumes the given path points a file. |
- // |
- // This method is called from DeleteDirectoryRecursive and Delete (both are |
- // non-virtual). |
- virtual PlatformFileError DeleteFile( |
- FileSystemOperationContext* unused, |
- const FilePath& file_path); |
+ // Creates or opens a file with the given flags. It is invalid to pass NULL |
+ // for the callback. |
+ // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
+ // a new file at the given |file_path| and calls back with |
+ // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. |
+ virtual PlatformFileError CreateOrOpen( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_path, |
+ int file_flags, |
+ PlatformFile* file_handle, |
+ bool* created); |
- // Deletes a single empty directory. |
- // It assumes the given path points an empty directory. |
- // |
- // This method is called from DeleteDirectoryRecursive and Delete (both are |
- // non-virtual). |
- virtual PlatformFileError DeleteSingleDirectory( |
- FileSystemOperationContext* unused, |
- const FilePath& file_path); |
+ // Close the given file handle. |
+ virtual PlatformFileError Close( |
+ FileSystemOperationContext* context, |
+ PlatformFile); |
+ |
+ // Ensures that the given |file_path| exist. This creates a empty new file |
+ // at |file_path| if the |file_path| does not exist. |
+ // If a new file han not existed and is created at the |file_path|, |
+ // |created| of the callback argument is set true and |error code| |
+ // is set PLATFORM_FILE_OK. |
+ // If the file already exists, |created| is set false and |error code| |
+ // is set PLATFORM_FILE_OK. |
+ // If the file hasn't existed but it couldn't be created for some other |
+ // reasons, |created| is set false and |error code| indicates the error. |
+ virtual PlatformFileError EnsureFileExists( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_path, bool* created); |
+ |
+ // Creates directory at given path. It's an error to create |
+ // if |exclusive| is true and dir already exists. |
+ virtual PlatformFileError CreateDirectory( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_path, |
+ bool exclusive, |
+ bool recursive); |
+ |
+ // Retrieves the information about a file. It is invalid to pass NULL for the |
+ // callback. |
+ virtual PlatformFileError GetFileInfo( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_, |
+ base::PlatformFileInfo* file_info, |
+ FilePath* platform_path); |
+ |
+ // Reads the filenames in |file_path|. |
+ virtual PlatformFileError ReadDirectory( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_path, |
+ std::vector<base::FileUtilProxy::Entry>* entries); |
+ |
+ // Returns a pointer to a new instance of AbstractFileEnumerator which is |
+ // implemented for each FileSystemFileUtil subclass. The instance needs to be |
+ // freed by the caller, and its lifetime should not extend past when the |
+ // current call returns to the main FILE message loop. |
+ virtual AbstractFileEnumerator* CreateFileEnumerator( |
+ FileSystemOperationContext* context, |
+ const FilePath& root_path); |
+ |
+ // Maps |virtual_path| given |context| into |local_path| which represents |
+ // physical file location on the host OS. This may not always make sense for |
+ // all subclasses. |
+ virtual PlatformFileError GetLocalFilePath( |
+ FileSystemOperationContext* context, |
+ const FilePath& virtual_path, |
+ FilePath* local_path); |
// Touches a file. The callback can be NULL. |
virtual PlatformFileError Touch( |
@@ -203,58 +189,55 @@ class FileSystemFileUtil { |
int64 length); |
virtual bool PathExists( |
- FileSystemOperationContext* unused, |
+ FileSystemOperationContext* context, |
const FilePath& file_path); |
virtual bool DirectoryExists( |
- FileSystemOperationContext* unused, |
+ FileSystemOperationContext* context, |
const FilePath& file_path); |
virtual bool IsDirectoryEmpty( |
- FileSystemOperationContext* unused, |
+ FileSystemOperationContext* context, |
const FilePath& file_path); |
- // It will be implemented by each subclass such as FileSystemFileEnumerator. |
- class AbstractFileEnumerator { |
- public: |
- virtual ~AbstractFileEnumerator() {} |
- |
- // Returns an empty string if there are no more results. |
- virtual FilePath Next() = 0; |
- |
- virtual bool IsDirectory() = 0; |
- }; |
+ virtual PlatformFileError CopyOrMoveFile( |
+ FileSystemOperationContext* context, |
+ const FilePath& src_file_path, |
+ const FilePath& dest_file_path, |
+ bool copy); |
- class EmptyFileEnumerator : public AbstractFileEnumerator { |
- virtual FilePath Next() { return FilePath(); } |
- virtual bool IsDirectory() { return false; } |
- }; |
+ // Copies in a single file from a different filesystem. The src_file_path is |
+ // a true local platform path, regardless of which subclass of |
+ // FileSystemFileUtil is being invoked. |
+ virtual PlatformFileError CopyInForeignFile( |
+ FileSystemOperationContext* context, |
+ const FilePath& src_file_path, |
+ const FilePath& dest_file_path); |
- // Returns a pointer to a new instance of AbstractFileEnumerator which is |
- // implemented for each FileUtil subclass. The instance needs to be freed |
- // by the caller, and its lifetime should not extend past when the current |
- // call returns to the main FILE message loop. |
- virtual AbstractFileEnumerator* CreateFileEnumerator( |
- FileSystemOperationContext* unused, |
- const FilePath& root_path); |
+ // Deletes a single file. |
+ // It assumes the given path points a file. |
+ // |
+ // This method is called from DeleteDirectoryRecursive and Delete (both are |
+ // non-virtual). |
+ virtual PlatformFileError DeleteFile( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_path); |
- protected: |
- // Deletes a directory and all entries under the directory. |
+ // Deletes a single empty directory. |
+ // It assumes the given path points an empty directory. |
// |
- // This method is called from Delete. It internally calls two following |
- // virtual methods, |
- // - (virtual) DeleteFile to delete files, and |
- // - (virtual) DeleteSingleDirectory to delete empty directories after all |
- // the files are deleted. |
- PlatformFileError DeleteDirectoryRecursive( |
+ // This method is called from DeleteDirectoryRecursive and Delete (both are |
+ // non-virtual). |
+ virtual PlatformFileError DeleteSingleDirectory( |
FileSystemOperationContext* context, |
const FilePath& file_path); |
+ protected: |
// This also removes the destination directory if it's non-empty and all |
// other checks are passed (so that the copy/move correctly overwrites the |
// destination). |
PlatformFileError PerformCommonCheckAndPreparationForMoveAndCopy( |
- FileSystemOperationContext* unused, |
+ FileSystemOperationContext* context, |
const FilePath& src_file_path, |
const FilePath& dest_file_path); |
@@ -278,9 +261,27 @@ class FileSystemFileUtil { |
const FilePath& dest_file_path, |
bool copy); |
+ // Deletes a directory and all entries under the directory. |
+ // |
+ // This method is called from Delete. It internally calls two following |
+ // virtual methods, |
+ // - (virtual) DeleteFile to delete files, and |
+ // - (virtual) DeleteSingleDirectory to delete empty directories after all |
+ // the files are deleted. |
+ PlatformFileError DeleteDirectoryRecursive( |
+ FileSystemOperationContext* context, |
+ const FilePath& file_path); |
+ |
+ FileSystemFileUtil* underlying_file_util() const { |
+ return underlying_file_util_.get(); |
+ } |
+ |
+ private: |
+ scoped_ptr<FileSystemFileUtil> underlying_file_util_; |
+ |
DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); |
}; |
} // namespace fileapi |
-#endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
+#endif // WEBKIT_FILEAPI_FILE_UTIL_H_ |