diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-28 07:51:20 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-28 07:51:20 +0000 |
commit | 95af73710463503d2b2087bbd4dd4019a1db75fe (patch) | |
tree | 376f02f794892c7590c7aa8c3873a3a52f54507a /webkit | |
parent | ade05b3441e3d36f109b75cbccba892246c65a50 (diff) | |
download | chromium_src-95af73710463503d2b2087bbd4dd4019a1db75fe.zip chromium_src-95af73710463503d2b2087bbd4dd4019a1db75fe.tar.gz chromium_src-95af73710463503d2b2087bbd4dd4019a1db75fe.tar.bz2 |
Unlayer ObfuscatedFileUtil.
In this CL:
- Stop layering under FileSystemFileUtil, and make it pure virtual class.
- Introduce LayeringFileUtil class, instead.
- Change NativeFileUtil to pure 'static' class.
- Change {Obfuscated,Local,Isolated}FileUtil to call NativeFileUtil directory.
BUG=114732
TEST='*File*'
Review URL: https://chromiumcodereview.appspot.com/10391102
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139226 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/chromeos/fileapi/cros_mount_point_provider.cc | 4 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util.cc | 225 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util.h | 48 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/isolated_file_util.cc | 91 | ||||
-rw-r--r-- | webkit/fileapi/isolated_file_util.h | 8 | ||||
-rw-r--r-- | webkit/fileapi/isolated_file_util_unittest.cc | 18 | ||||
-rw-r--r-- | webkit/fileapi/isolated_mount_point_provider.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/local_file_util.cc | 180 | ||||
-rw-r--r-- | webkit/fileapi/local_file_util.h | 5 | ||||
-rw-r--r-- | webkit/fileapi/local_file_util_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/native_file_util.cc | 134 | ||||
-rw-r--r-- | webkit/fileapi/native_file_util.h | 95 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util.cc | 238 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util.h | 31 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_mount_point_provider.cc | 3 | ||||
-rw-r--r-- | webkit/fileapi/test_mount_point_provider.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/webkit_fileapi.gypi | 1 |
18 files changed, 366 insertions, 723 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc index 4b1b0c2..119c288 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc @@ -20,7 +20,6 @@ #include "webkit/fileapi/file_system_file_reader.h" #include "webkit/fileapi/file_system_operation.h" #include "webkit/fileapi/file_system_util.h" -#include "webkit/fileapi/native_file_util.h" #include "webkit/glue/webkit_glue.h" namespace { @@ -59,8 +58,7 @@ CrosMountPointProvider::CrosMountPointProvider( scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) : special_storage_policy_(special_storage_policy), file_access_permissions_(new FileAccessPermissions()), - local_file_util_( - new fileapi::LocalFileUtil(new fileapi::NativeFileUtil())) { + local_file_util_(new fileapi::LocalFileUtil()) { const std::string home = GetHomeDirectory(); if (!home.empty()) { AddLocalMountPoint( diff --git a/webkit/fileapi/file_system_file_util.cc b/webkit/fileapi/file_system_file_util.cc deleted file mode 100644 index a8b5e66..0000000 --- a/webkit/fileapi/file_system_file_util.cc +++ /dev/null @@ -1,225 +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.h" - -#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 { - -FileSystemFileUtil::FileSystemFileUtil() { -} - -FileSystemFileUtil::FileSystemFileUtil(FileSystemFileUtil* underlying_file_util) - : underlying_file_util_(underlying_file_util) { -} - -FileSystemFileUtil::~FileSystemFileUtil() { -} - -PlatformFileError FileSystemFileUtil::CreateOrOpen( - FileSystemOperationContext* context, - const FileSystemPath& path, int file_flags, - PlatformFile* file_handle, bool* created) { - if (underlying_file_util_.get()) { - return underlying_file_util_->CreateOrOpen( - context, path, file_flags, file_handle, created); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::Close( - FileSystemOperationContext* context, - PlatformFile file_handle) { - if (underlying_file_util_.get()) { - return underlying_file_util_->Close(context, file_handle); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::EnsureFileExists( - FileSystemOperationContext* context, - const FileSystemPath& path, - bool* created) { - if (underlying_file_util_.get()) { - return underlying_file_util_->EnsureFileExists(context, path, created); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::CreateDirectory( - FileSystemOperationContext* context, - const FileSystemPath& path, - bool exclusive, - bool recursive) { - if (underlying_file_util_.get()) { - return underlying_file_util_->CreateDirectory( - context, path, exclusive, recursive); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::GetFileInfo( - FileSystemOperationContext* context, - const FileSystemPath& path, - base::PlatformFileInfo* file_info, - FilePath* platform_file_path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->GetFileInfo( - context, path, file_info, platform_file_path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -FileSystemFileUtil::AbstractFileEnumerator* -FileSystemFileUtil::CreateFileEnumerator( - FileSystemOperationContext* context, - const FileSystemPath& root_path, - bool recursive) { - if (underlying_file_util_.get()) { - return underlying_file_util_->CreateFileEnumerator(context, root_path, - recursive); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return NULL; -} - -PlatformFileError FileSystemFileUtil::GetLocalFilePath( - FileSystemOperationContext* context, - const FileSystemPath& file_system_path, - FilePath* local_file_path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->GetLocalFilePath( - context, file_system_path, local_file_path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::Touch( - FileSystemOperationContext* context, - 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, path, last_access_time, last_modified_time); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::Truncate( - FileSystemOperationContext* context, - const FileSystemPath& path, - int64 length) { - if (underlying_file_util_.get()) { - return underlying_file_util_->Truncate(context, path, length); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - - -bool FileSystemFileUtil::PathExists( - FileSystemOperationContext* context, - const FileSystemPath& path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->PathExists(context, path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return false; -} - -bool FileSystemFileUtil::DirectoryExists( - FileSystemOperationContext* context, - const FileSystemPath& path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->DirectoryExists(context, path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return false; -} - -bool FileSystemFileUtil::IsDirectoryEmpty( - FileSystemOperationContext* context, - const FileSystemPath& path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->IsDirectoryEmpty(context, path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return false; -} - -PlatformFileError FileSystemFileUtil::CopyOrMoveFile( - FileSystemOperationContext* context, - const FileSystemPath& src_path, - const FileSystemPath& dest_path, - bool copy) { - if (underlying_file_util_.get()) { - return underlying_file_util_->CopyOrMoveFile( - context, src_path, dest_path, copy); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::CopyInForeignFile( - FileSystemOperationContext* context, - const FilePath& src_file_path, - const FileSystemPath& dest_path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->CopyInForeignFile( - context, src_file_path, dest_path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::DeleteFile( - FileSystemOperationContext* context, - const FileSystemPath& path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->DeleteFile(context, path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError FileSystemFileUtil::DeleteSingleDirectory( - FileSystemOperationContext* context, - const FileSystemPath& path) { - if (underlying_file_util_.get()) { - return underlying_file_util_->DeleteSingleDirectory(context, path); - } - NOTREACHED() << "Subclasses must provide implementation if they have no" - << "underlying_file_util"; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_system_file_util.h b/webkit/fileapi/file_system_file_util.h index dfc2b25..9930f9f 100644 --- a/webkit/fileapi/file_system_file_util.h +++ b/webkit/fileapi/file_system_file_util.h @@ -23,8 +23,8 @@ class FileSystemOperationContext; // A file utility interface that provides basic file utility methods for // FileSystem API. // -// TODO(kinuko): Move all the default implementation out of this class -// and make this class pure abstract class. +// Layering structure of the FileSystemFileUtil was split out. +// See http://crbug.com/128136 if you need it. class FileSystemFileUtil { public: // It will be implemented by each subclass such as FileSystemFileEnumerator. @@ -49,7 +49,7 @@ class FileSystemFileUtil { virtual bool IsLink() OVERRIDE { return false; } }; - virtual ~FileSystemFileUtil(); + virtual ~FileSystemFileUtil() {} // Creates or opens a file with the given flags. // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create @@ -60,12 +60,12 @@ class FileSystemFileUtil { const FileSystemPath& path, int file_flags, PlatformFile* file_handle, - bool* created); + bool* created) = 0; // Closes the given file handle. virtual PlatformFileError Close( FileSystemOperationContext* context, - PlatformFile); + PlatformFile file) = 0; // Ensures that the given |path| exist. This creates a empty new file // at |path| if the |path| does not exist. @@ -78,7 +78,7 @@ class FileSystemFileUtil { // reasons, |created| is set false and |error code| indicates the error. virtual PlatformFileError EnsureFileExists( FileSystemOperationContext* context, - const FileSystemPath& path, bool* created); + const FileSystemPath& path, bool* created) = 0; // Creates directory at given path. It's an error to create // if |exclusive| is true and dir already exists. @@ -86,14 +86,14 @@ class FileSystemFileUtil { FileSystemOperationContext* context, const FileSystemPath& path, bool exclusive, - bool recursive); + bool recursive) = 0; // Retrieves the information about a file. virtual PlatformFileError GetFileInfo( FileSystemOperationContext* context, const FileSystemPath& path, base::PlatformFileInfo* file_info, - FilePath* platform_path); + FilePath* platform_path) = 0; // Returns a pointer to a new instance of AbstractFileEnumerator which is // implemented for each FileSystemFileUtil subclass. The instance needs to be @@ -105,7 +105,7 @@ class FileSystemFileUtil { virtual AbstractFileEnumerator* CreateFileEnumerator( FileSystemOperationContext* context, const FileSystemPath& root_path, - bool recursive); + bool recursive) = 0; // Maps |virtual_path| given |context| into |local_file_path| which represents // physical file location on the host OS. @@ -113,7 +113,7 @@ class FileSystemFileUtil { virtual PlatformFileError GetLocalFilePath( FileSystemOperationContext* context, const FileSystemPath& file_system_path, - FilePath* local_file_path); + FilePath* local_file_path) = 0; // Updates the file metadata information. Unlike posix's touch, it does // not create a file even if |path| does not exist, but instead fails @@ -122,36 +122,36 @@ class FileSystemFileUtil { FileSystemOperationContext* context, const FileSystemPath& path, const base::Time& last_access_time, - const base::Time& last_modified_time); + const base::Time& last_modified_time) = 0; // Truncates a file to the given length. If |length| is greater than the // current length of the file, the file will be extended with zeroes. virtual PlatformFileError Truncate( FileSystemOperationContext* context, const FileSystemPath& path, - int64 length); + int64 length) = 0; // Returns true if a given |path| exists. virtual bool PathExists( FileSystemOperationContext* context, - const FileSystemPath& path); + const FileSystemPath& path) = 0; // Returns true if a given |path| exists and is a directory. virtual bool DirectoryExists( FileSystemOperationContext* context, - const FileSystemPath& path); + const FileSystemPath& path) = 0; // Returns true if a given |path| is an empty directory. virtual bool IsDirectoryEmpty( FileSystemOperationContext* context, - const FileSystemPath& path); + const FileSystemPath& path) = 0; // Copies or moves a single file from |src_path| to |dest_path|. virtual PlatformFileError CopyOrMoveFile( FileSystemOperationContext* context, const FileSystemPath& src_path, const FileSystemPath& dest_path, - bool copy); + bool copy) = 0; // Copies in a single file from a different filesystem. The // |underlying_src_path| is a local path which can be handled by the @@ -159,32 +159,24 @@ class FileSystemFileUtil { virtual PlatformFileError CopyInForeignFile( FileSystemOperationContext* context, const FilePath& src_file_path, - const FileSystemPath& dest_path); + const FileSystemPath& dest_path) = 0; // Deletes a single file. // It assumes the given path points a file. virtual PlatformFileError DeleteFile( FileSystemOperationContext* context, - const FileSystemPath& path); + const FileSystemPath& path) = 0; // Deletes a single empty directory. // It assumes the given path points an empty directory. virtual PlatformFileError DeleteSingleDirectory( FileSystemOperationContext* context, - const FileSystemPath& path); + const FileSystemPath& path) = 0; protected: - FileSystemFileUtil(); - explicit FileSystemFileUtil(FileSystemFileUtil* underlying_file_util); - - // TODO(kinuko): We should stop FileUtil layering. - FileSystemFileUtil* underlying_file_util() const { - return underlying_file_util_.get(); - } + FileSystemFileUtil() {} private: - scoped_ptr<FileSystemFileUtil> underlying_file_util_; - DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); }; diff --git a/webkit/fileapi/file_system_file_util_unittest.cc b/webkit/fileapi/file_system_file_util_unittest.cc index e48f05f..ebb57e3 100644 --- a/webkit/fileapi/file_system_file_util_unittest.cc +++ b/webkit/fileapi/file_system_file_util_unittest.cc @@ -50,7 +50,7 @@ class FileSystemFileUtilTest : public testing::Test { ScopedTempDir base_dir; ASSERT_TRUE(base_dir.CreateUniqueTempDir()); scoped_ptr<ObfuscatedFileUtil> file_util( - new ObfuscatedFileUtil(base_dir.path(), new NativeFileUtil())); + new ObfuscatedFileUtil(base_dir.path())); FileSystemTestOriginHelper src_helper(src_origin, src_type); src_helper.SetUp(base_dir.path(), false, // unlimited quota diff --git a/webkit/fileapi/isolated_file_util.cc b/webkit/fileapi/isolated_file_util.cc index a337b3a..2dcbd14 100644 --- a/webkit/fileapi/isolated_file_util.cc +++ b/webkit/fileapi/isolated_file_util.cc @@ -12,6 +12,7 @@ #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_path.h" #include "webkit/fileapi/isolated_context.h" +#include "webkit/fileapi/native_file_util.h" using base::PlatformFileError; using base::PlatformFileInfo; @@ -24,15 +25,10 @@ namespace { // Used to enumerate top-level paths of an isolated filesystem. class SetFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { public: - SetFileEnumerator(FileSystemFileUtil* underlying_file_util, - const FileSystemOperationContext& context, - const std::vector<FilePath>& paths, - const FileSystemPath& root) - : underlying_file_util_(underlying_file_util), - context_(context), - paths_(paths), + SetFileEnumerator(const std::vector<FilePath>& paths, + const FilePath& root) + : paths_(paths), root_(root) { - DCHECK(underlying_file_util_); path_iter_ = paths_.begin(); } virtual ~SetFileEnumerator() {} @@ -41,11 +37,9 @@ class SetFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { virtual FilePath Next() OVERRIDE { if (path_iter_ == paths_.end()) return FilePath(); - FilePath platform_path; - underlying_file_util_->GetFileInfo( - &context_, root_.WithInternalPath(*path_iter_++), - &file_info_, &platform_path); - return root_.internal_path().Append(platform_path.BaseName()); + FilePath platform_path = *path_iter_++; + NativeFileUtil::GetFileInfo(platform_path, &file_info_); + return root_.Append(platform_path.BaseName()); } virtual int64 Size() OVERRIDE { return file_info_.size; } virtual bool IsDirectory() OVERRIDE { return file_info_.is_directory; } @@ -55,15 +49,9 @@ class SetFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { virtual bool IsLink() OVERRIDE { return file_info_.is_symbolic_link; } private: - // Not owned; Enumerator is instantiated only within methods of - // FileSystemFileUtil so it must be ok to assume the underlying_file_util - // is alive throughout the lifetime of the enumerator. - FileSystemFileUtil* underlying_file_util_; - - FileSystemOperationContext context_; std::vector<FilePath> paths_; std::vector<FilePath>::const_iterator path_iter_; - FileSystemPath root_; + FilePath root_; base::PlatformFileInfo file_info_; }; @@ -121,20 +109,15 @@ class PathConverterEnumerator class RecursiveSetFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { public: - RecursiveSetFileEnumerator(FileSystemFileUtil* underlying_file_util, - const FileSystemOperationContext& context, - const FilePath& virtual_base_path, + RecursiveSetFileEnumerator(const FilePath& virtual_base_path, const std::vector<FilePath>& paths, - const FileSystemPath& root) - : underlying_file_util_(underlying_file_util), - context_(context), - virtual_base_path_(virtual_base_path), + const FilePath& root) + : virtual_base_path_(virtual_base_path), paths_(paths), root_(root) { - DCHECK(underlying_file_util_); path_iter_ = paths_.begin(); current_enumerator_.reset( - new SetFileEnumerator(underlying_file_util, context, paths, root)); + new SetFileEnumerator(paths, root)); } virtual ~RecursiveSetFileEnumerator() {} @@ -158,15 +141,11 @@ class RecursiveSetFileEnumerator } private: - // Not owned. - FileSystemFileUtil* underlying_file_util_; - - FileSystemOperationContext context_; FilePath virtual_base_path_; std::vector<FilePath> paths_; std::vector<FilePath>::iterator path_iter_; base::PlatformFileInfo file_info_; - FileSystemPath root_; + FilePath root_; scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> current_enumerator_; }; @@ -185,9 +164,8 @@ FilePath RecursiveSetFileEnumerator::Next() { FilePath next_path = *path_iter_++; current_enumerator_.reset( new PathConverterEnumerator( - underlying_file_util_->CreateFileEnumerator( - &context_, root_.WithInternalPath(next_path), - true /* recursive */), + NativeFileUtil::CreateFileEnumerator( + next_path, true /* recursive */), virtual_base_path_, next_path)); DCHECK(current_enumerator_.get()); return current_enumerator_->Next(); @@ -195,9 +173,7 @@ FilePath RecursiveSetFileEnumerator::Next() { } // namespace -IsolatedFileUtil::IsolatedFileUtil(FileSystemFileUtil* underlying_file_util) - : FileSystemFileUtil(underlying_file_util) { - DCHECK(underlying_file_util); +IsolatedFileUtil::IsolatedFileUtil() { } PlatformFileError IsolatedFileUtil::CreateOrOpen( @@ -251,8 +227,11 @@ PlatformFileError IsolatedFileUtil::GetFileInfo( file_info->size = 0; return base::PLATFORM_FILE_OK; } - return underlying_file_util()->GetFileInfo( - context, path.WithInternalPath(cracked_path), file_info, platform_path); + base::PlatformFileError error = + NativeFileUtil::GetFileInfo(cracked_path, file_info); + if (error == base::PLATFORM_FILE_OK) + *platform_path = cracked_path; + return error; } FileSystemFileUtil::AbstractFileEnumerator* @@ -272,8 +251,7 @@ IsolatedFileUtil::CreateFileEnumerator( if (!cracked_path.empty()) { return new PathConverterEnumerator( - underlying_file_util()->CreateFileEnumerator( - context, root.WithInternalPath(cracked_path), recursive), + NativeFileUtil::CreateFileEnumerator(cracked_path, recursive), virtual_base_path, root_path); } @@ -281,10 +259,18 @@ IsolatedFileUtil::CreateFileEnumerator( std::vector<FilePath> toplevels; IsolatedContext::GetInstance()->GetTopLevelPaths(filesystem_id, &toplevels); if (!recursive) - return new SetFileEnumerator(underlying_file_util(), *context, - toplevels, root); - return new RecursiveSetFileEnumerator(underlying_file_util(), *context, - virtual_base_path, toplevels, root); + return new SetFileEnumerator(toplevels, root.internal_path()); + return new RecursiveSetFileEnumerator( + virtual_base_path, toplevels, root.internal_path()); +} + +PlatformFileError IsolatedFileUtil::GetLocalFilePath( + FileSystemOperationContext* context, + const FileSystemPath& file_system_path, + FilePath* local_file_path) { + if (GetPlatformPath(file_system_path, local_file_path)) + return base::PLATFORM_FILE_OK; + return base::PLATFORM_FILE_ERROR_SECURITY; } PlatformFileError IsolatedFileUtil::Touch( @@ -312,8 +298,7 @@ bool IsolatedFileUtil::PathExists( // The root directory case. return true; } - return underlying_file_util()->PathExists( - context, path.WithInternalPath(platform_path)); + return NativeFileUtil::PathExists(platform_path); } bool IsolatedFileUtil::DirectoryExists( @@ -326,8 +311,7 @@ bool IsolatedFileUtil::DirectoryExists( // The root directory case. return true; } - return underlying_file_util()->DirectoryExists( - context, path.WithInternalPath(platform_path)); + return NativeFileUtil::DirectoryExists(platform_path); } bool IsolatedFileUtil::IsDirectoryEmpty( @@ -345,8 +329,7 @@ bool IsolatedFileUtil::IsDirectoryEmpty( DCHECK(success); return toplevels.empty(); } - return underlying_file_util()->IsDirectoryEmpty( - context, path.WithInternalPath(platform_path)); + return NativeFileUtil::IsDirectoryEmpty(platform_path); } PlatformFileError IsolatedFileUtil::CopyOrMoveFile( diff --git a/webkit/fileapi/isolated_file_util.h b/webkit/fileapi/isolated_file_util.h index 907398d..f1643c8 100644 --- a/webkit/fileapi/isolated_file_util.h +++ b/webkit/fileapi/isolated_file_util.h @@ -21,7 +21,7 @@ class IsolatedContext; class IsolatedFileUtil : public FileSystemFileUtil { public: - explicit IsolatedFileUtil(FileSystemFileUtil* underlying_file_util); + IsolatedFileUtil(); virtual ~IsolatedFileUtil() {} // FileSystemFileUtil overrides. @@ -33,7 +33,7 @@ class IsolatedFileUtil : public FileSystemFileUtil { bool* created) OVERRIDE; virtual base::PlatformFileError Close( FileSystemOperationContext* context, - base::PlatformFile) OVERRIDE; + base::PlatformFile file) OVERRIDE; virtual base::PlatformFileError EnsureFileExists( FileSystemOperationContext* context, const FileSystemPath& path, bool* created) OVERRIDE; @@ -51,6 +51,10 @@ class IsolatedFileUtil : public FileSystemFileUtil { FileSystemOperationContext* context, const FileSystemPath& root_path, bool recursive) OVERRIDE; + virtual PlatformFileError GetLocalFilePath( + FileSystemOperationContext* context, + const FileSystemPath& file_system_path, + FilePath* local_file_path) OVERRIDE; virtual base::PlatformFileError Touch( FileSystemOperationContext* context, const FileSystemPath& path, diff --git a/webkit/fileapi/isolated_file_util_unittest.cc b/webkit/fileapi/isolated_file_util_unittest.cc index f115799..55925c4 100644 --- a/webkit/fileapi/isolated_file_util_unittest.cc +++ b/webkit/fileapi/isolated_file_util_unittest.cc @@ -54,7 +54,7 @@ class IsolatedFileUtilTest : public testing::Test { void SetUp() { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); - file_util_.reset(new IsolatedFileUtil(new NativeFileUtil())); + file_util_.reset(new IsolatedFileUtil()); // Register the files/directories of RegularTestCases (with random // root paths) as dropped files. @@ -69,7 +69,7 @@ class IsolatedFileUtilTest : public testing::Test { CreateAllowFileAccessOptions()); // For cross-FileUtil copy/move tests. - other_file_util_.reset(new LocalFileUtil(new NativeFileUtil())); + other_file_util_.reset(new LocalFileUtil()); other_file_util_helper_.SetUp(file_system_context_, other_file_util_.get()); } @@ -335,6 +335,20 @@ TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { } } +TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; + FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + + FileSystemOperationContext context(file_system_context()); + + FilePath local_file_path; + EXPECT_EQ(base::PLATFORM_FILE_OK, + file_util()->GetLocalFilePath(&context, path, &local_file_path)); + EXPECT_EQ(GetTestCasePlatformPath(test_case.path), local_file_path); + } +} + TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { scoped_ptr<FileSystemOperationContext> context( new FileSystemOperationContext(file_system_context())); diff --git a/webkit/fileapi/isolated_mount_point_provider.cc b/webkit/fileapi/isolated_mount_point_provider.cc index f32f28a..8dfbcc5 100644 --- a/webkit/fileapi/isolated_mount_point_provider.cc +++ b/webkit/fileapi/isolated_mount_point_provider.cc @@ -27,7 +27,7 @@ namespace fileapi { IsolatedMountPointProvider::IsolatedMountPointProvider() - : isolated_file_util_(new IsolatedFileUtil(new NativeFileUtil())) { + : isolated_file_util_(new IsolatedFileUtil()) { } IsolatedMountPointProvider::~IsolatedMountPointProvider() { diff --git a/webkit/fileapi/local_file_util.cc b/webkit/fileapi/local_file_util.cc index 19c48e6..27d9b1e 100644 --- a/webkit/fileapi/local_file_util.cc +++ b/webkit/fileapi/local_file_util.cc @@ -12,6 +12,7 @@ #include "webkit/fileapi/file_system_path.h" #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/file_system_util.h" +#include "webkit/fileapi/native_file_util.h" namespace fileapi { @@ -71,8 +72,7 @@ bool LocalFileEnumerator::IsLink() { return file_util::FileEnumerator::IsLink(file_util_info_); } -LocalFileUtil::LocalFileUtil(FileSystemFileUtil* underlying_file_util) - : FileSystemFileUtil(underlying_file_util) { +LocalFileUtil::LocalFileUtil() { } LocalFileUtil::~LocalFileUtil() { @@ -82,22 +82,28 @@ PlatformFileError LocalFileUtil::CreateOrOpen( FileSystemOperationContext* context, const FileSystemPath& path, int file_flags, PlatformFile* file_handle, bool* created) { - 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::CreateOrOpen( + file_path, file_flags, file_handle, created); +} + +PlatformFileError LocalFileUtil::Close(FileSystemOperationContext* context, + PlatformFile file) { + return NativeFileUtil::Close(file); } PlatformFileError LocalFileUtil::EnsureFileExists( FileSystemOperationContext* context, const FileSystemPath& path, bool* created) { - 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::EnsureFileExists(file_path, created); } PlatformFileError LocalFileUtil::CreateDirectory( @@ -105,11 +111,11 @@ PlatformFileError LocalFileUtil::CreateDirectory( const FileSystemPath& path, bool exclusive, bool recursive) { - 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::CreateDirectory(file_path, exclusive, recursive); } PlatformFileError LocalFileUtil::GetFileInfo( @@ -117,22 +123,26 @@ PlatformFileError LocalFileUtil::GetFileInfo( const FileSystemPath& path, base::PlatformFileInfo* file_info, FilePath* platform_file_path) { - 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + error = NativeFileUtil::GetFileInfo(file_path, file_info); + if (error == base::PLATFORM_FILE_OK) + *platform_file_path = file_path; + return error; } FileSystemFileUtil::AbstractFileEnumerator* LocalFileUtil::CreateFileEnumerator( FileSystemOperationContext* context, const FileSystemPath& root_path, bool recursive) { - FileSystemPath local_path = GetLocalPath(context, root_path); - if (local_path.internal_path().empty()) + FilePath file_path; + if (GetLocalFilePath(context, root_path, &file_path) != + base::PLATFORM_FILE_OK) return new EmptyFileEnumerator(); return new LocalFileEnumerator( - local_path.internal_path(), root_path.internal_path(), recursive, + file_path, root_path.internal_path(), recursive, static_cast<file_util::FileEnumerator::FileType>( file_util::FileEnumerator::FILES | file_util::FileEnumerator::DIRECTORIES)); @@ -140,13 +150,17 @@ FileSystemFileUtil::AbstractFileEnumerator* LocalFileUtil::CreateFileEnumerator( PlatformFileError LocalFileUtil::GetLocalFilePath( FileSystemOperationContext* context, - const FileSystemPath& file_system_path, + const FileSystemPath& 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_file_path = local_path.internal_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 base::PLATFORM_FILE_ERROR_NOT_FOUND; + *local_file_path = root.Append(path.internal_path()); return base::PLATFORM_FILE_OK; } @@ -155,52 +169,49 @@ PlatformFileError LocalFileUtil::Touch( const FileSystemPath& path, const base::Time& last_access_time, const base::Time& last_modified_time) { - 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::Touch(file_path, last_access_time, last_modified_time); } PlatformFileError LocalFileUtil::Truncate( FileSystemOperationContext* context, const FileSystemPath& path, int64 length) { - 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::Truncate(file_path, length); } bool LocalFileUtil::PathExists( FileSystemOperationContext* context, const FileSystemPath& path) { - FileSystemPath local_path = GetLocalPath(context, path); - if (local_path.internal_path().empty()) + FilePath file_path; + if (GetLocalFilePath(context, path, &file_path) != base::PLATFORM_FILE_OK) return false; - return underlying_file_util()->PathExists( - context, local_path); + return NativeFileUtil::PathExists(file_path); } bool LocalFileUtil::DirectoryExists( FileSystemOperationContext* context, const FileSystemPath& path) { - FileSystemPath local_path = GetLocalPath(context, path); - if (local_path.internal_path().empty()) + FilePath file_path; + if (GetLocalFilePath(context, path, &file_path) != base::PLATFORM_FILE_OK) return false; - return underlying_file_util()->DirectoryExists( - context, local_path); + return NativeFileUtil::DirectoryExists(file_path); } bool LocalFileUtil::IsDirectoryEmpty( FileSystemOperationContext* context, const FileSystemPath& path) { - FileSystemPath local_path = GetLocalPath(context, path); - if (local_path.internal_path().empty()) + FilePath file_path; + if (GetLocalFilePath(context, path, &file_path) != base::PLATFORM_FILE_OK) return true; - return underlying_file_util()->IsDirectoryEmpty( - context, local_path); + return NativeFileUtil::IsDirectoryEmpty(file_path); } PlatformFileError LocalFileUtil::CopyOrMoveFile( @@ -208,15 +219,17 @@ PlatformFileError LocalFileUtil::CopyOrMoveFile( const FileSystemPath& src_path, const FileSystemPath& dest_path, bool copy) { - // TODO(ericu): If they share a root URL, this could be optimized. - FileSystemPath local_src_path = GetLocalPath(context, src_path); - if (local_src_path.internal_path().empty()) - return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; - 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); + FilePath src_file_path; + PlatformFileError error = GetLocalFilePath(context, src_path, &src_file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + + FilePath dest_file_path; + error = GetLocalFilePath(context, dest_path, &dest_file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + + return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); } // TODO(dmikurube): Make it independent from CopyOrMoveFile. @@ -226,44 +239,33 @@ PlatformFileError LocalFileUtil::CopyInForeignFile( const FileSystemPath& dest_path) { if (src_file_path.empty()) return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; - 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()->CopyInForeignFile( - context, src_file_path, local_dest_path); + + FilePath dest_file_path; + PlatformFileError error = + GetLocalFilePath(context, dest_path, &dest_file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true); } PlatformFileError LocalFileUtil::DeleteFile( FileSystemOperationContext* context, 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); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::DeleteFile(file_path); } PlatformFileError LocalFileUtil::DeleteSingleDirectory( FileSystemOperationContext* context, 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); -} - -FileSystemPath LocalFileUtil::GetLocalPath( - FileSystemOperationContext* context, - 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 FileSystemPath(); - return path.WithInternalPath(root.Append(path.internal_path())); + FilePath file_path; + PlatformFileError error = GetLocalFilePath(context, path, &file_path); + if (error != base::PLATFORM_FILE_OK) + return error; + return NativeFileUtil::DeleteSingleDirectory(file_path); } } // namespace fileapi diff --git a/webkit/fileapi/local_file_util.h b/webkit/fileapi/local_file_util.h index 89ce879..bcb1932 100644 --- a/webkit/fileapi/local_file_util.h +++ b/webkit/fileapi/local_file_util.h @@ -38,7 +38,7 @@ class LocalFileUtil : public FileSystemFileUtil { // |underlying_file_util| is owned by the instance. It will be deleted by // the owner instance. For example, it can be instanciated as follows: // FileSystemFileUtil* file_util = new LocalFileUtil(new NativeFileUtil()); - explicit LocalFileUtil(FileSystemFileUtil* underlying_file_util); + LocalFileUtil(); virtual ~LocalFileUtil(); virtual PlatformFileError CreateOrOpen( @@ -47,6 +47,9 @@ class LocalFileUtil : public FileSystemFileUtil { int file_flags, PlatformFile* file_handle, bool* created) OVERRIDE; + virtual PlatformFileError Close( + FileSystemOperationContext* context, + PlatformFile file) OVERRIDE; virtual PlatformFileError EnsureFileExists( FileSystemOperationContext* context, const FileSystemPath& path, bool* created) OVERRIDE; diff --git a/webkit/fileapi/local_file_util_unittest.cc b/webkit/fileapi/local_file_util_unittest.cc index 2f3493c5..ed13ff9 100644 --- a/webkit/fileapi/local_file_util_unittest.cc +++ b/webkit/fileapi/local_file_util_unittest.cc @@ -25,7 +25,7 @@ namespace fileapi { class LocalFileUtilTest : public testing::Test { public: LocalFileUtilTest() - : local_file_util_(new LocalFileUtil(new NativeFileUtil())) { + : local_file_util_(new LocalFileUtil()) { } void SetUp() { diff --git a/webkit/fileapi/native_file_util.cc b/webkit/fileapi/native_file_util.cc index 26da7a1..ac962cf 100644 --- a/webkit/fileapi/native_file_util.cc +++ b/webkit/fileapi/native_file_util.cc @@ -83,39 +83,35 @@ bool NativeFileEnumerator::IsLink() { } PlatformFileError NativeFileUtil::CreateOrOpen( - FileSystemOperationContext* unused, - const FileSystemPath& path, int file_flags, + const FilePath& path, int file_flags, PlatformFile* file_handle, bool* created) { - if (!file_util::DirectoryExists(path.internal_path().DirName())) { + if (!file_util::DirectoryExists(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(path.internal_path(), file_flags, + *file_handle = base::CreatePlatformFile(path, file_flags, created, &error_code); return error_code; } -PlatformFileError NativeFileUtil::Close( - FileSystemOperationContext* unused, - PlatformFile file_handle) { +PlatformFileError NativeFileUtil::Close(PlatformFile file_handle) { if (!base::ClosePlatformFile(file_handle)) return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_OK; } PlatformFileError NativeFileUtil::EnsureFileExists( - FileSystemOperationContext* unused, - const FileSystemPath& path, + const FilePath& path, bool* created) { - if (!file_util::DirectoryExists(path.internal_path().DirName())) + if (!file_util::DirectoryExists(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 |path| exclusively. This should fail // with base::PLATFORM_FILE_ERROR_EXISTS if the path already exists. PlatformFile handle = base::CreatePlatformFile( - path.internal_path(), + path, base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, created, &error_code); if (error_code == base::PLATFORM_FILE_ERROR_EXISTS) { @@ -130,88 +126,70 @@ PlatformFileError NativeFileUtil::EnsureFileExists( } PlatformFileError NativeFileUtil::CreateDirectory( - FileSystemOperationContext* context, - const FileSystemPath& path, + const FilePath& path, bool exclusive, bool recursive) { // If parent dir of file doesn't exist. - if (!recursive && !file_util::PathExists(path.internal_path().DirName())) + if (!recursive && !file_util::PathExists(path.DirName())) return base::PLATFORM_FILE_ERROR_NOT_FOUND; - bool path_exists = file_util::PathExists(path.internal_path()); + bool path_exists = file_util::PathExists(path); if (exclusive && path_exists) return base::PLATFORM_FILE_ERROR_EXISTS; // If file exists at the path. - if (path_exists && !file_util::DirectoryExists(path.internal_path())) + if (path_exists && !file_util::DirectoryExists(path)) return base::PLATFORM_FILE_ERROR_EXISTS; - if (!file_util::CreateDirectory(path.internal_path())) + if (!file_util::CreateDirectory(path)) return base::PLATFORM_FILE_ERROR_FAILED; - if (!SetPlatformSpecificDirectoryPermissions(path.internal_path())) + if (!SetPlatformSpecificDirectoryPermissions(path)) return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_OK; } PlatformFileError NativeFileUtil::GetFileInfo( - FileSystemOperationContext* unused, - const FileSystemPath& path, - base::PlatformFileInfo* file_info, - FilePath* platform_file_path) { - if (!file_util::PathExists(path.internal_path())) + const FilePath& path, + base::PlatformFileInfo* file_info) { + if (!file_util::PathExists(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(path.internal_path())) + if (file_util::IsLink(path)) return base::PLATFORM_FILE_ERROR_NOT_FOUND; - if (!file_util::GetFileInfo(path.internal_path(), file_info)) + if (!file_util::GetFileInfo(path, file_info)) return base::PLATFORM_FILE_ERROR_FAILED; - *platform_file_path = path.internal_path(); return base::PLATFORM_FILE_OK; } FileSystemFileUtil::AbstractFileEnumerator* -NativeFileUtil::CreateFileEnumerator( - FileSystemOperationContext* unused, - const FileSystemPath& root_path, - bool recursive) { +NativeFileUtil::CreateFileEnumerator(const FilePath& root_path, + bool recursive) { return new NativeFileEnumerator( - root_path.internal_path(), recursive, + root_path, recursive, static_cast<file_util::FileEnumerator::FileType>( file_util::FileEnumerator::FILES | file_util::FileEnumerator::DIRECTORIES)); } -PlatformFileError NativeFileUtil::GetLocalFilePath( - FileSystemOperationContext* unused, - 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 FileSystemPath& path, + const FilePath& path, const base::Time& last_access_time, const base::Time& last_modified_time) { if (!file_util::TouchFile( - path.internal_path(), last_access_time, last_modified_time)) + path, last_access_time, last_modified_time)) return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_OK; } -PlatformFileError NativeFileUtil::Truncate( - FileSystemOperationContext* unused, - const FileSystemPath& path, - int64 length) { +PlatformFileError NativeFileUtil::Truncate(const FilePath& path, int64 length) { PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); PlatformFile file = base::CreatePlatformFile( - path.internal_path(), + path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, NULL, &error_code); @@ -225,76 +203,56 @@ PlatformFileError NativeFileUtil::Truncate( return error_code; } -bool NativeFileUtil::PathExists( - FileSystemOperationContext* unused, - const FileSystemPath& path) { - return file_util::PathExists(path.internal_path()); +bool NativeFileUtil::PathExists(const FilePath& path) { + return file_util::PathExists(path); } -bool NativeFileUtil::DirectoryExists( - FileSystemOperationContext* unused, - const FileSystemPath& path) { - return file_util::DirectoryExists(path.internal_path()); +bool NativeFileUtil::DirectoryExists(const FilePath& path) { + return file_util::DirectoryExists(path); } -bool NativeFileUtil::IsDirectoryEmpty( - FileSystemOperationContext* unused, - const FileSystemPath& path) { - return file_util::IsDirectoryEmpty(path.internal_path()); +bool NativeFileUtil::IsDirectoryEmpty(const FilePath& path) { + return file_util::IsDirectoryEmpty(path); } PlatformFileError NativeFileUtil::CopyOrMoveFile( - FileSystemOperationContext* unused, - const FileSystemPath& src_path, - const FileSystemPath& dest_path, + const FilePath& src_path, + const FilePath& dest_path, bool copy) { if (copy) { - if (file_util::CopyFile(src_path.internal_path(), - dest_path.internal_path())) + if (file_util::CopyFile(src_path, + dest_path)) return base::PLATFORM_FILE_OK; } else { - DCHECK(!file_util::DirectoryExists(src_path.internal_path())); - if (file_util::Move(src_path.internal_path(), dest_path.internal_path())) + DCHECK(!file_util::DirectoryExists(src_path)); + if (file_util::Move(src_path, dest_path)) return base::PLATFORM_FILE_OK; } return base::PLATFORM_FILE_ERROR_FAILED; } -PlatformFileError NativeFileUtil::CopyInForeignFile( - FileSystemOperationContext* context, - const FilePath& src_file_path, - const FileSystemPath& dest_path) { - if (file_util::CopyFile(src_file_path, dest_path.internal_path())) - return base::PLATFORM_FILE_OK; - return base::PLATFORM_FILE_ERROR_FAILED; -} - -PlatformFileError NativeFileUtil::DeleteFile( - FileSystemOperationContext* unused, - const FileSystemPath& path) { - if (!file_util::PathExists(path.internal_path())) +PlatformFileError NativeFileUtil::DeleteFile(const FilePath& path) { + if (!file_util::PathExists(path)) return base::PLATFORM_FILE_ERROR_NOT_FOUND; - if (file_util::DirectoryExists(path.internal_path())) + if (file_util::DirectoryExists(path)) return base::PLATFORM_FILE_ERROR_NOT_A_FILE; - if (!file_util::Delete(path.internal_path(), false)) + if (!file_util::Delete(path, false)) return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_OK; } -PlatformFileError NativeFileUtil::DeleteSingleDirectory( - FileSystemOperationContext* unused, - const FileSystemPath& path) { - if (!file_util::PathExists(path.internal_path())) +PlatformFileError NativeFileUtil::DeleteSingleDirectory(const FilePath& path) { + if (!file_util::PathExists(path)) return base::PLATFORM_FILE_ERROR_NOT_FOUND; - if (!file_util::DirectoryExists(path.internal_path())) { + if (!file_util::DirectoryExists(path)) { // TODO(dmikurube): Check if this error code is appropriate. return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; } - if (!file_util::IsDirectoryEmpty(path.internal_path())) { + if (!file_util::IsDirectoryEmpty(path)) { // TODO(dmikurube): Check if this error code is appropriate. return base::PLATFORM_FILE_ERROR_NOT_EMPTY; } - if (!file_util::Delete(path.internal_path(), false)) + if (!file_util::Delete(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 da3a4cc..ea141734 100644 --- a/webkit/fileapi/native_file_util.h +++ b/webkit/fileapi/native_file_util.h @@ -18,81 +18,42 @@ namespace fileapi { using base::PlatformFile; using base::PlatformFileError; -class FileSystemOperationContext; // TODO(dmikurube): Add unit tests for NativeFileUtil. // This class handles accessing the OS native filesystem. -class NativeFileUtil : public FileSystemFileUtil { +class NativeFileUtil { public: - NativeFileUtil() {} - virtual ~NativeFileUtil() {} - - virtual PlatformFileError CreateOrOpen( - FileSystemOperationContext* unused, - const FileSystemPath& path, + static PlatformFileError CreateOrOpen( + const FilePath& path, int file_flags, PlatformFile* file_handle, - bool* created) OVERRIDE; - virtual PlatformFileError Close( - FileSystemOperationContext* unused, - PlatformFile) OVERRIDE; - virtual PlatformFileError EnsureFileExists( - FileSystemOperationContext* unused, - const FileSystemPath& path, bool* created) OVERRIDE; - virtual PlatformFileError CreateDirectory( - FileSystemOperationContext* context, - const FileSystemPath& path, - bool exclusive, - bool recursive) OVERRIDE; - virtual PlatformFileError GetFileInfo( - FileSystemOperationContext* unused, - const FileSystemPath& path, - base::PlatformFileInfo* file_info, - FilePath* platform_file_path) OVERRIDE; - virtual AbstractFileEnumerator* CreateFileEnumerator( - FileSystemOperationContext* unused, - const FileSystemPath& root_path, - bool recursive) OVERRIDE; - virtual PlatformFileError GetLocalFilePath( - FileSystemOperationContext* unused, - const FileSystemPath& file_system_path, - FilePath* local_file_path) OVERRIDE; - virtual PlatformFileError Touch( - FileSystemOperationContext* unused, - const FileSystemPath& path, - const base::Time& last_access_time, - const base::Time& last_modified_time) OVERRIDE; - virtual PlatformFileError Truncate( - FileSystemOperationContext* unused, - const FileSystemPath& path, - int64 length) OVERRIDE; - virtual bool PathExists( - FileSystemOperationContext* unused, - const FileSystemPath& path) OVERRIDE; - virtual bool DirectoryExists( - FileSystemOperationContext* unused, - const FileSystemPath& path) OVERRIDE; - virtual bool IsDirectoryEmpty( - FileSystemOperationContext* unused, - const FileSystemPath& path) OVERRIDE; - virtual PlatformFileError CopyOrMoveFile( - FileSystemOperationContext* unused, - const FileSystemPath& src_path, - const FileSystemPath& dest_path, - bool copy) OVERRIDE; - virtual PlatformFileError CopyInForeignFile( - FileSystemOperationContext* unused, - const FilePath& src_file_path, - const FileSystemPath& dest_path) OVERRIDE; - virtual PlatformFileError DeleteFile( - FileSystemOperationContext* unused, - const FileSystemPath& path) OVERRIDE; - virtual PlatformFileError DeleteSingleDirectory( - FileSystemOperationContext* unused, - const FileSystemPath& path) OVERRIDE; + bool* created); + static PlatformFileError Close(PlatformFile file); + static PlatformFileError EnsureFileExists(const FilePath& path, + bool* created); + static PlatformFileError CreateDirectory(const FilePath& path, + bool exclusive, + bool recursive); + static PlatformFileError GetFileInfo(const FilePath& path, + base::PlatformFileInfo* file_info); + static FileSystemFileUtil::AbstractFileEnumerator* CreateFileEnumerator( + const FilePath& root_path, + bool recursive); + static PlatformFileError Touch(const FilePath& path, + const base::Time& last_access_time, + const base::Time& last_modified_time); + static PlatformFileError Truncate(const FilePath& path, int64 length); + static bool PathExists(const FilePath& path); + static bool DirectoryExists(const FilePath& path); + static bool IsDirectoryEmpty(const FilePath& path); + static PlatformFileError CopyOrMoveFile(const FilePath& src_path, + const FilePath& dest_path, + bool copy); + static PlatformFileError DeleteFile(const FilePath& path); + static PlatformFileError DeleteSingleDirectory(const FilePath& path); private: - DISALLOW_COPY_AND_ASSIGN(NativeFileUtil); + DISALLOW_IMPLICIT_CONSTRUCTORS(NativeFileUtil); }; } // namespace fileapi diff --git a/webkit/fileapi/obfuscated_file_util.cc b/webkit/fileapi/obfuscated_file_util.cc index 0ab54c6..d440a18 100644 --- a/webkit/fileapi/obfuscated_file_util.cc +++ b/webkit/fileapi/obfuscated_file_util.cc @@ -23,22 +23,17 @@ #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/native_file_util.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" #include "webkit/quota/quota_manager.h" // Example of various paths: // void ObfuscatedFileUtil::DoSomething(const FileSystemPath& path) { // FilePath virtual_path = path.internal_path(); -// FileSystemPath underlying_path = GetUnderlyingPath(path); -// FilePath local_file_path = GetLocalFilePath(path); +// FilePath local_path = GetLocalFilePath(path); // -// // |data_path| is native file path that is relative to the directory for -// // the origin and type. We store |data_path| in DirectoryDatabase. -// FilePath::StringType data_path = -// UnderlyingPathToDataPath(underlying_path); -// -// underlying_file_util()->DoSomething(underlying_path); -// file_util::DoAnother(local_file_path); +// NativeFileUtil::DoSomething(local_path); +// file_util::DoAnother(local_path); // } namespace fileapi { @@ -268,10 +263,8 @@ class ObfuscatedOriginEnumerator }; ObfuscatedFileUtil::ObfuscatedFileUtil( - const FilePath& file_system_directory, - FileSystemFileUtil* underlying_file_util) - : FileSystemFileUtil(underlying_file_util), - file_system_directory_(file_system_directory) { + const FilePath& file_system_directory) + : file_system_directory_(file_system_directory) { } ObfuscatedFileUtil::~ObfuscatedFileUtil() { @@ -320,35 +313,27 @@ PlatformFileError ObfuscatedFileUtil::CreateOrOpen( if (file_flags & base::PLATFORM_FILE_CREATE) return base::PLATFORM_FILE_ERROR_EXISTS; + base::PlatformFileInfo platform_file_info; + FilePath local_path; FileInfo file_info; + base::PlatformFileError error = GetFileInfoInternal( + db, context, path.origin(), path.type(), file_id, + &file_info, &platform_file_info, &local_path); + if (error != base::PLATFORM_FILE_OK) + return error; + if (file_info.is_directory()) + return base::PLATFORM_FILE_ERROR_NOT_A_FILE; + int64 delta = 0; if (file_flags & (base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED)) { // The file exists and we're truncating. - base::PlatformFileInfo platform_file_info; - FilePath local_file_path; - base::PlatformFileError error = GetFileInfoInternal( - db, context, path.origin(), path.type(), file_id, - &file_info, &platform_file_info, &local_file_path); - if (error != base::PLATFORM_FILE_OK) - return error; - if (file_info.is_directory()) - return base::PLATFORM_FILE_ERROR_NOT_A_FILE; delta = -platform_file_info.size; AllocateQuota(context, delta); - } else { - if (!db->GetFileInfo(file_id, &file_info)) { - NOTREACHED(); - return base::PLATFORM_FILE_ERROR_FAILED; - } - if (file_info.is_directory()) - return base::PLATFORM_FILE_ERROR_NOT_A_FILE; } - FileSystemPath underlying_path = DataPathToUnderlyingPath( - path.origin(), path.type(), file_info.data_path); - base::PlatformFileError error = underlying_file_util()->CreateOrOpen( - context, underlying_path, file_flags, file_handle, created); + error = NativeFileUtil::CreateOrOpen( + 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. @@ -363,6 +348,12 @@ PlatformFileError ObfuscatedFileUtil::CreateOrOpen( return error; } +PlatformFileError ObfuscatedFileUtil::Close( + FileSystemOperationContext* context, + base::PlatformFile file) { + return NativeFileUtil::Close(file); +} + PlatformFileError ObfuscatedFileUtil::EnsureFileExists( FileSystemOperationContext* context, const FileSystemPath& path, @@ -501,12 +492,25 @@ ObfuscatedFileUtil::CreateFileEnumerator( PlatformFileError ObfuscatedFileUtil::GetLocalFilePath( FileSystemOperationContext* context, const FileSystemPath& path, - FilePath* local_file_path) { - FileSystemPath underlying_path = GetUnderlyingPath(path); - if (underlying_path.internal_path().empty()) + FilePath* local_path) { + FileSystemDirectoryDatabase* db = GetDirectoryDatabase( + path.origin(), path.type(), false); + if (!db) + return base::PLATFORM_FILE_ERROR_NOT_FOUND; + FileId file_id; + if (!db->GetFileWithPath(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()) { + NOTREACHED(); + // Directories have no local file path. return base::PLATFORM_FILE_ERROR_NOT_FOUND; + } + *local_path = DataPathToLocalPath( + path.origin(), path.type(), file_info.data_path); - *local_file_path = underlying_path.internal_path(); + if (local_path->empty()) + return base::PLATFORM_FILE_ERROR_NOT_FOUND; return base::PLATFORM_FILE_OK; } @@ -533,11 +537,10 @@ PlatformFileError ObfuscatedFileUtil::Touch( return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_OK; } - FileSystemPath underlying_path = DataPathToUnderlyingPath( + FilePath local_path = DataPathToLocalPath( path.origin(), path.type(), file_info.data_path); - return underlying_file_util()->Touch( - context, underlying_path, - last_access_time, last_modified_time); + return NativeFileUtil::Touch( + local_path, last_access_time, last_modified_time); } PlatformFileError ObfuscatedFileUtil::Truncate( @@ -554,8 +557,7 @@ PlatformFileError ObfuscatedFileUtil::Truncate( int64 growth = length - file_info.size; if (!AllocateQuota(context, growth)) return base::PLATFORM_FILE_ERROR_NO_SPACE; - error = underlying_file_util()->Truncate( - context, path.WithInternalPath(local_path), length); + error = NativeFileUtil::Truncate(local_path, length); if (error == base::PLATFORM_FILE_OK) UpdateUsage(context, path.origin(), path.type(), growth); return error; @@ -649,10 +651,10 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( FileInfo src_file_info; base::PlatformFileInfo src_platform_file_info; - FilePath src_local_file_path; + FilePath src_local_path; base::PlatformFileError error = GetFileInfoInternal( db, context, src_path.origin(), src_path.type(), src_file_id, - &src_file_info, &src_platform_file_info, &src_local_file_path); + &src_file_info, &src_platform_file_info, &src_local_path); if (error != base::PLATFORM_FILE_OK) return error; if (src_file_info.is_directory()) @@ -660,20 +662,17 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( FileInfo dest_file_info; base::PlatformFileInfo dest_platform_file_info; // overwrite case only - FileSystemPath dest_underlying_path; + FilePath dest_local_path; // overwrite case only if (overwrite) { - FilePath dest_local_file_path; base::PlatformFileError error = GetFileInfoInternal( db, context, dest_path.origin(), dest_path.type(), dest_file_id, - &dest_file_info, &dest_platform_file_info, &dest_local_file_path); + &dest_file_info, &dest_platform_file_info, &dest_local_path); if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) overwrite = false; // fallback to non-overwrite case else if (error != base::PLATFORM_FILE_OK) return error; else if (dest_file_info.is_directory()) return base::PLATFORM_FILE_ERROR_FAILED; - else - dest_underlying_path = dest_path.WithInternalPath(dest_local_file_path); } if (!overwrite) { FileId dest_parent_id; @@ -718,13 +717,12 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( error = base::PLATFORM_FILE_ERROR_FAILED; if (copy) { if (overwrite) { - error = underlying_file_util()->CopyOrMoveFile( - context, - src_path.WithInternalPath(src_local_file_path), - dest_underlying_path, + error = NativeFileUtil::CopyOrMoveFile( + src_local_path, + dest_local_path, true /* copy */); } else { // non-overwrite - error = CreateFile(context, src_local_file_path, + error = CreateFile(context, src_local_path, dest_path.origin(), dest_path.type(), &dest_file_info, 0, NULL); } @@ -732,7 +730,7 @@ PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( if (overwrite) { if (db->OverwritingMoveFile(src_file_id, dest_file_id)) { if (base::PLATFORM_FILE_OK != - underlying_file_util()->DeleteFile(context, dest_underlying_path)) + NativeFileUtil::DeleteFile(dest_local_path)) LOG(WARNING) << "Leaked a backing file."; error = base::PLATFORM_FILE_OK; } else { @@ -777,10 +775,10 @@ PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( FileInfo dest_file_info; base::PlatformFileInfo dest_platform_file_info; // overwrite case only if (overwrite) { - FilePath dest_local_file_path; + FilePath dest_local_path; base::PlatformFileError error = GetFileInfoInternal( db, context, dest_path.origin(), dest_path.type(), dest_file_id, - &dest_file_info, &dest_platform_file_info, &dest_local_file_path); + &dest_file_info, &dest_platform_file_info, &dest_local_path); if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) overwrite = false; // fallback to non-overwrite case else if (error != base::PLATFORM_FILE_OK) @@ -810,10 +808,10 @@ PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( base::PlatformFileError error; if (overwrite) { - FileSystemPath dest_underlying_path = DataPathToUnderlyingPath( + FilePath dest_local_path = DataPathToLocalPath( dest_path.origin(), dest_path.type(), dest_file_info.data_path); - error = underlying_file_util()->CopyInForeignFile( - context, src_file_path, dest_underlying_path); + error = NativeFileUtil::CopyOrMoveFile( + src_file_path, dest_local_path, true); } else { error = CreateFile(context, src_file_path, dest_path.origin(), dest_path.type(), @@ -841,10 +839,10 @@ PlatformFileError ObfuscatedFileUtil::DeleteFile( FileInfo file_info; base::PlatformFileInfo platform_file_info; - FilePath local_file_path; + FilePath local_path; base::PlatformFileError error = GetFileInfoInternal( db, context, path.origin(), path.type(), file_id, - &file_info, &platform_file_info, &local_file_path); + &file_info, &platform_file_info, &local_path); if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && error != base::PLATFORM_FILE_OK) return error; @@ -866,8 +864,7 @@ PlatformFileError ObfuscatedFileUtil::DeleteFile( if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) return base::PLATFORM_FILE_OK; - error = underlying_file_util()->DeleteFile( - context, path.WithInternalPath(local_file_path)); + error = NativeFileUtil::DeleteFile(local_path); if (base::PLATFORM_FILE_OK != error) LOG(WARNING) << "Leaked a backing file."; return base::PLATFORM_FILE_OK; @@ -1113,11 +1110,13 @@ PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( } if (local_info->data_path.empty()) return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; - FileSystemPath underlying_path = DataPathToUnderlyingPath( + FilePath local_path = DataPathToLocalPath( origin, type, local_info->data_path); - base::PlatformFileError error = underlying_file_util()->GetFileInfo( - context, underlying_path, file_info, platform_file_path); - if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) { + base::PlatformFileError error = NativeFileUtil::GetFileInfo( + local_path, file_info); + if (error == base::PLATFORM_FILE_OK) { + *platform_file_path = local_path; + } else if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) { LOG(WARNING) << "Lost a backing file."; InvalidateUsageCache(context, origin, type); if (!db->RemoveFileInfo(file_id)) @@ -1137,28 +1136,26 @@ PlatformFileError ObfuscatedFileUtil::CreateFile( FileSystemDirectoryDatabase* db = GetDirectoryDatabase( dest_origin, dest_type, true); - FileSystemPath dest_path; - PlatformFileError error = GenerateNewUnderlyingPath( - db, context, dest_origin, dest_type, &dest_path); + FilePath root = GetDirectoryForOriginAndType(dest_origin, dest_type, false); + if (root.empty()) + return base::PLATFORM_FILE_ERROR_FAILED; + + FilePath dest_local_path; + PlatformFileError error = GenerateNewLocalPath( + db, context, dest_origin, dest_type, &dest_local_path); if (error != base::PLATFORM_FILE_OK) return error; - FilePath data_path = UnderlyingPathToDataPath(dest_path); - if (data_path.empty()) - return base::PLATFORM_FILE_ERROR_FAILED; - bool created = false; if (!src_file_path.empty()) { DCHECK(!file_flags); DCHECK(!handle); - error = underlying_file_util()->CopyInForeignFile( - context, src_file_path, dest_path); + error = NativeFileUtil::CopyOrMoveFile( + src_file_path, dest_local_path, true /* copy */); created = true; } else { - FilePath path; - underlying_file_util()->GetLocalFilePath(context, dest_path, &path); - if (file_util::PathExists(path)) { - if (!file_util::Delete(path, true)) { + if (file_util::PathExists(dest_local_path)) { + if (!file_util::Delete(dest_local_path, true /* recursive */)) { NOTREACHED(); return base::PLATFORM_FILE_ERROR_FAILED; } @@ -1167,13 +1164,12 @@ PlatformFileError ObfuscatedFileUtil::CreateFile( } if (handle) { - error = underlying_file_util()->CreateOrOpen( - context, dest_path, file_flags, handle, &created); + error = NativeFileUtil::CreateOrOpen( + dest_local_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, dest_path, &created); + error = NativeFileUtil::EnsureFileExists(dest_local_path, &created); } } if (error != base::PLATFORM_FILE_OK) @@ -1184,18 +1180,23 @@ PlatformFileError ObfuscatedFileUtil::CreateFile( if (handle) { DCHECK_NE(base::kInvalidPlatformFileValue, *handle); base::ClosePlatformFile(*handle); - underlying_file_util()->DeleteFile(context, dest_path); + file_util::Delete(dest_local_path, false /* recursive */); } return base::PLATFORM_FILE_ERROR_FAILED; } - dest_file_info->data_path = data_path; + + // This removes the root, including the trailing slash, leaving a relative + // path. + dest_file_info->data_path = FilePath( + dest_local_path.value().substr(root.value().length() + 1)); + FileId 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, dest_path); + file_util::Delete(dest_local_path, false /* recursive */); return base::PLATFORM_FILE_ERROR_FAILED; } TouchDirectory(db, dest_file_info->parent_id); @@ -1203,43 +1204,12 @@ PlatformFileError ObfuscatedFileUtil::CreateFile( return base::PLATFORM_FILE_OK; } -FileSystemPath ObfuscatedFileUtil::GetUnderlyingPath( - const FileSystemPath& path) { - FileSystemDirectoryDatabase* db = GetDirectoryDatabase( - path.origin(), path.type(), false); - if (!db) - return FileSystemPath(); - FileId file_id; - if (!db->GetFileWithPath(path.internal_path(), &file_id)) - return FileSystemPath(); - FileInfo file_info; - if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { - NOTREACHED(); - return FileSystemPath(); // Directories have no underlying path. - } - return DataPathToUnderlyingPath(path.origin(), - path.type(), - file_info.data_path); -} - -FileSystemPath ObfuscatedFileUtil::DataPathToUnderlyingPath( +FilePath ObfuscatedFileUtil::DataPathToLocalPath( const GURL& origin, FileSystemType type, const FilePath& data_path) { FilePath root = GetDirectoryForOriginAndType(origin, type, false); if (root.empty()) - return FileSystemPath(origin, type, root); - return FileSystemPath(origin, type, root.Append(data_path)); -} - -FilePath ObfuscatedFileUtil::UnderlyingPathToDataPath( - const FileSystemPath& underlying_path) { - FilePath root = GetDirectoryForOriginAndType( - underlying_path.origin(), underlying_path.type(), false); - if (root.empty()) return root; - // This removes the root, including the trailing slash, leaving a relative - // path. - FilePath local_file_path = underlying_path.internal_path(); - return FilePath(local_file_path.value().substr(root.value().length() + 1)); + return root.Append(data_path); } // TODO: How to do the whole validation-without-creation thing? We may not have @@ -1364,38 +1334,32 @@ bool ObfuscatedFileUtil::InitOriginDatabase(bool create) { return true; } -PlatformFileError ObfuscatedFileUtil::GenerateNewUnderlyingPath( +PlatformFileError ObfuscatedFileUtil::GenerateNewLocalPath( FileSystemDirectoryDatabase* db, FileSystemOperationContext* context, const GURL& origin, FileSystemType type, - FileSystemPath* underlying_path) { - DCHECK(underlying_path); + FilePath* local_path) { + DCHECK(local_path); 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_file_path is an OS path; - // underlying_file_util_ isn't guaranteed to understand OS paths. - FilePath local_file_path = GetDirectoryForOriginAndType(origin, type, false); - if (local_file_path.empty()) + FilePath new_local_path = GetDirectoryForOriginAndType(origin, type, false); + if (new_local_path.empty()) return base::PLATFORM_FILE_ERROR_FAILED; - local_file_path = local_file_path.AppendASCII( + new_local_path = new_local_path.AppendASCII( StringPrintf("%02" PRId64, directory_number)); - PlatformFileError error = underlying_file_util()->CreateDirectory( - context, FileSystemPath(origin, type, local_file_path), - false /* exclusive */, false /* recursive */); + PlatformFileError error = NativeFileUtil::CreateDirectory( + new_local_path, false /* exclusive */, false /* recursive */); if (error != base::PLATFORM_FILE_OK) return error; - local_file_path = local_file_path.AppendASCII( - StringPrintf("%08" PRId64, number)); - - *underlying_path = FileSystemPath(origin, type, local_file_path); + *local_path = new_local_path.AppendASCII(StringPrintf("%08" PRId64, number)); return base::PLATFORM_FILE_OK; } diff --git a/webkit/fileapi/obfuscated_file_util.h b/webkit/fileapi/obfuscated_file_util.h index 2e2db73..4b37abb 100644 --- a/webkit/fileapi/obfuscated_file_util.h +++ b/webkit/fileapi/obfuscated_file_util.h @@ -53,12 +53,7 @@ class ObfuscatedFileUtil : public FileSystemFileUtil { virtual bool HasFileSystemType(FileSystemType type) const = 0; }; - // |underlying_file_util| is owned by the instance. It will be deleted by - // the owner instance. For example, it can be instanciated as follows: - // FileSystemFileUtil* file_util = - // new ObfuscatedFileUtil(new NativeFileUtil()); - ObfuscatedFileUtil(const FilePath& file_system_directory, - FileSystemFileUtil* underlying_file_util); + explicit ObfuscatedFileUtil(const FilePath& file_system_directory); virtual ~ObfuscatedFileUtil(); virtual base::PlatformFileError CreateOrOpen( @@ -68,6 +63,10 @@ class ObfuscatedFileUtil : public FileSystemFileUtil { base::PlatformFile* file_handle, bool* created) OVERRIDE; + virtual PlatformFileError Close( + FileSystemOperationContext* context, + PlatformFile file) OVERRIDE; + virtual base::PlatformFileError EnsureFileExists( FileSystemOperationContext* context, const FileSystemPath& path, bool* created) OVERRIDE; @@ -92,7 +91,7 @@ class ObfuscatedFileUtil : public FileSystemFileUtil { virtual base::PlatformFileError GetLocalFilePath( FileSystemOperationContext* context, const FileSystemPath& file_system_path, - FilePath* local_file_path) OVERRIDE; + FilePath* local_path) OVERRIDE; virtual base::PlatformFileError Touch( FileSystemOperationContext* context, @@ -226,22 +225,14 @@ class ObfuscatedFileUtil : public FileSystemFileUtil { int file_flags, base::PlatformFile* handle); - // Given a virtual path, produces a real, full underlying path to the - // underlying data file. This does a database lookup (by - // calling DataPathToUnderlyingPath()), and verifies that the file exists. - FileSystemPath GetUnderlyingPath(const FileSystemPath& virtual_path); - // This converts from a relative path [as is stored in the FileInfo.data_path - // field] to an absolute underlying path that can be given to the underlying - // filesystem (as of now the returned path is assumed to be a platform path). - FileSystemPath DataPathToUnderlyingPath( + // field] to an absolute platform path that can be given to the native + // filesystem. + FilePath DataPathToLocalPath( const GURL& origin, FileSystemType type, const FilePath& data_file_path); - // This does the reverse of DataPathToUnderlyingPath. - FilePath UnderlyingPathToDataPath(const FileSystemPath& underlying_path); - // This returns NULL if |create| flag is false and a filesystem does not // exist for the given |origin_url| and |type|. // For read operations |create| should be false. @@ -262,12 +253,12 @@ class ObfuscatedFileUtil : public FileSystemFileUtil { void DropDatabases(); bool InitOriginDatabase(bool create); - base::PlatformFileError GenerateNewUnderlyingPath( + base::PlatformFileError GenerateNewLocalPath( FileSystemDirectoryDatabase* db, FileSystemOperationContext* context, const GURL& origin, FileSystemType type, - FileSystemPath* underlying_path); + FilePath* local_path); typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; DirectoryMap directories_; diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc index 232fe37..fde7c67 100644 --- a/webkit/fileapi/sandbox_mount_point_provider.cc +++ b/webkit/fileapi/sandbox_mount_point_provider.cc @@ -330,8 +330,7 @@ SandboxMountPointProvider::SandboxMountPointProvider( file_system_options_(file_system_options), sandbox_file_util_( new ObfuscatedFileUtil( - profile_path.Append(kNewFileSystemDirectory), - new NativeFileUtil())), + profile_path.Append(kNewFileSystemDirectory))), weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } diff --git a/webkit/fileapi/test_mount_point_provider.cc b/webkit/fileapi/test_mount_point_provider.cc index 446359f..726f1eb 100644 --- a/webkit/fileapi/test_mount_point_provider.cc +++ b/webkit/fileapi/test_mount_point_provider.cc @@ -82,7 +82,7 @@ TestMountPointProvider::TestMountPointProvider( base::SequencedTaskRunner* task_runner, const FilePath& base_path) : base_path_(base_path), - local_file_util_(new LocalFileUtil(new NativeFileUtil())), + local_file_util_(new LocalFileUtil()), quota_util_(new TestFileSystemQuotaUtil(task_runner)) { } diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi index 0543c74..121c67a 100644 --- a/webkit/fileapi/webkit_fileapi.gypi +++ b/webkit/fileapi/webkit_fileapi.gypi @@ -26,7 +26,6 @@ 'file_system_directory_database.h', 'file_system_file_reader.cc', 'file_system_file_reader.h', - 'file_system_file_util.cc', 'file_system_file_util.h', 'file_system_file_util_proxy.cc', 'file_system_file_util_proxy.h', |