summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
authordmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 23:52:21 +0000
committerdmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 23:52:21 +0000
commit0e02bfb77e1c726c9ab94b3eddc390baff45ed29 (patch)
tree47e4eb5c48c8d58cbfd92fdc78df837d01b7d439 /webkit/fileapi
parentbf144dca2ce7f7f8da2aec0f7e5e9ac0de405de3 (diff)
downloadchromium_src-0e02bfb77e1c726c9ab94b3eddc390baff45ed29.zip
chromium_src-0e02bfb77e1c726c9ab94b3eddc390baff45ed29.tar.gz
chromium_src-0e02bfb77e1c726c9ab94b3eddc390baff45ed29.tar.bz2
Virtualize file_util calls from FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy.
It refactors the TODO issue at http://codereview.chromium.org/6604020/ . BUG=74841 TEST=none Review URL: http://codereview.chromium.org/6625031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77375 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/file_system_file_util.cc138
-rw-r--r--webkit/fileapi/file_system_file_util.h21
2 files changed, 96 insertions, 63 deletions
diff --git a/webkit/fileapi/file_system_file_util.cc b/webkit/fileapi/file_system_file_util.cc
index c5e8fef..8c11c48 100644
--- a/webkit/fileapi/file_system_file_util.cc
+++ b/webkit/fileapi/file_system_file_util.cc
@@ -6,65 +6,6 @@
#include "base/file_util_proxy.h"
-// 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).
-// TODO(ericu, dmikurube): This method won't work with obfuscation and quota
-// since all (file_util::) operations should consider obfuscation and quota.
-// We will need to virtualize all these calls. We should do that by making this
-// method a non-virtual member of FileSystemFileUtil, but changing all of its
-// file_util calls to be FileSystemFileUtil calls. That way when we override
-// them for obfuscation or quota, it'll just work.
-static base::PlatformFileError PerformCommonCheckAndPreparationForMoveAndCopy(
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
- // Exits earlier if the source path does not exist.
- if (!file_util::PathExists(src_file_path))
- return base::PLATFORM_FILE_ERROR_NOT_FOUND;
-
- // The parent of the |dest_file_path| does not exist.
- if (!file_util::DirectoryExists(dest_file_path.DirName()))
- return base::PLATFORM_FILE_ERROR_NOT_FOUND;
-
- // It is an error to try to copy/move an entry into its child.
- if (src_file_path.IsParent(dest_file_path))
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
-
- // Now it is ok to return if the |dest_file_path| does not exist.
- if (!file_util::PathExists(dest_file_path))
- return base::PLATFORM_FILE_OK;
-
- // |src_file_path| exists and is a directory.
- // |dest_file_path| exists and is a file.
- bool src_is_directory = file_util::DirectoryExists(src_file_path);
- bool dest_is_directory = file_util::DirectoryExists(dest_file_path);
- if (src_is_directory && !dest_is_directory)
- return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
-
- // |src_file_path| exists and is a file.
- // |dest_file_path| exists and is a directory.
- if (!src_is_directory && dest_is_directory)
- return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
-
- // It is an error to copy/move an entry into the same path.
- if (src_file_path.value() == dest_file_path.value())
- return base::PLATFORM_FILE_ERROR_EXISTS;
-
- if (dest_is_directory) {
- // It is an error to copy/move an entry to a non-empty directory.
- // Otherwise the copy/move attempt must overwrite the destination, but
- // the file_util's Copy or Move method doesn't perform overwrite
- // on all platforms, so we delete the destination directory here.
- // TODO(kinuko): may be better to change the file_util::{Copy,Move}.
- if (!file_util::Delete(dest_file_path, false /* recursive */)) {
- if (!file_util::IsDirectoryEmpty(dest_file_path))
- return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
- return base::PLATFORM_FILE_ERROR_FAILED;
- }
- }
- return base::PLATFORM_FILE_OK;
-}
-
namespace fileapi {
FileSystemFileUtil* FileSystemFileUtil::GetInstance() {
@@ -177,13 +118,13 @@ PlatformFileError FileSystemFileUtil::CreateDirectory(
}
PlatformFileError FileSystemFileUtil::Copy(
- FileSystemOperationContext* unused,
+ FileSystemOperationContext* context,
const FilePath& src_file_path,
const FilePath& dest_file_path) {
PlatformFileError error_code;
error_code =
PerformCommonCheckAndPreparationForMoveAndCopy(
- src_file_path, dest_file_path);
+ context, src_file_path, dest_file_path);
if (error_code != base::PLATFORM_FILE_OK)
return error_code;
if (!file_util::CopyDirectory(src_file_path, dest_file_path,
@@ -193,13 +134,13 @@ PlatformFileError FileSystemFileUtil::Copy(
}
PlatformFileError FileSystemFileUtil::Move(
- FileSystemOperationContext* unused,
+ FileSystemOperationContext* context,
const FilePath& src_file_path,
const FilePath& dest_file_path) {
PlatformFileError error_code;
error_code =
PerformCommonCheckAndPreparationForMoveAndCopy(
- src_file_path, dest_file_path);
+ context, src_file_path, dest_file_path);
if (error_code != base::PLATFORM_FILE_OK)
return error_code;
if (!file_util::Move(src_file_path, dest_file_path))
@@ -254,4 +195,75 @@ PlatformFileError FileSystemFileUtil::Truncate(
return error_code;
}
+PlatformFileError
+FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy(
+ FileSystemOperationContext* context,
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path) {
+ // Exits earlier if the source path does not exist.
+ if (!PathExists(context, src_file_path))
+ return base::PLATFORM_FILE_ERROR_NOT_FOUND;
+
+ // The parent of the |dest_file_path| does not exist.
+ if (!DirectoryExists(context, dest_file_path.DirName()))
+ return base::PLATFORM_FILE_ERROR_NOT_FOUND;
+
+ // It is an error to try to copy/move an entry into its child.
+ if (src_file_path.IsParent(dest_file_path))
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+
+ // Now it is ok to return if the |dest_file_path| does not exist.
+ if (!PathExists(context, dest_file_path))
+ return base::PLATFORM_FILE_OK;
+
+ // |src_file_path| exists and is a directory.
+ // |dest_file_path| exists and is a file.
+ bool src_is_directory = DirectoryExists(context, src_file_path);
+ bool dest_is_directory = DirectoryExists(context, dest_file_path);
+ if (src_is_directory && !dest_is_directory)
+ return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
+
+ // |src_file_path| exists and is a file.
+ // |dest_file_path| exists and is a directory.
+ if (!src_is_directory && dest_is_directory)
+ return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
+
+ // It is an error to copy/move an entry into the same path.
+ if (src_file_path.value() == dest_file_path.value())
+ return base::PLATFORM_FILE_ERROR_EXISTS;
+
+ if (dest_is_directory) {
+ // It is an error to copy/move an entry to a non-empty directory.
+ // Otherwise the copy/move attempt must overwrite the destination, but
+ // the file_util's Copy or Move method doesn't perform overwrite
+ // on all platforms, so we delete the destination directory here.
+ // TODO(kinuko): may be better to change the file_util::{Copy,Move}.
+ if (base::PLATFORM_FILE_OK !=
+ Delete(context, dest_file_path, false /* recursive */)) {
+ if (!IsDirectoryEmpty(context, dest_file_path))
+ return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ }
+ return base::PLATFORM_FILE_OK;
+}
+
+bool FileSystemFileUtil::PathExists(
+ FileSystemOperationContext* unused,
+ const FilePath& file_path) {
+ return file_util::PathExists(file_path);
+}
+
+bool FileSystemFileUtil::DirectoryExists(
+ FileSystemOperationContext* unused,
+ const FilePath& file_path) {
+ return file_util::DirectoryExists(file_path);
+}
+
+bool FileSystemFileUtil::IsDirectoryEmpty(
+ FileSystemOperationContext* unused,
+ const FilePath& file_path) {
+ return file_util::IsDirectoryEmpty(file_path);
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_file_util.h b/webkit/fileapi/file_system_file_util.h
index 9b02a44..996c9f78 100644
--- a/webkit/fileapi/file_system_file_util.h
+++ b/webkit/fileapi/file_system_file_util.h
@@ -127,6 +127,27 @@ class FileSystemFileUtil {
protected:
FileSystemFileUtil() { }
+
+ // 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,
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path);
+
+ virtual bool PathExists(
+ FileSystemOperationContext* unused,
+ const FilePath& file_path);
+
+ virtual bool DirectoryExists(
+ FileSystemOperationContext* unused,
+ const FilePath& file_path);
+
+ virtual bool IsDirectoryEmpty(
+ FileSystemOperationContext* unused,
+ const FilePath& file_path);
+
friend struct DefaultSingletonTraits<FileSystemFileUtil>;
DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil);
};