diff options
author | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-24 00:49:40 +0000 |
---|---|---|
committer | ericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-24 00:49:40 +0000 |
commit | 073a04f0599beb27670d8a6738fcbbc22fa97bcf (patch) | |
tree | d7393b3cd3463dbfaf4bbdc02fdd0a4de0c83995 /webkit/fileapi/local_file_system_file_util.cc | |
parent | 6bcd5f36cd94649887eff0c87df4f4496001984a (diff) | |
download | chromium_src-073a04f0599beb27670d8a6738fcbbc22fa97bcf.zip chromium_src-073a04f0599beb27670d8a6738fcbbc22fa97bcf.tar.gz chromium_src-073a04f0599beb27670d8a6738fcbbc22fa97bcf.tar.bz2 |
Stop returning the true root path of each filesystem from openFileSystem.
Instead, return the FileSystem URI of the root. This will make it easier
to swap in different filesystem implementations.
BUG=71635
TEST=Just a couple in FileSystemUtilTests, but a bunch of existing ones [this doesn't add much new functionality].
Review URL: http://codereview.chromium.org/6603034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/local_file_system_file_util.cc')
-rw-r--r-- | webkit/fileapi/local_file_system_file_util.cc | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/webkit/fileapi/local_file_system_file_util.cc b/webkit/fileapi/local_file_system_file_util.cc new file mode 100644 index 0000000..a017d57 --- /dev/null +++ b/webkit/fileapi/local_file_system_file_util.cc @@ -0,0 +1,178 @@ +// Copyright (c) 2011 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/local_file_system_file_util.h" + +#include "base/file_util_proxy.h" +#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_manager.h" +#include "webkit/fileapi/file_system_types.h" +#include "webkit/fileapi/file_system_util.h" + +namespace fileapi { + +LocalFileSystemFileUtil* LocalFileSystemFileUtil::GetInstance() { + return Singleton<LocalFileSystemFileUtil>::get(); +} + +PlatformFileError LocalFileSystemFileUtil::CreateOrOpen( + FileSystemOperationContext* context, + const FilePath& file_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()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->CreateOrOpen( + context, local_path, file_flags, file_handle, created); +} + +PlatformFileError LocalFileSystemFileUtil::EnsureFileExists( + FileSystemOperationContext* context, + const FilePath& file_path, + bool* created) { + FilePath local_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + file_path); + if (local_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->EnsureFileExists( + context, local_path, created); +} + +PlatformFileError LocalFileSystemFileUtil::GetFileInfo( + FileSystemOperationContext* context, + const FilePath& file_path, + base::PlatformFileInfo* file_info) { + FilePath local_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + file_path); + if (local_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->GetFileInfo( + context, local_path, file_info); +} + +PlatformFileError LocalFileSystemFileUtil::ReadDirectory( + FileSystemOperationContext* context, + const FilePath& file_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()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->ReadDirectory( + context, local_path, entries); +} + +PlatformFileError LocalFileSystemFileUtil::CreateDirectory( + FileSystemOperationContext* context, + const FilePath& file_path, + bool exclusive, + bool recursive) { + FilePath local_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + file_path); + if (local_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->CreateDirectory( + context, local_path, exclusive, recursive); +} + +PlatformFileError LocalFileSystemFileUtil::Copy( + FileSystemOperationContext* context, + const FilePath& src_file_path, + const FilePath& dest_file_path) { + // TODO(ericu): If they share a root URL, this could be optimized. + FilePath local_src_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + src_file_path); + if (local_src_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + FilePath local_dest_path = + GetLocalPath(context, context->dest_origin_url(), context->dest_type(), + dest_file_path); + if (local_dest_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->Copy( + context, local_src_path, local_dest_path); +} + +PlatformFileError LocalFileSystemFileUtil::Move( + FileSystemOperationContext* context, + const FilePath& src_file_path, + const FilePath& dest_file_path) { + // TODO(ericu): If they share a root URL, this could be optimized. + FilePath local_src_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + src_file_path); + if (local_src_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + FilePath local_dest_path = + GetLocalPath(context, context->dest_origin_url(), context->dest_type(), + dest_file_path); + if (local_dest_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->Move( + context, local_src_path, local_dest_path); +} + +PlatformFileError LocalFileSystemFileUtil::Delete( + FileSystemOperationContext* context, + const FilePath& file_path, + bool recursive) { + FilePath local_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + file_path); + if (local_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->Delete( + context, local_path, recursive); +} + +PlatformFileError LocalFileSystemFileUtil::Touch( + FileSystemOperationContext* context, + const FilePath& file_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()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->Touch( + context, local_path, last_access_time, last_modified_time); +} + +PlatformFileError LocalFileSystemFileUtil::Truncate( + FileSystemOperationContext* context, + const FilePath& file_path, + int64 length) { + FilePath local_path = + GetLocalPath(context, context->src_origin_url(), context->src_type(), + file_path); + if (local_path.empty()) + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; + return FileSystemFileUtil::GetInstance()->Truncate( + context, local_path, length); +} + +FilePath LocalFileSystemFileUtil::GetLocalPath( + FileSystemOperationContext* context, + const GURL& origin_url, + FileSystemType type, + const FilePath& virtual_path) { + FilePath root = context->file_system_context()->path_manager()-> + GetFileSystemRootPathOnFileThread(origin_url, type, false); + if (root.empty()) + return FilePath(); + return root.Append(virtual_path); +} + +} // namespace fileapi |