| 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 8372784206bc6f9fa5673e031bf5beb51dfa1d2d..83a04c8538d932dceb24fd8f75f24f763f4718ec 100644
|
| --- a/webkit/fileapi/file_system_file_util.h
|
| +++ b/webkit/fileapi/file_system_file_util.h
|
| @@ -5,20 +5,11 @@
|
| #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
|
| #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
|
|
|
| -#include <vector>
|
| -
|
| -#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;
|
| }
|
|
|
| @@ -48,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 int64 Size() = 0;
|
| + 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() OVERRIDE { return FilePath(); }
|
| + virtual int64 Size() OVERRIDE { return 0; }
|
| + virtual bool IsDirectory() OVERRIDE { 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);
|
| + 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:
|
| @@ -171,23 +105,76 @@ 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.
|
| + // 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.
|
| //
|
| - // This method is called from DeleteDirectoryRecursive and Delete (both are
|
| - // non-virtual).
|
| - virtual PlatformFileError DeleteSingleDirectory(
|
| - FileSystemOperationContext* unused,
|
| - const FilePath& file_path);
|
| + // The supplied context must remain valid at least lifetime of the enumerator
|
| + // instance.
|
| + 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.
|
| // If the file doesn't exist, this fails with PLATFORM_FILE_ERROR_NOT_FOUND.
|
| @@ -206,63 +193,58 @@ 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 int64 Size() = 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() OVERRIDE { return FilePath(); }
|
| - virtual int64 Size() OVERRIDE { return 0; }
|
| - virtual bool IsDirectory() OVERRIDE { 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.
|
| + // Deletes a single file.
|
| + // It assumes the given path points a file.
|
| //
|
| - // The supplied context must remain valid at least lifetime of the enumerator
|
| - // instance.
|
| - virtual AbstractFileEnumerator* CreateFileEnumerator(
|
| + // This method is called from DeleteDirectoryRecursive and Delete (both are
|
| + // non-virtual).
|
| + virtual PlatformFileError DeleteFile(
|
| FileSystemOperationContext* context,
|
| - const FilePath& root_path);
|
| + 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:
|
| + FileSystemFileUtil();
|
| + explicit FileSystemFileUtil(FileSystemFileUtil* underlying_file_util);
|
| +
|
| // 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);
|
|
|
| @@ -286,6 +268,24 @@ 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);
|
| };
|
|
|
|
|