Index: chrome/browser/file_system/file_system_dispatcher_host.cc |
diff --git a/chrome/browser/file_system/file_system_dispatcher_host.cc b/chrome/browser/file_system/file_system_dispatcher_host.cc |
index 3ebda7b8aa1d78d549b796e5b1d0ca08d6d62b85..12b4d19c474beed209d4feb6bbe61e94703a137e 100644 |
--- a/chrome/browser/file_system/file_system_dispatcher_host.cc |
+++ b/chrome/browser/file_system/file_system_dispatcher_host.cc |
@@ -20,58 +20,13 @@ |
#include "chrome/common/render_messages_params.h" |
#include "googleurl/src/gurl.h" |
#include "net/url_request/url_request_context.h" |
+#include "webkit/fileapi/file_system_operation.h" |
#include "webkit/fileapi/file_system_path_manager.h" |
#include "webkit/fileapi/file_system_quota_manager.h" |
+#include "webkit/fileapi/sandboxed_file_system_operation.h" |
using fileapi::FileSystemQuotaManager; |
- |
-class FileSystemDispatcherHost::OpenFileSystemTask { |
- public: |
- static void Start( |
- int request_id, |
- const GURL& origin_url, |
- fileapi::FileSystemType type, |
- bool create, |
- FileSystemDispatcherHost* dispatcher_host) { |
- // The task is self-destructed. |
- new OpenFileSystemTask( |
- request_id, origin_url, type, create, dispatcher_host); |
- } |
- |
- private: |
- void DidGetRootPath(bool success, const FilePath& root_path, |
- const std::string& name) { |
- if (success) |
- dispatcher_host_->Send( |
- new ViewMsg_OpenFileSystemRequest_Complete( |
- request_id_, true, name, root_path)); |
- else |
- dispatcher_host_->Send( |
- new ViewMsg_OpenFileSystemRequest_Complete( |
- request_id_, false, std::string(), FilePath())); |
- delete this; |
- } |
- |
- OpenFileSystemTask( |
- int request_id, |
- const GURL& origin_url, |
- fileapi::FileSystemType type, |
- bool create, |
- FileSystemDispatcherHost* dispatcher_host) |
- : request_id_(request_id), |
- dispatcher_host_(dispatcher_host), |
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
- dispatcher_host->context_->path_manager()->GetFileSystemRootPath( |
- origin_url, type, create, |
- callback_factory_.NewCallback(&OpenFileSystemTask::DidGetRootPath)); |
- } |
- |
- int request_id_; |
- std::string name_; |
- FilePath root_path_; |
- scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; |
- base::ScopedCallbackFactory<OpenFileSystemTask> callback_factory_; |
-}; |
+using fileapi::SandboxedFileSystemOperation; |
FileSystemDispatcherHost::FileSystemDispatcherHost( |
IPC::Message::Sender* sender, Profile* profile) |
@@ -156,48 +111,32 @@ void FileSystemDispatcherHost::OnOpenFileSystem( |
return; |
} |
- OpenFileSystemTask::Start(request_id, origin_url, type, create, this); |
+ GetNewOperation(request_id)->OpenFileSystem(origin_url, type, create); |
} |
void FileSystemDispatcherHost::OnMove( |
int request_id, const FilePath& src_path, const FilePath& dest_path) { |
- if (!VerifyFileSystemPathForRead(src_path, request_id) || |
- !VerifyFileSystemPathForWrite(dest_path, request_id, true /* create */, |
- FileSystemQuotaManager::kUnknownSize)) |
- return; |
- |
GetNewOperation(request_id)->Move(src_path, dest_path); |
} |
void FileSystemDispatcherHost::OnCopy( |
int request_id, const FilePath& src_path, const FilePath& dest_path) { |
- if (!VerifyFileSystemPathForRead(src_path, request_id) || |
- !VerifyFileSystemPathForWrite(dest_path, request_id, true /* create */, |
- FileSystemQuotaManager::kUnknownSize)) |
- return; |
- |
GetNewOperation(request_id)->Copy(src_path, dest_path); |
} |
void FileSystemDispatcherHost::OnRemove( |
int request_id, const FilePath& path, bool recursive) { |
- if (!VerifyFileSystemPathForWrite(path, request_id, false /* create */, 0)) |
- return; |
GetNewOperation(request_id)->Remove(path, recursive); |
} |
void FileSystemDispatcherHost::OnReadMetadata( |
int request_id, const FilePath& path) { |
- if (!VerifyFileSystemPathForRead(path, request_id)) |
- return; |
GetNewOperation(request_id)->GetMetadata(path); |
} |
void FileSystemDispatcherHost::OnCreate( |
int request_id, const FilePath& path, bool exclusive, |
bool is_directory, bool recursive) { |
- if (!VerifyFileSystemPathForWrite(path, request_id, true /* create */, 0)) |
- return; |
if (is_directory) |
GetNewOperation(request_id)->CreateDirectory(path, exclusive, recursive); |
else |
@@ -206,8 +145,6 @@ void FileSystemDispatcherHost::OnCreate( |
void FileSystemDispatcherHost::OnExists( |
int request_id, const FilePath& path, bool is_directory) { |
- if (!VerifyFileSystemPathForRead(path, request_id)) |
- return; |
if (is_directory) |
GetNewOperation(request_id)->DirectoryExists(path); |
else |
@@ -216,8 +153,6 @@ void FileSystemDispatcherHost::OnExists( |
void FileSystemDispatcherHost::OnReadDirectory( |
int request_id, const FilePath& path) { |
- if (!VerifyFileSystemPathForRead(path, request_id)) |
- return; |
GetNewOperation(request_id)->ReadDirectory(path); |
} |
@@ -226,9 +161,6 @@ void FileSystemDispatcherHost::OnWrite( |
const FilePath& path, |
const GURL& blob_url, |
int64 offset) { |
- if (!VerifyFileSystemPathForWrite(path, request_id, true /* create */, |
- FileSystemQuotaManager::kUnknownSize)) |
- return; |
GetNewOperation(request_id)->Write( |
request_context_, path, blob_url, offset); |
} |
@@ -237,8 +169,6 @@ void FileSystemDispatcherHost::OnTruncate( |
int request_id, |
const FilePath& path, |
int64 length) { |
- if (!VerifyFileSystemPathForWrite(path, request_id, false /* create */, 0)) |
- return; |
GetNewOperation(request_id)->Truncate(path, length); |
} |
@@ -247,8 +177,6 @@ void FileSystemDispatcherHost::OnTouchFile( |
const FilePath& path, |
const base::Time& last_access_time, |
const base::Time& last_modified_time) { |
- if (!VerifyFileSystemPathForWrite(path, request_id, true /* create */, 0)) |
- return; |
GetNewOperation(request_id)->TouchFile( |
path, last_access_time, last_modified_time); |
} |
@@ -256,8 +184,8 @@ void FileSystemDispatcherHost::OnTouchFile( |
void FileSystemDispatcherHost::OnCancel( |
int request_id, |
int request_id_to_cancel) { |
- fileapi::FileSystemOperation* write = |
- operations_.Lookup(request_id_to_cancel); |
+ SandboxedFileSystemOperation* write = operations_.Lookup( |
+ request_id_to_cancel); |
if (write) { |
// The cancel will eventually send both the write failure and the cancel |
// success. |
@@ -277,69 +205,14 @@ void FileSystemDispatcherHost::Send(IPC::Message* message) { |
delete message; |
} |
-bool FileSystemDispatcherHost::VerifyFileSystemPathForRead( |
- const FilePath& path, int request_id) { |
- // We may want do more checks, but for now it just checks if the given |
- // |path| is under the valid FileSystem root path for this host context. |
- if (!context_->path_manager()->CrackFileSystemPath( |
- path, NULL, NULL, NULL)) { |
- Send(new ViewMsg_FileSystem_DidFail( |
- request_id, base::PLATFORM_FILE_ERROR_SECURITY)); |
- return false; |
- } |
- return true; |
-} |
- |
-bool FileSystemDispatcherHost::VerifyFileSystemPathForWrite( |
- const FilePath& path, int request_id, bool create, int64 growth) { |
- GURL origin_url; |
- FilePath virtual_path; |
- if (!context_->path_manager()->CrackFileSystemPath( |
- path, &origin_url, NULL, &virtual_path)) { |
- Send(new ViewMsg_FileSystem_DidFail( |
- request_id, base::PLATFORM_FILE_ERROR_SECURITY)); |
- return false; |
- } |
- // Any write access is disallowed on the root path. |
- if (virtual_path.value().length() == 0 || |
- virtual_path.DirName().value() == virtual_path.value()) { |
- Send(new ViewMsg_FileSystem_DidFail( |
- request_id, base::PLATFORM_FILE_ERROR_SECURITY)); |
- return false; |
- } |
- if (create && context_->path_manager()->IsRestrictedFileName( |
- path.BaseName())) { |
- Send(new ViewMsg_FileSystem_DidFail( |
- request_id, base::PLATFORM_FILE_ERROR_SECURITY)); |
- return false; |
- } |
- // TODO(kinuko): For operations with kUnknownSize we'll eventually |
- // need to resolve what amount of size it's going to write. |
- if (!context_->CheckOriginQuota(origin_url, growth)) { |
- Send(new ViewMsg_FileSystem_DidFail( |
- request_id, base::PLATFORM_FILE_ERROR_NO_SPACE)); |
- return false; |
- } |
- return true; |
-} |
- |
-bool FileSystemDispatcherHost::CheckIfFilePathIsSafe( |
- const FilePath& path, int request_id) { |
- if (context_->path_manager()->IsRestrictedFileName(path.BaseName())) { |
- Send(new ViewMsg_FileSystem_DidFail( |
- request_id, base::PLATFORM_FILE_ERROR_SECURITY)); |
- return false; |
- } |
- return true; |
-} |
- |
-fileapi::FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( |
+SandboxedFileSystemOperation* FileSystemDispatcherHost::GetNewOperation( |
int request_id) { |
BrowserFileSystemCallbackDispatcher* dispatcher = |
new BrowserFileSystemCallbackDispatcher(this, request_id); |
- fileapi::FileSystemOperation* operation = new fileapi::FileSystemOperation( |
+ SandboxedFileSystemOperation* operation = new SandboxedFileSystemOperation( |
dispatcher, |
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
+ context_.get()); |
operations_.AddWithID(operation, request_id); |
return operation; |
} |