Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: webkit/fileapi/local_file_util.cc

Issue 7470037: [Refactor] to rename and re-layer the file_util stack layers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/local_file_util.cc
diff --git a/webkit/fileapi/local_file_system_file_util.cc b/webkit/fileapi/local_file_util.cc
similarity index 78%
rename from webkit/fileapi/local_file_system_file_util.cc
rename to webkit/fileapi/local_file_util.cc
index ca028e42cb11499d7c46fb51d58a6e2e0e80d610..9b3d72891d4438b21cf029d4207cf2a6a34d0ca0 100644
--- a/webkit/fileapi/local_file_system_file_util.cc
+++ b/webkit/fileapi/local_file_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "webkit/fileapi/local_file_system_file_util.h"
+#include "webkit/fileapi/local_file_util.h"
#include "base/file_util_proxy.h"
#include "googleurl/src/gurl.h"
@@ -14,15 +14,52 @@
namespace fileapi {
-LocalFileSystemFileUtil::LocalFileSystemFileUtil(
- FileSystemFileUtil* underlying_file_util)
- : underlying_file_util_(underlying_file_util) {
+class LocalFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator {
+ public:
+ LocalFileEnumerator(const FilePath& platform_root_path,
+ const FilePath& virtual_root_path,
+ bool recursive,
+ file_util::FileEnumerator::FileType file_type)
+ : file_enum_(platform_root_path, recursive, file_type),
+ platform_root_path_(platform_root_path),
+ virtual_root_path_(virtual_root_path) {
+ }
+
+ ~LocalFileEnumerator() {}
+
+ virtual FilePath Next();
+ virtual bool IsDirectory();
+
+ private:
+ file_util::FileEnumerator file_enum_;
+ FilePath platform_root_path_;
+ FilePath virtual_root_path_;
+};
+
+FilePath LocalFileEnumerator::Next() {
+ FilePath next = file_enum_.Next();
+ if (next.empty())
+ return next;
+
+ FilePath path;
+ platform_root_path_.AppendRelativePath(next, &path);
+ return virtual_root_path_.Append(path);
+}
+
+bool LocalFileEnumerator::IsDirectory() {
+ file_util::FileEnumerator::FindInfo file_util_info;
+ file_enum_.GetFindInfo(&file_util_info);
+ return file_util::FileEnumerator::IsDirectory(file_util_info);
}
-LocalFileSystemFileUtil::~LocalFileSystemFileUtil() {
+LocalFileUtil::LocalFileUtil(FileSystemFileUtil* underlying_file_util)
+ : FileSystemFileUtil(underlying_file_util) {
}
-PlatformFileError LocalFileSystemFileUtil::CreateOrOpen(
+LocalFileUtil::~LocalFileUtil() {
+}
+
+PlatformFileError LocalFileUtil::CreateOrOpen(
FileSystemOperationContext* context,
const FilePath& file_path, int file_flags,
PlatformFile* file_handle, bool* created) {
@@ -31,11 +68,11 @@ PlatformFileError LocalFileSystemFileUtil::CreateOrOpen(
file_path);
if (local_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->CreateOrOpen(
+ return underlying_file_util()->CreateOrOpen(
context, local_path, file_flags, file_handle, created);
}
-PlatformFileError LocalFileSystemFileUtil::EnsureFileExists(
+PlatformFileError LocalFileUtil::EnsureFileExists(
FileSystemOperationContext* context,
const FilePath& file_path,
bool* created) {
@@ -44,25 +81,25 @@ PlatformFileError LocalFileSystemFileUtil::EnsureFileExists(
file_path);
if (local_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->EnsureFileExists(
+ return underlying_file_util()->EnsureFileExists(
context, local_path, created);
}
-PlatformFileError LocalFileSystemFileUtil::GetLocalFilePath(
+PlatformFileError LocalFileUtil::CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
- FilePath* local_path) {
- FilePath path =
+ const FilePath& file_path,
+ bool exclusive,
+ bool recursive) {
+ FilePath local_path =
GetLocalPath(context, context->src_origin_url(), context->src_type(),
- virtual_path);
- if (path.empty())
- return base::PLATFORM_FILE_ERROR_NOT_FOUND;
-
- *local_path = path;
- return base::PLATFORM_FILE_OK;
+ file_path);
+ if (local_path.empty())
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ return underlying_file_util()->CreateDirectory(
+ context, local_path, exclusive, recursive);
}
-PlatformFileError LocalFileSystemFileUtil::GetFileInfo(
+PlatformFileError LocalFileUtil::GetFileInfo(
FileSystemOperationContext* context,
const FilePath& file_path,
base::PlatformFileInfo* file_info,
@@ -72,11 +109,11 @@ PlatformFileError LocalFileSystemFileUtil::GetFileInfo(
file_path);
if (local_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->GetFileInfo(
+ return underlying_file_util()->GetFileInfo(
context, local_path, file_info, platform_file_path);
}
-PlatformFileError LocalFileSystemFileUtil::ReadDirectory(
+PlatformFileError LocalFileUtil::ReadDirectory(
FileSystemOperationContext* context,
const FilePath& file_path,
std::vector<base::FileUtilProxy::Entry>* entries) {
@@ -86,85 +123,40 @@ PlatformFileError LocalFileSystemFileUtil::ReadDirectory(
file_path);
if (local_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->ReadDirectory(
+ return underlying_file_util()->ReadDirectory(
context, local_path, entries);
}
-PlatformFileError LocalFileSystemFileUtil::CreateDirectory(
+FileSystemFileUtil::AbstractFileEnumerator* LocalFileUtil::CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& file_path,
- bool exclusive,
- bool recursive) {
+ const FilePath& root_path) {
FilePath local_path =
GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
+ root_path);
if (local_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->CreateDirectory(
- context, local_path, exclusive, recursive);
-}
-
-PlatformFileError LocalFileSystemFileUtil::CopyOrMoveFile(
- FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
- bool copy) {
- // TODO(ericu): If they share a root URL, this could be optimized.
- FilePath local_src_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- src_file_path);
- if (local_src_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- FilePath local_dest_path =
- GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
- dest_file_path);
- if (local_dest_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->CopyOrMoveFile(
- context, local_src_path, local_dest_path, copy);
-}
-
-// TODO(dmikurube): Make it independent from CopyOrMoveFile.
-PlatformFileError LocalFileSystemFileUtil::CopyInForeignFile(
- FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
- if (src_file_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- FilePath local_dest_path =
- GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
- dest_file_path);
- if (local_dest_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->CopyOrMoveFile(
- context, src_file_path, local_dest_path, true);
+ return new EmptyFileEnumerator();
+ return new LocalFileEnumerator(
+ local_path, root_path, true,
+ static_cast<file_util::FileEnumerator::FileType>(
+ file_util::FileEnumerator::FILES |
+ file_util::FileEnumerator::DIRECTORIES));
}
-PlatformFileError LocalFileSystemFileUtil::DeleteFile(
+PlatformFileError LocalFileUtil::GetLocalFilePath(
FileSystemOperationContext* context,
- const FilePath& file_path) {
- FilePath local_path =
+ const FilePath& virtual_path,
+ FilePath* local_path) {
+ FilePath path =
GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->DeleteFile(
- context, local_path);
-}
+ virtual_path);
+ if (path.empty())
+ return base::PLATFORM_FILE_ERROR_NOT_FOUND;
-PlatformFileError LocalFileSystemFileUtil::DeleteSingleDirectory(
- FileSystemOperationContext* context,
- const FilePath& file_path) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
- return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->DeleteSingleDirectory(
- context, local_path);
+ *local_path = path;
+ return base::PLATFORM_FILE_OK;
}
-PlatformFileError LocalFileSystemFileUtil::Touch(
+PlatformFileError LocalFileUtil::Touch(
FileSystemOperationContext* context,
const FilePath& file_path,
const base::Time& last_access_time,
@@ -174,11 +166,11 @@ PlatformFileError LocalFileSystemFileUtil::Touch(
file_path);
if (local_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->Touch(
+ return underlying_file_util()->Touch(
context, local_path, last_access_time, last_modified_time);
}
-PlatformFileError LocalFileSystemFileUtil::Truncate(
+PlatformFileError LocalFileUtil::Truncate(
FileSystemOperationContext* context,
const FilePath& file_path,
int64 length) {
@@ -187,11 +179,11 @@ PlatformFileError LocalFileSystemFileUtil::Truncate(
file_path);
if (local_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- return underlying_file_util_->Truncate(
+ return underlying_file_util()->Truncate(
context, local_path, length);
}
-bool LocalFileSystemFileUtil::PathExists(
+bool LocalFileUtil::PathExists(
FileSystemOperationContext* context,
const FilePath& file_path) {
FilePath local_path =
@@ -199,11 +191,11 @@ bool LocalFileSystemFileUtil::PathExists(
file_path);
if (local_path.empty())
return false;
- return underlying_file_util_->PathExists(
+ return underlying_file_util()->PathExists(
context, local_path);
}
-bool LocalFileSystemFileUtil::DirectoryExists(
+bool LocalFileUtil::DirectoryExists(
FileSystemOperationContext* context,
const FilePath& file_path) {
FilePath local_path =
@@ -211,11 +203,11 @@ bool LocalFileSystemFileUtil::DirectoryExists(
file_path);
if (local_path.empty())
return false;
- return underlying_file_util_->DirectoryExists(
+ return underlying_file_util()->DirectoryExists(
context, local_path);
}
-bool LocalFileSystemFileUtil::IsDirectoryEmpty(
+bool LocalFileUtil::IsDirectoryEmpty(
FileSystemOperationContext* context,
const FilePath& file_path) {
FilePath local_path =
@@ -223,66 +215,71 @@ bool LocalFileSystemFileUtil::IsDirectoryEmpty(
file_path);
if (local_path.empty())
return true;
- return underlying_file_util_->IsDirectoryEmpty(
+ return underlying_file_util()->IsDirectoryEmpty(
context, local_path);
}
-class LocalFileSystemFileEnumerator
- : public FileSystemFileUtil::AbstractFileEnumerator {
- public:
- LocalFileSystemFileEnumerator(const FilePath& platform_root_path,
- const FilePath& virtual_root_path,
- bool recursive,
- file_util::FileEnumerator::FileType file_type)
- : file_enum_(platform_root_path, recursive, file_type),
- platform_root_path_(platform_root_path),
- virtual_root_path_(virtual_root_path) {
- }
-
- ~LocalFileSystemFileEnumerator() {}
-
- virtual FilePath Next();
- virtual bool IsDirectory();
-
- private:
- file_util::FileEnumerator file_enum_;
- FilePath platform_root_path_;
- FilePath virtual_root_path_;
-};
-
-FilePath LocalFileSystemFileEnumerator::Next() {
- FilePath next = file_enum_.Next();
- if (next.empty())
- return next;
+PlatformFileError LocalFileUtil::CopyOrMoveFile(
+ FileSystemOperationContext* context,
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path,
+ bool copy) {
+ // TODO(ericu): If they share a root URL, this could be optimized.
+ FilePath local_src_path =
+ GetLocalPath(context, context->src_origin_url(), context->src_type(),
+ src_file_path);
+ if (local_src_path.empty())
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ FilePath local_dest_path =
+ GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
+ dest_file_path);
+ if (local_dest_path.empty())
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ return underlying_file_util()->CopyOrMoveFile(
+ context, local_src_path, local_dest_path, copy);
+}
- FilePath path;
- platform_root_path_.AppendRelativePath(next, &path);
- return virtual_root_path_.Append(path);
+// TODO(dmikurube): Make it independent from CopyOrMoveFile.
+PlatformFileError LocalFileUtil::CopyInForeignFile(
+ FileSystemOperationContext* context,
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path) {
+ if (src_file_path.empty())
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ FilePath local_dest_path =
+ GetLocalPath(context, context->dest_origin_url(), context->dest_type(),
+ dest_file_path);
+ if (local_dest_path.empty())
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ return underlying_file_util()->CopyOrMoveFile(
+ context, src_file_path, local_dest_path, true);
}
-bool LocalFileSystemFileEnumerator::IsDirectory() {
- file_util::FileEnumerator::FindInfo file_util_info;
- file_enum_.GetFindInfo(&file_util_info);
- return file_util::FileEnumerator::IsDirectory(file_util_info);
+PlatformFileError LocalFileUtil::DeleteFile(
+ FileSystemOperationContext* context,
+ const FilePath& file_path) {
+ FilePath local_path =
+ GetLocalPath(context, context->src_origin_url(), context->src_type(),
+ file_path);
+ if (local_path.empty())
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ return underlying_file_util()->DeleteFile(
+ context, local_path);
}
-FileSystemFileUtil::AbstractFileEnumerator*
-LocalFileSystemFileUtil::CreateFileEnumerator(
+PlatformFileError LocalFileUtil::DeleteSingleDirectory(
FileSystemOperationContext* context,
- const FilePath& root_path) {
+ const FilePath& file_path) {
FilePath local_path =
GetLocalPath(context, context->src_origin_url(), context->src_type(),
- root_path);
+ file_path);
if (local_path.empty())
- return new EmptyFileEnumerator();
- return new LocalFileSystemFileEnumerator(
- local_path, root_path, true,
- static_cast<file_util::FileEnumerator::FileType>(
- file_util::FileEnumerator::FILES |
- file_util::FileEnumerator::DIRECTORIES));
+ return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
+ return underlying_file_util()->DeleteSingleDirectory(
+ context, local_path);
}
-FilePath LocalFileSystemFileUtil::GetLocalPath(
+FilePath LocalFileUtil::GetLocalPath(
FileSystemOperationContext* context,
const GURL& origin_url,
FileSystemType type,

Powered by Google App Engine
This is Rietveld 408576698