Index: storage/browser/fileapi/obfuscated_file_util.cc |
diff --git a/webkit/browser/fileapi/obfuscated_file_util.cc b/storage/browser/fileapi/obfuscated_file_util.cc |
similarity index 78% |
rename from webkit/browser/fileapi/obfuscated_file_util.cc |
rename to storage/browser/fileapi/obfuscated_file_util.cc |
index 73722d4c82977d2c6ea94e408b06db1f2d397df6..b36605c61a2109c65c7a7cbd05272a59f776c29f 100644 |
--- a/webkit/browser/fileapi/obfuscated_file_util.cc |
+++ b/storage/browser/fileapi/obfuscated_file_util.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "webkit/browser/fileapi/obfuscated_file_util.h" |
+#include "storage/browser/fileapi/obfuscated_file_util.h" |
#include <queue> |
#include <string> |
@@ -20,19 +20,19 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "url/gurl.h" |
-#include "webkit/browser/fileapi/file_observers.h" |
-#include "webkit/browser/fileapi/file_system_context.h" |
-#include "webkit/browser/fileapi/file_system_operation_context.h" |
-#include "webkit/browser/fileapi/file_system_url.h" |
-#include "webkit/browser/fileapi/native_file_util.h" |
-#include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
-#include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" |
-#include "webkit/browser/fileapi/sandbox_origin_database.h" |
-#include "webkit/browser/fileapi/sandbox_prioritized_origin_database.h" |
-#include "webkit/browser/fileapi/timed_task_helper.h" |
-#include "webkit/browser/quota/quota_manager.h" |
-#include "webkit/common/database/database_identifier.h" |
-#include "webkit/common/fileapi/file_system_util.h" |
+#include "storage/browser/fileapi/file_observers.h" |
+#include "storage/browser/fileapi/file_system_context.h" |
+#include "storage/browser/fileapi/file_system_operation_context.h" |
+#include "storage/browser/fileapi/file_system_url.h" |
+#include "storage/browser/fileapi/native_file_util.h" |
+#include "storage/browser/fileapi/sandbox_file_system_backend.h" |
+#include "storage/browser/fileapi/sandbox_isolated_origin_database.h" |
+#include "storage/browser/fileapi/sandbox_origin_database.h" |
+#include "storage/browser/fileapi/sandbox_prioritized_origin_database.h" |
+#include "storage/browser/fileapi/timed_task_helper.h" |
+#include "storage/browser/quota/quota_manager.h" |
+#include "storage/common/database/database_identifier.h" |
+#include "storage/common/fileapi/file_system_util.h" |
// Example of various paths: |
// void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) { |
@@ -43,17 +43,16 @@ |
// file_util::DoAnother(local_path); |
// } |
-namespace fileapi { |
+namespace storage { |
namespace { |
typedef SandboxDirectoryDatabase::FileId FileId; |
typedef SandboxDirectoryDatabase::FileInfo FileInfo; |
-void InitFileInfo( |
- SandboxDirectoryDatabase::FileInfo* file_info, |
- SandboxDirectoryDatabase::FileId parent_id, |
- const base::FilePath::StringType& file_name) { |
+void InitFileInfo(SandboxDirectoryDatabase::FileInfo* file_info, |
+ SandboxDirectoryDatabase::FileId parent_id, |
+ const base::FilePath::StringType& file_name) { |
DCHECK(file_info); |
file_info->parent_id = parent_id; |
file_info->name = file_name; |
@@ -69,7 +68,7 @@ const int64 kPathByteQuotaCost = 2; // Bytes per byte of path length in UTF-8. |
int64 UsageForPath(size_t length) { |
return kPathCreationQuotaCost + |
- static_cast<int64>(length) * kPathByteQuotaCost; |
+ static_cast<int64>(length) * kPathByteQuotaCost; |
} |
bool AllocateQuota(FileSystemOperationContext* context, int64 growth) { |
@@ -83,12 +82,11 @@ bool AllocateQuota(FileSystemOperationContext* context, int64 growth) { |
return true; |
} |
-void UpdateUsage( |
- FileSystemOperationContext* context, |
- const FileSystemURL& url, |
- int64 growth) { |
- context->update_observers()->Notify( |
- &FileUpdateObserver::OnUpdate, MakeTuple(url, growth)); |
+void UpdateUsage(FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ int64 growth) { |
+ context->update_observers()->Notify(&FileUpdateObserver::OnUpdate, |
+ MakeTuple(url, growth)); |
} |
void TouchDirectory(SandboxDirectoryDatabase* db, FileId dir_id) { |
@@ -108,12 +106,11 @@ enum IsolatedOriginStatus { |
class ObfuscatedFileEnumerator |
: public FileSystemFileUtil::AbstractFileEnumerator { |
public: |
- ObfuscatedFileEnumerator( |
- SandboxDirectoryDatabase* db, |
- FileSystemOperationContext* context, |
- ObfuscatedFileUtil* obfuscated_file_util, |
- const FileSystemURL& root_url, |
- bool recursive) |
+ ObfuscatedFileEnumerator(SandboxDirectoryDatabase* db, |
+ FileSystemOperationContext* context, |
+ ObfuscatedFileUtil* obfuscated_file_util, |
+ const FileSystemURL& root_url, |
+ bool recursive) |
: db_(db), |
context_(context), |
obfuscated_file_util_(obfuscated_file_util), |
@@ -126,7 +123,7 @@ class ObfuscatedFileEnumerator |
if (!db_->GetFileWithPath(root_virtual_path, &file_id)) |
return; |
- FileRecord record = { file_id, root_virtual_path }; |
+ FileRecord record = {file_id, root_virtual_path}; |
recurse_queue_.push(record); |
} |
@@ -143,24 +140,26 @@ class ObfuscatedFileEnumerator |
FileInfo file_info; |
base::FilePath platform_file_path; |
base::File::Error error = |
- obfuscated_file_util_->GetFileInfoInternal( |
- db_, context_, root_url_, current_file_id_, |
- &file_info, ¤t_platform_file_info_, &platform_file_path); |
+ obfuscated_file_util_->GetFileInfoInternal(db_, |
+ context_, |
+ root_url_, |
+ current_file_id_, |
+ &file_info, |
+ ¤t_platform_file_info_, |
+ &platform_file_path); |
if (error != base::File::FILE_OK) |
return Next(); |
base::FilePath virtual_path = |
current_parent_virtual_path_.Append(file_info.name); |
if (recursive_ && file_info.is_directory()) { |
- FileRecord record = { current_file_id_, virtual_path }; |
+ FileRecord record = {current_file_id_, virtual_path}; |
recurse_queue_.push(record); |
} |
return virtual_path; |
} |
- virtual int64 Size() OVERRIDE { |
- return current_platform_file_info_.size; |
- } |
+ virtual int64 Size() OVERRIDE { return current_platform_file_info_.size; } |
virtual base::Time LastModifiedTime() OVERRIDE { |
return current_platform_file_info_.last_modified; |
@@ -209,9 +208,8 @@ class ObfuscatedOriginEnumerator |
: public ObfuscatedFileUtil::AbstractOriginEnumerator { |
public: |
typedef SandboxOriginDatabase::OriginRecord OriginRecord; |
- ObfuscatedOriginEnumerator( |
- SandboxOriginDatabaseInterface* origin_database, |
- const base::FilePath& base_file_path) |
+ ObfuscatedOriginEnumerator(SandboxOriginDatabaseInterface* origin_database, |
+ const base::FilePath& base_file_path) |
: base_file_path_(base_file_path) { |
if (origin_database) |
origin_database->ListAllOrigins(&origins_); |
@@ -271,9 +269,9 @@ ObfuscatedFileUtil::~ObfuscatedFileUtil() { |
DropDatabases(); |
} |
-base::File ObfuscatedFileUtil::CreateOrOpen( |
- FileSystemOperationContext* context, |
- const FileSystemURL& url, int file_flags) { |
+base::File ObfuscatedFileUtil::CreateOrOpen(FileSystemOperationContext* context, |
+ const FileSystemURL& url, |
+ int file_flags) { |
base::File file = CreateOrOpenInternal(context, url, file_flags); |
if (file.IsValid() && file_flags & base::File::FLAG_WRITE && |
context->quota_limit_type() == quota::kQuotaLimitTypeUnlimited && |
@@ -309,19 +307,19 @@ base::File::Error ObfuscatedFileUtil::EnsureFileExists( |
return base::File::FILE_ERROR_NOT_FOUND; |
FileInfo file_info; |
- InitFileInfo(&file_info, parent_id, |
- VirtualPath::BaseName(url.path()).value()); |
+ InitFileInfo( |
+ &file_info, parent_id, VirtualPath::BaseName(url.path()).value()); |
int64 growth = UsageForPath(file_info.name.size()); |
if (!AllocateQuota(context, growth)) |
return base::File::FILE_ERROR_NO_SPACE; |
- base::File::Error error = CreateFile(context, base::FilePath(), url, |
- &file_info); |
+ base::File::Error error = |
+ CreateFile(context, base::FilePath(), url, &file_info); |
if (created && base::File::FILE_OK == error) { |
*created = true; |
UpdateUsage(context, url, growth); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnCreateFile, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnCreateFile, |
+ MakeTuple(url)); |
} |
return error; |
} |
@@ -379,8 +377,8 @@ base::File::Error ObfuscatedFileUtil::CreateDirectory( |
if (error != base::File::FILE_OK) |
return error; |
UpdateUsage(context, url, growth); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnCreateDirectory, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnCreateDirectory, |
+ MakeTuple(url)); |
if (first) { |
first = false; |
TouchDirectory(db, file_info.parent_id); |
@@ -401,15 +399,13 @@ base::File::Error ObfuscatedFileUtil::GetFileInfo( |
if (!db->GetFileWithPath(url.path(), &file_id)) |
return base::File::FILE_ERROR_NOT_FOUND; |
FileInfo local_info; |
- return GetFileInfoInternal(db, context, url, |
- file_id, &local_info, |
- file_info, platform_file_path); |
+ return GetFileInfoInternal( |
+ db, context, url, file_id, &local_info, file_info, platform_file_path); |
} |
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
- ObfuscatedFileUtil::CreateFileEnumerator( |
- FileSystemOperationContext* context, |
- const FileSystemURL& root_url) { |
+ObfuscatedFileUtil::CreateFileEnumerator(FileSystemOperationContext* context, |
+ const FileSystemURL& root_url) { |
return CreateFileEnumerator(context, root_url, false /* recursive */); |
} |
@@ -458,9 +454,9 @@ base::File::Error ObfuscatedFileUtil::Touch( |
return base::File::FILE_ERROR_FAILED; |
return base::File::FILE_OK; |
} |
- return NativeFileUtil::Touch( |
- DataPathToLocalPath(url, file_info.data_path), |
- last_access_time, last_modified_time); |
+ return NativeFileUtil::Touch(DataPathToLocalPath(url, file_info.data_path), |
+ last_access_time, |
+ last_modified_time); |
} |
base::File::Error ObfuscatedFileUtil::Truncate( |
@@ -469,8 +465,7 @@ base::File::Error ObfuscatedFileUtil::Truncate( |
int64 length) { |
base::File::Info file_info; |
base::FilePath local_path; |
- base::File::Error error = |
- GetFileInfo(context, url, &file_info, &local_path); |
+ base::File::Error error = GetFileInfo(context, url, &file_info, &local_path); |
if (error != base::File::FILE_OK) |
return error; |
@@ -480,8 +475,8 @@ base::File::Error ObfuscatedFileUtil::Truncate( |
error = NativeFileUtil::Truncate(local_path, length); |
if (error == base::File::FILE_OK) { |
UpdateUsage(context, url, growth); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnModifyFile, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnModifyFile, |
+ MakeTuple(url)); |
} |
return error; |
} |
@@ -505,15 +500,18 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( |
return base::File::FILE_ERROR_NOT_FOUND; |
FileId dest_file_id; |
- bool overwrite = db->GetFileWithPath(dest_url.path(), |
- &dest_file_id); |
+ bool overwrite = db->GetFileWithPath(dest_url.path(), &dest_file_id); |
FileInfo src_file_info; |
base::File::Info src_platform_file_info; |
base::FilePath src_local_path; |
- base::File::Error error = GetFileInfoInternal( |
- db, context, src_url, src_file_id, |
- &src_file_info, &src_platform_file_info, &src_local_path); |
+ base::File::Error error = GetFileInfoInternal(db, |
+ context, |
+ src_url, |
+ src_file_id, |
+ &src_file_info, |
+ &src_platform_file_info, |
+ &src_local_path); |
if (error != base::File::FILE_OK) |
return error; |
if (src_file_info.is_directory()) |
@@ -521,11 +519,15 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( |
FileInfo dest_file_info; |
base::File::Info dest_platform_file_info; // overwrite case only |
- base::FilePath dest_local_path; // overwrite case only |
+ base::FilePath dest_local_path; // overwrite case only |
if (overwrite) { |
- base::File::Error error = GetFileInfoInternal( |
- db, context, dest_url, dest_file_id, |
- &dest_file_info, &dest_platform_file_info, &dest_local_path); |
+ base::File::Error error = GetFileInfoInternal(db, |
+ context, |
+ dest_url, |
+ dest_file_id, |
+ &dest_file_info, |
+ &dest_platform_file_info, |
+ &dest_local_path); |
if (error == base::File::FILE_ERROR_NOT_FOUND) |
overwrite = false; // fallback to non-overwrite case |
else if (error != base::File::FILE_OK) |
@@ -542,8 +544,7 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( |
dest_file_info = src_file_info; |
dest_file_info.parent_id = dest_parent_id; |
- dest_file_info.name = |
- VirtualPath::BaseName(dest_url.path()).value(); |
+ dest_file_info.name = VirtualPath::BaseName(dest_url.path()).value(); |
} |
int64 growth = 0; |
@@ -579,7 +580,7 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( |
src_local_path, |
dest_local_path, |
option, |
- fileapi::NativeFileUtil::CopyOrMoveModeForDestination( |
+ storage::NativeFileUtil::CopyOrMoveModeForDestination( |
dest_url, true /* copy */)); |
} else { // non-overwrite |
error = CreateFile(context, src_local_path, dest_url, &dest_file_info); |
@@ -587,8 +588,7 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( |
} else { |
if (overwrite) { |
if (db->OverwritingMoveFile(src_file_id, dest_file_id)) { |
- if (base::File::FILE_OK != |
- NativeFileUtil::DeleteFile(dest_local_path)) |
+ if (base::File::FILE_OK != NativeFileUtil::DeleteFile(dest_local_path)) |
LOG(WARNING) << "Leaked a backing file."; |
error = base::File::FILE_OK; |
} else { |
@@ -606,18 +606,16 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( |
return error; |
if (overwrite) { |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnModifyFile, |
- MakeTuple(dest_url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnModifyFile, |
+ MakeTuple(dest_url)); |
} else { |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnCreateFileFrom, |
- MakeTuple(dest_url, src_url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnCreateFileFrom, |
+ MakeTuple(dest_url, src_url)); |
} |
if (!copy) { |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnRemoveFile, MakeTuple(src_url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnRemoveFile, |
+ MakeTuple(src_url)); |
TouchDirectory(db, src_file_info.parent_id); |
} |
@@ -640,16 +638,19 @@ base::File::Error ObfuscatedFileUtil::CopyInForeignFile( |
return base::File::FILE_ERROR_NOT_FOUND; |
FileId dest_file_id; |
- bool overwrite = db->GetFileWithPath(dest_url.path(), |
- &dest_file_id); |
+ bool overwrite = db->GetFileWithPath(dest_url.path(), &dest_file_id); |
FileInfo dest_file_info; |
base::File::Info dest_platform_file_info; // overwrite case only |
if (overwrite) { |
base::FilePath dest_local_path; |
- base::File::Error error = GetFileInfoInternal( |
- db, context, dest_url, dest_file_id, |
- &dest_file_info, &dest_platform_file_info, &dest_local_path); |
+ base::File::Error error = GetFileInfoInternal(db, |
+ context, |
+ dest_url, |
+ dest_file_id, |
+ &dest_file_info, |
+ &dest_platform_file_info, |
+ &dest_local_path); |
if (error == base::File::FILE_ERROR_NOT_FOUND) |
overwrite = false; // fallback to non-overwrite case |
else if (error != base::File::FILE_OK) |
@@ -665,7 +666,8 @@ base::File::Error ObfuscatedFileUtil::CopyInForeignFile( |
} |
if (!dest_file_info.is_directory()) |
return base::File::FILE_ERROR_FAILED; |
- InitFileInfo(&dest_file_info, dest_parent_id, |
+ InitFileInfo(&dest_file_info, |
+ dest_parent_id, |
VirtualPath::BaseName(dest_url.path()).value()); |
} |
@@ -682,9 +684,10 @@ base::File::Error ObfuscatedFileUtil::CopyInForeignFile( |
base::FilePath dest_local_path = |
DataPathToLocalPath(dest_url, dest_file_info.data_path); |
error = NativeFileUtil::CopyOrMoveFile( |
- src_file_path, dest_local_path, |
+ src_file_path, |
+ dest_local_path, |
FileSystemOperation::OPTION_NONE, |
- fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, |
+ storage::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, |
true /* copy */)); |
} else { |
error = CreateFile(context, src_file_path, dest_url, &dest_file_info); |
@@ -694,11 +697,11 @@ base::File::Error ObfuscatedFileUtil::CopyInForeignFile( |
return error; |
if (overwrite) { |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnModifyFile, MakeTuple(dest_url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnModifyFile, |
+ MakeTuple(dest_url)); |
} else { |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnCreateFile, MakeTuple(dest_url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnCreateFile, |
+ MakeTuple(dest_url)); |
} |
UpdateUsage(context, dest_url, growth); |
@@ -721,8 +724,7 @@ base::File::Error ObfuscatedFileUtil::DeleteFile( |
base::FilePath local_path; |
base::File::Error error = GetFileInfoInternal( |
db, context, url, file_id, &file_info, &platform_file_info, &local_path); |
- if (error != base::File::FILE_ERROR_NOT_FOUND && |
- error != base::File::FILE_OK) |
+ if (error != base::File::FILE_ERROR_NOT_FOUND && error != base::File::FILE_OK) |
return error; |
if (file_info.is_directory()) |
@@ -737,8 +739,8 @@ base::File::Error ObfuscatedFileUtil::DeleteFile( |
UpdateUsage(context, url, growth); |
TouchDirectory(db, file_info.parent_id); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnRemoveFile, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnRemoveFile, |
+ MakeTuple(url)); |
if (error == base::File::FILE_ERROR_NOT_FOUND) |
return base::File::FILE_OK; |
@@ -772,12 +774,12 @@ base::File::Error ObfuscatedFileUtil::DeleteDirectory( |
AllocateQuota(context, growth); |
UpdateUsage(context, url, growth); |
TouchDirectory(db, file_info.parent_id); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnRemoveDirectory, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnRemoveDirectory, |
+ MakeTuple(url)); |
return base::File::FILE_OK; |
} |
-webkit_blob::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile( |
+storage::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile( |
FileSystemOperationContext* context, |
const FileSystemURL& url, |
base::File::Error* error, |
@@ -789,14 +791,13 @@ webkit_blob::ScopedFile ObfuscatedFileUtil::CreateSnapshotFile( |
*file_info = base::File::Info(); |
*error = base::File::FILE_ERROR_NOT_A_FILE; |
} |
- return webkit_blob::ScopedFile(); |
+ return storage::ScopedFile(); |
} |
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
- ObfuscatedFileUtil::CreateFileEnumerator( |
- FileSystemOperationContext* context, |
- const FileSystemURL& root_url, |
- bool recursive) { |
+ObfuscatedFileUtil::CreateFileEnumerator(FileSystemOperationContext* context, |
+ const FileSystemURL& root_url, |
+ bool recursive) { |
SandboxDirectoryDatabase* db = GetDirectoryDatabase(root_url, false); |
if (!db) { |
return scoped_ptr<AbstractFileEnumerator>(new EmptyFileEnumerator()); |
@@ -805,9 +806,8 @@ scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
new ObfuscatedFileEnumerator(db, context, this, root_url, recursive)); |
} |
-bool ObfuscatedFileUtil::IsDirectoryEmpty( |
- FileSystemOperationContext* context, |
- const FileSystemURL& url) { |
+bool ObfuscatedFileUtil::IsDirectoryEmpty(FileSystemOperationContext* context, |
+ const FileSystemURL& url) { |
SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, false); |
if (!db) |
return true; // Not a great answer, but it's what others do. |
@@ -843,9 +843,8 @@ base::FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType( |
base::File::Error error = base::File::FILE_OK; |
if (!base::DirectoryExists(path) && |
(!create || !base::CreateDirectory(path))) { |
- error = create ? |
- base::File::FILE_ERROR_FAILED : |
- base::File::FILE_ERROR_NOT_FOUND; |
+ error = create ? base::File::FILE_ERROR_FAILED |
+ : base::File::FILE_ERROR_NOT_FOUND; |
} |
if (error_code) |
@@ -857,8 +856,8 @@ bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType( |
const GURL& origin, |
const std::string& type_string) { |
base::File::Error error = base::File::FILE_OK; |
- base::FilePath origin_type_path = GetDirectoryForOriginAndType( |
- origin, type_string, false, &error); |
+ base::FilePath origin_type_path = |
+ GetDirectoryForOriginAndType(origin, type_string, false, &error); |
if (origin_type_path.empty()) |
return true; |
if (error != base::File::FILE_ERROR_NOT_FOUND) { |
@@ -910,8 +909,8 @@ ObfuscatedFileUtil::CreateOriginEnumerator() { |
std::vector<SandboxOriginDatabase::OriginRecord> origins; |
InitOriginDatabase(GURL(), false); |
- return new ObfuscatedOriginEnumerator( |
- origin_database_.get(), file_system_directory_); |
+ return new ObfuscatedOriginEnumerator(origin_database_.get(), |
+ file_system_directory_); |
} |
bool ObfuscatedFileUtil::DestroyDirectoryDatabase( |
@@ -928,8 +927,8 @@ bool ObfuscatedFileUtil::DestroyDirectoryDatabase( |
} |
base::File::Error error = base::File::FILE_OK; |
- base::FilePath path = GetDirectoryForOriginAndType( |
- origin, type_string, false, &error); |
+ base::FilePath path = |
+ GetDirectoryForOriginAndType(origin, type_string, false, &error); |
if (path.empty() || error == base::File::FILE_ERROR_NOT_FOUND) |
return true; |
return SandboxDirectoryDatabase::DestroyDatabase(path, env_override_); |
@@ -957,8 +956,8 @@ void ObfuscatedFileUtil::MaybePrepopulateDatabase( |
if (!ContainsKey(known_type_strings_, type_string)) |
continue; |
base::File::Error error = base::File::FILE_ERROR_FAILED; |
- base::FilePath path = GetDirectoryForOriginAndType( |
- origin, type_string, false, &error); |
+ base::FilePath path = |
+ GetDirectoryForOriginAndType(origin, type_string, false, &error); |
if (error != base::File::FILE_OK) |
continue; |
scoped_ptr<SandboxDirectoryDatabase> db( |
@@ -1017,8 +1016,7 @@ base::File::Error ObfuscatedFileUtil::GetFileInfoInternal( |
if (local_info->data_path.empty()) |
return base::File::FILE_ERROR_INVALID_OPERATION; |
base::FilePath local_path = DataPathToLocalPath(url, local_info->data_path); |
- base::File::Error error = NativeFileUtil::GetFileInfo( |
- local_path, file_info); |
+ base::File::Error error = NativeFileUtil::GetFileInfo(local_path, file_info); |
// We should not follow symbolic links in sandboxed file system. |
if (base::IsLink(local_path)) { |
LOG(WARNING) << "Found a symbolic file."; |
@@ -1038,12 +1036,13 @@ base::File::Error ObfuscatedFileUtil::GetFileInfoInternal( |
base::File ObfuscatedFileUtil::CreateAndOpenFile( |
FileSystemOperationContext* context, |
const FileSystemURL& dest_url, |
- FileInfo* dest_file_info, int file_flags) { |
+ FileInfo* dest_file_info, |
+ int file_flags) { |
SandboxDirectoryDatabase* db = GetDirectoryDatabase(dest_url, true); |
base::FilePath root, dest_local_path; |
- base::File::Error error = GenerateNewLocalPath(db, context, dest_url, &root, |
- &dest_local_path); |
+ base::File::Error error = |
+ GenerateNewLocalPath(db, context, dest_url, &root, &dest_local_path); |
if (error != base::File::FILE_OK) |
return base::File(error); |
@@ -1082,8 +1081,8 @@ base::File::Error ObfuscatedFileUtil::CreateFile( |
SandboxDirectoryDatabase* db = GetDirectoryDatabase(dest_url, true); |
base::FilePath root, dest_local_path; |
- base::File::Error error = GenerateNewLocalPath(db, context, dest_url, &root, |
- &dest_local_path); |
+ base::File::Error error = |
+ GenerateNewLocalPath(db, context, dest_url, &root, &dest_local_path); |
if (error != base::File::FILE_OK) |
return error; |
@@ -1099,9 +1098,10 @@ base::File::Error ObfuscatedFileUtil::CreateFile( |
error = NativeFileUtil::EnsureFileExists(dest_local_path, &created); |
} else { |
error = NativeFileUtil::CopyOrMoveFile( |
- src_file_path, dest_local_path, |
+ src_file_path, |
+ dest_local_path, |
FileSystemOperation::OPTION_NONE, |
- fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, |
+ storage::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, |
true /* copy */)); |
created = true; |
} |
@@ -1120,8 +1120,8 @@ base::File::Error ObfuscatedFileUtil::CommitCreateFile( |
FileInfo* dest_file_info) { |
// This removes the root, including the trailing slash, leaving a relative |
// path. |
- dest_file_info->data_path = base::FilePath( |
- local_path.value().substr(root.value().length() + 1)); |
+ dest_file_info->data_path = |
+ base::FilePath(local_path.value().substr(root.value().length() + 1)); |
FileId file_id; |
base::File::Error error = db->AddFileInfo(*dest_file_info, &file_id); |
@@ -1133,7 +1133,8 @@ base::File::Error ObfuscatedFileUtil::CommitCreateFile( |
} |
base::FilePath ObfuscatedFileUtil::DataPathToLocalPath( |
- const FileSystemURL& url, const base::FilePath& data_path) { |
+ const FileSystemURL& url, |
+ const base::FilePath& data_path) { |
base::File::Error error = base::File::FILE_OK; |
base::FilePath root = GetDirectoryForURL(url, false, &error); |
if (error != base::File::FILE_OK) |
@@ -1142,14 +1143,14 @@ base::FilePath ObfuscatedFileUtil::DataPathToLocalPath( |
} |
std::string ObfuscatedFileUtil::GetDirectoryDatabaseKey( |
- const GURL& origin, const std::string& type_string) { |
+ const GURL& origin, |
+ const std::string& type_string) { |
if (type_string.empty()) { |
LOG(WARNING) << "Unknown filesystem type requested:" << type_string; |
return std::string(); |
} |
// For isolated origin we just use a type string as a key. |
- return webkit_database::GetIdentifierFromOrigin(origin) + |
- type_string; |
+ return webkit_database::GetIdentifierFromOrigin(origin) + type_string; |
} |
// TODO(ericu): How to do the whole validation-without-creation thing? |
@@ -1157,9 +1158,10 @@ std::string ObfuscatedFileUtil::GetDirectoryDatabaseKey( |
// Ah, in that case don't even get here? |
// Still doesn't answer the quota issue, though. |
SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( |
- const FileSystemURL& url, bool create) { |
- std::string key = GetDirectoryDatabaseKey( |
- url.origin(), CallGetTypeStringForURL(url)); |
+ const FileSystemURL& url, |
+ bool create) { |
+ std::string key = |
+ GetDirectoryDatabaseKey(url.origin(), CallGetTypeStringForURL(url)); |
if (key.empty()) |
return NULL; |
@@ -1172,8 +1174,8 @@ SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( |
base::File::Error error = base::File::FILE_OK; |
base::FilePath path = GetDirectoryForURL(url, create, &error); |
if (error != base::File::FILE_OK) { |
- LOG(WARNING) << "Failed to get origin+type directory: " |
- << url.DebugString() << " error:" << error; |
+ LOG(WARNING) << "Failed to get origin+type directory: " << url.DebugString() |
+ << " error:" << error; |
return NULL; |
} |
MarkUsed(); |
@@ -1184,12 +1186,13 @@ SandboxDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( |
} |
base::FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( |
- const GURL& origin, bool create, base::File::Error* error_code) { |
+ const GURL& origin, |
+ bool create, |
+ base::File::Error* error_code) { |
if (!InitOriginDatabase(origin, create)) { |
if (error_code) { |
- *error_code = create ? |
- base::File::FILE_ERROR_FAILED : |
- base::File::FILE_ERROR_NOT_FOUND; |
+ *error_code = create ? base::File::FILE_ERROR_FAILED |
+ : base::File::FILE_ERROR_NOT_FOUND; |
} |
return base::FilePath(); |
} |
@@ -1222,9 +1225,8 @@ base::FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( |
if (!exists_in_fs) { |
if (!create || !base::CreateDirectory(path)) { |
if (error_code) |
- *error_code = create ? |
- base::File::FILE_ERROR_FAILED : |
- base::File::FILE_ERROR_NOT_FOUND; |
+ *error_code = create ? base::File::FILE_ERROR_FAILED |
+ : base::File::FILE_ERROR_NOT_FOUND; |
return base::FilePath(); |
} |
} |
@@ -1250,17 +1252,17 @@ void ObfuscatedFileUtil::MarkUsed() { |
if (timer_->IsRunning()) { |
timer_->Reset(); |
} else { |
- timer_->Start(FROM_HERE, |
- base::TimeDelta::FromSeconds(db_flush_delay_seconds_), |
- base::Bind(&ObfuscatedFileUtil::DropDatabases, |
- base::Unretained(this))); |
+ timer_->Start( |
+ FROM_HERE, |
+ base::TimeDelta::FromSeconds(db_flush_delay_seconds_), |
+ base::Bind(&ObfuscatedFileUtil::DropDatabases, base::Unretained(this))); |
} |
} |
void ObfuscatedFileUtil::DropDatabases() { |
origin_database_.reset(); |
- STLDeleteContainerPairSecondPointers( |
- directories_.begin(), directories_.end()); |
+ STLDeleteContainerPairSecondPointers(directories_.begin(), |
+ directories_.end()); |
directories_.clear(); |
timer_.reset(); |
} |
@@ -1273,8 +1275,8 @@ bool ObfuscatedFileUtil::InitOriginDatabase(const GURL& origin_hint, |
if (!create && !base::DirectoryExists(file_system_directory_)) |
return false; |
if (!base::CreateDirectory(file_system_directory_)) { |
- LOG(WARNING) << "Failed to create FileSystem directory: " << |
- file_system_directory_.value(); |
+ LOG(WARNING) << "Failed to create FileSystem directory: " |
+ << file_system_directory_.value(); |
return false; |
} |
@@ -1300,8 +1302,7 @@ bool ObfuscatedFileUtil::InitOriginDatabase(const GURL& origin_hint, |
prioritized_origin_database->GetSandboxOriginDatabase()); |
} |
- prioritized_origin_database->InitializePrimaryOrigin( |
- isolated_origin_string); |
+ prioritized_origin_database->InitializePrimaryOrigin(isolated_origin_string); |
return true; |
} |
@@ -1324,8 +1325,8 @@ base::File::Error ObfuscatedFileUtil::GenerateNewLocalPath( |
// We use the third- and fourth-to-last digits as the directory. |
int64 directory_number = number % 10000 / 100; |
- base::FilePath new_local_path = root->AppendASCII( |
- base::StringPrintf("%02" PRId64, directory_number)); |
+ base::FilePath new_local_path = |
+ root->AppendASCII(base::StringPrintf("%02" PRId64, directory_number)); |
error = NativeFileUtil::CreateDirectory( |
new_local_path, false /* exclusive */, false /* recursive */); |
@@ -1339,26 +1340,29 @@ base::File::Error ObfuscatedFileUtil::GenerateNewLocalPath( |
base::File ObfuscatedFileUtil::CreateOrOpenInternal( |
FileSystemOperationContext* context, |
- const FileSystemURL& url, int file_flags) { |
- DCHECK(!(file_flags & (base::File::FLAG_DELETE_ON_CLOSE | |
- base::File::FLAG_HIDDEN | base::File::FLAG_EXCLUSIVE_READ | |
- base::File::FLAG_EXCLUSIVE_WRITE))); |
+ const FileSystemURL& url, |
+ int file_flags) { |
+ DCHECK( |
+ !(file_flags & |
+ (base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_HIDDEN | |
+ base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_EXCLUSIVE_WRITE))); |
SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, true); |
if (!db) |
return base::File(base::File::FILE_ERROR_FAILED); |
FileId file_id; |
if (!db->GetFileWithPath(url.path(), &file_id)) { |
// The file doesn't exist. |
- if (!(file_flags & (base::File::FLAG_CREATE | |
- base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_ALWAYS))) { |
+ if (!(file_flags & |
+ (base::File::FLAG_CREATE | base::File::FLAG_CREATE_ALWAYS | |
+ base::File::FLAG_OPEN_ALWAYS))) { |
return base::File(base::File::FILE_ERROR_NOT_FOUND); |
} |
FileId parent_id; |
if (!db->GetFileWithPath(VirtualPath::DirName(url.path()), &parent_id)) |
return base::File(base::File::FILE_ERROR_NOT_FOUND); |
FileInfo file_info; |
- InitFileInfo(&file_info, parent_id, |
- VirtualPath::BaseName(url.path()).value()); |
+ InitFileInfo( |
+ &file_info, parent_id, VirtualPath::BaseName(url.path()).value()); |
int64 growth = UsageForPath(file_info.name.size()); |
if (!AllocateQuota(context, growth)) |
@@ -1366,8 +1370,8 @@ base::File ObfuscatedFileUtil::CreateOrOpenInternal( |
base::File file = CreateAndOpenFile(context, url, &file_info, file_flags); |
if (file.IsValid()) { |
UpdateUsage(context, url, growth); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnCreateFile, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnCreateFile, |
+ MakeTuple(url)); |
} |
return file.Pass(); |
} |
@@ -1386,8 +1390,8 @@ base::File ObfuscatedFileUtil::CreateOrOpenInternal( |
return base::File(base::File::FILE_ERROR_NOT_A_FILE); |
int64 delta = 0; |
- if (file_flags & (base::File::FLAG_CREATE_ALWAYS | |
- base::File::FLAG_OPEN_TRUNCATED)) { |
+ if (file_flags & |
+ (base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED)) { |
// The file exists and we're truncating. |
delta = -platform_file_info.size; |
AllocateQuota(context, delta); |
@@ -1409,15 +1413,15 @@ base::File ObfuscatedFileUtil::CreateOrOpenInternal( |
// If truncating we need to update the usage. |
if (delta) { |
UpdateUsage(context, url, delta); |
- context->change_observers()->Notify( |
- &FileChangeObserver::OnModifyFile, MakeTuple(url)); |
+ context->change_observers()->Notify(&FileChangeObserver::OnModifyFile, |
+ MakeTuple(url)); |
} |
return file.Pass(); |
} |
bool ObfuscatedFileUtil::HasIsolatedStorage(const GURL& origin) { |
return special_storage_policy_.get() && |
- special_storage_policy_->HasIsolatedStorage(origin); |
+ special_storage_policy_->HasIsolatedStorage(origin); |
} |
-} // namespace fileapi |
+} // namespace storage |