summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-26 11:53:50 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-26 11:53:50 +0000
commit08f8feb39b2c8801dd39a1531fb5958644162e6d (patch)
tree8353404b39167b55fde8adb6c3d0b24b4fccdfee
parentf516f4e5d8eff9285234cf18a62108d18229367c (diff)
downloadchromium_src-08f8feb39b2c8801dd39a1531fb5958644162e6d.zip
chromium_src-08f8feb39b2c8801dd39a1531fb5958644162e6d.tar.gz
chromium_src-08f8feb39b2c8801dd39a1531fb5958644162e6d.tar.bz2
Move src/dest info out of FileSystemOperationContext
Current FileSystemOperationContext has both src and dest path file info in it but this is making the code for cross-FileUtil operations way complex. This patch removes src/dest information from FileSystemOperationContext and instead: - introduce new FileSystemPath class, which represents a file path information in a filesystem - replace all the FilePath args in FileSystemFileUtil with FileSystemPath The resulting code still has some ugly part, and if we get rid of cross-FU operations from each FU code eventually we may end up converting FileSystemPath back to FilePath, but I think this change is not far from the way we want to go. BUG=114732, 110121 TEST=existing tests Review URL: http://codereview.chromium.org/9413009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123689 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job_unittest.cc34
-rw-r--r--webkit/fileapi/file_system_file_util.cc277
-rw-r--r--webkit/fileapi/file_system_file_util.h99
-rw-r--r--webkit/fileapi/file_system_file_util_unittest.cc26
-rw-r--r--webkit/fileapi/file_system_mount_point_provider.h2
-rw-r--r--webkit/fileapi/file_system_operation.cc362
-rw-r--r--webkit/fileapi/file_system_operation.h115
-rw-r--r--webkit/fileapi/file_system_operation_context.cc26
-rw-r--r--webkit/fileapi/file_system_operation_context.h73
-rw-r--r--webkit/fileapi/file_system_operation_unittest.cc3
-rw-r--r--webkit/fileapi/file_system_path.cc40
-rw-r--r--webkit/fileapi/file_system_path.h94
-rw-r--r--webkit/fileapi/file_system_quota_client_unittest.cc40
-rw-r--r--webkit/fileapi/file_system_test_helper.cc21
-rw-r--r--webkit/fileapi/file_system_test_helper.h9
-rw-r--r--webkit/fileapi/file_system_url_request_job_unittest.cc20
-rw-r--r--webkit/fileapi/file_writer_delegate.cc37
-rw-r--r--webkit/fileapi/file_writer_delegate.h3
-rw-r--r--webkit/fileapi/file_writer_delegate_unittest.cc2
-rw-r--r--webkit/fileapi/local_file_util.cc168
-rw-r--r--webkit/fileapi/local_file_util.h51
-rw-r--r--webkit/fileapi/local_file_util_unittest.cc4
-rw-r--r--webkit/fileapi/native_file_util.cc122
-rw-r--r--webkit/fileapi/native_file_util.h42
-rw-r--r--webkit/fileapi/obfuscated_file_util.cc414
-rw-r--r--webkit/fileapi/obfuscated_file_util.h83
-rw-r--r--webkit/fileapi/obfuscated_file_util_unittest.cc233
-rw-r--r--webkit/fileapi/quota_file_util.cc41
-rw-r--r--webkit/fileapi/quota_file_util.h10
-rw-r--r--webkit/fileapi/quota_file_util_unittest.cc4
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc7
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider_unittest.cc47
-rw-r--r--webkit/fileapi/webkit_fileapi.gypi2
33 files changed, 1247 insertions, 1264 deletions
diff --git a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
index a329092..f0459ba 100644
--- a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc
@@ -32,6 +32,7 @@
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_path.h"
#include "webkit/fileapi/mock_file_system_options.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/mock_special_storage_policy.h"
@@ -110,45 +111,50 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
TestRequestHelper(url, false);
}
- FileSystemOperationContext* NewOperationContext(const FilePath& path) {
- FileSystemOperationContext* context(new FileSystemOperationContext(
- file_system_context_, file_util()));
+ FileSystemPath CreatePath(const FilePath& file_path) {
+ return FileSystemPath(GURL("http://remote"),
+ fileapi::kFileSystemTypeTemporary,
+ file_path,
+ file_util());
+ }
- context->set_src_origin_url(GURL("http://remote"));
- context->set_src_type(fileapi::kFileSystemTypeTemporary);
+ FileSystemOperationContext* NewOperationContext() {
+ FileSystemOperationContext* context(new FileSystemOperationContext(
+ file_system_context_));
context->set_allowed_bytes_growth(1024);
return context;
}
- void CreateDirectory(const base::StringPiece dir_name) {
+ void CreateDirectory(const base::StringPiece& dir_name) {
FilePath path = FilePath().AppendASCII(dir_name);
- scoped_ptr<FileSystemOperationContext> context(NewOperationContext(path));
+ scoped_ptr<FileSystemOperationContext> context(NewOperationContext());
ASSERT_EQ(base::PLATFORM_FILE_OK, file_util()->CreateDirectory(
context.get(),
- path,
+ CreatePath(path),
false /* exclusive */,
false /* recursive */));
}
void EnsureFileExists(const base::StringPiece file_name) {
FilePath path = FilePath().AppendASCII(file_name);
- scoped_ptr<FileSystemOperationContext> context(NewOperationContext(path));
+ scoped_ptr<FileSystemOperationContext> context(NewOperationContext());
ASSERT_EQ(base::PLATFORM_FILE_OK, file_util()->EnsureFileExists(
- context.get(), path, NULL));
+ context.get(), CreatePath(path), NULL));
}
void TruncateFile(const base::StringPiece file_name, int64 length) {
FilePath path = FilePath().AppendASCII(file_name);
- scoped_ptr<FileSystemOperationContext> context(NewOperationContext(path));
+ scoped_ptr<FileSystemOperationContext> context(NewOperationContext());
ASSERT_EQ(base::PLATFORM_FILE_OK, file_util()->Truncate(
- context.get(), path, length));
+ context.get(), CreatePath(path), length));
}
PlatformFileError GetFileInfo(const FilePath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_file_path) {
- scoped_ptr<FileSystemOperationContext> context(NewOperationContext(path));
- return file_util()->GetFileInfo(context.get(), path,
+ scoped_ptr<FileSystemOperationContext> context(NewOperationContext());
+ return file_util()->GetFileInfo(context.get(),
+ CreatePath(path),
file_info, platform_file_path);
}
diff --git a/webkit/fileapi/file_system_file_util.cc b/webkit/fileapi/file_system_file_util.cc
index 5daa6a6..9156075 100644
--- a/webkit/fileapi/file_system_file_util.cc
+++ b/webkit/fileapi/file_system_file_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -7,6 +7,7 @@
#include <stack>
#include "base/memory/scoped_ptr.h"
+#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation_context.h"
namespace fileapi {
@@ -15,13 +16,14 @@ namespace {
// This assumes that the root exists.
bool ParentExists(FileSystemOperationContext* context,
- FileSystemFileUtil* file_util, const FilePath& file_path) {
- // If file_path is in the root, file_path.DirName() will be ".",
+ const FileSystemPath& path) {
+ // If path is in the root, path.DirName() will be ".",
// since we use paths with no leading '/'.
- FilePath parent = file_path.DirName();
+ FilePath parent = path.internal_path().DirName();
if (parent == FilePath(FILE_PATH_LITERAL(".")))
return true;
- return file_util->DirectoryExists(context, parent);
+ return path.file_util()->DirectoryExists(
+ context, path.WithInternalPath(parent));
}
} // namespace
@@ -38,62 +40,62 @@ FileSystemFileUtil::~FileSystemFileUtil() {
PlatformFileError FileSystemFileUtil::Copy(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path) {
PlatformFileError error_code;
error_code =
PerformCommonCheckAndPreparationForMoveAndCopy(
- context, src_file_path, dest_file_path);
+ context, src_path, dest_path);
if (error_code != base::PLATFORM_FILE_OK)
return error_code;
- if (DirectoryExists(context, src_file_path))
- return CopyOrMoveDirectory(context, src_file_path, dest_file_path,
+ if (DirectoryExists(context, src_path))
+ return CopyOrMoveDirectory(context, src_path, dest_path,
true /* copy */);
- return CopyOrMoveFileHelper(context, src_file_path, dest_file_path,
+ return CopyOrMoveFileHelper(context, src_path, dest_path,
true /* copy */);
}
PlatformFileError FileSystemFileUtil::Move(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path) {
PlatformFileError error_code;
error_code =
PerformCommonCheckAndPreparationForMoveAndCopy(
- context, src_file_path, dest_file_path);
+ context, src_path, dest_path);
if (error_code != base::PLATFORM_FILE_OK)
return error_code;
// TODO(dmikurube): ReplaceFile if in the same domain and filesystem type.
- if (DirectoryExists(context, src_file_path))
- return CopyOrMoveDirectory(context, src_file_path, dest_file_path,
+ if (DirectoryExists(context, src_path))
+ return CopyOrMoveDirectory(context, src_path, dest_path,
false /* copy */);
- return CopyOrMoveFileHelper(context, src_file_path, dest_file_path,
+ return CopyOrMoveFileHelper(context, src_path, dest_path,
false /* copy */);
}
PlatformFileError FileSystemFileUtil::Delete(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool recursive) {
- if (DirectoryExists(context, file_path)) {
+ if (DirectoryExists(context, path)) {
if (!recursive)
- return DeleteSingleDirectory(context, file_path);
+ return DeleteSingleDirectory(context, path);
else
- return DeleteDirectoryRecursive(context, file_path);
+ return DeleteDirectoryRecursive(context, path);
} else {
- return DeleteFile(context, file_path);
+ return DeleteFile(context, path);
}
}
PlatformFileError FileSystemFileUtil::CreateOrOpen(
FileSystemOperationContext* context,
- const FilePath& file_path, int file_flags,
+ const FileSystemPath& path, int file_flags,
PlatformFile* file_handle, bool* created) {
if (underlying_file_util_.get()) {
return underlying_file_util_->CreateOrOpen(
- context, file_path, file_flags, file_handle, created);
+ context, path, file_flags, file_handle, created);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -113,10 +115,10 @@ PlatformFileError FileSystemFileUtil::Close(
PlatformFileError FileSystemFileUtil::EnsureFileExists(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool* created) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->EnsureFileExists(context, file_path, created);
+ return underlying_file_util_->EnsureFileExists(context, path, created);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -125,12 +127,12 @@ PlatformFileError FileSystemFileUtil::EnsureFileExists(
PlatformFileError FileSystemFileUtil::CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool exclusive,
bool recursive) {
if (underlying_file_util_.get()) {
return underlying_file_util_->CreateDirectory(
- context, file_path, exclusive, recursive);
+ context, path, exclusive, recursive);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -139,12 +141,12 @@ PlatformFileError FileSystemFileUtil::CreateDirectory(
PlatformFileError FileSystemFileUtil::GetFileInfo(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_file_path) {
if (underlying_file_util_.get()) {
return underlying_file_util_->GetFileInfo(
- context, file_path, file_info, platform_file_path);
+ context, path, file_info, platform_file_path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -153,10 +155,10 @@ PlatformFileError FileSystemFileUtil::GetFileInfo(
PlatformFileError FileSystemFileUtil::ReadDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->ReadDirectory(context, file_path, entries);
+ return underlying_file_util_->ReadDirectory(context, path, entries);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -166,7 +168,7 @@ PlatformFileError FileSystemFileUtil::ReadDirectory(
FileSystemFileUtil::AbstractFileEnumerator*
FileSystemFileUtil::CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& root_path) {
+ const FileSystemPath& root_path) {
if (underlying_file_util_.get()) {
return underlying_file_util_->CreateFileEnumerator(context, root_path);
}
@@ -177,11 +179,11 @@ FileSystemFileUtil::CreateFileEnumerator(
PlatformFileError FileSystemFileUtil::GetLocalFilePath(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
- FilePath* local_path) {
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) {
if (underlying_file_util_.get()) {
return underlying_file_util_->GetLocalFilePath(
- context, virtual_path, local_path);
+ context, file_system_path, local_file_path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -190,12 +192,12 @@ PlatformFileError FileSystemFileUtil::GetLocalFilePath(
PlatformFileError FileSystemFileUtil::Touch(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
if (underlying_file_util_.get()) {
return underlying_file_util_->Touch(
- context, file_path, last_access_time, last_modified_time);
+ context, path, last_access_time, last_modified_time);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -204,10 +206,10 @@ PlatformFileError FileSystemFileUtil::Touch(
PlatformFileError FileSystemFileUtil::Truncate(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
int64 length) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->Truncate(context, file_path, length);
+ return underlying_file_util_->Truncate(context, path, length);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -217,9 +219,9 @@ PlatformFileError FileSystemFileUtil::Truncate(
bool FileSystemFileUtil::PathExists(
FileSystemOperationContext* context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->PathExists(context, file_path);
+ return underlying_file_util_->PathExists(context, path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -228,9 +230,9 @@ bool FileSystemFileUtil::PathExists(
bool FileSystemFileUtil::DirectoryExists(
FileSystemOperationContext* context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->DirectoryExists(context, file_path);
+ return underlying_file_util_->DirectoryExists(context, path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -239,9 +241,9 @@ bool FileSystemFileUtil::DirectoryExists(
bool FileSystemFileUtil::IsDirectoryEmpty(
FileSystemOperationContext* context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->IsDirectoryEmpty(context, file_path);
+ return underlying_file_util_->IsDirectoryEmpty(context, path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -250,12 +252,12 @@ bool FileSystemFileUtil::IsDirectoryEmpty(
PlatformFileError FileSystemFileUtil::CopyOrMoveFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) {
if (underlying_file_util_.get()) {
return underlying_file_util_->CopyOrMoveFile(
- context, src_file_path, dest_file_path, copy);
+ context, src_path, dest_path, copy);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -264,11 +266,11 @@ PlatformFileError FileSystemFileUtil::CopyOrMoveFile(
PlatformFileError FileSystemFileUtil::CopyInForeignFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) {
if (underlying_file_util_.get()) {
return underlying_file_util_->CopyInForeignFile(
- context, src_file_path, dest_file_path);
+ context, underlying_src_path, dest_path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -277,9 +279,9 @@ PlatformFileError FileSystemFileUtil::CopyInForeignFile(
PlatformFileError FileSystemFileUtil::DeleteFile(
FileSystemOperationContext* context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->DeleteFile(context, file_path);
+ return underlying_file_util_->DeleteFile(context, path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -288,9 +290,9 @@ PlatformFileError FileSystemFileUtil::DeleteFile(
PlatformFileError FileSystemFileUtil::DeleteSingleDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
if (underlying_file_util_.get()) {
- return underlying_file_util_->DeleteSingleDirectory(context, file_path);
+ return underlying_file_util_->DeleteSingleDirectory(context, path);
}
NOTREACHED() << "Subclasses must provide implementation if they have no"
<< "underlying_file_util";
@@ -300,59 +302,47 @@ PlatformFileError FileSystemFileUtil::DeleteSingleDirectory(
PlatformFileError
FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
- bool same_file_system =
- (context->src_origin_url() == context->dest_origin_url()) &&
- (context->src_type() == context->dest_type());
- FileSystemFileUtil* dest_util = context->dest_file_util();
- DCHECK(dest_util);
- scoped_ptr<FileSystemOperationContext> local_dest_context;
- FileSystemOperationContext* dest_context = NULL;
- if (same_file_system) {
- dest_context = context;
- DCHECK(context->src_file_util() == context->dest_file_util());
- } else {
- local_dest_context.reset(context->CreateInheritedContextForDest());
- // All the single-path virtual FSFU methods expect the context information
- // to be in the src_* variables, not the dest_* variables, so we have to
- // make a new context if we want to call them on the dest_file_path.
- dest_context = local_dest_context.get();
- }
-
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path) {
// Exits earlier if the source path does not exist.
- if (!PathExists(context, src_file_path))
+ if (!PathExists(context, src_path))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- // The parent of the |dest_file_path| does not exist.
- if (!ParentExists(dest_context, dest_util, dest_file_path))
+ // It is an error to copy/move an entry into the same path.
+ if (src_path == dest_path)
+ return base::PLATFORM_FILE_ERROR_EXISTS;
+
+ bool same_file_system =
+ (src_path.origin() == dest_path.origin()) &&
+ (src_path.type() == dest_path.type());
+ FileSystemFileUtil* dest_util = dest_path.file_util();
+ DCHECK(dest_util);
+
+ // The parent of the |dest_path| does not exist.
+ if (!ParentExists(context, dest_path))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
// It is an error to try to copy/move an entry into its child.
- if (same_file_system && src_file_path.IsParent(dest_file_path))
+ if (same_file_system && src_path.IsParent(dest_path))
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- // Now it is ok to return if the |dest_file_path| does not exist.
- if (!dest_util->PathExists(dest_context, dest_file_path))
+ // Now it is ok to return if the |dest_path| does not exist.
+ if (!dest_util->PathExists(context, dest_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);
+ // |src_path| exists and is a directory.
+ // |dest_path| exists and is a file.
+ bool src_is_directory = DirectoryExists(context, src_path);
bool dest_is_directory =
- dest_util->DirectoryExists(dest_context, dest_file_path);
+ dest_util->DirectoryExists(context, dest_path);
if (src_is_directory && !dest_is_directory)
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- // |src_file_path| exists and is a file.
- // |dest_file_path| exists and is a directory.
+ // |src_path| exists and is a file.
+ // |dest_path| exists and is a directory.
if (!src_is_directory && dest_is_directory)
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- // It is an error to copy/move an entry into the same path.
- if (same_file_system && (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
@@ -360,72 +350,65 @@ FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy(
// 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 !=
- dest_util->Delete(dest_context, dest_file_path,
- false /* recursive */)) {
- if (!dest_util->IsDirectoryEmpty(dest_context, dest_file_path))
+ dest_util->Delete(context, dest_path, false /* recursive */)) {
+ if (!dest_util->IsDirectoryEmpty(context, dest_path))
return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
return base::PLATFORM_FILE_ERROR_FAILED;
}
- // Reflect changes in usage back to the original context.
- if (!same_file_system)
- context->set_allowed_bytes_growth(dest_context->allowed_bytes_growth());
}
return base::PLATFORM_FILE_OK;
}
PlatformFileError FileSystemFileUtil::CopyOrMoveDirectory(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) {
- FileSystemFileUtil* dest_util = context->dest_file_util();
- // All the single-path virtual FSFU methods expect the context information to
- // be in the src_* variables, not the dest_* variables, so we have to make a
- // new context if we want to call them on the dest_file_path.
- scoped_ptr<FileSystemOperationContext> dest_context(
- context->CreateInheritedContextForDest());
+ FileSystemFileUtil* dest_util = dest_path.file_util();
// Re-check PerformCommonCheckAndPreparationForMoveAndCopy() by DCHECK.
- DCHECK(DirectoryExists(context, src_file_path));
- DCHECK(ParentExists(dest_context.get(), dest_util, dest_file_path));
- DCHECK(!dest_util->PathExists(dest_context.get(), dest_file_path));
- if ((context->src_origin_url() == context->dest_origin_url()) &&
- (context->src_type() == context->dest_type()))
- DCHECK(!src_file_path.IsParent(dest_file_path));
-
- if (!dest_util->DirectoryExists(dest_context.get(), dest_file_path)) {
- PlatformFileError error = dest_util->CreateDirectory(dest_context.get(),
- dest_file_path, false, false);
+ DCHECK(DirectoryExists(context, src_path));
+ DCHECK(ParentExists(context, dest_path));
+ DCHECK(!dest_util->PathExists(context, dest_path));
+ if ((src_path.origin() == dest_path.origin()) &&
+ (src_path.type() == dest_path.type()))
+ DCHECK(!src_path.IsParent(dest_path));
+
+ if (!dest_util->DirectoryExists(context, dest_path)) {
+ PlatformFileError error = dest_util->CreateDirectory(
+ context, dest_path, false, false);
if (error != base::PLATFORM_FILE_OK)
return error;
- // Reflect changes in usage back to the original context.
- context->set_allowed_bytes_growth(dest_context->allowed_bytes_growth());
}
scoped_ptr<AbstractFileEnumerator> file_enum(
- CreateFileEnumerator(context, src_file_path));
+ CreateFileEnumerator(context, src_path));
FilePath src_file_path_each;
while (!(src_file_path_each = file_enum->Next()).empty()) {
- FilePath dest_file_path_each(dest_file_path);
- src_file_path.AppendRelativePath(src_file_path_each, &dest_file_path_each);
+ FilePath dest_file_path_each(dest_path.internal_path());
+ src_path.internal_path().AppendRelativePath(
+ src_file_path_each, &dest_file_path_each);
if (file_enum->IsDirectory()) {
- PlatformFileError error = dest_util->CreateDirectory(dest_context.get(),
- dest_file_path_each, false, false);
+ PlatformFileError error = dest_util->CreateDirectory(
+ context,
+ dest_path.WithInternalPath(dest_file_path_each),
+ false, false);
if (error != base::PLATFORM_FILE_OK)
return error;
- // Reflect changes in usage back to the original context.
- context->set_allowed_bytes_growth(dest_context->allowed_bytes_growth());
} else {
PlatformFileError error = CopyOrMoveFileHelper(
- context, src_file_path_each, dest_file_path_each, copy);
+ context,
+ src_path.WithInternalPath(src_file_path_each),
+ dest_path.WithInternalPath(dest_file_path_each),
+ copy);
if (error != base::PLATFORM_FILE_OK)
return error;
}
}
if (!copy) {
- PlatformFileError error = Delete(context, src_file_path, true);
+ PlatformFileError error = Delete(context, src_path, true);
if (error != base::PLATFORM_FILE_OK)
return error;
}
@@ -435,45 +418,46 @@ PlatformFileError FileSystemFileUtil::CopyOrMoveDirectory(
PlatformFileError FileSystemFileUtil::CopyOrMoveFileHelper(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) {
// CopyOrMoveFile here is the virtual overridden member function.
- if ((context->src_origin_url() == context->dest_origin_url()) &&
- (context->src_type() == context->dest_type())) {
- DCHECK(context->src_file_util() == context->dest_file_util());
- return CopyOrMoveFile(context, src_file_path, dest_file_path, copy);
+ if ((src_path.origin() == dest_path.origin()) &&
+ (src_path.type() == dest_path.type())) {
+ DCHECK(src_path.file_util() == dest_path.file_util());
+ return CopyOrMoveFile(context, src_path, dest_path, copy);
}
+
base::PlatformFileInfo file_info;
- FilePath platform_file_path;
+ FilePath underlying_file_path;
PlatformFileError error_code;
- error_code =
- GetFileInfo(context, src_file_path, &file_info, &platform_file_path);
+ error_code = src_path.file_util()->GetFileInfo(
+ context, src_path, &file_info, &underlying_file_path);
if (error_code != base::PLATFORM_FILE_OK)
return error_code;
- DCHECK(context->dest_file_util());
- error_code = context->dest_file_util()->CopyInForeignFile(
- context, platform_file_path, dest_file_path);
+ DCHECK(dest_path.file_util());
+ error_code = dest_path.file_util()->CopyInForeignFile(
+ context, src_path.WithInternalPath(underlying_file_path), dest_path);
if (copy || error_code != base::PLATFORM_FILE_OK)
return error_code;
- return DeleteFile(context, src_file_path);
+ return src_path.file_util()->DeleteFile(context, src_path);
}
PlatformFileError FileSystemFileUtil::DeleteDirectoryRecursive(
FileSystemOperationContext* context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
scoped_ptr<AbstractFileEnumerator> file_enum(
- CreateFileEnumerator(context, file_path));
+ CreateFileEnumerator(context, path));
FilePath file_path_each;
-
std::stack<FilePath> directories;
while (!(file_path_each = file_enum->Next()).empty()) {
if (file_enum->IsDirectory()) {
directories.push(file_path_each);
} else {
// DeleteFile here is the virtual overridden member function.
- PlatformFileError error = DeleteFile(context, file_path_each);
+ PlatformFileError error = DeleteFile(
+ context, path.WithInternalPath(file_path_each));
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND)
return base::PLATFORM_FILE_ERROR_FAILED;
else if (error != base::PLATFORM_FILE_OK)
@@ -482,14 +466,15 @@ PlatformFileError FileSystemFileUtil::DeleteDirectoryRecursive(
}
while (!directories.empty()) {
- PlatformFileError error = DeleteSingleDirectory(context, directories.top());
+ PlatformFileError error = DeleteSingleDirectory(
+ context, path.WithInternalPath(directories.top()));
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND)
return base::PLATFORM_FILE_ERROR_FAILED;
else if (error != base::PLATFORM_FILE_OK)
return error;
directories.pop();
}
- return DeleteSingleDirectory(context, file_path);
+ return DeleteSingleDirectory(context, path);
}
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_file_util.h b/webkit/fileapi/file_system_file_util.h
index f96e532..08b2891 100644
--- a/webkit/fileapi/file_system_file_util.h
+++ b/webkit/fileapi/file_system_file_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -8,6 +8,7 @@
#include "base/file_path.h"
#include "base/file_util_proxy.h"
#include "base/platform_file.h"
+#include "webkit/fileapi/file_system_path.h"
namespace base {
class Time;
@@ -58,7 +59,7 @@ class FileSystemFileUtil {
virtual ~FileSystemFileUtil();
// Copies or moves a single file.
- // Copies a file or a directory from |src_file_path| to |dest_file_path|.
+ // Copies a file or a directory from |src_path| to |dest_path|.
//
// Error cases:
// If destination's parent doesn't exist.
@@ -71,12 +72,14 @@ class FileSystemFileUtil {
// target is a directory or not.
// - (virtual) CopyOrMoveFile or
// - (non-virtual) CopyOrMoveDirectory.
+ //
+ // TODO(kinuko,kinaba): Move this cross-FileUtil code out of this interface.
PlatformFileError Copy(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path);
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path);
- // Moves a file or a directory from src_file_path to dest_file_path.
+ // Moves a file or a directory from src_path to dest_path.
//
// Error cases are similar to Copy method's error cases.
//
@@ -84,10 +87,12 @@ class FileSystemFileUtil {
// target is a directory or not.
// - (virtual) CopyOrMoveFile or
// - (non-virtual) CopyOrMoveDirectory.
+ //
+ // TODO(kinuko,kinaba): Move this cross-FileUtil code out of this interface.
PlatformFileError Move(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path);
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path);
// Deletes a file or a directory.
// It is an error to delete a non-empty directory with recursive=false.
@@ -100,17 +105,17 @@ class FileSystemFileUtil {
// - (non-virtual) DeleteDirectoryRecursive which calls two methods above.
PlatformFileError Delete(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool recursive);
// 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.
+ // a new file at the given |path| and calls back with
+ // PLATFORM_FILE_ERROR_FILE_EXISTS if the |path| already exists.
virtual PlatformFileError CreateOrOpen(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
int file_flags,
PlatformFile* file_handle,
bool* created);
@@ -120,9 +125,9 @@ class FileSystemFileUtil {
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|,
+ // Ensures that the given |path| exist. This creates a empty new file
+ // at |path| if the |path| does not exist.
+ // If a new file han not existed and is created at the |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|
@@ -131,13 +136,13 @@ class FileSystemFileUtil {
// reasons, |created| is set false and |error code| indicates the error.
virtual PlatformFileError EnsureFileExists(
FileSystemOperationContext* context,
- const FilePath& file_path, bool* created);
+ const FileSystemPath& 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,
+ const FileSystemPath& path,
bool exclusive,
bool recursive);
@@ -145,14 +150,14 @@ class FileSystemFileUtil {
// callback.
virtual PlatformFileError GetFileInfo(
FileSystemOperationContext* context,
- const FilePath& file_,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_path);
- // Reads the filenames in |file_path|.
+ // Reads the filenames in |path|.
virtual PlatformFileError ReadDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries);
// Returns a pointer to a new instance of AbstractFileEnumerator which is
@@ -164,21 +169,21 @@ class FileSystemFileUtil {
// instance.
virtual AbstractFileEnumerator* CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& root_path);
+ const FileSystemPath& 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.
+ // Maps |virtual_path| given |context| into |local_file_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);
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path);
// Touches a file. The callback can be NULL.
// If the file doesn't exist, this fails with PLATFORM_FILE_ERROR_NOT_FOUND.
virtual PlatformFileError Touch(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time);
@@ -187,34 +192,34 @@ class FileSystemFileUtil {
// The callback can be NULL.
virtual PlatformFileError Truncate(
FileSystemOperationContext* context,
- const FilePath& path,
+ const FileSystemPath& path,
int64 length);
virtual bool PathExists(
FileSystemOperationContext* context,
- const FilePath& file_path);
+ const FileSystemPath& path);
virtual bool DirectoryExists(
FileSystemOperationContext* context,
- const FilePath& file_path);
+ const FileSystemPath& path);
virtual bool IsDirectoryEmpty(
FileSystemOperationContext* context,
- const FilePath& file_path);
+ const FileSystemPath& path);
virtual PlatformFileError CopyOrMoveFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_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.
+ // Copies in a single file from a different filesystem. The
+ // underlying_src_path is a local path which can be handled by the
+ // underlying filesystem.
virtual PlatformFileError CopyInForeignFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path);
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path);
// Deletes a single file.
// It assumes the given path points a file.
@@ -223,7 +228,7 @@ class FileSystemFileUtil {
// non-virtual).
virtual PlatformFileError DeleteFile(
FileSystemOperationContext* context,
- const FilePath& file_path);
+ const FileSystemPath& path);
// Deletes a single empty directory.
// It assumes the given path points an empty directory.
@@ -232,7 +237,7 @@ class FileSystemFileUtil {
// non-virtual).
virtual PlatformFileError DeleteSingleDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path);
+ const FileSystemPath& path);
protected:
FileSystemFileUtil();
@@ -243,17 +248,17 @@ class FileSystemFileUtil {
// destination).
PlatformFileError PerformCommonCheckAndPreparationForMoveAndCopy(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path);
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path);
// Performs recursive copy or move by calling CopyOrMoveFile for individual
// files. Operations for recursive traversal are encapsulated in this method.
- // It assumes src_file_path and dest_file_path have passed
+ // It assumes src_path and dest_path have passed
// PerformCommonCheckAndPreparationForMoveAndCopy().
PlatformFileError CopyOrMoveDirectory(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy);
// Determines whether a simple same-filesystem move or copy can be done. If
@@ -262,8 +267,8 @@ class FileSystemFileUtil {
// move] calls DeleteFile on the source file.
PlatformFileError CopyOrMoveFileHelper(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy);
// Deletes a directory and all entries under the directory.
@@ -275,7 +280,7 @@ class FileSystemFileUtil {
// the files are deleted.
PlatformFileError DeleteDirectoryRecursive(
FileSystemOperationContext* context,
- const FilePath& file_path);
+ const FileSystemPath& path);
FileSystemFileUtil* underlying_file_util() const {
return underlying_file_util_.get();
diff --git a/webkit/fileapi/file_system_file_util_unittest.cc b/webkit/fileapi/file_system_file_util_unittest.cc
index e036405..13071d4 100644
--- a/webkit/fileapi/file_system_file_util_unittest.cc
+++ b/webkit/fileapi/file_system_file_util_unittest.cc
@@ -55,16 +55,17 @@ class FileSystemFileUtilTest : public testing::Test {
false, // unlimited quota
NULL, // quota::QuotaManagerProxy
file_util.get());
+
FileSystemTestOriginHelper dest_helper(dest_origin, dest_type);
- dest_helper.SetUp(src_helper.file_system_context(), NULL);
+ dest_helper.SetUp(src_helper.file_system_context(), file_util.get());
// Set up all the source data.
scoped_ptr<FileSystemOperationContext> context;
- FilePath test_root(FILE_PATH_LITERAL("root directory"));
+ FileSystemPath src_root = src_helper.CreatePathFromUTF8("root directory");
for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
- FilePath path = test_root.Append(test_case.path);
+ FileSystemPath path = src_root.Append(test_case.path);
if (test_case.is_directory) {
context.reset(NewContext(&src_helper));
ASSERT_EQ(base::PLATFORM_FILE_OK,
@@ -81,29 +82,24 @@ class FileSystemFileUtilTest : public testing::Test {
}
}
+ FileSystemPath dest_root = dest_helper.CreatePathFromUTF8("root directory");
+
// Do the actual copy or move.
- FileSystemContext* file_system_context = dest_helper.file_system_context();
scoped_ptr<FileSystemOperationContext> copy_context(
- new FileSystemOperationContext(file_system_context, NULL));
- copy_context->set_src_file_util(file_util);
- copy_context->set_dest_file_util(file_util);
- copy_context->set_src_origin_url(src_helper.origin());
- copy_context->set_dest_origin_url(dest_helper.origin());
- copy_context->set_src_type(src_helper.type());
- copy_context->set_dest_type(dest_helper.type());
+ src_helper.NewOperationContext());
copy_context->set_allowed_bytes_growth(1024 * 1024); // OFSFU path quota.
if (copy)
ASSERT_EQ(base::PLATFORM_FILE_OK,
- file_util->Copy(copy_context.get(), test_root, test_root));
+ file_util->Copy(copy_context.get(), src_root, dest_root));
else
ASSERT_EQ(base::PLATFORM_FILE_OK,
- file_util->Move(copy_context.get(), test_root, test_root));
+ file_util->Move(copy_context.get(), src_root, dest_root));
// Validate that the destination paths are correct.
for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
- FilePath path = test_root.Append(test_case.path);
+ FileSystemPath path = dest_root.Append(test_case.path);
base::PlatformFileInfo dest_file_info;
FilePath data_path;
@@ -127,7 +123,7 @@ class FileSystemFileUtilTest : public testing::Test {
// a move].
for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
- FilePath path = test_root.Append(test_case.path);
+ FileSystemPath path = src_root.Append(test_case.path);
base::PlatformFileInfo src_file_info;
FilePath data_path;
context.reset(NewContext(&src_helper));
diff --git a/webkit/fileapi/file_system_mount_point_provider.h b/webkit/fileapi/file_system_mount_point_provider.h
index ee14ed8..e6b55a9 100644
--- a/webkit/fileapi/file_system_mount_point_provider.h
+++ b/webkit/fileapi/file_system_mount_point_provider.h
@@ -114,7 +114,7 @@ class ExternalFileSystemMountPointProvider
virtual void RemoveMountPoint(const FilePath& mount_point) = 0;
// Gets virtual path by known filesystem path. Returns false when filesystem
// path is not exposed by this provider.
- virtual bool GetVirtualPath(const FilePath& filesystem_path,
+ virtual bool GetVirtualPath(const FilePath& file_system_path,
FilePath* virtual_path) = 0;
};
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index 10a3fc6..3dbe7d8 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -32,7 +32,7 @@ class FileSystemOperation::ScopedQuotaUtilHelper {
private:
FileSystemQuotaUtil* quota_util_;
- const GURL& origin_url_;
+ const GURL origin_url_;
FileSystemType type_;
DISALLOW_COPY_AND_ASSIGN(ScopedQuotaUtilHelper);
};
@@ -41,7 +41,7 @@ FileSystemOperation::ScopedQuotaUtilHelper::ScopedQuotaUtilHelper(
FileSystemContext* context, const GURL& origin_url, FileSystemType type)
: origin_url_(origin_url), type_(type) {
DCHECK(context);
- DCHECK(type != kFileSystemTypeUnknown);
+ DCHECK(type_ != kFileSystemTypeUnknown);
quota_util_ = context->GetQuotaUtil(type_);
if (quota_util_) {
DCHECK(quota_util_->proxy());
@@ -63,26 +63,28 @@ FileSystemOperation::~FileSystemOperation() {
base::FileUtilProxy::RelayClose(
proxy_,
base::Bind(&FileSystemFileUtil::Close,
- base::Unretained(c->src_file_util()),
+ base::Unretained(src_path_.file_util()),
base::Owned(c)),
file_writer_delegate_->file(),
base::FileUtilProxy::StatusCallback());
}
}
-void FileSystemOperation::CreateFile(const GURL& path,
+void FileSystemOperation::CreateFile(const GURL& path_url,
bool exclusive,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateFile));
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
+
GetUsageAndQuotaThenCallback(
- operation_context_.src_origin_url(),
+ src_path_.origin(), src_path_.type(),
base::Bind(&FileSystemOperation::DelayedCreateFileForQuota,
base::Unretained(this), callback, exclusive));
}
@@ -95,34 +97,36 @@ void FileSystemOperation::DelayedCreateFileForQuota(
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.src_origin_url(),
- operation_context_.src_type()));
+ src_path_.origin(),
+ src_path_.type()));
FileSystemFileUtilProxy::RelayEnsureFileExists(
proxy_,
base::Bind(&FileSystemFileUtil::EnsureFileExists,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_,
+ src_path_),
base::Bind(
exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
: &FileSystemOperation::DidEnsureFileExistsNonExclusive,
base::Owned(this), callback));
}
-void FileSystemOperation::CreateDirectory(const GURL& path,
+void FileSystemOperation::CreateDirectory(const GURL& path_url,
bool exclusive,
bool recursive,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateDirectory));
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
GetUsageAndQuotaThenCallback(
- operation_context_.src_origin_url(),
+ src_path_.origin(), src_path_.type(),
base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota,
base::Unretained(this), callback, exclusive, recursive));
}
@@ -135,27 +139,28 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota(
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.src_origin_url(),
- operation_context_.src_type()));
+ src_path_.origin(),
+ src_path_.type()));
base::FileUtilProxy::RelayFileTask(
proxy_, FROM_HERE,
base::Bind(&FileSystemFileUtil::CreateDirectory,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(src_path_.file_util()),
&operation_context_,
- src_virtual_path_, exclusive, recursive),
+ src_path_, exclusive, recursive),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void FileSystemOperation::Copy(const GURL& src_path,
- const GURL& dest_path,
+void FileSystemOperation::Copy(const GURL& src_path_url,
+ const GURL& dest_path_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy));
- base::PlatformFileError result = SetupSrcContextForRead(src_path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ src_path_url, &src_path_, PATH_FOR_READ);
if (result == base::PLATFORM_FILE_OK)
- result = SetupDestContextForWrite(dest_path, true);
+ result = SetUpFileSystemPath(dest_path_url, &dest_path_, PATH_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -163,7 +168,7 @@ void FileSystemOperation::Copy(const GURL& src_path,
}
GetUsageAndQuotaThenCallback(
- operation_context_.dest_origin_url(),
+ dest_path_.origin(), dest_path_.type(),
base::Bind(&FileSystemOperation::DelayedCopyForQuota,
base::Unretained(this), callback));
}
@@ -175,27 +180,29 @@ void FileSystemOperation::DelayedCopyForQuota(const StatusCallback& callback,
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.dest_origin_url(),
- operation_context_.dest_type()));
+ dest_path_.origin(),
+ dest_path_.type()));
base::FileUtilProxy::RelayFileTask(
proxy_, FROM_HERE,
base::Bind(&FileSystemFileUtil::Copy,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(dest_path_.file_util()),
&operation_context_,
- src_virtual_path_, dest_virtual_path_),
+ src_path_,
+ dest_path_),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void FileSystemOperation::Move(const GURL& src_path,
- const GURL& dest_path,
+void FileSystemOperation::Move(const GURL& src_path_url,
+ const GURL& dest_path_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationMove));
- base::PlatformFileError result = SetupSrcContextForWrite(src_path, false);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ src_path_url, &src_path_, PATH_FOR_WRITE);
if (result == base::PLATFORM_FILE_OK)
- result = SetupDestContextForWrite(dest_path, true);
+ result = SetUpFileSystemPath(dest_path_url, &dest_path_, PATH_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -203,7 +210,7 @@ void FileSystemOperation::Move(const GURL& src_path,
}
GetUsageAndQuotaThenCallback(
- operation_context_.dest_origin_url(),
+ dest_path_.origin(), dest_path_.type(),
base::Bind(&FileSystemOperation::DelayedMoveForQuota,
base::Unretained(this), callback));
}
@@ -215,24 +222,26 @@ void FileSystemOperation::DelayedMoveForQuota(const StatusCallback& callback,
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.dest_origin_url(),
- operation_context_.dest_type()));
+ dest_path_.origin(),
+ dest_path_.type()));
base::FileUtilProxy::RelayFileTask(
proxy_, FROM_HERE,
base::Bind(&FileSystemFileUtil::Move,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(dest_path_.file_util()),
&operation_context_,
- src_virtual_path_, dest_virtual_path_),
+ src_path_,
+ dest_path_),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void FileSystemOperation::DirectoryExists(const GURL& path,
+void FileSystemOperation::DirectoryExists(const GURL& path_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationDirectoryExists));
- base::PlatformFileError result = SetupSrcContextForRead(path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -242,17 +251,19 @@ void FileSystemOperation::DirectoryExists(const GURL& path,
FileSystemFileUtilProxy::RelayGetFileInfo(
proxy_,
base::Bind(&FileSystemFileUtil::GetFileInfo,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_,
+ src_path_),
base::Bind(&FileSystemOperation::DidDirectoryExists,
base::Owned(this), callback));
}
-void FileSystemOperation::FileExists(const GURL& path,
+void FileSystemOperation::FileExists(const GURL& path_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationFileExists));
- base::PlatformFileError result = SetupSrcContextForRead(path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -262,17 +273,18 @@ void FileSystemOperation::FileExists(const GURL& path,
FileSystemFileUtilProxy::RelayGetFileInfo(
proxy_,
base::Bind(&FileSystemFileUtil::GetFileInfo,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_, src_path_),
base::Bind(&FileSystemOperation::DidFileExists,
base::Owned(this), callback));
}
-void FileSystemOperation::GetMetadata(const GURL& path,
+void FileSystemOperation::GetMetadata(const GURL& path_url,
const GetMetadataCallback& callback) {
DCHECK(SetPendingOperationType(kOperationGetMetadata));
- base::PlatformFileError result = SetupSrcContextForRead(path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), FilePath());
delete this;
@@ -282,17 +294,18 @@ void FileSystemOperation::GetMetadata(const GURL& path,
FileSystemFileUtilProxy::RelayGetFileInfo(
proxy_,
base::Bind(&FileSystemFileUtil::GetFileInfo,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_, src_path_),
base::Bind(&FileSystemOperation::DidGetMetadata,
base::Owned(this), callback));
}
-void FileSystemOperation::ReadDirectory(const GURL& path,
+void FileSystemOperation::ReadDirectory(const GURL& path_url,
const ReadDirectoryCallback& callback) {
DCHECK(SetPendingOperationType(kOperationReadDirectory));
- base::PlatformFileError result = SetupSrcContextForRead(path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
delete this;
@@ -302,17 +315,18 @@ void FileSystemOperation::ReadDirectory(const GURL& path,
FileSystemFileUtilProxy::RelayReadDirectory(
proxy_,
base::Bind(&FileSystemFileUtil::ReadDirectory,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_, src_path_),
base::Bind(&FileSystemOperation::DidReadDirectory,
base::Owned(this), callback));
}
-void FileSystemOperation::Remove(const GURL& path, bool recursive,
+void FileSystemOperation::Remove(const GURL& path_url, bool recursive,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetupSrcContextForWrite(path, false);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -322,35 +336,38 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive,
base::FileUtilProxy::RelayFileTask(
proxy_, FROM_HERE,
base::Bind(&FileSystemFileUtil::Delete,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_, recursive),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_, src_path_,
+ recursive),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
void FileSystemOperation::Write(
const net::URLRequestContext* url_request_context,
- const GURL& path,
+ const GURL& path_url,
const GURL& blob_url,
int64 offset,
const WriteCallback& callback) {
DCHECK(SetPendingOperationType(kOperationWrite));
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, 0, false);
delete this;
return;
}
DCHECK(blob_url.is_valid());
- file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_));
+ file_writer_delegate_.reset(new FileWriterDelegate(
+ this, src_path_, offset, proxy_));
set_write_callback(callback);
blob_request_.reset(
new net::URLRequest(blob_url, file_writer_delegate_.get()));
blob_request_->set_context(url_request_context);
GetUsageAndQuotaThenCallback(
- operation_context_.src_origin_url(),
+ src_path_.origin(), src_path_.type(),
base::Bind(&FileSystemOperation::DelayedWriteForQuota,
base::Unretained(this)));
}
@@ -361,8 +378,8 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.src_origin_url(),
- operation_context_.src_type()));
+ src_path_.origin(),
+ src_path_.type()));
int file_flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_WRITE |
@@ -371,27 +388,30 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
base::FileUtilProxy::RelayCreateOrOpen(
proxy_,
base::Bind(&FileSystemFileUtil::CreateOrOpen,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_, file_flags),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_,
+ src_path_,
+ file_flags),
base::Bind(&FileSystemFileUtil::Close,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(src_path_.file_util()),
&operation_context_),
base::Bind(&FileSystemOperation::OnFileOpenedForWrite,
base::Unretained(this)));
}
-void FileSystemOperation::Truncate(const GURL& path, int64 length,
+void FileSystemOperation::Truncate(const GURL& path_url, int64 length,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTruncate));
- base::PlatformFileError result = SetupSrcContextForWrite(path, false);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
GetUsageAndQuotaThenCallback(
- operation_context_.src_origin_url(),
+ src_path_.origin(), src_path_.type(),
base::Bind(&FileSystemOperation::DelayedTruncateForQuota,
base::Unretained(this), callback, length));
}
@@ -403,25 +423,26 @@ void FileSystemOperation::DelayedTruncateForQuota(
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.src_origin_url(),
- operation_context_.src_type()));
+ src_path_.origin(),
+ src_path_.type()));
base::FileUtilProxy::RelayFileTask(
proxy_, FROM_HERE,
base::Bind(&FileSystemFileUtil::Truncate,
- base::Unretained(operation_context_.src_file_util()),
- &operation_context_, src_virtual_path_, length),
+ base::Unretained(src_path_.file_util()),
+ &operation_context_, src_path_, length),
base::Bind(&FileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void FileSystemOperation::TouchFile(const GURL& path,
+void FileSystemOperation::TouchFile(const GURL& path_url,
const base::Time& last_access_time,
const base::Time& last_modified_time,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTouchFile));
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -431,18 +452,20 @@ void FileSystemOperation::TouchFile(const GURL& path,
base::FileUtilProxy::RelayFileTask(
proxy_, FROM_HERE,
base::Bind(&FileSystemFileUtil::Touch,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(src_path_.file_util()),
&operation_context_,
- src_virtual_path_, last_access_time, last_modified_time),
+ src_path_,
+ last_access_time, last_modified_time),
base::Bind(&FileSystemOperation::DidTouchFile,
base::Owned(this), callback));
}
-void FileSystemOperation::OpenFile(const GURL& path,
+void FileSystemOperation::OpenFile(const GURL& path_url,
int file_flags,
base::ProcessHandle peer_handle,
const OpenFileCallback& callback) {
DCHECK(SetPendingOperationType(kOperationOpenFile));
+ scoped_ptr<FileSystemOperation> deleter(this);
peer_handle_ = peer_handle;
@@ -451,7 +474,6 @@ void FileSystemOperation::OpenFile(const GURL& path,
base::PLATFORM_FILE_HIDDEN))) {
callback.Run(base::PLATFORM_FILE_ERROR_FAILED,
base::PlatformFile(), base::ProcessHandle());
- delete this;
return;
}
if (file_flags &
@@ -460,24 +482,24 @@ void FileSystemOperation::OpenFile(const GURL& path,
base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
- base::PlatformFileError result = SetupSrcContextForWrite(path, true);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
- delete this;
return;
}
} else {
- base::PlatformFileError result = SetupSrcContextForRead(path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
- delete this;
return;
}
}
GetUsageAndQuotaThenCallback(
- operation_context_.src_origin_url(),
+ src_path_.origin(), src_path_.type(),
base::Bind(&FileSystemOperation::DelayedOpenFileForQuota,
- base::Unretained(this), callback, file_flags));
+ base::Unretained(deleter.release()), callback, file_flags));
}
void FileSystemOperation::DelayedOpenFileForQuota(
@@ -487,17 +509,17 @@ void FileSystemOperation::DelayedOpenFileForQuota(
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
- operation_context_.src_origin_url(),
- operation_context_.src_type()));
+ src_path_.origin(),
+ src_path_.type()));
base::FileUtilProxy::RelayCreateOrOpen(
proxy_,
base::Bind(&FileSystemFileUtil::CreateOrOpen,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(src_path_.file_util()),
&operation_context_,
- src_virtual_path_, file_flags),
+ src_path_, file_flags),
base::Bind(&FileSystemFileUtil::Close,
- base::Unretained(operation_context_.src_file_util()),
+ base::Unretained(src_path_.file_util()),
&operation_context_),
base::Bind(&FileSystemOperation::DidOpenFile,
base::Owned(this), callback));
@@ -540,18 +562,19 @@ FileSystemOperation* FileSystemOperation::AsFileSystemOperation() {
return this;
}
-void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
+void FileSystemOperation::SyncGetPlatformPath(const GURL& path_url,
FilePath* platform_path) {
DCHECK(SetPendingOperationType(kOperationGetLocalPath));
- base::PlatformFileError result = SetupSrcContextForRead(path);
+ base::PlatformFileError result = SetUpFileSystemPath(
+ path_url, &src_path_, PATH_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
delete this;
return;
}
- operation_context_.src_file_util()->GetLocalFilePath(
- &operation_context_, src_virtual_path_, platform_path);
+ src_path_.file_util()->GetLocalFilePath(
+ &operation_context_, src_path_, platform_path);
delete this;
}
@@ -560,19 +583,18 @@ FileSystemOperation::FileSystemOperation(
scoped_refptr<base::MessageLoopProxy> proxy,
FileSystemContext* file_system_context)
: proxy_(proxy),
- operation_context_(file_system_context, NULL),
+ operation_context_(file_system_context),
peer_handle_(base::kNullProcessHandle),
pending_operation_(kOperationNone) {
}
void FileSystemOperation::GetUsageAndQuotaThenCallback(
- const GURL& origin_url,
+ const GURL& origin, FileSystemType type,
const quota::QuotaManager::GetUsageAndQuotaCallback& callback) {
quota::QuotaManagerProxy* quota_manager_proxy =
file_system_context()->quota_manager_proxy();
if (!quota_manager_proxy ||
- !file_system_context()->GetQuotaUtil(
- operation_context_.src_type())) {
+ !file_system_context()->GetQuotaUtil(type)) {
// If we don't have the quota manager or the requested filesystem type
// does not support quota, we should be able to let it go.
callback.Run(quota::kQuotaStatusOk, 0, kint64max);
@@ -581,9 +603,8 @@ void FileSystemOperation::GetUsageAndQuotaThenCallback(
DCHECK(quota_manager_proxy);
DCHECK(quota_manager_proxy->quota_manager());
quota_manager_proxy->quota_manager()->GetUsageAndQuota(
- operation_context_.src_origin_url(),
- FileSystemTypeToQuotaStorageType(
- operation_context_.src_type()),
+ origin,
+ FileSystemTypeToQuotaStorageType(type),
callback);
}
@@ -696,114 +717,65 @@ void FileSystemOperation::OnFileOpenedForWrite(
file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get());
}
-base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForRead(
- const GURL& path, GURL* origin_url, FileSystemType* type,
- FilePath* virtual_path, FileSystemFileUtil** file_util) {
- base::PlatformFileError rv =
- VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
- if (rv != base::PLATFORM_FILE_OK)
- return rv;
-
- // We notify this read access whether the read access succeeds or not.
- // This must be ok since this is used to let the QM's eviction logic know
- // someone is interested in reading the origin data and therefore to indicate
- // that evicting this origin may not be a good idea.
- FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type);
- if (quota_util) {
- quota_util->NotifyOriginWasAccessedOnIOThread(
- file_system_context()->quota_manager_proxy(),
- *origin_url,
- *type);
- }
-
- return base::PLATFORM_FILE_OK;
-}
-
-base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForWrite(
- const GURL& path, bool create, GURL* origin_url, FileSystemType* type,
- FilePath* virtual_path, FileSystemFileUtil** file_util) {
- base::PlatformFileError rv =
- VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util);
- if (rv != base::PLATFORM_FILE_OK)
- return rv;
+base::PlatformFileError FileSystemOperation::SetUpFileSystemPath(
+ const GURL& path_url,
+ FileSystemPath* file_system_path,
+ SetUpPathMode mode) {
+ DCHECK(file_system_path);
+ GURL origin_url;
+ FileSystemType type;
+ FilePath cracked_path;
+ if (!CrackFileSystemURL(path_url, &origin_url, &type, &cracked_path))
+ return base::PLATFORM_FILE_ERROR_INVALID_URL;
- // Any write access is disallowed on the root path.
- if (virtual_path->value().length() == 0 ||
- virtual_path->DirName().value() == virtual_path->value()) {
+ if (!file_system_context()->GetMountPointProvider(type)->IsAccessAllowed(
+ origin_url, type, cracked_path))
return base::PLATFORM_FILE_ERROR_SECURITY;
- }
- if (create &&
- file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName(
- virtual_path->BaseName())) {
+
+ FileSystemFileUtil* file_util = file_system_context()->GetFileUtil(type);
+ if (!file_util)
return base::PLATFORM_FILE_ERROR_SECURITY;
- }
- return base::PLATFORM_FILE_OK;
-}
+ file_system_path->set_origin(origin_url);
+ file_system_path->set_type(type);
+ file_system_path->set_internal_path(cracked_path);
+ if (!file_system_path->file_util())
+ file_system_path->set_file_util(file_util);
+
+ if (mode == PATH_FOR_READ) {
+ // We notify this read access whether the read access succeeds or not.
+ // This must be ok since this is used to let the QM's eviction logic know
+ // someone is interested in reading the origin data and therefore to
+ // indicate that evicting this origin may not be a good idea.
+ FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(type);
+ if (quota_util) {
+ quota_util->NotifyOriginWasAccessedOnIOThread(
+ file_system_context()->quota_manager_proxy(),
+ file_system_path->origin(),
+ file_system_path->type());
+ }
+ return base::PLATFORM_FILE_OK;
+ }
-base::PlatformFileError FileSystemOperation::VerifyFileSystemPath(
- const GURL& path, GURL* origin_url, FileSystemType* type,
- FilePath* virtual_path, FileSystemFileUtil** file_util) {
- DCHECK(file_system_context());
+ DCHECK(mode == PATH_FOR_WRITE || mode == PATH_FOR_CREATE);
- if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) {
- return base::PLATFORM_FILE_ERROR_INVALID_URL;
- }
- if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed(
- *origin_url, *type, *virtual_path)) {
+ // Any write access is disallowed on the root path.
+ if (cracked_path.value().length() == 0 ||
+ cracked_path.DirName().value() == cracked_path.value())
return base::PLATFORM_FILE_ERROR_SECURITY;
+
+ if (mode == PATH_FOR_CREATE) {
+ FileSystemMountPointProvider* provider = file_system_context()->
+ GetMountPointProvider(type);
+
+ // Check if the cracked file name looks good to create.
+ if (provider->IsRestrictedFileName(cracked_path.BaseName()))
+ return base::PLATFORM_FILE_ERROR_SECURITY;
}
- DCHECK(file_util);
- *file_util = file_system_context()->GetFileUtil(*type);
- DCHECK(*file_util);
return base::PLATFORM_FILE_OK;
}
-base::PlatformFileError FileSystemOperation::SetupSrcContextForRead(
- const GURL& path) {
- GURL origin_url;
- FileSystemType type;
- FileSystemFileUtil* file_util;
- base::PlatformFileError result = VerifyFileSystemPathForRead(
- path, &origin_url, &type, &src_virtual_path_, &file_util);
- operation_context_.set_src_origin_url(origin_url);
- operation_context_.set_src_type(type);
- if (!operation_context_.src_file_util())
- operation_context_.set_src_file_util(file_util);
- return result;
-}
-
-base::PlatformFileError FileSystemOperation::SetupSrcContextForWrite(
- const GURL& path,
- bool create) {
- GURL origin_url;
- FileSystemType type;
- FileSystemFileUtil* file_util = NULL;
- base::PlatformFileError result = VerifyFileSystemPathForWrite(
- path, create, &origin_url, &type, &src_virtual_path_, &file_util);
- operation_context_.set_src_origin_url(origin_url);
- operation_context_.set_src_type(type);
- if (!operation_context_.src_file_util())
- operation_context_.set_src_file_util(file_util);
- return result;
-}
-
-base::PlatformFileError FileSystemOperation::SetupDestContextForWrite(
- const GURL& path,
- bool create) {
- GURL origin_url;
- FileSystemType type;
- FileSystemFileUtil* file_util = NULL;
- base::PlatformFileError result = VerifyFileSystemPathForWrite(
- path, create, &origin_url, &type, &dest_virtual_path_, &file_util);
- operation_context_.set_dest_origin_url(origin_url);
- operation_context_.set_dest_type(type);
- if (!operation_context_.dest_file_util())
- operation_context_.set_dest_file_util(file_util);
- return result;
-}
-
bool FileSystemOperation::SetPendingOperationType(OperationType type) {
if (pending_operation_ != kOperationNone)
return false;
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 5c05c97..b70d3dfa 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -49,49 +49,49 @@ class FileSystemOperation : public FileSystemOperationInterface {
virtual ~FileSystemOperation();
// FileSystemOperation overrides.
- virtual void CreateFile(const GURL& path,
+ virtual void CreateFile(const GURL& path_url,
bool exclusive,
const StatusCallback& callback) OVERRIDE;
- virtual void CreateDirectory(const GURL& path,
+ virtual void CreateDirectory(const GURL& path_url,
bool exclusive,
bool recursive,
const StatusCallback& callback) OVERRIDE;
- virtual void Copy(const GURL& src_path,
- const GURL& dest_path,
+ virtual void Copy(const GURL& src_path_url,
+ const GURL& dest_path_url,
const StatusCallback& callback) OVERRIDE;
- virtual void Move(const GURL& src_path,
- const GURL& dest_path,
+ virtual void Move(const GURL& src_path_url,
+ const GURL& dest_path_url,
const StatusCallback& callback) OVERRIDE;
- virtual void DirectoryExists(const GURL& path,
+ virtual void DirectoryExists(const GURL& path_url,
const StatusCallback& callback) OVERRIDE;
- virtual void FileExists(const GURL& path,
+ virtual void FileExists(const GURL& path_url,
const StatusCallback& callback) OVERRIDE;
- virtual void GetMetadata(const GURL& path,
+ virtual void GetMetadata(const GURL& path_url,
const GetMetadataCallback& callback) OVERRIDE;
- virtual void ReadDirectory(const GURL& path,
+ virtual void ReadDirectory(const GURL& path_url,
const ReadDirectoryCallback& callback) OVERRIDE;
- virtual void Remove(const GURL& path, bool recursive,
+ virtual void Remove(const GURL& path_url, bool recursive,
const StatusCallback& callback) OVERRIDE;
virtual void Write(const net::URLRequestContext* url_request_context,
- const GURL& path,
+ const GURL& path_url,
const GURL& blob_url,
int64 offset,
const WriteCallback& callback) OVERRIDE;
- virtual void Truncate(const GURL& path, int64 length,
+ virtual void Truncate(const GURL& path_url, int64 length,
const StatusCallback& callback) OVERRIDE;
- virtual void TouchFile(const GURL& path,
+ virtual void TouchFile(const GURL& path_url,
const base::Time& last_access_time,
const base::Time& last_modified_time,
const StatusCallback& callback) OVERRIDE;
- virtual void OpenFile(const GURL& path,
+ virtual void OpenFile(const GURL& path_url,
int file_flags,
base::ProcessHandle peer_handle,
const OpenFileCallback& callback) OVERRIDE;
virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE;
virtual FileSystemOperation* AsFileSystemOperation() OVERRIDE;
- // Synchronously gets the platform path for the given |path|.
- void SyncGetPlatformPath(const GURL& path, FilePath* platform_path);
+ // Synchronously gets the platform path for the given |path_url|.
+ void SyncGetPlatformPath(const GURL& path_url, FilePath* platform_path);
protected:
class ScopedQuotaUtilHelper;
@@ -123,12 +123,13 @@ class FileSystemOperation : public FileSystemOperationInterface {
// file_util on their own should call this before performing the actual
// operation. If it is given it will not be overwritten by the class.
void set_override_file_util(FileSystemFileUtil* file_util) {
- operation_context_.set_src_file_util(file_util);
- operation_context_.set_dest_file_util(file_util);
+ src_path_.set_file_util(file_util);
+ dest_path_.set_file_util(file_util);
}
void GetUsageAndQuotaThenCallback(
- const GURL& origin_url,
+ const GURL& origin,
+ FileSystemType type,
const quota::QuotaManager::GetUsageAndQuotaCallback& callback);
void DelayedCreateFileForQuota(const StatusCallback& callback,
@@ -202,60 +203,18 @@ class FileSystemOperation : public FileSystemOperationInterface {
base::PassPlatformFile file,
bool created);
- // Checks the validity of a given |path| for reading, cracks the path into
- // root URL and virtual path components, and returns the correct
- // FileSystemFileUtil subclass for this type.
- // Returns true if the given |path| is a valid FileSystem path.
- // Otherwise it calls dispatcher's DidFail method with
- // PLATFORM_FILE_ERROR_SECURITY and returns false.
- // (Note: this doesn't delete this when it calls DidFail and returns false;
- // it's the caller's responsibility.)
- base::PlatformFileError VerifyFileSystemPathForRead(
- const GURL& path,
- GURL* root_url,
- FileSystemType* type,
- FilePath* virtual_path,
- FileSystemFileUtil** file_util);
-
- // Checks the validity of a given |path| for writing, cracks the path into
- // root URL and virtual path components, and returns the correct
- // FileSystemFileUtil subclass for this type.
- // Returns true if the given |path| is a valid FileSystem path, and
- // its origin embedded in the path has the right to write.
- // Otherwise it fires dispatcher's DidFail method with
- // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing,
- // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to
- // write to the storage.
- // In either case it returns false after firing DidFail.
- // If |create| flag is true this also checks if the |path| contains
- // any restricted names and chars. If it does, the call fires dispatcher's
- // DidFail with PLATFORM_FILE_ERROR_SECURITY and returns false.
- // (Note: this doesn't delete this when it calls DidFail and returns false;
- // it's the caller's responsibility.)
- base::PlatformFileError VerifyFileSystemPathForWrite(
- const GURL& path,
- bool create,
- GURL* root_url,
- FileSystemType* type,
- FilePath* virtual_path,
- FileSystemFileUtil** file_util);
-
- // Common internal routine for VerifyFileSystemPathFor{Read,Write}.
- base::PlatformFileError VerifyFileSystemPath(const GURL& path,
- GURL* root_url,
- FileSystemType* type,
- FilePath* virtual_path,
- FileSystemFileUtil** file_util);
-
- // Setup*Context*() functions will call the appropriate VerifyFileSystem
- // function and store the results to operation_context_ and
- // *_virtual_path_.
- // Return the result of VerifyFileSystem*().
- base::PlatformFileError SetupSrcContextForRead(const GURL& path);
- base::PlatformFileError SetupSrcContextForWrite(const GURL& path,
- bool create);
- base::PlatformFileError SetupDestContextForWrite(const GURL& path,
- bool create);
+ enum SetUpPathMode {
+ PATH_FOR_READ,
+ PATH_FOR_WRITE,
+ PATH_FOR_CREATE,
+ };
+
+ // Checks the validity of a given |path_url| and and sets up the
+ // |file_system_path| for |mode|.
+ base::PlatformFileError SetUpFileSystemPath(
+ const GURL& path_url,
+ FileSystemPath* file_system_path,
+ SetUpPathMode mode);
// Used only for internal assertions.
// Returns false if there's another inflight pending operation.
@@ -265,6 +224,8 @@ class FileSystemOperation : public FileSystemOperationInterface {
scoped_refptr<base::MessageLoopProxy> proxy_;
FileSystemOperationContext operation_context_;
+ FileSystemPath src_path_;
+ FileSystemPath dest_path_;
scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_;
@@ -287,12 +248,6 @@ class FileSystemOperation : public FileSystemOperationInterface {
// requesting process.
base::ProcessHandle peer_handle_;
- // Used to keep a virtual path around while we check for quota.
- // If an operation needs only one path, use src_virtual_path_, even if it's a
- // write.
- FilePath src_virtual_path_;
- FilePath dest_virtual_path_;
-
// A flag to make sure we call operation only once per instance.
OperationType pending_operation_;
diff --git a/webkit/fileapi/file_system_operation_context.cc b/webkit/fileapi/file_system_operation_context.cc
index 5f0abf0..0f33024 100644
--- a/webkit/fileapi/file_system_operation_context.cc
+++ b/webkit/fileapi/file_system_operation_context.cc
@@ -1,36 +1,18 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_context.h"
-#include "webkit/fileapi/file_system_util.h"
namespace fileapi {
FileSystemOperationContext::FileSystemOperationContext(
- FileSystemContext* context,
- FileSystemFileUtil* file_util)
+ FileSystemContext* context)
: file_system_context_(context),
- src_file_util_(file_util),
- dest_file_util_(file_util),
- src_type_(kFileSystemTypeUnknown),
- dest_type_(kFileSystemTypeUnknown),
- allowed_bytes_growth_(0) {
-}
+ allowed_bytes_growth_(0) {}
-FileSystemOperationContext::~FileSystemOperationContext() {
-}
-
-FileSystemOperationContext*
-FileSystemOperationContext::CreateInheritedContextForDest() const {
- FileSystemOperationContext* context = new FileSystemOperationContext(
- file_system_context_.get(), dest_file_util_);
- context->set_src_origin_url(dest_origin_url_);
- context->set_src_type(dest_type_);
- context->set_allowed_bytes_growth(allowed_bytes_growth_);
- return context;
-}
+FileSystemOperationContext::~FileSystemOperationContext() {}
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_operation_context.h b/webkit/fileapi/file_system_operation_context.h
index e61aac8..8901cb1 100644
--- a/webkit/fileapi/file_system_operation_context.h
+++ b/webkit/fileapi/file_system_operation_context.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -17,91 +17,22 @@ class FileSystemContext;
class FileSystemOperationContext {
public:
- // The |file_util| parameter is so that unit tests can force their own
- // preferred class in for both src and dest FSFU; in general these will get
- // set later by the FileSystemOperation.
- FileSystemOperationContext(FileSystemContext* context,
- FileSystemFileUtil* file_util);
+ FileSystemOperationContext(FileSystemContext* context);
~FileSystemOperationContext();
FileSystemContext* file_system_context() const {
return file_system_context_.get();
}
- void set_src_file_util(FileSystemFileUtil* util) {
- DCHECK(!src_file_util_);
- src_file_util_ = util;
- }
-
- FileSystemFileUtil* src_file_util() const {
- return src_file_util_;
- }
-
- void set_dest_file_util(FileSystemFileUtil* util) {
- DCHECK(!dest_file_util_);
- dest_file_util_ = util;
- }
-
- FileSystemFileUtil* dest_file_util() const {
- return dest_file_util_;
- }
-
- void set_src_origin_url(const GURL& url) {
- src_origin_url_ = url;
- }
-
- const GURL& src_origin_url() const {
- return src_origin_url_;
- }
-
- void set_dest_origin_url(const GURL& url) {
- dest_origin_url_ = url;
- }
-
- const GURL& dest_origin_url() const {
- return dest_origin_url_;
- }
-
- FileSystemType src_type() const {
- return src_type_;
- }
-
- void set_src_type(FileSystemType src_type) {
- src_type_ = src_type;
- }
-
- FileSystemType dest_type() const {
- return dest_type_;
- }
-
- void set_dest_type(FileSystemType dest_type) {
- dest_type_ = dest_type;
- }
-
void set_allowed_bytes_growth(const int64& allowed_bytes_growth) {
allowed_bytes_growth_ = allowed_bytes_growth;
}
-
int64 allowed_bytes_growth() const { return allowed_bytes_growth_; }
- FileSystemOperationContext* CreateInheritedContextForDest() const;
-
private:
scoped_refptr<FileSystemContext> file_system_context_;
- // These *_file_util_ are not "owned" by FileSystemOperationContext. They
- // are supposed to be pointers to objects that will outlive us.
- FileSystemFileUtil* src_file_util_;
- FileSystemFileUtil* dest_file_util_;
- GURL src_origin_url_; // Also used for any single-path operation.
- GURL dest_origin_url_;
- FileSystemType src_type_; // Also used for any single-path operation.
- FileSystemType dest_type_;
int64 allowed_bytes_growth_;
-
- // Used for delayed operation by quota.
- FilePath src_virtual_path_; // Also used for any single-path operation.
- FilePath dest_virtual_path_;
};
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc
index b8b86c4..15f0d2b 100644
--- a/webkit/fileapi/file_system_operation_unittest.cc
+++ b/webkit/fileapi/file_system_operation_unittest.cc
@@ -149,8 +149,7 @@ FilePath ASCIIToFilePath(const std::string& str) {
} // namespace (anonymous)
-// Test class for FileSystemOperation. Note that this just tests low-level
-// operations but doesn't test OpenFileSystem.
+// Test class for FileSystemOperation.
class FileSystemOperationTest
: public testing::Test,
public base::SupportsWeakPtr<FileSystemOperationTest> {
diff --git a/webkit/fileapi/file_system_path.cc b/webkit/fileapi/file_system_path.cc
new file mode 100644
index 0000000..ed2d89d
--- /dev/null
+++ b/webkit/fileapi/file_system_path.cc
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 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.
+
+#include "webkit/fileapi/file_system_path.h"
+
+#include "webkit/fileapi/file_system_types.h"
+
+namespace fileapi {
+
+FileSystemPath::FileSystemPath()
+ : type_(kFileSystemTypeUnknown),
+ file_util_(NULL) {}
+
+FileSystemPath::FileSystemPath(
+ const GURL& origin,
+ FileSystemType type,
+ const FilePath& internal_path,
+ FileSystemFileUtil* file_util)
+ : origin_(origin),
+ type_(type),
+ internal_path_(internal_path),
+ file_util_(file_util) {}
+
+FileSystemPath::~FileSystemPath() {}
+
+FileSystemPath FileSystemPath::WithInternalPath(const FilePath& internal_path)
+ const {
+ FileSystemPath new_path(*this);
+ new_path.set_internal_path(internal_path);
+ return new_path;
+}
+
+bool FileSystemPath::operator==(const FileSystemPath& that) const {
+ return origin_ == that.origin_ &&
+ type_ == that.type_ &&
+ internal_path_ == that.internal_path_;
+}
+
+} // namespace fileapi
diff --git a/webkit/fileapi/file_system_path.h b/webkit/fileapi/file_system_path.h
new file mode 100644
index 0000000..7a9e9fe
--- /dev/null
+++ b/webkit/fileapi/file_system_path.h
@@ -0,0 +1,94 @@
+// Copyright (c) 2012 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_PATH_H_
+#define WEBKIT_FILEAPI_FILE_SYSTEM_PATH_H_
+
+#include "base/file_path.h"
+#include "base/platform_file.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_types.h"
+
+namespace fileapi {
+
+class FileSystemFileUtil;
+
+// A class representing a filesystem path which consists of origin URL,
+// type and an internal path used inside the filesystem. The class also has
+// a corresponding FileSystemFileUtil by which the filesystem file is
+// handled.
+// NOTE: If we completely get rid of cross-filesystem operations under
+// FileSystemOperation we may end up converting all the FileSystemPath
+// occurences back to a FilePath's.
+class FileSystemPath {
+ public:
+ FileSystemPath();
+ FileSystemPath(const GURL& origin,
+ FileSystemType type,
+ const FilePath& internal_path,
+ FileSystemFileUtil* file_util);
+ ~FileSystemPath();
+
+ // Gets and sets the origin URL of this filesystem.
+ const GURL& origin() const { return origin_; }
+ void set_origin(const GURL& origin) { origin_ = origin; }
+
+ // Gets and sets the type of this filesystem (e.g. FileSystemTypeTemporary).
+ FileSystemType type() const { return type_; }
+ void set_type(FileSystemType type) { type_ = type; }
+
+ // Gets and sets the internal path of this filesystem, which is the path
+ // used to specify the file in the filesystem. The value could be either
+ // virtual or platform path depending on filesystem types and corresponding
+ // file_util's.
+ const FilePath& internal_path() const { return internal_path_; }
+ void set_internal_path(const FilePath& internal_path) {
+ internal_path_ = internal_path;
+ }
+
+ // Gets and sets the FileSystemFileUtil with which the file pointed by this
+ // FileSystemPath is handled.
+ FileSystemFileUtil* file_util() const { return file_util_; }
+ void set_file_util(FileSystemFileUtil* util) { file_util_ = util; }
+
+ // Returns a new FileSystemPath with the given internal_path.
+ // This doesn't change the calling instance's data.
+ FileSystemPath WithInternalPath(const FilePath& internal_path) const;
+
+ // Path related convenient methods.
+ FileSystemPath BaseName() const {
+ return WithInternalPath(internal_path().BaseName());
+ }
+ FileSystemPath DirName() const {
+ return WithInternalPath(internal_path().DirName());
+ }
+ FileSystemPath Append(const FilePath& component) const {
+ return WithInternalPath(internal_path().Append(component));
+ }
+ FileSystemPath Append(const FilePath::StringType& component) const {
+ return WithInternalPath(internal_path().Append(component));
+ }
+ FileSystemPath AppendASCII(const base::StringPiece& component) const {
+ return WithInternalPath(internal_path().AppendASCII(component));
+ }
+ bool IsParent(const FileSystemPath& other) const {
+ return internal_path_.IsParent(other.internal_path());
+ }
+
+ bool operator==(const FileSystemPath& that) const;
+
+ private:
+ GURL origin_;
+ FileSystemType type_;
+ FilePath internal_path_;
+
+ // Not owned.
+ // TODO(kinuko): This needs to be cleaned up; this value doesn't always
+ // reflect the current FileUtil in underlying filesystems.
+ FileSystemFileUtil* file_util_;
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_FILE_SYSTEM_PATH_H_
diff --git a/webkit/fileapi/file_system_quota_client_unittest.cc b/webkit/fileapi/file_system_quota_client_unittest.cc
index df0e345..837c479 100644
--- a/webkit/fileapi/file_system_quota_client_unittest.cc
+++ b/webkit/fileapi/file_system_quota_client_unittest.cc
@@ -119,36 +119,22 @@ class FileSystemQuotaClientTest : public testing::Test {
weak_factory_.GetWeakPtr()));
}
- FilePath GetOriginBasePath(const std::string& origin_url,
- quota::StorageType type) {
- // Note: this test assumes sandbox_provider impl is used for
- // temporary and persistent filesystem.
- return file_system_context_->sandbox_provider()->
- GetBaseDirectoryForOriginAndType(
- GURL(origin_url), QuotaStorageTypeToFileSystemType(type), true);
- }
-
- FileSystemOperationContext* CreateFileSystemOperationContext(
- FileSystemFileUtil* file_util,
- const FilePath& virtual_path,
- const std::string& origin_url,
- quota::StorageType type) {
+ FileSystemOperationContext* CreateFileSystemOperationContext() {
FileSystemOperationContext* context =
- new FileSystemOperationContext(file_system_context_, file_util);
- context->set_src_origin_url(GURL(origin_url));
- context->set_src_type(QuotaStorageTypeToFileSystemType(type));
+ new FileSystemOperationContext(file_system_context_);
context->set_allowed_bytes_growth(100000000);
return context;
}
- bool CreateFileSystemDirectory(const FilePath& path,
+ bool CreateFileSystemDirectory(const FilePath& file_path,
const std::string& origin_url,
- quota::StorageType type) {
- FileSystemFileUtil* file_util = file_system_context_->
- GetFileUtil(QuotaStorageTypeToFileSystemType(type));
+ quota::StorageType storage_type) {
+ FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type);
+ FileSystemFileUtil* file_util = file_system_context_->GetFileUtil(type);
+ FileSystemPath path(GURL(origin_url), type, file_path, file_util);
scoped_ptr<FileSystemOperationContext> context(
- CreateFileSystemOperationContext(file_util, path, origin_url, type));
+ CreateFileSystemOperationContext());
base::PlatformFileError result =
file_util->CreateDirectory(context.get(), path, false, false);
@@ -157,18 +143,20 @@ class FileSystemQuotaClientTest : public testing::Test {
return true;
}
- bool CreateFileSystemFile(const FilePath& path,
+ bool CreateFileSystemFile(const FilePath& file_path,
int64 file_size,
const std::string& origin_url,
- quota::StorageType type) {
- if (path.empty())
+ quota::StorageType storage_type) {
+ if (file_path.empty())
return false;
FileSystemFileUtil* file_util = file_system_context_->
sandbox_provider()->GetFileUtil();
+ FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type);
+ FileSystemPath path(GURL(origin_url), type, file_path, file_util);
scoped_ptr<FileSystemOperationContext> context(
- CreateFileSystemOperationContext(file_util, path, origin_url, type));
+ CreateFileSystemOperationContext());
bool created = false;
if (base::PLATFORM_FILE_OK !=
diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc
index 0d31f1d..96f50ea 100644
--- a/webkit/fileapi/file_system_test_helper.cc
+++ b/webkit/fileapi/file_system_test_helper.cc
@@ -106,7 +106,7 @@ FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) {
DCHECK(file_util_);
FilePath local_path;
scoped_ptr<FileSystemOperationContext> context(NewOperationContext());
- file_util_->GetLocalFilePath(context.get(), path, &local_path);
+ file_util_->GetLocalFilePath(context.get(), CreatePath(path), &local_path);
return local_path;
}
@@ -125,6 +125,11 @@ FilePath FileSystemTestOriginHelper::GetUsageCachePath() const {
sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_);
}
+FileSystemPath FileSystemTestOriginHelper::CreatePath(
+ const FilePath& path) const {
+ return FileSystemPath(origin_, type_, path, file_util_);
+}
+
int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const {
return FileSystemUsageCache::GetUsage(GetUsageCachePath());
}
@@ -147,26 +152,14 @@ FileSystemOperation* FileSystemTestOriginHelper::NewOperation() {
new FileSystemOperation(base::MessageLoopProxy::current(),
file_system_context_.get());
operation->set_override_file_util(file_util_);
- InitializeOperationContext(operation->file_system_operation_context());
return operation;
}
FileSystemOperationContext* FileSystemTestOriginHelper::NewOperationContext() {
DCHECK(file_system_context_.get());
- DCHECK(file_util_);
FileSystemOperationContext* context =
- new FileSystemOperationContext(file_system_context_.get(), file_util_);
- InitializeOperationContext(context);
+ new FileSystemOperationContext(file_system_context_.get());
return context;
}
-void FileSystemTestOriginHelper::InitializeOperationContext(
- FileSystemOperationContext* context) {
- DCHECK(context);
- context->set_src_origin_url(origin_);
- context->set_src_type(type_);
- context->set_dest_origin_url(origin_);
- context->set_dest_type(type_);
-}
-
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_test_helper.h b/webkit/fileapi/file_system_test_helper.h
index 10ec99d..af654ce 100644
--- a/webkit/fileapi/file_system_test_helper.h
+++ b/webkit/fileapi/file_system_test_helper.h
@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_path.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/quota/quota_types.h"
@@ -56,6 +57,12 @@ class FileSystemTestOriginHelper {
GURL GetURLForPath(const FilePath& path) const;
FilePath GetUsageCachePath() const;
+ // Creates a new FileSystemPath for the given |path|.
+ FileSystemPath CreatePath(const FilePath& path) const;
+ FileSystemPath CreatePathFromUTF8(const std::string& utf8) const {
+ return CreatePath(FilePath::FromUTF8Unsafe(utf8));
+ }
+
int64 GetCachedOriginUsage() const;
bool RevokeUsageCache() const;
@@ -77,8 +84,6 @@ class FileSystemTestOriginHelper {
FileSystemFileUtil* file_util() { return file_util_; }
private:
- void InitializeOperationContext(FileSystemOperationContext* context);
-
scoped_refptr<FileSystemContext> file_system_context_;
const GURL origin_;
const FileSystemType type_;
diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc
index 6a49af7..5664289 100644
--- a/webkit/fileapi/file_system_url_request_job_unittest.cc
+++ b/webkit/fileapi/file_system_url_request_job_unittest.cc
@@ -139,12 +139,14 @@ class FileSystemURLRequestJobTest : public testing::Test {
}
void CreateDirectory(const base::StringPiece& dir_name) {
- FilePath path = FilePath().AppendASCII(dir_name);
FileSystemFileUtil* file_util = file_system_context_->
sandbox_provider()->GetFileUtil();
- FileSystemOperationContext context(file_system_context_, file_util);
- context.set_src_origin_url(GURL("http://remote"));
- context.set_src_type(fileapi::kFileSystemTypeTemporary);
+ FileSystemPath path(GURL("http://remote"),
+ kFileSystemTypeTemporary,
+ FilePath().AppendASCII(dir_name),
+ file_util);
+
+ FileSystemOperationContext context(file_system_context_);
context.set_allowed_bytes_growth(1024);
ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory(
@@ -156,12 +158,14 @@ class FileSystemURLRequestJobTest : public testing::Test {
void WriteFile(const base::StringPiece& file_name,
const char* buf, int buf_size) {
- FilePath path = FilePath().AppendASCII(file_name);
FileSystemFileUtil* file_util = file_system_context_->
sandbox_provider()->GetFileUtil();
- FileSystemOperationContext context(file_system_context_, file_util);
- context.set_src_origin_url(GURL("http://remote"));
- context.set_src_type(fileapi::kFileSystemTypeTemporary);
+ FileSystemPath path(GURL("http://remote"),
+ kFileSystemTypeTemporary,
+ FilePath().AppendASCII(file_name),
+ file_util);
+
+ FileSystemOperationContext context(file_system_context_);
context.set_allowed_bytes_growth(1024);
base::PlatformFile handle = base::kInvalidPlatformFileValue;
diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc
index 4aafb88..577e796 100644
--- a/webkit/fileapi/file_writer_delegate.cc
+++ b/webkit/fileapi/file_writer_delegate.cc
@@ -30,12 +30,14 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
public:
InitializeTask(
base::PlatformFile file,
+ const FileSystemPath& path,
FileSystemOperationContext* context,
const InitializeTaskCallback& callback)
: origin_message_loop_proxy_(
base::MessageLoopProxy::current()),
error_code_(base::PLATFORM_FILE_OK),
file_(file),
+ path_(path),
context_(*context),
callback_(callback) {
DCHECK_EQ(false, callback.is_null());
@@ -58,11 +60,10 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
void ProcessOnTargetThread() {
DCHECK(context_.file_system_context());
FileSystemQuotaUtil* quota_util = context_.file_system_context()->
- GetQuotaUtil(context_.src_type());
+ GetQuotaUtil(path_.type());
if (quota_util) {
DCHECK(quota_util->proxy());
- quota_util->proxy()->StartUpdateOrigin(
- context_.src_origin_url(), context_.src_type());
+ quota_util->proxy()->StartUpdateOrigin(path_.origin(), path_.type());
}
if (!base::GetPlatformFileInfo(file_, &file_info_))
error_code_ = base::PLATFORM_FILE_ERROR_FAILED;
@@ -75,6 +76,7 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
base::PlatformFileError error_code_;
base::PlatformFile file_;
+ FileSystemPath path_;
FileSystemOperationContext context_;
InitializeTaskCallback callback_;
@@ -84,10 +86,13 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
} // namespace (anonymous)
FileWriterDelegate::FileWriterDelegate(
- FileSystemOperation* file_system_operation, int64 offset,
+ FileSystemOperation* file_system_operation,
+ const FileSystemPath& path,
+ int64 offset,
scoped_refptr<base::MessageLoopProxy> proxy)
: file_system_operation_(file_system_operation),
file_(base::kInvalidPlatformFileValue),
+ path_(path),
offset_(offset),
proxy_(proxy),
bytes_written_backlog_(0),
@@ -132,7 +137,8 @@ void FileWriterDelegate::Start(base::PlatformFile file,
request_ = request;
scoped_refptr<InitializeTask> relay = new InitializeTask(
- file_, file_system_operation_context(),
+ file_, path_,
+ file_system_operation_context(),
base::Bind(&FileWriterDelegate::OnGetFileInfoAndCallStartUpdate,
weak_factory_.GetWeakPtr()));
relay->Start(proxy_, FROM_HERE);
@@ -268,11 +274,8 @@ void FileWriterDelegate::OnError(base::PlatformFileError error) {
request_->set_delegate(NULL);
request_->Cancel();
- if (quota_util()) {
- quota_util()->proxy()->EndUpdateOrigin(
- file_system_operation_context()->src_origin_url(),
- file_system_operation_context()->src_type());
- }
+ if (quota_util())
+ quota_util()->proxy()->EndUpdateOrigin(path_.origin(), path_.type());
file_system_operation_->DidWrite(error, 0, true);
}
@@ -287,8 +290,7 @@ void FileWriterDelegate::OnProgress(int bytes_written, bool done) {
overlapped = size_ - total_bytes_written_ - offset_;
quota_util()->proxy()->UpdateOriginUsage(
file_system_operation_->file_system_context()->quota_manager_proxy(),
- file_system_operation_context()->src_origin_url(),
- file_system_operation_context()->src_type(),
+ path_.origin(), path_.type(),
bytes_written - overlapped);
}
static const int kMinProgressDelayMS = 200;
@@ -299,13 +301,8 @@ void FileWriterDelegate::OnProgress(int bytes_written, bool done) {
bytes_written += bytes_written_backlog_;
last_progress_event_time_ = currentTime;
bytes_written_backlog_ = 0;
- if (done && quota_util()) {
- if (quota_util()) {
- quota_util()->proxy()->EndUpdateOrigin(
- file_system_operation_context()->src_origin_url(),
- file_system_operation_context()->src_type());
- }
- }
+ if (done && quota_util())
+ quota_util()->proxy()->EndUpdateOrigin(path_.origin(), path_.type());
file_system_operation_->DidWrite(
base::PLATFORM_FILE_OK, bytes_written, done);
return;
@@ -325,7 +322,7 @@ FileSystemQuotaUtil* FileWriterDelegate::quota_util() const {
DCHECK(file_system_operation_->file_system_context());
DCHECK(file_system_operation_->file_system_operation_context());
return file_system_operation_->file_system_context()->GetQuotaUtil(
- file_system_operation_context()->src_type());
+ path_.type());
}
} // namespace fileapi
diff --git a/webkit/fileapi/file_writer_delegate.h b/webkit/fileapi/file_writer_delegate.h
index bd33163..dbb2d7c 100644
--- a/webkit/fileapi/file_writer_delegate.h
+++ b/webkit/fileapi/file_writer_delegate.h
@@ -14,6 +14,7 @@
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
+#include "webkit/fileapi/file_system_path.h"
namespace fileapi {
@@ -25,6 +26,7 @@ class FileWriterDelegate : public net::URLRequest::Delegate {
public:
FileWriterDelegate(
FileSystemOperation* write_operation,
+ const FileSystemPath& path,
int64 offset,
scoped_refptr<base::MessageLoopProxy> proxy);
virtual ~FileWriterDelegate();
@@ -66,6 +68,7 @@ class FileWriterDelegate : public net::URLRequest::Delegate {
FileSystemOperation* file_system_operation_;
base::PlatformFile file_;
+ FileSystemPath path_;
int64 size_;
int64 offset_;
scoped_refptr<base::MessageLoopProxy> proxy_;
diff --git a/webkit/fileapi/file_writer_delegate_unittest.cc b/webkit/fileapi/file_writer_delegate_unittest.cc
index efde1e7..82ac10b 100644
--- a/webkit/fileapi/file_writer_delegate_unittest.cc
+++ b/webkit/fileapi/file_writer_delegate_unittest.cc
@@ -114,6 +114,7 @@ class FileWriterDelegateTest : public PlatformTest {
result_.reset(new Result());
file_writer_delegate_.reset(new FileWriterDelegate(
CreateNewOperation(result_.get(), allowed_growth),
+ test_helper_.CreatePath(file_path_),
offset, base::MessageLoopProxy::current()));
request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get()));
}
@@ -321,6 +322,7 @@ TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimitConcurrent) {
result2.reset(new Result());
file_writer_delegate2.reset(new FileWriterDelegate(
CreateNewOperation(result2.get(), QuotaFileUtil::kNoLimit),
+ test_helper_.CreatePath(file_path2),
0, base::MessageLoopProxy::current()));
request2.reset(new net::URLRequest(kBlobURL2, file_writer_delegate2.get()));
diff --git a/webkit/fileapi/local_file_util.cc b/webkit/fileapi/local_file_util.cc
index 68b9c64..0e0cb69 100644
--- a/webkit/fileapi/local_file_util.cc
+++ b/webkit/fileapi/local_file_util.cc
@@ -9,6 +9,7 @@
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_path.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
@@ -69,12 +70,10 @@ LocalFileUtil::~LocalFileUtil() {
PlatformFileError LocalFileUtil::CreateOrOpen(
FileSystemOperationContext* context,
- const FilePath& file_path, int file_flags,
+ const FileSystemPath& path, int file_flags,
PlatformFile* file_handle, bool* created) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->CreateOrOpen(
context, local_path, file_flags, file_handle, created);
@@ -82,12 +81,10 @@ PlatformFileError LocalFileUtil::CreateOrOpen(
PlatformFileError LocalFileUtil::EnsureFileExists(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool* created) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->EnsureFileExists(
context, local_path, created);
@@ -95,13 +92,11 @@ PlatformFileError LocalFileUtil::EnsureFileExists(
PlatformFileError LocalFileUtil::CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool exclusive,
bool recursive) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->CreateDirectory(
context, local_path, exclusive, recursive);
@@ -109,13 +104,11 @@ PlatformFileError LocalFileUtil::CreateDirectory(
PlatformFileError LocalFileUtil::GetFileInfo(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_file_path) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->GetFileInfo(
context, local_path, file_info, platform_file_path);
@@ -123,13 +116,11 @@ PlatformFileError LocalFileUtil::GetFileInfo(
PlatformFileError LocalFileUtil::ReadDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries) {
// TODO(kkanetkar): Implement directory read in multiple chunks.
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->ReadDirectory(
context, local_path, entries);
@@ -137,14 +128,12 @@ PlatformFileError LocalFileUtil::ReadDirectory(
FileSystemFileUtil::AbstractFileEnumerator* LocalFileUtil::CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& root_path) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- root_path);
- if (local_path.empty())
+ const FileSystemPath& root_path) {
+ FileSystemPath local_path = GetLocalPath(context, root_path);
+ if (local_path.internal_path().empty())
return new EmptyFileEnumerator();
return new LocalFileEnumerator(
- local_path, root_path, true,
+ local_path.internal_path(), root_path.internal_path(), true,
static_cast<file_util::FileEnumerator::FileType>(
file_util::FileEnumerator::FILES |
file_util::FileEnumerator::DIRECTORIES));
@@ -152,27 +141,23 @@ FileSystemFileUtil::AbstractFileEnumerator* LocalFileUtil::CreateFileEnumerator(
PlatformFileError LocalFileUtil::GetLocalFilePath(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
- FilePath* local_path) {
- FilePath path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- virtual_path);
- if (path.empty())
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) {
+ FileSystemPath local_path = GetLocalPath(context, file_system_path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- *local_path = path;
+ *local_file_path = local_path.internal_path();
return base::PLATFORM_FILE_OK;
}
PlatformFileError LocalFileUtil::Touch(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->Touch(
context, local_path, last_access_time, last_modified_time);
@@ -180,12 +165,10 @@ PlatformFileError LocalFileUtil::Touch(
PlatformFileError LocalFileUtil::Truncate(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
int64 length) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->Truncate(
context, local_path, length);
@@ -193,11 +176,9 @@ PlatformFileError LocalFileUtil::Truncate(
bool LocalFileUtil::PathExists(
FileSystemOperationContext* context,
- const FilePath& file_path) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ const FileSystemPath& path) {
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return false;
return underlying_file_util()->PathExists(
context, local_path);
@@ -205,11 +186,9 @@ bool LocalFileUtil::PathExists(
bool LocalFileUtil::DirectoryExists(
FileSystemOperationContext* context,
- const FilePath& file_path) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ const FileSystemPath& path) {
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return false;
return underlying_file_util()->DirectoryExists(
context, local_path);
@@ -217,11 +196,9 @@ bool LocalFileUtil::DirectoryExists(
bool LocalFileUtil::IsDirectoryEmpty(
FileSystemOperationContext* context,
- const FilePath& file_path) {
- FilePath local_path =
- GetLocalPath(context, context->src_origin_url(), context->src_type(),
- file_path);
- if (local_path.empty())
+ const FileSystemPath& path) {
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return true;
return underlying_file_util()->IsDirectoryEmpty(
context, local_path);
@@ -229,19 +206,15 @@ bool LocalFileUtil::IsDirectoryEmpty(
PlatformFileError LocalFileUtil::CopyOrMoveFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_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())
+ FileSystemPath local_src_path = GetLocalPath(context, src_path);
+ if (local_src_path.internal_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())
+ FileSystemPath local_dest_path = GetLocalPath(context, dest_path);
+ if (local_dest_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->CopyOrMoveFile(
context, local_src_path, local_dest_path, copy);
@@ -250,26 +223,24 @@ PlatformFileError LocalFileUtil::CopyOrMoveFile(
// 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())
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) {
+ if (underlying_src_path.internal_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())
+ FileSystemPath local_dest_path = GetLocalPath(context, dest_path);
+ if (local_dest_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->CopyOrMoveFile(
- context, src_file_path, local_dest_path, true);
+ context,
+ underlying_src_path,
+ local_dest_path, true);
}
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())
+ const FileSystemPath& path) {
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->DeleteFile(
context, local_path);
@@ -277,26 +248,25 @@ PlatformFileError LocalFileUtil::DeleteFile(
PlatformFileError LocalFileUtil::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())
+ const FileSystemPath& path) {
+ FileSystemPath local_path = GetLocalPath(context, path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
return underlying_file_util()->DeleteSingleDirectory(
context, local_path);
}
-FilePath LocalFileUtil::GetLocalPath(
+FileSystemPath LocalFileUtil::GetLocalPath(
FileSystemOperationContext* context,
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path) {
- FilePath root = context->file_system_context()->GetMountPointProvider(type)->
- GetFileSystemRootPathOnFileThread(origin_url, type, virtual_path, false);
+ const FileSystemPath& path) {
+ FileSystemMountPointProvider* provider =
+ context->file_system_context()->GetMountPointProvider(path.type());
+ DCHECK(provider);
+ FilePath root = provider->GetFileSystemRootPathOnFileThread(
+ path.origin(), path.type(), path.internal_path(), false);
if (root.empty())
- return FilePath();
- return root.Append(virtual_path);
+ return FileSystemPath();
+ return path.WithInternalPath(root.Append(path.internal_path()));
}
} // namespace fileapi
diff --git a/webkit/fileapi/local_file_util.h b/webkit/fileapi/local_file_util.h
index 1c24ce4..c981183 100644
--- a/webkit/fileapi/local_file_util.h
+++ b/webkit/fileapi/local_file_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -30,6 +30,7 @@ using base::PlatformFile;
using base::PlatformFileError;
class FileSystemOperationContext;
+class FileSystemPath;
// An instance of this class is created and owned by *MountPointProvider.
class LocalFileUtil : public FileSystemFileUtil {
@@ -42,76 +43,74 @@ class LocalFileUtil : public FileSystemFileUtil {
virtual PlatformFileError CreateOrOpen(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
int file_flags,
PlatformFile* file_handle,
bool* created) OVERRIDE;
virtual PlatformFileError EnsureFileExists(
FileSystemOperationContext* context,
- const FilePath& file_path, bool* created) OVERRIDE;
+ const FileSystemPath& path, bool* created) OVERRIDE;
virtual PlatformFileError CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool exclusive,
bool recursive) OVERRIDE;
virtual PlatformFileError GetFileInfo(
FileSystemOperationContext* context,
- const FilePath& file,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_file) OVERRIDE;
virtual PlatformFileError ReadDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries) OVERRIDE;
virtual AbstractFileEnumerator* CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& root_path) OVERRIDE;
+ const FileSystemPath& root_path) OVERRIDE;
virtual PlatformFileError GetLocalFilePath(
FileSystemOperationContext* context,
- const FilePath& virtual_file,
- FilePath* local_path) OVERRIDE;
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) OVERRIDE;
virtual PlatformFileError Touch(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) OVERRIDE;
virtual PlatformFileError Truncate(
FileSystemOperationContext* context,
- const FilePath& path,
+ const FileSystemPath& path,
int64 length) OVERRIDE;
virtual bool PathExists(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual bool DirectoryExists(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual bool IsDirectoryEmpty(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual PlatformFileError CopyOrMoveFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) OVERRIDE;
virtual PlatformFileError CopyInForeignFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) OVERRIDE;
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) OVERRIDE;
virtual PlatformFileError DeleteFile(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual PlatformFileError DeleteSingleDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
private:
- // Given the filesystem's root URL and a virtual path, produces a real, full
- // local path.
- FilePath GetLocalPath(
+ // Given the filesystem path, produces a real, full local path for the
+ // underlying filesystem (which is usually the native filesystem).
+ FileSystemPath GetLocalPath(
FileSystemOperationContext* context,
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path);
+ const FileSystemPath& path);
DISALLOW_COPY_AND_ASSIGN(LocalFileUtil);
};
diff --git a/webkit/fileapi/local_file_util_unittest.cc b/webkit/fileapi/local_file_util_unittest.cc
index e1a138e..4851dc9 100644
--- a/webkit/fileapi/local_file_util_unittest.cc
+++ b/webkit/fileapi/local_file_util_unittest.cc
@@ -47,8 +47,8 @@ class LocalFileUtilTest : public testing::Test {
return local_file_util_.get();
}
- static FilePath Path(const std::string& file_name) {
- return FilePath().AppendASCII(file_name);
+ FileSystemPath Path(const std::string& file_name) {
+ return test_helper_.CreatePathFromUTF8(file_name);
}
FilePath LocalPath(const char *file_name) {
diff --git a/webkit/fileapi/native_file_util.cc b/webkit/fileapi/native_file_util.cc
index b87fca7..a30ac1c 100644
--- a/webkit/fileapi/native_file_util.cc
+++ b/webkit/fileapi/native_file_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -51,14 +51,14 @@ bool NativeFileEnumerator::IsDirectory() {
PlatformFileError NativeFileUtil::CreateOrOpen(
FileSystemOperationContext* unused,
- const FilePath& file_path, int file_flags,
+ const FileSystemPath& path, int file_flags,
PlatformFile* file_handle, bool* created) {
- if (!file_util::DirectoryExists(file_path.DirName())) {
+ if (!file_util::DirectoryExists(path.internal_path().DirName())) {
// If its parent does not exist, should return NOT_FOUND error.
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
}
PlatformFileError error_code = base::PLATFORM_FILE_OK;
- *file_handle = base::CreatePlatformFile(file_path, file_flags,
+ *file_handle = base::CreatePlatformFile(path.internal_path(), file_flags,
created, &error_code);
return error_code;
}
@@ -73,16 +73,16 @@ PlatformFileError NativeFileUtil::Close(
PlatformFileError NativeFileUtil::EnsureFileExists(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool* created) {
- if (!file_util::DirectoryExists(file_path.DirName()))
+ if (!file_util::DirectoryExists(path.internal_path().DirName()))
// If its parent does not exist, should return NOT_FOUND error.
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
PlatformFileError error_code = base::PLATFORM_FILE_OK;
- // Tries to create the |file_path| exclusively. This should fail
+ // Tries to create the |path| exclusively. This should fail
// with base::PLATFORM_FILE_ERROR_EXISTS if the path already exists.
PlatformFile handle = base::CreatePlatformFile(
- file_path,
+ path.internal_path(),
base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ,
created, &error_code);
if (error_code == base::PLATFORM_FILE_ERROR_EXISTS) {
@@ -98,56 +98,57 @@ PlatformFileError NativeFileUtil::EnsureFileExists(
PlatformFileError NativeFileUtil::CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool exclusive,
bool recursive) {
// If parent dir of file doesn't exist.
- if (!recursive && !file_util::PathExists(file_path.DirName()))
+ if (!recursive && !file_util::PathExists(path.internal_path().DirName()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- bool path_exists = file_util::PathExists(file_path);
+ bool path_exists = file_util::PathExists(path.internal_path());
if (exclusive && path_exists)
return base::PLATFORM_FILE_ERROR_EXISTS;
// If file exists at the path.
- if (path_exists && !file_util::DirectoryExists(file_path))
+ if (path_exists && !file_util::DirectoryExists(path.internal_path()))
return base::PLATFORM_FILE_ERROR_EXISTS;
- if (!file_util::CreateDirectory(file_path))
+ if (!file_util::CreateDirectory(path.internal_path()))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
PlatformFileError NativeFileUtil::GetFileInfo(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_file_path) {
- if (!file_util::PathExists(file_path))
+ if (!file_util::PathExists(path.internal_path()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
// TODO(rkc): Fix this hack once we have refactored file_util to handle
// symlinks correctly.
// http://code.google.com/p/chromium-os/issues/detail?id=15948
- if (file_util::IsLink(file_path))
+ if (file_util::IsLink(path.internal_path()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- if (!file_util::GetFileInfo(file_path, file_info))
+ if (!file_util::GetFileInfo(path.internal_path(), file_info))
return base::PLATFORM_FILE_ERROR_FAILED;
- *platform_file_path = file_path;
+ *platform_file_path = path.internal_path();
return base::PLATFORM_FILE_OK;
}
PlatformFileError NativeFileUtil::ReadDirectory(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries) {
// TODO(kkanetkar): Implement directory read in multiple chunks.
- if (!file_util::DirectoryExists(file_path))
+ if (!file_util::DirectoryExists(path.internal_path()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
file_util::FileEnumerator file_enum(
- file_path, false, static_cast<file_util::FileEnumerator::FileType>(
- file_util::FileEnumerator::FILES |
- file_util::FileEnumerator::DIRECTORIES));
+ path.internal_path(), false,
+ static_cast<file_util::FileEnumerator::FileType>(
+ file_util::FileEnumerator::FILES |
+ file_util::FileEnumerator::DIRECTORIES));
FilePath current;
while (!(current = file_enum.Next()).empty()) {
base::FileUtilProxy::Entry entry;
@@ -164,7 +165,7 @@ PlatformFileError NativeFileUtil::ReadDirectory(
// http://code.google.com/p/chromium-os/issues/detail?id=15948
// This currently just prevents a file from showing up at all
// if it's a link, hence preventing arbitary 'read' exploits.
- if (!file_util::IsLink(file_path.Append(entry.name)))
+ if (!file_util::IsLink(path.internal_path().Append(entry.name)))
entries->push_back(entry);
}
return base::PLATFORM_FILE_OK;
@@ -173,40 +174,41 @@ PlatformFileError NativeFileUtil::ReadDirectory(
FileSystemFileUtil::AbstractFileEnumerator*
NativeFileUtil::CreateFileEnumerator(
FileSystemOperationContext* unused,
- const FilePath& root_path) {
+ const FileSystemPath& root_path) {
return new NativeFileEnumerator(
- root_path, true, static_cast<file_util::FileEnumerator::FileType>(
- file_util::FileEnumerator::FILES |
- file_util::FileEnumerator::DIRECTORIES));
+ root_path.internal_path(), true,
+ static_cast<file_util::FileEnumerator::FileType>(
+ file_util::FileEnumerator::FILES |
+ file_util::FileEnumerator::DIRECTORIES));
}
PlatformFileError NativeFileUtil::GetLocalFilePath(
FileSystemOperationContext* unused,
- const FilePath& virtual_path,
- FilePath* local_path) {
- *local_path = virtual_path;
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) {
+ *local_file_path = file_system_path.internal_path();
return base::PLATFORM_FILE_OK;
}
PlatformFileError NativeFileUtil::Touch(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
if (!file_util::TouchFile(
- file_path, last_access_time, last_modified_time))
+ path.internal_path(), last_access_time, last_modified_time))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
PlatformFileError NativeFileUtil::Truncate(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
int64 length) {
PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED);
PlatformFile file =
base::CreatePlatformFile(
- file_path,
+ path.internal_path(),
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
NULL,
&error_code);
@@ -222,33 +224,34 @@ PlatformFileError NativeFileUtil::Truncate(
bool NativeFileUtil::PathExists(
FileSystemOperationContext* unused,
- const FilePath& file_path) {
- return file_util::PathExists(file_path);
+ const FileSystemPath& path) {
+ return file_util::PathExists(path.internal_path());
}
bool NativeFileUtil::DirectoryExists(
FileSystemOperationContext* unused,
- const FilePath& file_path) {
- return file_util::DirectoryExists(file_path);
+ const FileSystemPath& path) {
+ return file_util::DirectoryExists(path.internal_path());
}
bool NativeFileUtil::IsDirectoryEmpty(
FileSystemOperationContext* unused,
- const FilePath& file_path) {
- return file_util::IsDirectoryEmpty(file_path);
+ const FileSystemPath& path) {
+ return file_util::IsDirectoryEmpty(path.internal_path());
}
PlatformFileError NativeFileUtil::CopyOrMoveFile(
FileSystemOperationContext* unused,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) {
if (copy) {
- if (file_util::CopyFile(src_file_path, dest_file_path))
+ if (file_util::CopyFile(src_path.internal_path(),
+ dest_path.internal_path()))
return base::PLATFORM_FILE_OK;
} else {
- DCHECK(!file_util::DirectoryExists(src_file_path));
- if (file_util::Move(src_file_path, dest_file_path))
+ DCHECK(!file_util::DirectoryExists(src_path.internal_path()));
+ if (file_util::Move(src_path.internal_path(), dest_path.internal_path()))
return base::PLATFORM_FILE_OK;
}
return base::PLATFORM_FILE_ERROR_FAILED;
@@ -256,37 +259,40 @@ PlatformFileError NativeFileUtil::CopyOrMoveFile(
PlatformFileError NativeFileUtil::CopyInForeignFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
- return CopyOrMoveFile(context, src_file_path, dest_file_path, true);
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) {
+ return CopyOrMoveFile(context,
+ underlying_src_path,
+ dest_path,
+ true);
}
PlatformFileError NativeFileUtil::DeleteFile(
FileSystemOperationContext* unused,
- const FilePath& file_path) {
- if (!file_util::PathExists(file_path))
+ const FileSystemPath& path) {
+ if (!file_util::PathExists(path.internal_path()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- if (file_util::DirectoryExists(file_path))
+ if (file_util::DirectoryExists(path.internal_path()))
return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
- if (!file_util::Delete(file_path, false))
+ if (!file_util::Delete(path.internal_path(), false))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
PlatformFileError NativeFileUtil::DeleteSingleDirectory(
FileSystemOperationContext* unused,
- const FilePath& file_path) {
- if (!file_util::PathExists(file_path))
+ const FileSystemPath& path) {
+ if (!file_util::PathExists(path.internal_path()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- if (!file_util::DirectoryExists(file_path)) {
+ if (!file_util::DirectoryExists(path.internal_path())) {
// TODO(dmikurube): Check if this error code is appropriate.
return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
}
- if (!file_util::IsDirectoryEmpty(file_path)) {
+ if (!file_util::IsDirectoryEmpty(path.internal_path())) {
// TODO(dmikurube): Check if this error code is appropriate.
return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
}
- if (!file_util::Delete(file_path, false))
+ if (!file_util::Delete(path.internal_path(), false))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
diff --git a/webkit/fileapi/native_file_util.h b/webkit/fileapi/native_file_util.h
index 5669680..0e2ee05 100644
--- a/webkit/fileapi/native_file_util.h
+++ b/webkit/fileapi/native_file_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -29,7 +29,7 @@ class NativeFileUtil : public FileSystemFileUtil {
virtual PlatformFileError CreateOrOpen(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
int file_flags,
PlatformFile* file_handle,
bool* created) OVERRIDE;
@@ -38,61 +38,61 @@ class NativeFileUtil : public FileSystemFileUtil {
PlatformFile) OVERRIDE;
virtual PlatformFileError EnsureFileExists(
FileSystemOperationContext* unused,
- const FilePath& file_path, bool* created) OVERRIDE;
+ const FileSystemPath& path, bool* created) OVERRIDE;
virtual PlatformFileError CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool exclusive,
bool recursive) OVERRIDE;
virtual PlatformFileError GetFileInfo(
FileSystemOperationContext* unused,
- const FilePath& file_,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
- FilePath* platform_path) OVERRIDE;
+ FilePath* platform_file_path) OVERRIDE;
virtual PlatformFileError ReadDirectory(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries) OVERRIDE;
virtual AbstractFileEnumerator* CreateFileEnumerator(
FileSystemOperationContext* unused,
- const FilePath& root_path) OVERRIDE;
+ const FileSystemPath& root_path) OVERRIDE;
virtual PlatformFileError GetLocalFilePath(
FileSystemOperationContext* unused,
- const FilePath& virtual_path,
- FilePath* local_path) OVERRIDE;
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) OVERRIDE;
virtual PlatformFileError Touch(
FileSystemOperationContext* unused,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) OVERRIDE;
virtual PlatformFileError Truncate(
FileSystemOperationContext* unused,
- const FilePath& path,
+ const FileSystemPath& path,
int64 length) OVERRIDE;
virtual bool PathExists(
FileSystemOperationContext* unused,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual bool DirectoryExists(
FileSystemOperationContext* unused,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual bool IsDirectoryEmpty(
FileSystemOperationContext* unused,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual PlatformFileError CopyOrMoveFile(
FileSystemOperationContext* unused,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) OVERRIDE;
virtual PlatformFileError CopyInForeignFile(
FileSystemOperationContext* unused,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) OVERRIDE;
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) OVERRIDE;
virtual PlatformFileError DeleteFile(
FileSystemOperationContext* unused,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual PlatformFileError DeleteSingleDirectory(
FileSystemOperationContext* unused,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(NativeFileUtil);
diff --git a/webkit/fileapi/obfuscated_file_util.cc b/webkit/fileapi/obfuscated_file_util.cc
index 8cb1702..06090d8 100644
--- a/webkit/fileapi/obfuscated_file_util.cc
+++ b/webkit/fileapi/obfuscated_file_util.cc
@@ -19,11 +19,14 @@
#include "googleurl/src/gurl.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_path.h"
#include "webkit/fileapi/file_system_quota_util.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/quota_manager.h"
+namespace fileapi {
+
namespace {
const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes
@@ -32,17 +35,17 @@ const char kOriginDatabaseName[] = "Origins";
const char kDirectoryDatabaseName[] = "Paths";
void InitFileInfo(
- fileapi::FileSystemDirectoryDatabase::FileInfo* file_info,
- fileapi::FileSystemDirectoryDatabase::FileId parent_id,
+ FileSystemDirectoryDatabase::FileInfo* file_info,
+ FileSystemDirectoryDatabase::FileId parent_id,
const FilePath::StringType& file_name) {
DCHECK(file_info);
file_info->parent_id = parent_id;
file_info->name = file_name;
}
-bool IsRootDirectory(const FilePath& virtual_path) {
- return (virtual_path.empty() ||
- virtual_path.value() == FILE_PATH_LITERAL("/"));
+bool IsRootDirectory(const FileSystemPath& virtual_path) {
+ return (virtual_path.internal_path().empty() ||
+ virtual_path.internal_path().value() == FILE_PATH_LITERAL("/"));
}
// Costs computed as per crbug.com/86114, based on the LevelDB implementation of
@@ -61,7 +64,7 @@ int64 GetPathQuotaUsage(
}
bool AllocateQuotaForPath(
- fileapi::FileSystemOperationContext* context,
+ FileSystemOperationContext* context,
int growth_in_number_of_paths,
int64 growth_in_bytes_of_path_length) {
int64 growth = GetPathQuotaUsage(growth_in_number_of_paths,
@@ -76,23 +79,23 @@ bool AllocateQuotaForPath(
}
void UpdatePathQuotaUsage(
- fileapi::FileSystemOperationContext* context,
- const GURL& origin_url,
- fileapi::FileSystemType type,
+ FileSystemOperationContext* context,
+ const GURL& origin,
+ FileSystemType type,
int growth_in_number_of_paths, // -1, 0, or 1
int64 growth_in_bytes_of_path_length) {
int64 growth = GetPathQuotaUsage(growth_in_number_of_paths,
growth_in_bytes_of_path_length);
- fileapi::FileSystemQuotaUtil* quota_util =
+ FileSystemQuotaUtil* quota_util =
context->file_system_context()->GetQuotaUtil(type);
quota::QuotaManagerProxy* quota_manager_proxy =
context->file_system_context()->quota_manager_proxy();
- quota_util->UpdateOriginUsageOnFileThread(quota_manager_proxy, origin_url,
- type, growth);
+ quota_util->UpdateOriginUsageOnFileThread(
+ quota_manager_proxy, origin, type, growth);
}
-void TouchDirectory(fileapi::FileSystemDirectoryDatabase* db,
- fileapi::FileSystemDirectoryDatabase::FileId dir_id) {
+void TouchDirectory(FileSystemDirectoryDatabase* db,
+ FileSystemDirectoryDatabase::FileId dir_id) {
DCHECK(db);
if (!db->UpdateModificationTime(dir_id, base::Time::Now()))
NOTREACHED();
@@ -105,8 +108,6 @@ const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p");
} // namespace
-namespace fileapi {
-
using base::PlatformFile;
using base::PlatformFileError;
@@ -118,8 +119,9 @@ class ObfuscatedFileEnumerator
FileSystemDirectoryDatabase* db,
FileSystemOperationContext* context,
FileSystemFileUtil* underlying_file_util,
- const FilePath& virtual_root_path)
+ const FileSystemPath& virtual_root_path)
: base_path_(base_path),
+ virtual_root_path_(virtual_root_path),
db_(db),
context_(context),
underlying_file_util_(underlying_file_util) {
@@ -129,13 +131,14 @@ class ObfuscatedFileEnumerator
FileId file_id;
FileInfo file_info;
- if (!db_->GetFileWithPath(virtual_root_path, &file_id))
+ if (!db_->GetFileWithPath(virtual_root_path.internal_path(), &file_id))
return;
if (!db_->GetFileInfo(file_id, &file_info))
return;
if (!file_info.is_directory())
return;
- FileRecord record = { file_id, file_info, virtual_root_path };
+ FileRecord record = { file_id, file_info,
+ virtual_root_path.internal_path() };
display_queue_.push(record);
Next(); // Enumerators don't include the directory itself.
}
@@ -162,7 +165,9 @@ class ObfuscatedFileEnumerator
FilePath local_path = base_path_.Append(current_.file_info.data_path);
base::PlatformFileError error = underlying_file_util_->GetFileInfo(
- context_, local_path, &file_info, &platform_file_path);
+ context_,
+ virtual_root_path_.WithInternalPath(local_path),
+ &file_info, &platform_file_path);
if (error != base::PLATFORM_FILE_OK) {
LOG(WARNING) << "Lost a backing file.";
return 0;
@@ -207,6 +212,7 @@ class ObfuscatedFileEnumerator
std::queue<FileRecord> recurse_queue_;
FileRecord current_;
FilePath base_path_;
+ FileSystemPath virtual_root_path_;
FileSystemDirectoryDatabase* db_;
FileSystemOperationContext* context_;
FileSystemFileUtil* underlying_file_util_;
@@ -270,31 +276,34 @@ ObfuscatedFileUtil::~ObfuscatedFileUtil() {
PlatformFileError ObfuscatedFileUtil::CreateOrOpen(
FileSystemOperationContext* context,
- const FilePath& virtual_path, int file_flags,
+ const FileSystemPath& virtual_path, int file_flags,
PlatformFile* file_handle, bool* created) {
DCHECK(!(file_flags & (base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_HIDDEN | base::PLATFORM_FILE_EXCLUSIVE_READ |
base::PLATFORM_FILE_EXCLUSIVE_WRITE)));
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), true);
+ virtual_path.origin(), virtual_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id)) {
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id)) {
// The file doesn't exist.
if (!(file_flags & (base::PLATFORM_FILE_CREATE |
base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_ALWAYS)))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileId parent_id;
- if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path().DirName(),
+ &parent_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
- InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value());
+ InitFileInfo(&file_info, parent_id,
+ virtual_path.internal_path().BaseName().value());
if (!AllocateQuotaForPath(context, 1, file_info.name.size()))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
PlatformFileError error = CreateFile(
- context, context->src_origin_url(), context->src_type(), FilePath(),
- &file_info, file_flags, file_handle);
+ context, FileSystemPath(),
+ virtual_path.origin(), virtual_path.type(), &file_info,
+ file_flags, file_handle);
if (created && base::PLATFORM_FILE_OK == error)
*created = true;
return error;
@@ -309,16 +318,15 @@ PlatformFileError ObfuscatedFileUtil::CreateOrOpen(
}
if (file_info.is_directory())
return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
- FilePath local_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), file_info.data_path);
+ FileSystemPath local_path = DataPathToLocalPath(
+ virtual_path.origin(), virtual_path.type(), file_info.data_path);
base::PlatformFileError error = underlying_file_util()->CreateOrOpen(
context, local_path, file_flags, file_handle, created);
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
// TODO(tzik): Also invalidate on-memory usage cache in UsageTracker.
// TODO(tzik): Delete database entry after ensuring the file lost.
- context->file_system_context()->GetQuotaUtil(context->src_type())->
- InvalidateUsageCache(context->src_origin_url(),
- context->src_type());
+ context->file_system_context()->GetQuotaUtil(virtual_path.type())->
+ InvalidateUsageCache(virtual_path.origin(), virtual_path.type());
LOG(WARNING) << "Lost a backing file.";
error = base::PLATFORM_FILE_ERROR_FAILED;
}
@@ -327,14 +335,14 @@ PlatformFileError ObfuscatedFileUtil::CreateOrOpen(
PlatformFileError ObfuscatedFileUtil::EnsureFileExists(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
+ const FileSystemPath& virtual_path,
bool* created) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), true);
+ virtual_path.origin(), virtual_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId file_id;
- if (db->GetFileWithPath(virtual_path, &file_id)) {
+ if (db->GetFileWithPath(virtual_path.internal_path(), &file_id)) {
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info)) {
NOTREACHED();
@@ -347,15 +355,18 @@ PlatformFileError ObfuscatedFileUtil::EnsureFileExists(
return base::PLATFORM_FILE_OK;
}
FileId parent_id;
- if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path().DirName(), &parent_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
- InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value());
+ InitFileInfo(&file_info, parent_id,
+ virtual_path.internal_path().BaseName().value());
if (!AllocateQuotaForPath(context, 1, file_info.name.size()))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
- PlatformFileError error = CreateFile(context, context->src_origin_url(),
- context->src_type(), FilePath(), &file_info, 0, NULL);
+ PlatformFileError error = CreateFile(context,
+ FileSystemPath(),
+ virtual_path.origin(), virtual_path.type(), &file_info,
+ 0, NULL);
if (created && base::PLATFORM_FILE_OK == error)
*created = true;
return error;
@@ -363,15 +374,15 @@ PlatformFileError ObfuscatedFileUtil::EnsureFileExists(
PlatformFileError ObfuscatedFileUtil::CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
+ const FileSystemPath& virtual_path,
bool exclusive,
bool recursive) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), true);
+ virtual_path.origin(), virtual_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId file_id;
- if (db->GetFileWithPath(virtual_path, &file_id)) {
+ if (db->GetFileWithPath(virtual_path.internal_path(), &file_id)) {
FileInfo file_info;
if (exclusive)
return base::PLATFORM_FILE_ERROR_EXISTS;
@@ -385,7 +396,7 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory(
}
std::vector<FilePath::StringType> components;
- virtual_path.GetComponents(&components);
+ virtual_path.internal_path().GetComponents(&components);
FileId parent_id = 0;
size_t index;
for (index = 0; index < components.size(); ++index) {
@@ -411,8 +422,8 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory(
NOTREACHED();
return base::PLATFORM_FILE_ERROR_FAILED;
}
- UpdatePathQuotaUsage(context, context->src_origin_url(),
- context->src_type(), 1, file_info.name.size());
+ UpdatePathQuotaUsage(context, virtual_path.origin(), virtual_path.type(),
+ 1, file_info.name.size());
if (first) {
first = false;
TouchDirectory(db, file_info.parent_id);
@@ -423,28 +434,30 @@ PlatformFileError ObfuscatedFileUtil::CreateDirectory(
PlatformFileError ObfuscatedFileUtil::GetFileInfo(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
+ const FileSystemPath& virtual_path,
base::PlatformFileInfo* file_info,
FilePath* platform_file_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db)
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo local_info;
- return GetFileInfoInternal(db, context, file_id,
- &local_info, file_info, platform_file_path);
+ return GetFileInfoInternal(db, context,
+ virtual_path.origin(), virtual_path.type(),
+ file_id, &local_info,
+ file_info, platform_file_path);
}
PlatformFileError ObfuscatedFileUtil::ReadDirectory(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
+ const FileSystemPath& virtual_path,
std::vector<base::FileUtilProxy::Entry>* entries) {
// TODO(kkanetkar): Implement directory read in multiple chunks.
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db) {
if (IsRootDirectory(virtual_path)) {
// It's the root directory and the database hasn't been initialized yet.
@@ -454,7 +467,7 @@ PlatformFileError ObfuscatedFileUtil::ReadDirectory(
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
}
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info)) {
@@ -474,8 +487,10 @@ PlatformFileError ObfuscatedFileUtil::ReadDirectory(
for (iter = children.begin(); iter != children.end(); ++iter) {
base::PlatformFileInfo platform_file_info;
FilePath file_path;
- if (GetFileInfoInternal(db, context, *iter,
- &file_info, &platform_file_info, &file_path) !=
+ if (GetFileInfoInternal(db, context,
+ virtual_path.origin(), virtual_path.type(),
+ *iter, &file_info, &platform_file_info,
+ &file_path) !=
base::PLATFORM_FILE_OK) {
LOG(WARNING) << "Lost a backing file.";
// TODO(tzik): We found a file entry in directory database without
@@ -497,14 +512,14 @@ PlatformFileError ObfuscatedFileUtil::ReadDirectory(
FileSystemFileUtil::AbstractFileEnumerator*
ObfuscatedFileUtil::CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& root_path) {
+ const FileSystemPath& root_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ root_path.origin(), root_path.type(), false);
if (!db)
return new FileSystemFileUtil::EmptyFileEnumerator();
return new ObfuscatedFileEnumerator(
- GetDirectoryForOriginAndType(context->src_origin_url(),
- context->src_type(), false),
+ GetDirectoryForOriginAndType(root_path.origin(),
+ root_path.type(), false),
db,
context,
underlying_file_util(),
@@ -513,29 +528,27 @@ ObfuscatedFileUtil::CreateFileEnumerator(
PlatformFileError ObfuscatedFileUtil::GetLocalFilePath(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
- FilePath* local_path) {
- FilePath path =
- GetLocalPath(context->src_origin_url(), context->src_type(),
- virtual_path);
- if (path.empty())
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) {
+ FileSystemPath local_path = GetLocalPath(file_system_path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- *local_path = path;
+ *local_file_path = local_path.internal_path();
return base::PLATFORM_FILE_OK;
}
PlatformFileError ObfuscatedFileUtil::Touch(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
+ const FileSystemPath& virtual_path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db)
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
@@ -548,39 +561,37 @@ PlatformFileError ObfuscatedFileUtil::Touch(
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
- FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), file_info.data_path);
+ FileSystemPath local_path = DataPathToLocalPath(
+ virtual_path.origin(), virtual_path.type(), file_info.data_path);
return underlying_file_util()->Touch(
- context, data_path, last_access_time, last_modified_time);
+ context, local_path,
+ last_access_time, last_modified_time);
}
PlatformFileError ObfuscatedFileUtil::Truncate(
FileSystemOperationContext* context,
- const FilePath& virtual_path,
+ const FileSystemPath& virtual_path,
int64 length) {
- FilePath local_path =
- GetLocalPath(context->src_origin_url(), context->src_type(),
- virtual_path);
- if (local_path.empty())
+ FileSystemPath local_path = GetLocalPath(virtual_path);
+ if (local_path.internal_path().empty())
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
- return underlying_file_util()->Truncate(
- context, local_path, length);
+ return underlying_file_util()->Truncate(context, local_path, length);
}
bool ObfuscatedFileUtil::PathExists(
FileSystemOperationContext* context,
- const FilePath& virtual_path) {
+ const FileSystemPath& virtual_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db)
return false;
FileId file_id;
- return db->GetFileWithPath(virtual_path, &file_id);
+ return db->GetFileWithPath(virtual_path.internal_path(), &file_id);
}
bool ObfuscatedFileUtil::DirectoryExists(
FileSystemOperationContext* context,
- const FilePath& virtual_path) {
+ const FileSystemPath& virtual_path) {
if (IsRootDirectory(virtual_path)) {
// It's questionable whether we should return true or false for the
// root directory of nonexistent origin, but here we return true
@@ -592,11 +603,11 @@ bool ObfuscatedFileUtil::DirectoryExists(
return true;
}
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db)
return false;
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return false;
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info)) {
@@ -608,13 +619,13 @@ bool ObfuscatedFileUtil::DirectoryExists(
bool ObfuscatedFileUtil::IsDirectoryEmpty(
FileSystemOperationContext* context,
- const FilePath& virtual_path) {
+ const FileSystemPath& virtual_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db)
return true; // Not a great answer, but it's what others do.
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return true; // Ditto.
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info)) {
@@ -633,22 +644,23 @@ bool ObfuscatedFileUtil::IsDirectoryEmpty(
PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) {
// Cross-filesystem copies and moves should be handled via CopyInForeignFile.
- DCHECK(context->src_origin_url() == context->dest_origin_url());
- DCHECK(context->src_type() == context->dest_type());
+ DCHECK(src_path.origin() == dest_path.origin());
+ DCHECK(src_path.type() == dest_path.type());
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), true);
+ src_path.origin(), src_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId src_file_id;
- if (!db->GetFileWithPath(src_file_path, &src_file_id))
+ if (!db->GetFileWithPath(src_path.internal_path(), &src_file_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileId dest_file_id;
- bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id);
+ bool overwrite = db->GetFileWithPath(dest_path.internal_path(),
+ &dest_file_id);
FileInfo src_file_info;
FileInfo dest_file_info;
if (!db->GetFileInfo(src_file_id, &src_file_info) ||
@@ -678,38 +690,38 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
* Just update metadata
*/
if (copy) {
- FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), src_file_info.data_path);
- if (!underlying_file_util()->PathExists(context, src_data_path)) {
+ FileSystemPath src_local_path = DataPathToLocalPath(
+ src_path.origin(), src_path.type(), src_file_info.data_path);
+ if (!underlying_file_util()->PathExists(context, src_local_path)) {
// TODO(tzik): Also invalidate on-memory usage cache in UsageTracker.
- context->file_system_context()->GetQuotaUtil(context->src_type())->
- InvalidateUsageCache(context->src_origin_url(),
- context->src_type());
+ context->file_system_context()->GetQuotaUtil(src_path.type())->
+ InvalidateUsageCache(src_path.origin(), src_path.type());
LOG(WARNING) << "Lost a backing file.";
return base::PLATFORM_FILE_ERROR_FAILED;
}
if (overwrite) {
- FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), dest_file_info.data_path);
+ FileSystemPath dest_local_path = DataPathToLocalPath(
+ dest_path.origin(), dest_path.type(), dest_file_info.data_path);
PlatformFileError error = underlying_file_util()->CopyOrMoveFile(context,
- src_data_path, dest_data_path, copy);
+ src_local_path, dest_local_path, copy);
if (error == base::PLATFORM_FILE_OK)
TouchDirectory(db, dest_file_info.parent_id);
return error;
} else {
FileId dest_parent_id;
- if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
+ if (!db->GetFileWithPath(dest_path.internal_path().DirName(),
+ &dest_parent_id)) {
NOTREACHED(); // We shouldn't be called in this case.
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
}
InitFileInfo(&dest_file_info, dest_parent_id,
- dest_file_path.BaseName().value());
+ dest_path.internal_path().BaseName().value());
if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size()))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
- return CreateFile(context, context->dest_origin_url(),
- context->dest_type(), src_data_path, &dest_file_info, 0,
- NULL);
+ return CreateFile(context, src_local_path,
+ dest_path.origin(), dest_path.type(), &dest_file_info,
+ 0, NULL);
}
} else { // It's a move.
if (overwrite) {
@@ -717,37 +729,39 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
-static_cast<int64>(src_file_info.name.size()));
if (!db->OverwritingMoveFile(src_file_id, dest_file_id))
return base::PLATFORM_FILE_ERROR_FAILED;
- FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), dest_file_info.data_path);
+ FileSystemPath dest_local_path = DataPathToLocalPath(
+ dest_path.origin(), dest_path.type(), dest_file_info.data_path);
if (base::PLATFORM_FILE_OK !=
- underlying_file_util()->DeleteFile(context, dest_data_path))
+ underlying_file_util()->DeleteFile(context, dest_local_path))
LOG(WARNING) << "Leaked a backing file.";
- UpdatePathQuotaUsage(context, context->src_origin_url(),
- context->src_type(), -1,
- -static_cast<int64>(src_file_info.name.size()));
+ UpdatePathQuotaUsage(context, src_path.origin(), src_path.type(),
+ -1, -static_cast<int64>(src_file_info.name.size()));
TouchDirectory(db, src_file_info.parent_id);
TouchDirectory(db, dest_file_info.parent_id);
return base::PLATFORM_FILE_OK;
} else {
FileId dest_parent_id;
- if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
+ if (!db->GetFileWithPath(dest_path.internal_path().DirName(),
+ &dest_parent_id)) {
NOTREACHED();
return base::PLATFORM_FILE_ERROR_FAILED;
}
+ FilePath dest_internal_path = dest_path.internal_path();
+ FilePath src_internal_path = src_path.internal_path();
if (!AllocateQuotaForPath(
context, 0,
- static_cast<int64>(dest_file_path.BaseName().value().size())
- - static_cast<int64>(src_file_info.name.size())))
+ static_cast<int64>(dest_internal_path.BaseName().value().size())
+ -static_cast<int64>(src_file_info.name.size())))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
FileId src_parent_id = src_file_info.parent_id;
src_file_info.parent_id = dest_parent_id;
- src_file_info.name = dest_file_path.BaseName().value();
+ src_file_info.name = dest_path.internal_path().BaseName().value();
if (!db->UpdateFileInfo(src_file_id, src_file_info))
return base::PLATFORM_FILE_ERROR_FAILED;
UpdatePathQuotaUsage(
- context, context->src_origin_url(), context->src_type(), 0,
- static_cast<int64>(dest_file_path.BaseName().value().size()) -
- static_cast<int64>(src_file_path.BaseName().value().size()));
+ context, src_path.origin(), src_path.type(), 0,
+ static_cast<int64>(dest_internal_path.BaseName().value().size()) -
+ static_cast<int64>(src_internal_path.BaseName().value().size()));
TouchDirectory(db, src_parent_id);
TouchDirectory(db, dest_parent_id);
return base::PLATFORM_FILE_OK;
@@ -759,14 +773,15 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile(
PlatformFileError ObfuscatedFileUtil::CopyInForeignFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) {
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->dest_origin_url(), context->dest_type(), true);
+ dest_path.origin(), dest_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId dest_file_id;
- bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id);
+ bool overwrite = db->GetFileWithPath(dest_path.internal_path(),
+ &dest_file_id);
FileInfo dest_file_info;
if (overwrite) {
if (!db->GetFileInfo(dest_file_id, &dest_file_info) ||
@@ -774,35 +789,38 @@ PlatformFileError ObfuscatedFileUtil::CopyInForeignFile(
NOTREACHED();
return base::PLATFORM_FILE_ERROR_FAILED;
}
- FilePath dest_data_path = DataPathToLocalPath(context->dest_origin_url(),
- context->dest_type(), dest_file_info.data_path);
+ FileSystemPath dest_local_path = DataPathToLocalPath(
+ dest_path.origin(), dest_path.type(), dest_file_info.data_path);
return underlying_file_util()->CopyOrMoveFile(context,
- src_file_path, dest_data_path, true /* copy */);
+ underlying_src_path,
+ dest_local_path, true /* copy */);
} else {
FileId dest_parent_id;
- if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) {
+ if (!db->GetFileWithPath(dest_path.internal_path().DirName(),
+ &dest_parent_id)) {
NOTREACHED(); // We shouldn't be called in this case.
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
}
InitFileInfo(&dest_file_info, dest_parent_id,
- dest_file_path.BaseName().value());
+ dest_path.internal_path().BaseName().value());
if (!AllocateQuotaForPath(context, 1, dest_file_info.name.size()))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
- return CreateFile(context, context->dest_origin_url(),
- context->dest_type(), src_file_path, &dest_file_info, 0, NULL);
+ return CreateFile(context, underlying_src_path,
+ dest_path.origin(), dest_path.type(), &dest_file_info,
+ 0, NULL);
}
return base::PLATFORM_FILE_ERROR_FAILED;
}
PlatformFileError ObfuscatedFileUtil::DeleteFile(
FileSystemOperationContext* context,
- const FilePath& virtual_path) {
+ const FileSystemPath& virtual_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), true);
+ virtual_path.origin(), virtual_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) {
@@ -814,12 +832,12 @@ PlatformFileError ObfuscatedFileUtil::DeleteFile(
return base::PLATFORM_FILE_ERROR_FAILED;
}
AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size()));
- UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(),
+ UpdatePathQuotaUsage(context, virtual_path.origin(), virtual_path.type(),
-1, -static_cast<int64>(file_info.name.size()));
- FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), file_info.data_path);
+ FileSystemPath local_path = DataPathToLocalPath(
+ virtual_path.origin(), virtual_path.type(), file_info.data_path);
if (base::PLATFORM_FILE_OK !=
- underlying_file_util()->DeleteFile(context, data_path))
+ underlying_file_util()->DeleteFile(context, local_path))
LOG(WARNING) << "Leaked a backing file.";
TouchDirectory(db, file_info.parent_id);
return base::PLATFORM_FILE_OK;
@@ -827,13 +845,13 @@ PlatformFileError ObfuscatedFileUtil::DeleteFile(
PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory(
FileSystemOperationContext* context,
- const FilePath& virtual_path) {
+ const FileSystemPath& virtual_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- context->src_origin_url(), context->src_type(), true);
+ virtual_path.origin(), virtual_path.type(), true);
if (!db)
return base::PLATFORM_FILE_ERROR_FAILED;
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) {
@@ -843,7 +861,7 @@ PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory(
if (!db->RemoveFileInfo(file_id))
return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
AllocateQuotaForPath(context, -1, -static_cast<int64>(file_info.name.size()));
- UpdatePathQuotaUsage(context, context->src_origin_url(), context->src_type(),
+ UpdatePathQuotaUsage(context, virtual_path.origin(), virtual_path.type(),
-1, -static_cast<int64>(file_info.name.size()));
TouchDirectory(db, file_info.parent_id);
return base::PLATFORM_FILE_OK;
@@ -1022,6 +1040,8 @@ int64 ObfuscatedFileUtil::ComputeFilePathCost(const FilePath& path) {
PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal(
FileSystemDirectoryDatabase* db,
FileSystemOperationContext* context,
+ const GURL& origin,
+ FileSystemType type,
FileId file_id,
FileInfo* local_info,
base::PlatformFileInfo* file_info,
@@ -1046,71 +1066,83 @@ PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal(
}
if (local_info->data_path.empty())
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
- context->src_type(), local_info->data_path);
+ FileSystemPath local_path = DataPathToLocalPath(
+ origin, type, local_info->data_path);
return underlying_file_util()->GetFileInfo(
- context, data_path, file_info, platform_file_path);
+ context, local_path, file_info, platform_file_path);
}
PlatformFileError ObfuscatedFileUtil::CreateFile(
FileSystemOperationContext* context,
- const GURL& origin_url, FileSystemType type, const FilePath& source_path,
- FileInfo* file_info, int file_flags, PlatformFile* handle) {
+ const FileSystemPath& source_path,
+ const GURL& dest_origin,
+ FileSystemType dest_type,
+ FileInfo* dest_file_info, int file_flags, PlatformFile* handle) {
if (handle)
*handle = base::kInvalidPlatformFileValue;
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- origin_url, type, true);
+ dest_origin, dest_type, true);
int64 number;
if (!db || !db->GetNextInteger(&number))
return base::PLATFORM_FILE_ERROR_FAILED;
// We use the third- and fourth-to-last digits as the directory.
int64 directory_number = number % 10000 / 100;
- // TODO(ericu): local_path is an OS path; underlying_file_util_ isn't
- // guaranteed to understand OS paths.
- FilePath local_path =
- GetDirectoryForOriginAndType(origin_url, type, false);
- if (local_path.empty())
+ // TODO(ericu): dest_file_path is an OS path;
+ // underlying_file_util_ isn't guaranteed to understand OS paths.
+ FilePath dest_file_path =
+ GetDirectoryForOriginAndType(dest_origin, dest_type, false);
+ if (dest_file_path.empty())
return base::PLATFORM_FILE_ERROR_FAILED;
- local_path = local_path.AppendASCII(StringPrintf("%02" PRIu64,
- directory_number));
+ dest_file_path = dest_file_path.AppendASCII(
+ StringPrintf("%02" PRIu64, directory_number));
+ FileSystemPath dest_path(dest_origin, dest_type, dest_file_path,
+ underlying_file_util());
+
PlatformFileError error;
error = underlying_file_util()->CreateDirectory(
- context, local_path, false /* exclusive */, false /* recursive */);
+ context,
+ dest_path,
+ false /* exclusive */, false /* recursive */);
if (base::PLATFORM_FILE_OK != error)
return error;
- local_path = local_path.AppendASCII(StringPrintf("%08" PRIu64, number));
- FilePath data_path = LocalPathToDataPath(origin_url, type, local_path);
+
+ dest_file_path = dest_file_path.AppendASCII(
+ StringPrintf("%08" PRIu64, number));
+ dest_path.set_internal_path(dest_file_path);
+
+ FilePath data_path = LocalPathToDataPath(dest_path);
if (data_path.empty())
return base::PLATFORM_FILE_ERROR_FAILED;
+
bool created = false;
- if (!source_path.empty()) {
+ if (!source_path.internal_path().empty()) {
DCHECK(!file_flags);
DCHECK(!handle);
error = underlying_file_util()->CopyOrMoveFile(
- context, source_path, local_path, true /* copy */);
+ context, source_path, dest_path, true /* copy */);
created = true;
} else {
FilePath path;
- underlying_file_util()->GetLocalFilePath(context, local_path, &path);
+ underlying_file_util()->GetLocalFilePath(context, dest_path, &path);
if (file_util::PathExists(path)) {
if (!file_util::Delete(path, true)) {
NOTREACHED();
return base::PLATFORM_FILE_ERROR_FAILED;
}
LOG(WARNING) << "A stray file detected";
- context->file_system_context()->GetQuotaUtil(context->src_type())->
- InvalidateUsageCache(context->src_origin_url(), context->src_type());
+ context->file_system_context()->GetQuotaUtil(dest_type)->
+ InvalidateUsageCache(dest_origin, dest_type);
}
if (handle) {
error = underlying_file_util()->CreateOrOpen(
- context, local_path, file_flags, handle, &created);
+ context, dest_path, file_flags, handle, &created);
// If this succeeds, we must close handle on any subsequent error.
} else {
DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
error = underlying_file_util()->EnsureFileExists(
- context, local_path, &created);
+ context, dest_path, &created);
}
}
if (error != base::PLATFORM_FILE_OK)
@@ -1121,61 +1153,65 @@ PlatformFileError ObfuscatedFileUtil::CreateFile(
if (handle) {
DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
base::ClosePlatformFile(*handle);
- underlying_file_util()->DeleteFile(context, local_path);
+ underlying_file_util()->DeleteFile(context, dest_path);
}
return base::PLATFORM_FILE_ERROR_FAILED;
}
- file_info->data_path = data_path;
+ dest_file_info->data_path = data_path;
FileId file_id;
- if (!db->AddFileInfo(*file_info, &file_id)) {
+ if (!db->AddFileInfo(*dest_file_info, &file_id)) {
if (handle) {
DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
base::ClosePlatformFile(*handle);
}
- underlying_file_util()->DeleteFile(context, local_path);
+ underlying_file_util()->DeleteFile(context, dest_path);
return base::PLATFORM_FILE_ERROR_FAILED;
}
- UpdatePathQuotaUsage(context, origin_url, type, 1, file_info->name.size());
- TouchDirectory(db, file_info->parent_id);
+ UpdatePathQuotaUsage(context, dest_origin, dest_type,
+ 1, dest_file_info->name.size());
+ TouchDirectory(db, dest_file_info->parent_id);
return base::PLATFORM_FILE_OK;
}
-FilePath ObfuscatedFileUtil::GetLocalPath(
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path) {
+FileSystemPath ObfuscatedFileUtil::GetLocalPath(
+ const FileSystemPath& virtual_path) {
FileSystemDirectoryDatabase* db = GetDirectoryDatabase(
- origin_url, type, false);
+ virtual_path.origin(), virtual_path.type(), false);
if (!db)
- return FilePath();
+ return FileSystemPath();
FileId file_id;
- if (!db->GetFileWithPath(virtual_path, &file_id))
- return FilePath();
+ if (!db->GetFileWithPath(virtual_path.internal_path(), &file_id))
+ return FileSystemPath();
FileInfo file_info;
if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) {
NOTREACHED();
- return FilePath(); // Directories have no local path.
+ return FileSystemPath(); // Directories have no local path.
}
- return DataPathToLocalPath(origin_url, type, file_info.data_path);
+ return DataPathToLocalPath(virtual_path.origin(),
+ virtual_path.type(),
+ file_info.data_path);
}
-FilePath ObfuscatedFileUtil::DataPathToLocalPath(
+FileSystemPath ObfuscatedFileUtil::DataPathToLocalPath(
const GURL& origin, FileSystemType type, const FilePath& data_path) {
FilePath root = GetDirectoryForOriginAndType(origin, type, false);
if (root.empty())
- return root;
- return root.Append(data_path);
+ return FileSystemPath(origin, type, root, underlying_file_util());
+ return FileSystemPath(origin, type, root.Append(data_path),
+ underlying_file_util());
}
FilePath ObfuscatedFileUtil::LocalPathToDataPath(
- const GURL& origin, FileSystemType type, const FilePath& local_path) {
- FilePath root = GetDirectoryForOriginAndType(origin, type, false);
+ const FileSystemPath& local_path) {
+ FilePath root = GetDirectoryForOriginAndType(
+ local_path.origin(), local_path.type(), false);
if (root.empty())
return root;
// This removes the root, including the trailing slash, leaving a relative
// path.
- return FilePath(local_path.value().substr(root.value().length() + 1));
+ FilePath internal_path = local_path.internal_path();
+ return FilePath(internal_path.value().substr(root.value().length() + 1));
}
// TODO: How to do the whole validation-without-creation thing? We may not have
diff --git a/webkit/fileapi/obfuscated_file_util.h b/webkit/fileapi/obfuscated_file_util.h
index aaef51f..be9fb85 100644
--- a/webkit/fileapi/obfuscated_file_util.h
+++ b/webkit/fileapi/obfuscated_file_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -17,6 +17,7 @@
#include "webkit/fileapi/file_system_directory_database.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_origin_database.h"
+#include "webkit/fileapi/file_system_path.h"
#include "webkit/fileapi/file_system_types.h"
namespace base {
@@ -68,82 +69,82 @@ class ObfuscatedFileUtil : public FileSystemFileUtil,
virtual base::PlatformFileError CreateOrOpen(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
int file_flags,
base::PlatformFile* file_handle,
bool* created) OVERRIDE;
virtual base::PlatformFileError EnsureFileExists(
FileSystemOperationContext* context,
- const FilePath& file_path, bool* created) OVERRIDE;
+ const FileSystemPath& path, bool* created) OVERRIDE;
virtual base::PlatformFileError CreateDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
bool exclusive,
bool recursive) OVERRIDE;
virtual base::PlatformFileError GetFileInfo(
FileSystemOperationContext* context,
- const FilePath& file,
+ const FileSystemPath& path,
base::PlatformFileInfo* file_info,
FilePath* platform_file) OVERRIDE;
virtual base::PlatformFileError ReadDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
std::vector<base::FileUtilProxy::Entry>* entries) OVERRIDE;
virtual AbstractFileEnumerator* CreateFileEnumerator(
FileSystemOperationContext* context,
- const FilePath& root_path) OVERRIDE;
+ const FileSystemPath& root_path) OVERRIDE;
virtual base::PlatformFileError GetLocalFilePath(
FileSystemOperationContext* context,
- const FilePath& virtual_file,
- FilePath* local_path) OVERRIDE;
+ const FileSystemPath& file_system_path,
+ FilePath* local_file_path) OVERRIDE;
virtual base::PlatformFileError Touch(
FileSystemOperationContext* context,
- const FilePath& file_path,
+ const FileSystemPath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) OVERRIDE;
virtual base::PlatformFileError Truncate(
FileSystemOperationContext* context,
- const FilePath& path,
+ const FileSystemPath& path,
int64 length) OVERRIDE;
virtual bool PathExists(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual bool DirectoryExists(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual bool IsDirectoryEmpty(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual base::PlatformFileError CopyOrMoveFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) OVERRIDE;
virtual PlatformFileError CopyInForeignFile(
FileSystemOperationContext* context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path) OVERRIDE;
+ const FileSystemPath& underlying_src_path,
+ const FileSystemPath& dest_path) OVERRIDE;
virtual base::PlatformFileError DeleteFile(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
virtual base::PlatformFileError DeleteSingleDirectory(
FileSystemOperationContext* context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
// Gets the topmost directory specific to this origin and type. This will
// contain both the directory database's files and all the backing file
@@ -196,46 +197,48 @@ class ObfuscatedFileUtil : public FileSystemFileUtil,
base::PlatformFileError GetFileInfoInternal(
FileSystemDirectoryDatabase* db,
FileSystemOperationContext* context,
+ const GURL& origin,
+ FileSystemType type,
FileId file_id,
FileInfo* local_info,
base::PlatformFileInfo* file_info,
FilePath* platform_file_path);
// Creates a new file, both the underlying backing file and the entry in the
- // database. file_info is an in-out parameter. Supply the name and
+ // database. |dest_file_info| is an in-out parameter. Supply the name and
// parent_id; data_path is ignored. On success, data_path will
// always be set to the relative path [from the root of the type-specific
// filesystem directory] of a NEW backing file, and handle, if supplied, will
// hold open PlatformFile for the backing file, which the caller is
- // responsible for closing. If you supply a path in source_path, it will be
+ // responsible for closing. If you supply a path in |source_path|, it will be
// used as a source from which to COPY data.
// Caveat: do not supply handle if you're also supplying a data path. It was
// easier not to support this, and no code has needed it so far, so it will
// DCHECK and handle will hold base::kInvalidPlatformFileValue.
base::PlatformFileError CreateFile(
FileSystemOperationContext* context,
- const GURL& origin_url, FileSystemType type,
- const FilePath& source_path, FileInfo* file_info,
- int file_flags, base::PlatformFile* handle);
-
- // Given the filesystem's root URL and a virtual path, produces a real, full
- // local path to the underlying data file. This does a database lookup, and
- // verifies that the file exists.
- FilePath GetLocalPath(
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path);
+ const FileSystemPath& source_path,
+ const GURL& dest_origin,
+ FileSystemType dest_type,
+ FileInfo* dest_file_info,
+ int file_flags,
+ base::PlatformFile* handle);
+
+ // Given a virtual path, produces a real, full local path to the
+ // underlying data file. This does a database lookup (by
+ // calling DataPathToLocalPath()), and verifies that the file exists.
+ FileSystemPath GetLocalPath(const FileSystemPath& virtual_path);
// This converts from a relative path [as is stored in the FileInfo.data_path
- // field] to an absolute local path that can be given to the operating system.
- // It does no checks as to whether the file actually exists; it's pure path
- // manipulation.
- FilePath DataPathToLocalPath(
- const GURL& origin, FileSystemType type, const FilePath& data_path);
+ // field] to an absolute local path that can be given to the underlying
+ // filesystem (as of now the returned path is assumed to be a platform path).
+ FileSystemPath DataPathToLocalPath(
+ const GURL& origin,
+ FileSystemType type,
+ const FilePath& data_file_path);
// This does the reverse of DataPathToLocalPath.
- FilePath LocalPathToDataPath(
- const GURL& origin, FileSystemType type, const FilePath& local_path);
+ FilePath LocalPathToDataPath(const FileSystemPath& local_path);
// This returns NULL if |create| flag is false and a filesystem does not
// exist for the given |origin_url| and |type|.
diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc
index 5f42905..8eb2344 100644
--- a/webkit/fileapi/obfuscated_file_util_unittest.cc
+++ b/webkit/fileapi/obfuscated_file_util_unittest.cc
@@ -199,6 +199,14 @@ class ObfuscatedFileUtilTest : public testing::Test {
int64 usage() const { return usage_; }
+ FileSystemPath CreatePathFromUTF8(const std::string& path) {
+ return test_helper_.CreatePathFromUTF8(path);
+ }
+
+ FileSystemPath CreatePath(const FilePath& path) {
+ return test_helper_.CreatePath(path);
+ }
+
void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) {
EXPECT_EQ(quota::kQuotaStatusOk, status);
quota_status_ = status;
@@ -206,7 +214,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
}
void CheckFileAndCloseHandle(
- const FilePath& virtual_path, PlatformFile file_handle) {
+ const FileSystemPath& virtual_path, PlatformFile file_handle) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
FilePath local_path;
EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
@@ -265,7 +273,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
}
void ValidateTestDirectory(
- const FilePath& root_path,
+ const FileSystemPath& root_path,
const std::set<FilePath::StringType>& files,
const std::set<FilePath::StringType>& directories) {
scoped_ptr<FileSystemOperationContext> context;
@@ -287,7 +295,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
}
void FillTestDirectory(
- const FilePath& root_path,
+ const FileSystemPath& root_path,
std::set<FilePath::StringType>* files,
std::set<FilePath::StringType>* directories) {
scoped_ptr<FileSystemOperationContext> context;
@@ -311,7 +319,9 @@ class ObfuscatedFileUtilTest : public testing::Test {
context.reset(NewContext(NULL));
ASSERT_EQ(base::PLATFORM_FILE_OK,
ofu()->EnsureFileExists(
- context.get(), root_path.Append(*iter), &created));
+ context.get(),
+ root_path.Append(*iter),
+ &created));
ASSERT_TRUE(created);
}
for (iter = directories->begin(); iter != directories->end(); ++iter) {
@@ -325,7 +335,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
ValidateTestDirectory(root_path, *files, *directories);
}
- void TestReadDirectoryHelper(const FilePath& root_path) {
+ void TestReadDirectoryHelper(const FileSystemPath& root_path) {
std::set<FilePath::StringType> files;
std::set<FilePath::StringType> directories;
FillTestDirectory(root_path, &files, &directories);
@@ -353,7 +363,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
}
}
- void TestTouchHelper(const FilePath& path, bool is_file) {
+ void TestTouchHelper(const FileSystemPath& path, bool is_file) {
base::Time last_access_time = base::Time::Now();
base::Time last_modified_time = base::Time::Now();
@@ -388,9 +398,10 @@ class ObfuscatedFileUtilTest : public testing::Test {
void TestCopyInForeignFileHelper(bool overwrite) {
ScopedTempDir source_dir;
ASSERT_TRUE(source_dir.CreateUniqueTempDir());
- FilePath root_path = source_dir.path();
- FilePath src_path = root_path.AppendASCII("file_name");
- FilePath dest_path(FILE_PATH_LITERAL("new file"));
+ FilePath root_file_path = source_dir.path();
+ FilePath src_file_path = root_file_path.AppendASCII("file_name");
+ FileSystemPath dest_path = CreatePathFromUTF8("new file");
+ FileSystemPath src_path = CreatePath(src_file_path);
int64 src_file_length = 87;
base::PlatformFileError error_code;
@@ -398,7 +409,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
base::PlatformFile file_handle =
base::CreatePlatformFile(
- src_path, file_flags, &created, &error_code);
+ src_file_path, file_flags, &created, &error_code);
EXPECT_TRUE(created);
ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
@@ -415,7 +426,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
}
const int64 path_cost =
- ObfuscatedFileUtil::ComputeFilePathCost(dest_path);
+ ObfuscatedFileUtil::ComputeFilePathCost(dest_path.internal_path());
if (!overwrite) {
// Verify that file creation requires sufficient quota for the path.
context.reset(NewContext(NULL));
@@ -438,7 +449,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
FilePath data_path;
EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
context.get(), dest_path, &file_info, &data_path));
- EXPECT_NE(data_path, src_path);
+ EXPECT_NE(data_path, src_file_path);
EXPECT_TRUE(FileExists(data_path));
EXPECT_EQ(src_file_length, GetSize(data_path));
@@ -446,14 +457,14 @@ class ObfuscatedFileUtilTest : public testing::Test {
ofu()->DeleteFile(context.get(), dest_path));
}
- void ClearTimestamp(const FilePath& path) {
+ void ClearTimestamp(const FileSystemPath& path) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->Touch(context.get(), path, base::Time(), base::Time()));
EXPECT_EQ(base::Time(), GetModifiedTime(path));
}
- base::Time GetModifiedTime(const FilePath& path) {
+ base::Time GetModifiedTime(const FileSystemPath& path) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
FilePath data_path;
base::PlatformFileInfo file_info;
@@ -463,15 +474,15 @@ class ObfuscatedFileUtilTest : public testing::Test {
return file_info.last_modified;
}
- void TestDirectoryTimestampHelper(const FilePath& base_dir,
+ void TestDirectoryTimestampHelper(const FileSystemPath& base_dir,
bool copy,
bool overwrite) {
scoped_ptr<FileSystemOperationContext> context;
- const FilePath src_dir_path(base_dir.AppendASCII("foo_dir"));
- const FilePath dest_dir_path(base_dir.AppendASCII("bar_dir"));
+ const FileSystemPath src_dir_path(base_dir.AppendASCII("foo_dir"));
+ const FileSystemPath dest_dir_path(base_dir.AppendASCII("bar_dir"));
- const FilePath src_file_path(src_dir_path.AppendASCII("hoge"));
- const FilePath dest_file_path(dest_dir_path.AppendASCII("fuga"));
+ const FileSystemPath src_file_path(src_dir_path.AppendASCII("hoge"));
+ const FileSystemPath dest_file_path(dest_dir_path.AppendASCII("fuga"));
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
@@ -524,7 +535,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
bool created;
- FilePath path = FilePath::FromUTF8Unsafe("fake/file");
+ FileSystemPath path = CreatePathFromUTF8("fake/file");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
@@ -537,19 +548,19 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
ofu()->DeleteFile(context.get(), path));
- path = FilePath::FromUTF8Unsafe("test file");
+ path = CreatePathFromUTF8("test file");
// Verify that file creation requires sufficient quota for the path.
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(path) - 1);
+ ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()) - 1);
ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
ofu()->CreateOrOpen(
context.get(), path, file_flags, &file_handle, &created));
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(path));
+ ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
ofu()->CreateOrOpen(
context.get(), path, file_flags, &file_handle, &created));
@@ -571,13 +582,14 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->DeleteFile(context.get(), path));
EXPECT_FALSE(file_util::PathExists(local_path));
- EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(path),
+ EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()),
context->allowed_bytes_growth());
context.reset(NewContext(NULL));
bool exclusive = true;
bool recursive = true;
- FilePath directory_path = FilePath::FromUTF8Unsafe("series/of/directories");
+ FileSystemPath directory_path = CreatePathFromUTF8(
+ "series/of/directories");
path = directory_path.AppendASCII("file name");
EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
context.get(), directory_path, exclusive, recursive));
@@ -605,7 +617,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
TEST_F(ObfuscatedFileUtilTest, TestTruncate) {
bool created = false;
- FilePath path = FilePath::FromUTF8Unsafe("file");
+ FileSystemPath path = CreatePathFromUTF8("file");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
@@ -639,7 +651,7 @@ TEST_F(ObfuscatedFileUtilTest, TestTruncate) {
}
TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) {
- FilePath path = FilePath::FromUTF8Unsafe("fake/file");
+ FileSystemPath path = CreatePathFromUTF8("fake/file");
bool created = false;
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
@@ -648,17 +660,17 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) {
// Verify that file creation requires sufficient quota for the path.
context.reset(NewContext(NULL));
- path = FilePath::FromUTF8Unsafe("test file");
+ path = CreatePathFromUTF8("test file");
created = false;
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(path) - 1);
+ ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()) - 1);
ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
ofu()->EnsureFileExists(context.get(), path, &created));
ASSERT_FALSE(created);
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(path));
+ ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
ofu()->EnsureFileExists(context.get(), path, &created));
ASSERT_TRUE(created);
@@ -671,7 +683,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) {
ASSERT_FALSE(created);
// Also test in a subdirectory.
- path = FilePath::FromUTF8Unsafe("path/to/file.txt");
+ path = CreatePathFromUTF8("path/to/file.txt");
context.reset(NewContext(NULL));
bool exclusive = true;
bool recursive = true;
@@ -693,7 +705,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
bool exclusive = false;
bool recursive = false;
- FilePath path = FilePath::FromUTF8Unsafe("foo/bar");
+ FileSystemPath path = CreatePathFromUTF8("foo/bar");
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CreateDirectory(
context.get(), path, exclusive, recursive));
@@ -701,7 +713,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
ofu()->DeleteSingleDirectory(context.get(), path));
- FilePath root = FilePath::FromUTF8Unsafe("");
+ FileSystemPath root = CreatePathFromUTF8("");
context.reset(NewContext(NULL));
EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
context.reset(NewContext(NULL));
@@ -756,10 +768,10 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
context->set_allowed_bytes_growth(0);
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->DeleteSingleDirectory(context.get(), path));
- EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(path),
+ EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()),
context->allowed_bytes_growth());
- path = FilePath::FromUTF8Unsafe("foo/bop");
+ path = CreatePathFromUTF8("foo/bop");
context.reset(NewContext(NULL));
EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
@@ -775,13 +787,13 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
recursive = false;
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(path) - 1);
+ ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()) - 1);
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, ofu()->CreateDirectory(
context.get(), path, exclusive, recursive));
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(path));
+ ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path()));
EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
context.get(), path, exclusive, recursive));
@@ -797,11 +809,11 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
exclusive = true;
recursive = false;
- path = FilePath::FromUTF8Unsafe("foo");
+ path = CreatePathFromUTF8("foo");
EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory(
context.get(), path, exclusive, recursive));
- path = FilePath::FromUTF8Unsafe("blah");
+ path = CreatePathFromUTF8("blah");
context.reset(NewContext(NULL));
EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
@@ -828,22 +840,22 @@ TEST_F(ObfuscatedFileUtilTest, TestReadDirectory) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
bool exclusive = true;
bool recursive = true;
- FilePath path = FilePath::FromUTF8Unsafe("directory/to/use");
+ FileSystemPath path = CreatePathFromUTF8("directory/to/use");
EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
context.get(), path, exclusive, recursive));
TestReadDirectoryHelper(path);
}
TEST_F(ObfuscatedFileUtilTest, TestReadRootWithSlash) {
- TestReadDirectoryHelper(FilePath::FromUTF8Unsafe(""));
+ TestReadDirectoryHelper(CreatePathFromUTF8(""));
}
TEST_F(ObfuscatedFileUtilTest, TestReadRootWithEmptyString) {
- TestReadDirectoryHelper(FilePath::FromUTF8Unsafe("/"));
+ TestReadDirectoryHelper(CreatePathFromUTF8("/"));
}
TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) {
- FilePath path = FilePath::FromUTF8Unsafe("file");
+ FileSystemPath path = CreatePathFromUTF8("file");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
bool created = false;
@@ -860,7 +872,7 @@ TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) {
}
TEST_F(ObfuscatedFileUtilTest, TestTouch) {
- FilePath path = FilePath::FromUTF8Unsafe("file");
+ FileSystemPath path = CreatePathFromUTF8("file");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
base::Time last_access_time = base::Time::Now();
@@ -883,17 +895,17 @@ TEST_F(ObfuscatedFileUtilTest, TestTouch) {
context.reset(NewContext(NULL));
bool exclusive = true;
bool recursive = false;
- path = FilePath::FromUTF8Unsafe("dir");
+ path = CreatePathFromUTF8("dir");
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(context.get(),
path, exclusive, recursive));
TestTouchHelper(path, false);
}
TEST_F(ObfuscatedFileUtilTest, TestPathQuotas) {
- FilePath path = FilePath::FromUTF8Unsafe("fake/file");
+ FileSystemPath path = CreatePathFromUTF8("fake/file");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
- path = FilePath::FromUTF8Unsafe("file name");
+ path = CreatePathFromUTF8("file name");
context->set_allowed_bytes_growth(5);
bool created = false;
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
@@ -903,15 +915,16 @@ TEST_F(ObfuscatedFileUtilTest, TestPathQuotas) {
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->EnsureFileExists(context.get(), path, &created));
EXPECT_TRUE(created);
- int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(path);
+ int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(
+ path.internal_path());
EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
context->set_allowed_bytes_growth(1024);
bool exclusive = true;
bool recursive = true;
- path = FilePath::FromUTF8Unsafe("directory/to/use");
+ path = CreatePathFromUTF8("directory/to/use");
std::vector<FilePath::StringType> components;
- path.GetComponents(&components);
+ path.internal_path().GetComponents(&components);
path_cost = 0;
for (std::vector<FilePath::StringType>::iterator iter = components.begin();
iter != components.end(); ++iter) {
@@ -926,8 +939,8 @@ TEST_F(ObfuscatedFileUtilTest, TestPathQuotas) {
}
TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) {
- FilePath source_path = FilePath::FromUTF8Unsafe("path0.txt");
- FilePath dest_path = FilePath::FromUTF8Unsafe("path1.txt");
+ FileSystemPath source_path = CreatePathFromUTF8("path0.txt");
+ FileSystemPath dest_path = CreatePathFromUTF8("path1.txt");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
bool is_copy_not_move = false;
@@ -939,7 +952,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) {
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
ofu()->CopyOrMoveFile(context.get(), source_path, dest_path,
is_copy_not_move));
- source_path = FilePath::FromUTF8Unsafe("dir/dir/file");
+ source_path = CreatePathFromUTF8("dir/dir/file");
bool exclusive = true;
bool recursive = true;
context.reset(NewContext(NULL));
@@ -975,8 +988,8 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) {
bool exclusive = false;
bool recursive = true;
- FilePath source_path = FilePath::FromUTF8Unsafe(test_case.source_path);
- FilePath dest_path = FilePath::FromUTF8Unsafe(test_case.dest_path);
+ FileSystemPath source_path = CreatePathFromUTF8(test_case.source_path);
+ FileSystemPath dest_path = CreatePathFromUTF8(test_case.dest_path);
context.reset(NewContext(NULL));
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
@@ -1036,8 +1049,8 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) {
}
TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) {
- FilePath src_path = FilePath::FromUTF8Unsafe("src path");
- FilePath dest_path = FilePath::FromUTF8Unsafe("destination path");
+ FileSystemPath src_path = CreatePathFromUTF8("src path");
+ FileSystemPath dest_path = CreatePathFromUTF8("destination path");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
bool created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(
@@ -1046,12 +1059,12 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) {
bool is_copy = true;
// Copy, no overwrite.
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(dest_path) - 1);
+ ObfuscatedFileUtil::ComputeFilePathCost(dest_path.internal_path()) - 1);
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy));
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(dest_path));
+ ObfuscatedFileUtil::ComputeFilePathCost(dest_path.internal_path()));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy));
@@ -1063,8 +1076,8 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) {
}
TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) {
- FilePath src_path = FilePath::FromUTF8Unsafe("src path");
- FilePath dest_path = FilePath::FromUTF8Unsafe("destination path");
+ FileSystemPath src_path = CreatePathFromUTF8("src path");
+ FileSystemPath dest_path = CreatePathFromUTF8("destination path");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
bool created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(
@@ -1074,14 +1087,14 @@ TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) {
// Move, rename, no overwrite.
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(dest_path) -
- ObfuscatedFileUtil::ComputeFilePathCost(src_path) - 1);
+ ObfuscatedFileUtil::ComputeFilePathCost(dest_path.internal_path()) -
+ ObfuscatedFileUtil::ComputeFilePathCost(src_path.internal_path()) - 1);
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy));
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
- ObfuscatedFileUtil::ComputeFilePathCost(dest_path) -
- ObfuscatedFileUtil::ComputeFilePathCost(src_path));
+ ObfuscatedFileUtil::ComputeFilePathCost(dest_path.internal_path()) -
+ ObfuscatedFileUtil::ComputeFilePathCost(src_path.internal_path()));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy));
@@ -1097,7 +1110,7 @@ TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) {
}
TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) {
- FilePath src_path = FilePath::FromUTF8Unsafe("src path");
+ FileSystemPath src_path = CreatePathFromUTF8("src path");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
bool created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists(
@@ -1105,12 +1118,12 @@ TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) {
bool exclusive = true;
bool recursive = false;
- FilePath dir_path = FilePath::FromUTF8Unsafe("directory path");
+ FileSystemPath dir_path = CreatePathFromUTF8("directory path");
context.reset(NewContext(NULL));
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
context.get(), dir_path, exclusive, recursive));
- FilePath dest_path = dir_path.Append(src_path);
+ FileSystemPath dest_path = dir_path.Append(src_path.internal_path());
bool is_copy = false;
int64 allowed_bytes_growth = -1000; // Over quota, this should still work.
@@ -1131,7 +1144,7 @@ TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) {
ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy));
EXPECT_EQ(
allowed_bytes_growth +
- ObfuscatedFileUtil::ComputeFilePathCost(src_path),
+ ObfuscatedFileUtil::ComputeFilePathCost(src_path.internal_path()),
context->allowed_bytes_growth());
}
@@ -1142,7 +1155,7 @@ TEST_F(ObfuscatedFileUtilTest, TestCopyInForeignFile) {
TEST_F(ObfuscatedFileUtilTest, TestEnumerator) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
- FilePath src_path = FilePath::FromUTF8Unsafe("source dir");
+ FileSystemPath src_path = CreatePathFromUTF8("source dir");
bool exclusive = true;
bool recursive = false;
ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
@@ -1152,7 +1165,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnumerator) {
std::set<FilePath::StringType> directories;
FillTestDirectory(src_path, &files, &directories);
- FilePath dest_path = FilePath::FromUTF8Unsafe("destination dir");
+ FileSystemPath dest_path = CreatePathFromUTF8("destination dir");
context.reset(NewContext(NULL));
EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path));
@@ -1196,7 +1209,7 @@ TEST_F(ObfuscatedFileUtilTest, TestMigration) {
FilePath data_path;
SCOPED_TRACE(testing::Message() << "Path is " << test_case.path);
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->GetFileInfo(context.get(), FilePath(test_case.path),
+ ofu()->GetFileInfo(context.get(), CreatePath(FilePath(test_case.path)),
&ofu_file_info, &data_path));
if (test_case.is_directory) {
EXPECT_TRUE(ofu_file_info.is_directory);
@@ -1243,24 +1256,24 @@ TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) {
scoped_ptr<FileSystemTestOriginHelper> helper(
NewHelper(origin_url, kFileSystemTypeTemporary));
scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get()));
- context->set_src_origin_url(origin_url);
- context->set_src_type(kFileSystemTypeTemporary);
bool created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->EnsureFileExists(context.get(),
- FilePath::FromUTF8Unsafe("file"), &created));
+ ofu()->EnsureFileExists(
+ context.get(),
+ helper->CreatePathFromUTF8("file"),
+ &created));
EXPECT_TRUE(created);
}
if (record.has_persistent) {
scoped_ptr<FileSystemTestOriginHelper> helper(
NewHelper(origin_url, kFileSystemTypePersistent));
scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get()));
- context->set_src_origin_url(origin_url);
- context->set_src_type(kFileSystemTypePersistent);
bool created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->EnsureFileExists(context.get(),
- FilePath::FromUTF8Unsafe("file"), &created));
+ ofu()->EnsureFileExists(
+ context.get(),
+ helper->CreatePathFromUTF8("file"),
+ &created));
EXPECT_TRUE(created);
}
}
@@ -1310,21 +1323,24 @@ TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) {
for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i);
const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
- FilePath path(test_case.path);
- expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(path);
+ FilePath file_path(test_case.path);
+ expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(file_path);
if (test_case.is_directory) {
bool exclusive = true;
bool recursive = false;
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->CreateDirectory(context.get(), path, exclusive, recursive));
+ ofu()->CreateDirectory(context.get(), CreatePath(file_path),
+ exclusive, recursive));
} else {
bool created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->EnsureFileExists(context.get(), path, &created));
+ ofu()->EnsureFileExists(context.get(), CreatePath(file_path),
+ &created));
ASSERT_TRUE(created);
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->Truncate(context.get(), path,
- test_case.data_file_size));
+ ofu()->Truncate(context.get(),
+ CreatePath(file_path),
+ test_case.data_file_size));
expected_quota += test_case.data_file_size;
}
}
@@ -1337,8 +1353,8 @@ TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) {
}
TEST_F(ObfuscatedFileUtilTest, TestInconsistency) {
- const FilePath kPath1 = FilePath::FromUTF8Unsafe("hoge");
- const FilePath kPath2 = FilePath::FromUTF8Unsafe("fuga");
+ const FileSystemPath kPath1 = CreatePathFromUTF8("hoge");
+ const FileSystemPath kPath2 = CreatePathFromUTF8("fuga");
scoped_ptr<FileSystemOperationContext> context;
base::PlatformFile file;
@@ -1398,7 +1414,7 @@ TEST_F(ObfuscatedFileUtilTest, TestInconsistency) {
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2,
- true /* copy */));
+ true /* copy */));
ofu()->DestroyDirectoryDatabase(origin(), type());
context.reset(NewContext(NULL));
@@ -1414,11 +1430,12 @@ TEST_F(ObfuscatedFileUtilTest, TestInconsistency) {
}
TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) {
- const FilePath kPath[] = {
- FilePath::FromUTF8Unsafe("foo"),
- FilePath::FromUTF8Unsafe("bar"),
- FilePath::FromUTF8Unsafe("baz")
+ const FileSystemPath kPath[] = {
+ CreatePathFromUTF8("foo"),
+ CreatePathFromUTF8("bar"),
+ CreatePathFromUTF8("baz")
};
+ const FileSystemPath empty_path = CreatePath(FilePath());
scoped_ptr<FileSystemOperationContext> context;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) {
@@ -1432,7 +1449,7 @@ TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) {
context.reset(NewContext(NULL));
std::vector<base::FileUtilProxy::Entry> entries;
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->ReadDirectory(context.get(), FilePath(), &entries));
+ ofu()->ReadDirectory(context.get(), empty_path, &entries));
EXPECT_EQ(3u, entries.size());
context.reset(NewContext(NULL));
@@ -1444,20 +1461,20 @@ TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) {
context.reset(NewContext(NULL));
entries.clear();
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->ReadDirectory(context.get(), FilePath(), &entries));
+ ofu()->ReadDirectory(context.get(), empty_path, &entries));
EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size());
}
TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
- const FilePath dir_path(FILE_PATH_LITERAL("foo_dir"));
+ const FileSystemPath dir_path = CreatePathFromUTF8("foo_dir");
// Create working directory.
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CreateDirectory(context.get(), dir_path, false, false));
// EnsureFileExists, create case.
- FilePath path(dir_path.AppendASCII("EnsureFileExists_file"));
+ FileSystemPath path(dir_path.AppendASCII("EnsureFileExists_file"));
bool created = false;
ClearTimestamp(dir_path);
context.reset(NewContext(NULL));
@@ -1533,7 +1550,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
// CreateDirectory, create case.
// Creating CreateDirectory_dir and CreateDirectory_dir/subdir.
path = dir_path.AppendASCII("CreateDirectory_dir");
- FilePath subdir_path(path.AppendASCII("subdir"));
+ FileSystemPath subdir_path(path.AppendASCII("subdir"));
ClearTimestamp(dir_path);
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
@@ -1564,7 +1581,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
// CopyInForeignFile, create case.
path = dir_path.AppendASCII("CopyInForeignFile_file");
- FilePath src_path = dir_path.AppendASCII("CopyInForeignFile_src_file");
+ FileSystemPath src_path = dir_path.AppendASCII("CopyInForeignFile_src_file");
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->EnsureFileExists(context.get(), src_path, &created));
@@ -1577,20 +1594,22 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
ClearTimestamp(dir_path);
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->CopyInForeignFile(context.get(), src_local_path, path));
+ ofu()->CopyInForeignFile(context.get(),
+ CreatePath(src_local_path),
+ path));
EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
}
TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForDeletion) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
- const FilePath dir_path(FILE_PATH_LITERAL("foo_dir"));
+ const FileSystemPath dir_path = CreatePathFromUTF8("foo_dir");
// Create working directory.
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CreateDirectory(context.get(), dir_path, false, false));
// DeleteFile, delete case.
- FilePath path = dir_path.AppendASCII("DeleteFile_file");
+ FileSystemPath path = dir_path.AppendASCII("DeleteFile_file");
bool created = false;
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
@@ -1612,7 +1631,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForDeletion) {
// DeleteSingleDirectory, fail case.
path = dir_path.AppendASCII("DeleteSingleDirectory_dir");
- FilePath file_path(path.AppendASCII("pakeratta"));
+ FileSystemPath file_path(path.AppendASCII("pakeratta"));
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CreateDirectory(context.get(), path, true, true));
@@ -1642,11 +1661,11 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForDeletion) {
TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCopyAndMove) {
TestDirectoryTimestampHelper(
- FilePath(FILE_PATH_LITERAL("copy overwrite")), true, true);
+ CreatePathFromUTF8("copy overwrite"), true, true);
TestDirectoryTimestampHelper(
- FilePath(FILE_PATH_LITERAL("copy non-overwrite")), true, false);
+ CreatePathFromUTF8("copy non-overwrite"), true, false);
TestDirectoryTimestampHelper(
- FilePath(FILE_PATH_LITERAL("move overwrite")), false, true);
+ CreatePathFromUTF8("move overwrite"), false, true);
TestDirectoryTimestampHelper(
- FilePath(FILE_PATH_LITERAL("move non-overwrite")), false, false);
+ CreatePathFromUTF8("move non-overwrite"), false, false);
}
diff --git a/webkit/fileapi/quota_file_util.cc b/webkit/fileapi/quota_file_util.cc
index 7593b63..ed973b3e 100644
--- a/webkit/fileapi/quota_file_util.cc
+++ b/webkit/fileapi/quota_file_util.cc
@@ -22,6 +22,8 @@ namespace {
// Checks if copying in the same filesystem can be performed.
// This method is not called for moving within a single filesystem.
+// Note: this method assumes the underlying file system uses platform
+// file paths.
bool CanCopy(
const FilePath& src_file_path,
const FilePath& dest_file_path,
@@ -46,7 +48,7 @@ bool CanCopy(
}
void NotifyUpdate(FileSystemOperationContext* operation_context,
- const GURL& origin_url,
+ const GURL& origin,
FileSystemType type,
int64 growth) {
DCHECK(operation_context);
@@ -62,7 +64,7 @@ void NotifyUpdate(FileSystemOperationContext* operation_context,
operation_context->allowed_bytes_growth() - growth);
if (quota_util)
quota_util->UpdateOriginUsageOnFileThread(
- quota_manager_proxy, origin_url, type, growth);
+ quota_manager_proxy, origin, type, growth);
}
} // namespace (anonymous)
@@ -81,13 +83,13 @@ QuotaFileUtil* QuotaFileUtil::CreateDefault() {
base::PlatformFileError QuotaFileUtil::Truncate(
FileSystemOperationContext* fs_context,
- const FilePath& path,
+ const FileSystemPath& path,
int64 length) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
int64 growth = 0;
base::PlatformFileInfo file_info;
- if (!file_util::GetFileInfo(path, &file_info))
+ if (!file_util::GetFileInfo(path.internal_path(), &file_info))
return base::PLATFORM_FILE_ERROR_FAILED;
growth = length - file_info.size;
@@ -99,9 +101,7 @@ base::PlatformFileError QuotaFileUtil::Truncate(
fs_context, path, length);
if (error == base::PLATFORM_FILE_OK)
- NotifyUpdate(fs_context,
- fs_context->src_origin_url(),
- fs_context->src_type(),
+ NotifyUpdate(fs_context, path.origin(), path.type(),
growth);
return error;
@@ -109,8 +109,8 @@ base::PlatformFileError QuotaFileUtil::Truncate(
base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
FileSystemOperationContext* fs_context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) {
DCHECK(fs_context);
@@ -121,25 +121,23 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
if (copy) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
// The third argument (growth) is not used for now.
- if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth, &growth))
+ if (!CanCopy(src_path.internal_path(), dest_path.internal_path(),
+ allowed_bytes_growth, &growth))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
} else {
base::PlatformFileInfo dest_file_info;
- if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
+ if (!file_util::GetFileInfo(dest_path.internal_path(), &dest_file_info))
dest_file_info.size = 0;
growth = -dest_file_info.size;
}
base::PlatformFileError error = underlying_file_util()->CopyOrMoveFile(
- fs_context, src_file_path, dest_file_path, copy);
+ fs_context, src_path, dest_path, copy);
if (error == base::PLATFORM_FILE_OK) {
// TODO(kinuko): For cross-filesystem move case, call this with -growth
// for source and growth for dest.
- NotifyUpdate(fs_context,
- fs_context->dest_origin_url(),
- fs_context->dest_type(),
- growth);
+ NotifyUpdate(fs_context, dest_path.origin(), dest_path.type(), growth);
}
return error;
@@ -147,23 +145,20 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
base::PlatformFileError QuotaFileUtil::DeleteFile(
FileSystemOperationContext* fs_context,
- const FilePath& file_path) {
+ const FileSystemPath& path) {
DCHECK(fs_context);
int64 growth = 0;
base::PlatformFileInfo file_info;
- if (!file_util::GetFileInfo(file_path, &file_info))
+ if (!file_util::GetFileInfo(path.internal_path(), &file_info))
file_info.size = 0;
growth = -file_info.size;
base::PlatformFileError error = underlying_file_util()->DeleteFile(
- fs_context, file_path);
+ fs_context, path);
if (error == base::PLATFORM_FILE_OK)
- NotifyUpdate(fs_context,
- fs_context->src_origin_url(),
- fs_context->src_type(),
- growth);
+ NotifyUpdate(fs_context, path.origin(), path.type(), growth);
return error;
}
diff --git a/webkit/fileapi/quota_file_util.h b/webkit/fileapi/quota_file_util.h
index 25be5f3..cf8e069 100644
--- a/webkit/fileapi/quota_file_util.h
+++ b/webkit/fileapi/quota_file_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -31,16 +31,16 @@ class QuotaFileUtil : public FileSystemFileUtil {
virtual base::PlatformFileError Truncate(
FileSystemOperationContext* fs_context,
- const FilePath& path,
+ const FileSystemPath& path,
int64 length) OVERRIDE;
virtual base::PlatformFileError CopyOrMoveFile(
FileSystemOperationContext* fs_context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
+ const FileSystemPath& src_path,
+ const FileSystemPath& dest_path,
bool copy) OVERRIDE;
virtual base::PlatformFileError DeleteFile(
FileSystemOperationContext* fs_context,
- const FilePath& file_path) OVERRIDE;
+ const FileSystemPath& path) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(QuotaFileUtil);
diff --git a/webkit/fileapi/quota_file_util_unittest.cc b/webkit/fileapi/quota_file_util_unittest.cc
index 8790352..da29ba1 100644
--- a/webkit/fileapi/quota_file_util_unittest.cc
+++ b/webkit/fileapi/quota_file_util_unittest.cc
@@ -38,8 +38,8 @@ class QuotaFileUtilTest : public testing::Test {
return quota_test_helper_.NewOperationContext();
}
- FilePath Path(const std::string& file_name) {
- return base_dir_.AppendASCII(file_name);
+ FileSystemPath Path(const std::string& file_name) {
+ return quota_test_helper_.CreatePath(base_dir_.AppendASCII(file_name));
}
base::PlatformFileError CreateFile(const char* file_name,
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index cbcda1d..a659615 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -520,11 +520,10 @@ int64 SandboxMountPointProvider::GetOriginUsageOnFileThread(
// Get the directory size now and update the cache.
FileSystemUsageCache::Delete(usage_file_path);
- FileSystemOperationContext context(NULL, sandbox_file_util_);
- context.set_src_origin_url(origin_url);
- context.set_src_type(type);
+ FileSystemOperationContext context(NULL);
+ FileSystemPath path(origin_url, type, FilePath(), sandbox_file_util_);
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator(
- sandbox_file_util_->CreateFileEnumerator(&context, FilePath()));
+ sandbox_file_util_->CreateFileEnumerator(&context, path));
FilePath file_path_each;
int64 usage = 0;
diff --git a/webkit/fileapi/sandbox_mount_point_provider_unittest.cc b/webkit/fileapi/sandbox_mount_point_provider_unittest.cc
index 2f07dc5..7dd6355 100644
--- a/webkit/fileapi/sandbox_mount_point_provider_unittest.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider_unittest.cc
@@ -196,13 +196,8 @@ class SandboxMountPointProviderMigrationTest : public testing::Test {
root.AppendASCII(seed).AppendASCII("d 0").AppendASCII("file 2"));
}
- FileSystemOperationContext* NewContext(const GURL& origin_url,
- fileapi::FileSystemType type) {
- FileSystemOperationContext* context = new FileSystemOperationContext(
- file_system_context_, file_util());
- context->set_src_origin_url(origin_url);
- context->set_src_type(type);
- return context;
+ FileSystemOperationContext* NewContext() {
+ return new FileSystemOperationContext(file_system_context_);
}
std::string URLAndTypeToSeedString(const GURL& origin_url,
@@ -215,37 +210,40 @@ class SandboxMountPointProviderMigrationTest : public testing::Test {
const GURL& origin_url, fileapi::FileSystemType type) {
scoped_ptr<FileSystemOperationContext> context;
- FilePath seed = FilePath().AppendASCII(
+ FilePath seed_file_path = FilePath().AppendASCII(
URLAndTypeToSeedString(origin_url, type));
- context.reset(NewContext(origin_url, type));
+ FileSystemPath root(origin_url, type, FilePath(), file_util());
+ FileSystemPath seed = root.Append(seed_file_path);
+
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->DirectoryExists(
context.get(), seed));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->DirectoryExists(
- context.get(), seed.Append(seed)));
- context.reset(NewContext(origin_url, type));
+ context.get(), seed.Append(seed_file_path)));
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->DirectoryExists(
context.get(), seed.AppendASCII("d 0")));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->DirectoryExists(
context.get(), seed.AppendASCII("d 1")));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->PathExists(
- context.get(), FilePath().AppendASCII("file 0")));
- context.reset(NewContext(origin_url, type));
+ context.get(), root.AppendASCII("file 0")));
+ context.reset(NewContext());
EXPECT_FALSE(file_util()->DirectoryExists(
context.get(), seed.AppendASCII("file 0")));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->PathExists(
context.get(), seed.AppendASCII("d 0").AppendASCII("file 1")));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_FALSE(file_util()->DirectoryExists(
context.get(), seed.AppendASCII("d 0").AppendASCII("file 1")));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_TRUE(file_util()->PathExists(
context.get(), seed.AppendASCII("d 0").AppendASCII("file 2")));
- context.reset(NewContext(origin_url, type));
+ context.reset(NewContext());
EXPECT_FALSE(file_util()->DirectoryExists(
context.get(), seed.AppendASCII("d 0").AppendASCII("file 2")));
}
@@ -308,27 +306,26 @@ class SandboxMountPointProviderMigrationTest : public testing::Test {
type, host, &origins);
break;
case 6:
- sandbox_provider()->GetOriginUsageOnFileThread(
- origin_url, type);
+ sandbox_provider()->GetOriginUsageOnFileThread(origin_url, type);
break;
case 7:
// This case has to use an origin that already exists in the
// migrated data.
sandbox_provider()->UpdateOriginUsageOnFileThread(
NULL, kMigrationTestRecords[0].origin,
- fileapi::kFileSystemTypeTemporary, delta);
+ kFileSystemTypeTemporary, delta);
break;
case 8:
// This case has to use a filesystem that already exists in the
// migrated data.
sandbox_provider()->StartUpdateOriginOnFileThread(
- kMigrationTestRecords[0].origin, fileapi::kFileSystemTypeTemporary);
+ kMigrationTestRecords[0].origin, kFileSystemTypeTemporary);
break;
case 9:
// This case has to use a filesystem that already exists in the
// migrated data.
sandbox_provider()->EndUpdateOriginOnFileThread(
- kMigrationTestRecords[0].origin, fileapi::kFileSystemTypeTemporary);
+ kMigrationTestRecords[0].origin, kFileSystemTypeTemporary);
break;
default:
FAIL();
diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi
index 9e7f815..02781d4 100644
--- a/webkit/fileapi/webkit_fileapi.gypi
+++ b/webkit/fileapi/webkit_fileapi.gypi
@@ -37,6 +37,8 @@
'file_system_options.h',
'file_system_origin_database.cc',
'file_system_origin_database.h',
+ 'file_system_path.cc',
+ 'file_system_path.h',
'file_system_quota_client.cc',
'file_system_quota_client.h',
'file_system_quota_util.cc',