diff options
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.cc | 294 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.h | 161 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_unittest.cc | 193 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url.cc | 7 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url.h | 11 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url_unittest.cc | 48 | ||||
-rw-r--r-- | webkit/fileapi/file_util_helper.cc | 379 | ||||
-rw-r--r-- | webkit/fileapi/file_util_helper.h | 64 | ||||
-rw-r--r-- | webkit/fileapi/webkit_fileapi.gypi | 2 |
9 files changed, 0 insertions, 1159 deletions
diff --git a/webkit/fileapi/file_system_file_util_proxy.cc b/webkit/fileapi/file_system_file_util_proxy.cc deleted file mode 100644 index 8ab1c4f..0000000 --- a/webkit/fileapi/file_system_file_util_proxy.cc +++ /dev/null @@ -1,294 +0,0 @@ -// 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_file_util_proxy.h" - -#include "base/bind.h" -#include "base/memory/scoped_ptr.h" -#include "base/sequenced_task_runner.h" -#include "base/task_runner_util.h" -#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_util_helper.h" - -namespace fileapi { - -using base::Bind; -using base::Callback; -using base::Owned; -using base::PlatformFileError; -using base::Unretained; - -namespace { - -typedef fileapi::FileSystemFileUtilProxy Proxy; - -class EnsureFileExistsHelper { - public: - EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {} - - void RunWork(FileSystemFileUtil* file_util, - FileSystemOperationContext* context, - const FileSystemURL& url) { - error_ = file_util->EnsureFileExists(context, url, &created_); - } - - void Reply(const Proxy::EnsureFileExistsCallback& callback) { - if (!callback.is_null()) - callback.Run(error_, created_); - } - - private: - base::PlatformFileError error_; - bool created_; - DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); -}; - -class GetFileInfoHelper { - public: - GetFileInfoHelper() - : error_(base::PLATFORM_FILE_OK), - snapshot_policy_(FileSystemFileUtil::kSnapshotFileUnknown) {} - - void GetFileInfo(FileSystemFileUtil* file_util, - FileSystemOperationContext* context, - const FileSystemURL& url) { - error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_); - } - - void CreateSnapshotFile(FileSystemFileUtil* file_util, - FileSystemOperationContext* context, - const FileSystemURL& url) { - error_ = file_util->CreateSnapshotFile( - context, url, &file_info_, &platform_path_, &snapshot_policy_); - } - - void ReplyFileInfo(const Proxy::GetFileInfoCallback& callback) { - if (!callback.is_null()) - callback.Run(error_, file_info_, platform_path_); - } - - void ReplySnapshotFile(const Proxy::SnapshotFileCallback& callback) { - DCHECK(snapshot_policy_ != FileSystemFileUtil::kSnapshotFileUnknown); - if (!callback.is_null()) - callback.Run(error_, file_info_, platform_path_, snapshot_policy_); - } - - private: - base::PlatformFileError error_; - base::PlatformFileInfo file_info_; - base::FilePath platform_path_; - FileSystemFileUtil::SnapshotFilePolicy snapshot_policy_; - DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); -}; - -class ReadDirectoryHelper { - public: - ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK) {} - - void RunWork(FileSystemFileUtil* file_util, - FileSystemOperationContext* context, - const FileSystemURL& url) { - error_ = FileUtilHelper::ReadDirectory(context, file_util, url, &entries_); - } - - void Reply(const Proxy::ReadDirectoryCallback& callback) { - if (!callback.is_null()) - callback.Run(error_, entries_, false /* has_more */); - } - - private: - base::PlatformFileError error_; - std::vector<Proxy::Entry> entries_; - DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper); -}; - -} // namespace - -// static -bool FileSystemFileUtilProxy::DeleteFile( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::DeleteFile, Unretained(file_util), - context, url), - callback); -} - -// static -bool FileSystemFileUtilProxy::DeleteDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::DeleteDirectory, Unretained(file_util), - context, url), - callback); -} - -// static -bool FileSystemFileUtilProxy::CreateOrOpen( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - int file_flags, - const CreateOrOpenCallback& callback) { - return base::FileUtilProxy::RelayCreateOrOpen( - context->task_runner(), - Bind(&FileSystemFileUtil::CreateOrOpen, Unretained(file_util), - context, url, file_flags), - Bind(&FileSystemFileUtil::Close, Unretained(file_util), - context), - callback); -} - -// static -bool FileSystemFileUtilProxy::CopyFileLocal( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& src_url, - const FileSystemURL& dest_url, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::CopyOrMoveFile, Unretained(file_util), - context, src_url, dest_url, true /* copy */), - callback); -} - -// static -bool FileSystemFileUtilProxy::MoveFileLocal( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& src_url, - const FileSystemURL& dest_url, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::CopyOrMoveFile, Unretained(file_util), - context, src_url, dest_url, false /* copy */), - callback); -} - -// static -bool FileSystemFileUtilProxy::CopyInForeignFile( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const base::FilePath& src_local_disk_file_path, - const FileSystemURL& dest_url, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::CopyInForeignFile, Unretained(file_util), - context, src_local_disk_file_path, dest_url), - callback); -} - -// static -bool FileSystemFileUtilProxy::EnsureFileExists( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const EnsureFileExistsCallback& callback) { - EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; - return context->task_runner()->PostTaskAndReply( - FROM_HERE, - Bind(&EnsureFileExistsHelper::RunWork, Unretained(helper), - file_util, context, url), - Bind(&EnsureFileExistsHelper::Reply, Owned(helper), callback)); -} - -// static -bool FileSystemFileUtilProxy::CreateDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - bool exclusive, - bool recursive, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::CreateDirectory, Unretained(file_util), - context, url, exclusive, recursive), - callback); -} - -// static -bool FileSystemFileUtilProxy::GetFileInfo( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const GetFileInfoCallback& callback) { - GetFileInfoHelper* helper = new GetFileInfoHelper; - return context->task_runner()->PostTaskAndReply( - FROM_HERE, - Bind(&GetFileInfoHelper::GetFileInfo, Unretained(helper), - file_util, context, url), - Bind(&GetFileInfoHelper::ReplyFileInfo, Owned(helper), callback)); -} - -// static -bool FileSystemFileUtilProxy::CreateSnapshotFile( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const SnapshotFileCallback& callback) { - GetFileInfoHelper* helper = new GetFileInfoHelper; - return context->task_runner()->PostTaskAndReply( - FROM_HERE, - Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), - file_util, context, url), - Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); -} - -// static -bool FileSystemFileUtilProxy::ReadDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const ReadDirectoryCallback& callback) { - ReadDirectoryHelper* helper = new ReadDirectoryHelper; - return context->task_runner()->PostTaskAndReply( - FROM_HERE, - Bind(&ReadDirectoryHelper::RunWork, Unretained(helper), - file_util, context, url), - Bind(&ReadDirectoryHelper::Reply, Owned(helper), callback)); -} - -// static -bool FileSystemFileUtilProxy::Touch( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::Touch, Unretained(file_util), - context, url, last_access_time, last_modified_time), - callback); -} - -// static -bool FileSystemFileUtilProxy::Truncate( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - int64 length, - const StatusCallback& callback) { - return base::PostTaskAndReplyWithResult( - context->task_runner(), FROM_HERE, - Bind(&FileSystemFileUtil::Truncate, Unretained(file_util), - context, url, length), - callback); -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_system_file_util_proxy.h b/webkit/fileapi/file_system_file_util_proxy.h deleted file mode 100644 index 349880f..0000000 --- a/webkit/fileapi/file_system_file_util_proxy.h +++ /dev/null @@ -1,161 +0,0 @@ -// 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_FILE_UTIL_PROXY_H_ -#define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ - -#include "base/callback.h" -#include "base/file_path.h" -#include "base/files/file_util_proxy.h" -#include "base/platform_file.h" -#include "webkit/fileapi/file_system_file_util.h" -#include "webkit/fileapi/file_system_operation.h" - -namespace fileapi { - -class FileSystemFileUtil; -class FileSystemOperationContext; -class FileSystemURL; - -// This class provides asynchronous access to FileSystemFileUtil methods for -// FileSystem API operations. This also implements cross-FileUtil copy/move -// operations on top of FileSystemFileUtil methods. -class FileSystemFileUtilProxy { - public: - // Some of the proxy routines are just wrapping around the FileUtilProxy's - // relay methods, so we use the same types as FileUtilProxy for them. - typedef base::FileUtilProxy::Entry Entry; - typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback; - - typedef base::Callback<void(base::PlatformFileError status)> StatusCallback; - typedef base::Callback<void(base::PlatformFileError status, - bool created)> EnsureFileExistsCallback; - typedef FileSystemOperation::GetMetadataCallback GetFileInfoCallback; - typedef FileSystemOperation::ReadDirectoryCallback ReadDirectoryCallback; - - typedef base::Callback< - void(base::PlatformFileError result, - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path, - FileSystemFileUtil::SnapshotFilePolicy snapshot_policy)> - SnapshotFileCallback; - - // Deletes a file on the given context's task_runner. - static bool DeleteFile( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const StatusCallback& callback); - - // Deletes a directory on the given context's task_runner. - static bool DeleteDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const StatusCallback& callback); - - // Creates or opens a file with the given flags by calling |file_util|'s - // CreateOrOpen method on the given context's task_runner. - static bool CreateOrOpen( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - int file_flags, - const CreateOrOpenCallback& callback); - - // Copies a local file or a directory from |src_url| to |dest_url|. - static bool CopyFileLocal( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& src_url, - const FileSystemURL& dest_url, - const StatusCallback& callback); - - // Moves a local file or a directory from |src_url| to |dest_url|. - static bool MoveFileLocal( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& src_url, - const FileSystemURL& dest_url, - const StatusCallback& callback); - - // Copies a file from local disk to the given filesystem destination. - // Primarily used for the Syncable filesystem type (e.g. Drive). - static bool CopyInForeignFile( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const base::FilePath& src_local_disk_file_path, - const FileSystemURL& dest_url, - const StatusCallback& callback); - - // Ensures that the given |url| exist by calling |file_util|'s - // EnsureFileExists method on the given context's task_runner. - static bool EnsureFileExists( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const EnsureFileExistsCallback& callback); - - // Creates directory at a given url by calling |file_util|'s - // CreateDirectory method on the given context's task_runner. - static bool CreateDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - bool exclusive, - bool recursive, - const StatusCallback& callback); - - // Retrieves the information about a file by calling |file_util|'s - // GetFileInfo method on the given context's task_runner. - static bool GetFileInfo( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const GetFileInfoCallback& callback); - - // Creates a snapshot file by calling |file_util|'s CreateSnapshotFile - // method on the given context's task_runner. - static bool CreateSnapshotFile( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const SnapshotFileCallback& callback); - - // Reads the filenames in |url| by calling |file_util|'s - // ReadDirectory method on the given context's task_runner. - // TODO(kinuko): this should support returning entries in multiple chunks. - // (http://crbug.com/145908) - static bool ReadDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const ReadDirectoryCallback& callback); - - // Touches a file by calling |file_util|'s Touch method - // on the given context's task_runner. - static bool Touch( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const StatusCallback& callback); - - // Truncates a file to the given length by calling |file_util|'s - // Truncate method on the given context's task_runner. - static bool Truncate( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - int64 length, - const StatusCallback& callback); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy); -}; - -} // namespace fileapi - -#endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_PROXY_H_ diff --git a/webkit/fileapi/file_system_file_util_unittest.cc b/webkit/fileapi/file_system_file_util_unittest.cc deleted file mode 100644 index f42b6eb..0000000 --- a/webkit/fileapi/file_system_file_util_unittest.cc +++ /dev/null @@ -1,193 +0,0 @@ -// 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 "base/file_path.h" -#include "base/files/scoped_temp_dir.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "base/platform_file.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/fileapi/file_system_context.h" -#include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_util_helper.h" -#include "webkit/fileapi/local_file_system_test_helper.h" -#include "webkit/fileapi/native_file_util.h" -#include "webkit/fileapi/obfuscated_file_util.h" -#include "webkit/fileapi/test_file_set.h" - -namespace fileapi { - -// This is not yet a full unit test for FileSystemFileUtil. TODO(ericu): Adapt -// the other subclasses' unit tests, as mentioned in the comments in -// ObfuscatedFileUtil's unit test. -// Currently this is just a test of cross-filesystem copy and move, which -// actually exercises subclasses of FileSystemFileUtil as well as the class -// itself. We currently only test copies between obfuscated filesystems. -// TODO(ericu): Add a test for copying between obfuscated and local filesystems, -// and between different local filesystems. -class FileSystemFileUtilTest : public testing::Test { - public: - FileSystemFileUtilTest() { - } - - virtual void SetUp() { - } - - FileSystemOperationContext* NewContext( - LocalFileSystemTestOriginHelper* helper) { - FileSystemOperationContext* context = helper->NewOperationContext(); - // We need to allocate quota for paths for - // TestCrossFileSystemCopyMoveHelper, since it calls into OFSFU, which - // charges quota for paths. - context->set_allowed_bytes_growth(1024 * 1024); - return context; - } - - void TestCrossFileSystemCopyMoveHelper( - const GURL& src_origin, fileapi::FileSystemType src_type, - const GURL& dest_origin, fileapi::FileSystemType dest_type, - bool copy) { - base::ScopedTempDir base_dir; - ASSERT_TRUE(base_dir.CreateUniqueTempDir()); - LocalFileSystemTestOriginHelper src_helper(src_origin, src_type); - src_helper.SetUp(base_dir.path(), - false, // unlimited quota - NULL); // quota::QuotaManagerProxy - - LocalFileSystemTestOriginHelper dest_helper(dest_origin, dest_type); - dest_helper.SetUp(src_helper.file_system_context()); - - ObfuscatedFileUtil* file_util = static_cast<ObfuscatedFileUtil*>( - src_helper.file_util()); - - // Set up all the source data. - scoped_ptr<FileSystemOperationContext> context; - FileSystemURL src_root = src_helper.CreateURLFromUTF8("root directory"); - - for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { - const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; - FileSystemURL url = src_root.WithPath( - src_root.path().Append(test_case.path)); - if (test_case.is_directory) { - context.reset(NewContext(&src_helper)); - ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util->CreateDirectory(context.get(), url, true, true)); - } else { - context.reset(NewContext(&src_helper)); - bool created = false; - ASSERT_EQ(base::PLATFORM_FILE_OK, - file_util->EnsureFileExists(context.get(), url, &created)); - ASSERT_TRUE(created); - context.reset(NewContext(&src_helper)); - ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->Truncate( - context.get(), url, test_case.data_file_size)); - } - } - - FileSystemURL dest_root = dest_helper.CreateURLFromUTF8("root directory"); - - // Do the actual copy or move. - scoped_ptr<FileSystemOperationContext> copy_context( - src_helper.NewOperationContext()); - copy_context->set_allowed_bytes_growth(1024 * 1024); // OFSFU path quota. - - if (copy) { - ASSERT_EQ( - base::PLATFORM_FILE_OK, - FileUtilHelper::Copy( - copy_context.get(), - src_helper.file_util(), dest_helper.file_util(), - src_root, dest_root)); - } else { - ASSERT_EQ( - base::PLATFORM_FILE_OK, - FileUtilHelper::Move( - copy_context.get(), - src_helper.file_util(), dest_helper.file_util(), - 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]; - FileSystemURL url = dest_root.WithPath( - dest_root.path().Append(test_case.path)); - - base::PlatformFileInfo dest_file_info; - base::FilePath data_path; - context.reset(NewContext(&dest_helper)); - EXPECT_EQ(base::PLATFORM_FILE_OK, - file_util->GetFileInfo( - context.get(), url, &dest_file_info, &data_path)); - if (test_case.is_directory) { - EXPECT_TRUE(dest_file_info.is_directory); - } else { - base::PlatformFileInfo platform_file_info; - ASSERT_TRUE(file_util::GetFileInfo(data_path, &platform_file_info)); - EXPECT_EQ(test_case.data_file_size, platform_file_info.size); - EXPECT_FALSE(platform_file_info.is_directory); - EXPECT_EQ(platform_file_info.size, dest_file_info.size); - EXPECT_FALSE(dest_file_info.is_directory); - } - } - - // Validate that the source paths are still there [for a copy] or gone [for - // a move]. - for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { - const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; - FileSystemURL url = src_root.WithPath( - src_root.path().Append(test_case.path)); - base::PlatformFileInfo src_file_info; - base::FilePath data_path; - context.reset(NewContext(&src_helper)); - base::PlatformFileError expected_result; - if (copy) - expected_result = base::PLATFORM_FILE_OK; - else - expected_result = base::PLATFORM_FILE_ERROR_NOT_FOUND; - EXPECT_EQ(expected_result, - file_util->GetFileInfo( - context.get(), url, &src_file_info, &data_path)); - } - } - - private: - MessageLoop message_loop_; - DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtilTest); -}; - -TEST_F(FileSystemFileUtilTest, TestCrossFileSystemCopyDifferentOrigins) { - GURL src_origin("http://www.example.com"); - fileapi::FileSystemType type = kFileSystemTypePersistent; - GURL dest_origin("http://www.not.the.same.domain.com"); - - TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, true); -} - -TEST_F(FileSystemFileUtilTest, TestCrossFileSystemCopySameOrigin) { - GURL origin("http://www.example.com"); - fileapi::FileSystemType src_type = kFileSystemTypePersistent; - fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; - - TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, true); -} - -TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveDifferentOrigins) { - GURL src_origin("http://www.example.com"); - fileapi::FileSystemType type = kFileSystemTypePersistent; - GURL dest_origin("http://www.not.the.same.domain.com"); - - TestCrossFileSystemCopyMoveHelper(src_origin, type, dest_origin, type, false); -} - -TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveSameOrigin) { - GURL origin("http://www.example.com"); - fileapi::FileSystemType src_type = kFileSystemTypePersistent; - fileapi::FileSystemType dest_type = kFileSystemTypeTemporary; - - TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, false); -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_system_url.cc b/webkit/fileapi/file_system_url.cc index e77cb1a..725e2e4 100644 --- a/webkit/fileapi/file_system_url.cc +++ b/webkit/fileapi/file_system_url.cc @@ -151,13 +151,6 @@ std::string FileSystemURL::DebugString() const { return ss.str(); } -FileSystemURL FileSystemURL::WithPath(const base::FilePath& path) const { - FileSystemURL url = *this; - url.path_ = path; - url.virtual_path_.clear(); - return url; -} - bool FileSystemURL::IsParent(const FileSystemURL& child) const { return origin() == child.origin() && type() == child.type() && diff --git a/webkit/fileapi/file_system_url.h b/webkit/fileapi/file_system_url.h index f4eacd0..66c4fae 100644 --- a/webkit/fileapi/file_system_url.h +++ b/webkit/fileapi/file_system_url.h @@ -111,17 +111,6 @@ class WEBKIT_STORAGE_EXPORT FileSystemURL { std::string DebugString() const; - // DEPRECATED: Returns a new FileSystemURL with the given path. - // This creates a new FileSystemURL, copies all fields of this instance - // to that one, resets the path_ to the given |path| and resets the - // virtual_path to *empty*. - // Note that the resulting FileSystemURL loses original URL information - // if it was a cracked filesystem; i.e. virtual_path and mount_type will - // be set to empty values. - // - // TODO(kinuko): deprecate this. http://crbug.com/174576 - FileSystemURL WithPath(const base::FilePath& path) const; - // Returns true if this URL is a strict parent of the |child|. bool IsParent(const FileSystemURL& child) const; diff --git a/webkit/fileapi/file_system_url_unittest.cc b/webkit/fileapi/file_system_url_unittest.cc index 158f768..e3fa393 100644 --- a/webkit/fileapi/file_system_url_unittest.cc +++ b/webkit/fileapi/file_system_url_unittest.cc @@ -138,54 +138,6 @@ TEST(FileSystemURLTest, CompareURLs) { EXPECT_EQ(b.type() < a.type(), compare(b, a)); } -TEST(FileSystemURLTest, WithPath) { - const GURL kURL("filesystem:http://chromium.org/temporary/dir"); - const base::FilePath::StringType paths[] = { - FPL("dir a"), - FPL("dir a/file 1"), - FPL("dir a/dir b"), - FPL("dir a/dir b/file 2"), - }; - - const FileSystemURL base = FileSystemURL::CreateForTest(kURL); - for (size_t i = 0; i < arraysize(paths); ++i) { - const FileSystemURL url = base.WithPath(base::FilePath(paths[i])); - EXPECT_EQ(paths[i], url.path().value()); - EXPECT_EQ(base.origin().spec(), url.origin().spec()); - EXPECT_EQ(base.type(), url.type()); - EXPECT_EQ(base.mount_type(), url.mount_type()); - EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); - } -} - -TEST(FileSystemURLTest, WithPathForExternal) { - const std::string kId = "foo"; - ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, base::FilePath()); - const base::FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath(); - - const base::FilePath::CharType kBasePath[] = FPL("dir"); - const base::FilePath::StringType paths[] = { - FPL("dir a"), - FPL("dir a/file 1"), - FPL("dir a/dir b"), - FPL("dir a/dir b/file 2"), - }; - - const FileSystemURL base = FileSystemURL::CreateForTest( - GURL("http://example.com/"), - kFileSystemTypeExternal, - kVirtualRoot.Append(kBasePath)); - - for (size_t i = 0; i < arraysize(paths); ++i) { - const FileSystemURL url = base.WithPath(base::FilePath(paths[i])); - EXPECT_EQ(paths[i], url.path().value()); - EXPECT_EQ(base.origin().spec(), url.origin().spec()); - EXPECT_EQ(base.type(), url.type()); - EXPECT_EQ(base.mount_type(), url.mount_type()); - EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); - } -} - TEST(FileSystemURLTest, IsParent) { ScopedExternalFileSystem scoped1("foo", kFileSystemTypeSyncable, base::FilePath()); ScopedExternalFileSystem scoped2("bar", kFileSystemTypeSyncable, base::FilePath()); diff --git a/webkit/fileapi/file_util_helper.cc b/webkit/fileapi/file_util_helper.cc deleted file mode 100644 index 49ea72c..0000000 --- a/webkit/fileapi/file_util_helper.cc +++ /dev/null @@ -1,379 +0,0 @@ -// 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_util_helper.h" - -#include <stack> -#include <utility> - -#include "webkit/fileapi/file_system_file_util.h" -#include "webkit/fileapi/file_system_operation_context.h" -#include "webkit/fileapi/file_system_url.h" -#include "webkit/fileapi/file_system_util.h" - -using base::PlatformFileError; - -namespace fileapi { - -namespace { - -// A helper class to delete a temporary file. -class ScopedFileDeleter { - public: - explicit ScopedFileDeleter(const base::FilePath& path) : path_(path) {} - ~ScopedFileDeleter() { - file_util::Delete(path_, false /* recursive */); - } - - private: - base::FilePath path_; -}; - -bool IsInRoot(const FileSystemURL& url) { - // If path is in the root, path.DirName() will be ".", - // since we use paths with no leading '/'. - base::FilePath parent = url.path().DirName(); - return parent.empty() || parent == base::FilePath(FILE_PATH_LITERAL(".")); -} - -// A helper class for cross-FileUtil Copy/Move operations. -class CrossFileUtilHelper { - public: - enum Operation { - OPERATION_COPY, - OPERATION_MOVE - }; - - CrossFileUtilHelper(FileSystemOperationContext* context, - FileSystemFileUtil* src_util, - FileSystemFileUtil* dest_util, - const FileSystemURL& src_url, - const FileSystemURL& dest_url, - Operation operation); - ~CrossFileUtilHelper(); - - base::PlatformFileError DoWork(); - - private: - // Performs common pre-operation check and preparation. - // This may delete the destination directory if it's empty. - base::PlatformFileError PerformErrorCheckAndPreparation(); - - // Performs recursive copy or move by calling CopyOrMoveFile for individual - // files. Operations for recursive traversal are encapsulated in this method. - // It assumes src_url and dest_url have passed - // PerformErrorCheckAndPreparationForMoveAndCopy(). - base::PlatformFileError CopyOrMoveDirectory( - const FileSystemURL& src_url, - const FileSystemURL& dest_url); - - // Determines whether a simple same-filesystem move or copy can be done. If - // so, it delegates to CopyOrMoveFile. Otherwise it looks up the true - // platform path of the source file, delegates to CopyInForeignFile, and [for - // move] calls DeleteFile on the source file. - base::PlatformFileError CopyOrMoveFile( - const FileSystemURL& src_url, - const FileSystemURL& dest_url); - - FileSystemOperationContext* context_; - FileSystemFileUtil* src_util_; // Not owned. - FileSystemFileUtil* dest_util_; // Not owned. - const FileSystemURL& src_root_url_; - const FileSystemURL& dest_root_url_; - Operation operation_; - bool same_file_system_; - - DISALLOW_COPY_AND_ASSIGN(CrossFileUtilHelper); -}; - -CrossFileUtilHelper::CrossFileUtilHelper( - FileSystemOperationContext* context, - FileSystemFileUtil* src_util, - FileSystemFileUtil* dest_util, - const FileSystemURL& src_url, - const FileSystemURL& dest_url, - Operation operation) - : context_(context), - src_util_(src_util), - dest_util_(dest_util), - src_root_url_(src_url), - dest_root_url_(dest_url), - operation_(operation) { - DCHECK(src_util_); - DCHECK(dest_util_); - same_file_system_ = - src_root_url_.origin() == dest_root_url_.origin() && - src_root_url_.type() == dest_root_url_.type(); -} - -CrossFileUtilHelper::~CrossFileUtilHelper() {} - -base::PlatformFileError CrossFileUtilHelper::DoWork() { - // It is an error to try to copy/move an entry into its child. - if (same_file_system_ && src_root_url_.path().IsParent(dest_root_url_.path())) - 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_root_url_.path() == dest_root_url_.path()) - return base::PLATFORM_FILE_ERROR_EXISTS; - - // First try to copy/move the file. - base::PlatformFileError error = CopyOrMoveFile(src_root_url_, dest_root_url_); - if (error == base::PLATFORM_FILE_OK || - error != base::PLATFORM_FILE_ERROR_NOT_A_FILE) - return error; - - // Now we should be sure that the source (and destination if exists) - // is directory. - // Now let's try to remove the destination directory, this must - // fail if the directory isn't empty or its parent doesn't exist. - error = dest_util_->DeleteDirectory(context_, dest_root_url_); - if (error == base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY) - return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; - if (error != base::PLATFORM_FILE_OK && - error != base::PLATFORM_FILE_ERROR_NOT_FOUND) - return error; - - // Perform the actual work for directory copy/move. - return CopyOrMoveDirectory(src_root_url_, dest_root_url_); -} - -PlatformFileError CrossFileUtilHelper::CopyOrMoveDirectory( - const FileSystemURL& src_url, - const FileSystemURL& dest_url) { - // At this point we must have gone through - // PerformErrorCheckAndPreparationForMoveAndCopy so this must be true. - DCHECK(!same_file_system_ || - !src_url.path().IsParent(dest_url.path())); - - PlatformFileError error = dest_util_->CreateDirectory( - context_, dest_url, false /* exclusive */, false /* recursive */); - if (error != base::PLATFORM_FILE_OK) - return error; - - typedef std::pair<FileSystemURL, base::Time> MovedDirectoryPair; - typedef std::vector<MovedDirectoryPair> MovedDirectories; - MovedDirectories directories; - - // Store modified timestamp of the root directory. - if (operation_ == OPERATION_MOVE) { - base::PlatformFileInfo file_info; - base::FilePath platform_file_path; - error = src_util_->GetFileInfo( - context_, src_url, &file_info, &platform_file_path); - if (error != base::PLATFORM_FILE_OK) - return error; - directories.push_back( - std::make_pair(dest_url, file_info.last_modified)); - } - - scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( - src_util_->CreateFileEnumerator(context_, - src_url, - true /* recursive */)); - base::FilePath src_file_path_each; - while (!(src_file_path_each = file_enum->Next()).empty()) { - base::FilePath dest_file_path_each(dest_url.path()); - src_url.path().AppendRelativePath( - src_file_path_each, &dest_file_path_each); - - if (file_enum->IsDirectory()) { - error = dest_util_->CreateDirectory( - context_, - dest_url.WithPath(dest_file_path_each), - true /* exclusive */, false /* recursive */); - if (error != base::PLATFORM_FILE_OK) - return error; - - directories.push_back(std::make_pair( - dest_url.WithPath(dest_file_path_each), - file_enum->LastModifiedTime())); - } else { - error = CopyOrMoveFile(src_url.WithPath(src_file_path_each), - dest_url.WithPath(dest_file_path_each)); - if (error != base::PLATFORM_FILE_OK) - return error; - } - } - - if (operation_ == OPERATION_MOVE) { - // Restore modified timestamp of destination directories. - for (MovedDirectories::const_iterator it(directories.begin()); - it != directories.end(); ++it) { - error = dest_util_->Touch(context_, it->first, it->second, it->second); - if (error != base::PLATFORM_FILE_OK) - return error; - } - - error = FileUtilHelper::Delete( - context_, src_util_, src_url, true /* recursive */); - if (error != base::PLATFORM_FILE_OK) - return error; - } - - return base::PLATFORM_FILE_OK; -} - -PlatformFileError CrossFileUtilHelper::CopyOrMoveFile( - const FileSystemURL& src_url, - const FileSystemURL& dest_url) { - if (same_file_system_) { - DCHECK(src_util_ == dest_util_); - // Source and destination are in the same FileSystemFileUtil; now we can - // safely call FileSystemFileUtil method on src_util_ (== dest_util_). - return src_util_->CopyOrMoveFile(context_, src_url, dest_url, - operation_ == OPERATION_COPY); - } - - // Resolve the src_url's underlying file path. - base::PlatformFileInfo file_info; - base::FilePath platform_file_path; - SnapshotFilePolicy snapshot_policy; - - PlatformFileError error = src_util_->CreateSnapshotFile( - context_, src_url, &file_info, &platform_file_path, &snapshot_policy); - if (error != base::PLATFORM_FILE_OK) - return error; - - // For now we don't support non-snapshot file case. - // TODO(kinuko): Address this case too. - DCHECK(!platform_file_path.empty()); - - scoped_ptr<ScopedFileDeleter> file_deleter; - if (snapshot_policy == kSnapshotFileTemporary) - file_deleter.reset(new ScopedFileDeleter(platform_file_path)); - - // Call CopyInForeignFile() on the dest_util_ with the resolved source path - // to perform limited cross-FileSystemFileUtil copy/move. - error = dest_util_->CopyInForeignFile( - context_, platform_file_path, dest_url); - - if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK) - return error; - return src_util_->DeleteFile(context_, src_url); -} - -} // anonymous namespace - -// static -bool FileUtilHelper::DirectoryExists(FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url) { - if (url.path().empty()) - return true; - - base::PlatformFileInfo file_info; - base::FilePath platform_path; - PlatformFileError error = file_util->GetFileInfo( - context, url, &file_info, &platform_path); - return error == base::PLATFORM_FILE_OK && file_info.is_directory; -} - -// static -base::PlatformFileError FileUtilHelper::Copy( - FileSystemOperationContext* context, - FileSystemFileUtil* src_file_util, - FileSystemFileUtil* dest_file_util, - const FileSystemURL& src_root_url, - const FileSystemURL& dest_root_url) { - return CrossFileUtilHelper(context, src_file_util, dest_file_util, - src_root_url, dest_root_url, - CrossFileUtilHelper::OPERATION_COPY).DoWork(); -} - -// static -base::PlatformFileError FileUtilHelper::Move( - FileSystemOperationContext* context, - FileSystemFileUtil* src_file_util, - FileSystemFileUtil* dest_file_util, - const FileSystemURL& src_root_url, - const FileSystemURL& dest_root_url) { - return CrossFileUtilHelper(context, src_file_util, dest_file_util, - src_root_url, dest_root_url, - CrossFileUtilHelper::OPERATION_MOVE).DoWork(); -} - -// static -base::PlatformFileError FileUtilHelper::Delete( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - bool recursive) { - if (DirectoryExists(context, file_util, url)) { - if (!recursive) - return file_util->DeleteDirectory(context, url); - else - return DeleteDirectoryRecursive(context, file_util, url); - } else { - return file_util->DeleteFile(context, url); - } -} - -// static -base::PlatformFileError FileUtilHelper::ReadDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - std::vector<base::FileUtilProxy::Entry>* entries) { - DCHECK(entries); - - base::PlatformFileInfo file_info; - base::FilePath platform_path; - PlatformFileError error = file_util->GetFileInfo( - context, url, &file_info, &platform_path); - if (error != base::PLATFORM_FILE_OK) - return error; - if (!file_info.is_directory) - return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; - - scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( - file_util->CreateFileEnumerator(context, url, false /* recursive */)); - - base::FilePath current; - while (!(current = file_enum->Next()).empty()) { - base::FileUtilProxy::Entry entry; - entry.is_directory = file_enum->IsDirectory(); - entry.name = VirtualPath::BaseName(current).value(); - entry.size = file_enum->Size(); - entry.last_modified_time = file_enum->LastModifiedTime(); - entries->push_back(entry); - } - return base::PLATFORM_FILE_OK; -} - -// static -base::PlatformFileError FileUtilHelper::DeleteDirectoryRecursive( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url) { - - scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( - file_util->CreateFileEnumerator(context, url, true /* recursive */)); - base::FilePath file_path_each; - std::stack<base::FilePath> directories; - while (!(file_path_each = file_enum->Next()).empty()) { - if (file_enum->IsDirectory()) { - directories.push(file_path_each); - } else { - PlatformFileError error = file_util->DeleteFile( - context, url.WithPath(file_path_each)); - if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && - error != base::PLATFORM_FILE_OK) - return error; - } - } - - while (!directories.empty()) { - PlatformFileError error = file_util->DeleteDirectory( - context, url.WithPath(directories.top())); - if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && - error != base::PLATFORM_FILE_OK) - return error; - directories.pop(); - } - return file_util->DeleteDirectory(context, url); -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_util_helper.h b/webkit/fileapi/file_util_helper.h deleted file mode 100644 index 876324e..0000000 --- a/webkit/fileapi/file_util_helper.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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_UTIL_HELPER_H_ -#define WEBKIT_FILEAPI_FILE_UTIL_HELPER_H_ - -#include <vector> - -#include "base/files/file_util_proxy.h" -#include "base/platform_file.h" -#include "webkit/storage/webkit_storage_export.h" - -namespace fileapi { - -class FileSystemFileUtil; -class FileSystemOperationContext; -class FileSystemURL; - -// A collection of static methods that are usually called by -// FileSystemFileUtilProxy. The method should be called on FILE thread. -class WEBKIT_STORAGE_EXPORT_PRIVATE FileUtilHelper { - public: - static bool DirectoryExists( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url); - - static base::PlatformFileError Copy( - FileSystemOperationContext* context, - FileSystemFileUtil* src_file_util, - FileSystemFileUtil* dest_file_utile, - const FileSystemURL& src_root_url, - const FileSystemURL& dest_root_url); - - static base::PlatformFileError Move( - FileSystemOperationContext* context, - FileSystemFileUtil* src_file_util, - FileSystemFileUtil* dest_file_utile, - const FileSystemURL& src_root_url, - const FileSystemURL& dest_root_url); - - static base::PlatformFileError Delete( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - bool recursive); - - static base::PlatformFileError ReadDirectory( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url, - std::vector<base::FileUtilProxy::Entry>* entries); - - private: - static base::PlatformFileError DeleteDirectoryRecursive( - FileSystemOperationContext* context, - FileSystemFileUtil* file_util, - const FileSystemURL& url); -}; - -} // namespace fileapi - -#endif // WEBKIT_FILEAPI_FILE_UTIL_HELPER_H_ diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi index 154ed3d..9ed3c59 100644 --- a/webkit/fileapi/webkit_fileapi.gypi +++ b/webkit/fileapi/webkit_fileapi.gypi @@ -52,8 +52,6 @@ '../fileapi/file_system_usage_cache.h', '../fileapi/file_system_util.cc', '../fileapi/file_system_util.h', - '../fileapi/file_util_helper.cc', - '../fileapi/file_util_helper.h', '../fileapi/file_writer_delegate.cc', '../fileapi/file_writer_delegate.h', '../fileapi/isolated_context.cc', |