summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/file_system/file_system_dispatcher_host.cc67
-rw-r--r--content/browser/file_system/file_system_dispatcher_host.h12
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.cc13
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.h7
-rw-r--r--webkit/fileapi/file_system_context.cc20
-rw-r--r--webkit/fileapi/file_system_context.h12
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job.cc24
-rw-r--r--webkit/fileapi/file_system_dir_url_request_job.h6
-rw-r--r--webkit/fileapi/file_system_mount_point_provider.h21
-rw-r--r--webkit/fileapi/file_system_operation.cc30
-rw-r--r--webkit/fileapi/file_system_operation.h14
-rw-r--r--webkit/fileapi/file_system_operation_interface.h6
-rw-r--r--webkit/fileapi/file_system_url_request_job.cc18
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc12
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.h7
-rw-r--r--webkit/tools/test_shell/simple_file_system.cc35
-rw-r--r--webkit/tools/test_shell/simple_file_system.h8
-rw-r--r--webkit/tools/test_shell/simple_file_writer.cc16
18 files changed, 238 insertions, 90 deletions
diff --git a/content/browser/file_system/file_system_dispatcher_host.cc b/content/browser/file_system/file_system_dispatcher_host.cc
index e4469af..3be7331 100644
--- a/content/browser/file_system/file_system_dispatcher_host.cc
+++ b/content/browser/file_system/file_system_dispatcher_host.cc
@@ -21,9 +21,9 @@
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
-#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_quota_util.h"
#include "webkit/fileapi/file_system_util.h"
+#include "webkit/fileapi/sandbox_mount_point_provider.h"
using content::BrowserMessageFilter;
using content::BrowserThread;
@@ -31,6 +31,7 @@ using content::UserMetricsAction;
using fileapi::FileSystemCallbackDispatcher;
using fileapi::FileSystemFileUtil;
using fileapi::FileSystemOperation;
+using fileapi::FileSystemOperationInterface;
class BrowserFileSystemCallbackDispatcher
: public FileSystemCallbackDispatcher {
@@ -186,44 +187,45 @@ void FileSystemDispatcherHost::OnOpen(
void FileSystemDispatcherHost::OnMove(
int request_id, const GURL& src_path, const GURL& dest_path) {
- GetNewOperation(request_id)->Move(src_path, dest_path);
+ GetNewOperation(src_path, request_id)->Move(src_path, dest_path);
}
void FileSystemDispatcherHost::OnCopy(
int request_id, const GURL& src_path, const GURL& dest_path) {
- GetNewOperation(request_id)->Copy(src_path, dest_path);
+ GetNewOperation(src_path, request_id)->Copy(src_path, dest_path);
}
void FileSystemDispatcherHost::OnRemove(
int request_id, const GURL& path, bool recursive) {
- GetNewOperation(request_id)->Remove(path, recursive);
+ GetNewOperation(path, request_id)->Remove(path, recursive);
}
void FileSystemDispatcherHost::OnReadMetadata(
int request_id, const GURL& path) {
- GetNewOperation(request_id)->GetMetadata(path);
+ GetNewOperation(path, request_id)->GetMetadata(path);
}
void FileSystemDispatcherHost::OnCreate(
int request_id, const GURL& path, bool exclusive,
bool is_directory, bool recursive) {
if (is_directory)
- GetNewOperation(request_id)->CreateDirectory(path, exclusive, recursive);
+ GetNewOperation(path, request_id)->CreateDirectory(
+ path, exclusive, recursive);
else
- GetNewOperation(request_id)->CreateFile(path, exclusive);
+ GetNewOperation(path, request_id)->CreateFile(path, exclusive);
}
void FileSystemDispatcherHost::OnExists(
int request_id, const GURL& path, bool is_directory) {
if (is_directory)
- GetNewOperation(request_id)->DirectoryExists(path);
+ GetNewOperation(path, request_id)->DirectoryExists(path);
else
- GetNewOperation(request_id)->FileExists(path);
+ GetNewOperation(path, request_id)->FileExists(path);
}
void FileSystemDispatcherHost::OnReadDirectory(
int request_id, const GURL& path) {
- GetNewOperation(request_id)->ReadDirectory(path);
+ GetNewOperation(path, request_id)->ReadDirectory(path);
}
void FileSystemDispatcherHost::OnWrite(
@@ -236,7 +238,7 @@ void FileSystemDispatcherHost::OnWrite(
NOTREACHED();
return;
}
- GetNewOperation(request_id)->Write(
+ GetNewOperation(path, request_id)->Write(
request_context_, path, blob_url, offset);
}
@@ -244,7 +246,7 @@ void FileSystemDispatcherHost::OnTruncate(
int request_id,
const GURL& path,
int64 length) {
- GetNewOperation(request_id)->Truncate(path, length);
+ GetNewOperation(path, request_id)->Truncate(path, length);
}
void FileSystemDispatcherHost::OnTouchFile(
@@ -252,14 +254,14 @@ void FileSystemDispatcherHost::OnTouchFile(
const GURL& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
- GetNewOperation(request_id)->TouchFile(
+ GetNewOperation(path, request_id)->TouchFile(
path, last_access_time, last_modified_time);
}
void FileSystemDispatcherHost::OnCancel(
int request_id,
int request_id_to_cancel) {
- FileSystemOperation* write = operations_.Lookup(
+ FileSystemOperationInterface* write = operations_.Lookup(
request_id_to_cancel);
if (write) {
// The cancel will eventually send both the write failure and the cancel
@@ -275,7 +277,7 @@ void FileSystemDispatcherHost::OnCancel(
void FileSystemDispatcherHost::OnOpenFile(
int request_id, const GURL& path, int file_flags) {
- GetNewOperation(request_id)->OpenFile(path, file_flags, peer_handle());
+ GetNewOperation(path, request_id)->OpenFile(path, file_flags, peer_handle());
}
void FileSystemDispatcherHost::OnWillUpdate(const GURL& path) {
@@ -308,20 +310,37 @@ void FileSystemDispatcherHost::OnSyncGetPlatformPath(
DCHECK(platform_path);
*platform_path = FilePath();
- FileSystemOperation* operation = new FileSystemOperation(
- scoped_ptr<FileSystemCallbackDispatcher>(NULL),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
- context_);
+ GURL origin_url;
+ fileapi::FileSystemType file_system_type = fileapi::kFileSystemTypeUnknown;
+ FilePath file_path;
+ if (!fileapi::CrackFileSystemURL(
+ path, &origin_url, &file_system_type, &file_path)) {
+ return;
+ }
+ // This is called only by pepper plugin as of writing to get the
+ // underlying platform path to upload a file in the sandboxed filesystem
+ // (e.g. TEMPORARY or PERSISTENT).
+ // TODO(kinuko): this hack should go away once appropriate upload-stream
+ // handling based on element types is supported.
+ FileSystemOperation* operation =
+ context_->CreateFileSystemOperation(
+ path, scoped_ptr<FileSystemCallbackDispatcher>(NULL),
+ BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::FILE))->AsFileSystemOperation();
+ DCHECK(operation);
operation->SyncGetPlatformPath(path, platform_path);
}
-FileSystemOperation* FileSystemDispatcherHost::GetNewOperation(
+FileSystemOperationInterface* FileSystemDispatcherHost::GetNewOperation(
+ const GURL& target_path,
int request_id) {
- FileSystemOperation* operation = new FileSystemOperation(
- BrowserFileSystemCallbackDispatcher::Create(this, request_id),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
- context_);
+ FileSystemOperationInterface* operation =
+ context_->CreateFileSystemOperation(
+ target_path,
+ BrowserFileSystemCallbackDispatcher::Create(this, request_id),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
+ DCHECK(operation);
operations_.AddWithID(operation, request_id);
return operation;
}
diff --git a/content/browser/file_system/file_system_dispatcher_host.h b/content/browser/file_system/file_system_dispatcher_host.h
index 17fe2db..ebce214 100644
--- a/content/browser/file_system/file_system_dispatcher_host.h
+++ b/content/browser/file_system/file_system_dispatcher_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -21,7 +21,7 @@ class Time;
namespace fileapi {
class FileSystemContext;
-class FileSystemOperation;
+class FileSystemOperationInterface;
}
namespace net {
@@ -88,13 +88,15 @@ class FileSystemDispatcherHost : public content::BrowserMessageFilter {
void OnSyncGetPlatformPath(const GURL& path,
FilePath* platform_path);
- // Creates a new FileSystemOperation.
- fileapi::FileSystemOperation* GetNewOperation(int request_id);
+ // Creates a new FileSystemOperationInterface based on |target_path|.
+ fileapi::FileSystemOperationInterface* GetNewOperation(
+ const GURL& target_path,
+ int request_id);
fileapi::FileSystemContext* context_;
// Keeps ongoing file system operations.
- typedef IDMap<fileapi::FileSystemOperation> OperationsMap;
+ typedef IDMap<fileapi::FileSystemOperationInterface> OperationsMap;
OperationsMap operations_;
// The getter holds the context until Init() can be called from the
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
index 8951c0c7..a28cf159 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
@@ -16,6 +16,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "webkit/chromeos/fileapi/file_access_permissions.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"
@@ -177,6 +178,18 @@ fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil() {
return local_file_util_.get();
}
+FileSystemOperationInterface* CrosMountPointProvider::CreateFileSystemOperation(
+ const GURL& origin_url,
+ FileSystemType file_system_type,
+ const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy,
+ FileSystemContext* context) const {
+ // TODO(satorux,zel): instantiate appropriate FileSystemOperation that
+ // implements async/remote operations.
+ return new FileSystemOperation(dispatcher.Pass(), file_proxy, context);
+}
+
bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path,
FilePath* virtual_path) {
for (MountPointMap::const_iterator iter = mount_point_map_.begin();
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h
index 7cf55ea..8ca6216 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.h
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h
@@ -53,6 +53,13 @@ class CrosMountPointProvider
virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE;
virtual std::vector<FilePath> GetRootDirectories() const OVERRIDE;
virtual fileapi::FileSystemFileUtil* GetFileUtil() OVERRIDE;
+ virtual FileSystemOperationInterface* CreateFileSystemOperation(
+ const GURL& origin_url,
+ FileSystemType file_system_type,
+ const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy,
+ FileSystemContext* context) const OVERRIDE;
// fileapi::ExternalFileSystemMountPointProvider overrides.
virtual void GrantFullAccessToExtension(
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc
index 7cdc66d..3abc454 100644
--- a/webkit/fileapi/file_system_context.cc
+++ b/webkit/fileapi/file_system_context.cc
@@ -11,6 +11,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_file_util.h"
+#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/fileapi/file_system_options.h"
#include "webkit/fileapi/file_system_quota_client.h"
#include "webkit/fileapi/file_system_util.h"
@@ -159,6 +160,7 @@ void FileSystemContext::OpenFileSystem(
bool create,
scoped_ptr<FileSystemCallbackDispatcher> dispatcher) {
DCHECK(dispatcher.get());
+
FileSystemMountPointProvider* mount_point_provider =
GetMountPointProvider(type);
if (!mount_point_provider) {
@@ -175,6 +177,24 @@ void FileSystemContext::OpenFileSystem(
base::Passed(&dispatcher), root_url, name));
}
+FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation(
+ const GURL& url,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy) {
+ GURL origin_url;
+ FileSystemType file_system_type = kFileSystemTypeUnknown;
+ FilePath file_path;
+ if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path))
+ return NULL;
+ FileSystemMountPointProvider* mount_point_provider =
+ GetMountPointProvider(file_system_type);
+ if (!mount_point_provider)
+ return NULL;
+ return mount_point_provider->CreateFileSystemOperation(
+ origin_url, file_system_type, file_path,
+ dispatcher.Pass(), file_proxy, this);
+}
+
} // namespace fileapi
COMPILE_ASSERT(int(WebKit::WebFileSystem::TypeTemporary) == \
diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h
index f7e1086..d57b2e3 100644
--- a/webkit/fileapi/file_system_context.h
+++ b/webkit/fileapi/file_system_context.h
@@ -7,6 +7,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/platform_file.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/quota/special_storage_policy.h"
@@ -28,6 +29,7 @@ class FileSystemCallbackDispatcher;
class FileSystemContext;
class FileSystemFileUtil;
class FileSystemMountPointProvider;
+class FileSystemOperationInterface;
class FileSystemOptions;
class FileSystemPathManager;
class FileSystemQuotaUtil;
@@ -97,6 +99,16 @@ class FileSystemContext
bool create,
scoped_ptr<FileSystemCallbackDispatcher> dispatcher);
+ // Creates a new FileSystemOperation instance by cracking
+ // the given filesystem URL |url| to get an appropriate MountPointProvider
+ // and calling the provider's corresponding CreateFileSystemOperation method.
+ // The resolved MountPointProvider could perform further specialization
+ // depending on the filesystem type pointed by the |url|.
+ FileSystemOperationInterface* CreateFileSystemOperation(
+ const GURL& url,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy);
+
private:
friend struct DefaultContextDeleter;
void DeleteOnCorrectThread() const;
diff --git a/webkit/fileapi/file_system_dir_url_request_job.cc b/webkit/fileapi/file_system_dir_url_request_job.cc
index 83a5455..b96d7e4 100644
--- a/webkit/fileapi/file_system_dir_url_request_job.cc
+++ b/webkit/fileapi/file_system_dir_url_request_job.cc
@@ -21,6 +21,7 @@
#include "net/base/net_util.h"
#include "net/url_request/url_request.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
+#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_util.h"
@@ -139,8 +140,15 @@ bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) {
}
void FileSystemDirURLRequestJob::StartAsync() {
- if (request_)
- GetNewOperation()->ReadDirectory(request_->url());
+ if (!request_)
+ return;
+ FileSystemOperationInterface* operation = GetNewOperation(request_->url());
+ if (!operation) {
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
+ net::ERR_INVALID_URL));
+ return;
+ }
+ operation->ReadDirectory(request_->url());
}
void FileSystemDirURLRequestJob::DidReadDirectory(
@@ -174,17 +182,19 @@ void FileSystemDirURLRequestJob::DidReadDirectory(
}
if (has_more) {
- GetNewOperation()->ReadDirectory(request_->url());
+ GetNewOperation(request_->url())->ReadDirectory(request_->url());
} else {
set_expected_content_size(data_.size());
NotifyHeadersComplete();
}
}
-FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation() {
- return new FileSystemOperation(CallbackDispatcher::Create(this),
- file_thread_proxy_,
- file_system_context_);
+FileSystemOperationInterface*
+FileSystemDirURLRequestJob::GetNewOperation(const GURL& url) {
+ return file_system_context_->CreateFileSystemOperation(
+ url,
+ CallbackDispatcher::Create(this),
+ file_thread_proxy_);
}
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_dir_url_request_job.h b/webkit/fileapi/file_system_dir_url_request_job.h
index 6176e12..1e7179b 100644
--- a/webkit/fileapi/file_system_dir_url_request_job.h
+++ b/webkit/fileapi/file_system_dir_url_request_job.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -18,7 +18,7 @@
namespace fileapi {
class FileSystemContext;
-class FileSystemOperation;
+class FileSystemOperationInterface;
// A request job that handles reading filesystem: URLs for directories.
class FileSystemDirURLRequestJob : public net::URLRequestJob {
@@ -49,7 +49,7 @@ class FileSystemDirURLRequestJob : public net::URLRequestJob {
void StartAsync();
void DidReadDirectory(const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more);
- FileSystemOperation* GetNewOperation();
+ FileSystemOperationInterface* GetNewOperation(const GURL& url);
std::string data_;
FileSystemContext* file_system_context_;
diff --git a/webkit/fileapi/file_system_mount_point_provider.h b/webkit/fileapi/file_system_mount_point_provider.h
index 24a8f53..c51e967 100644
--- a/webkit/fileapi/file_system_mount_point_provider.h
+++ b/webkit/fileapi/file_system_mount_point_provider.h
@@ -9,15 +9,23 @@
#include <vector>
#include "base/callback_forward.h"
+#include "base/platform_file.h"
#include "base/file_path.h"
#include "base/platform_file.h"
#include "webkit/fileapi/file_system_types.h"
class GURL;
+namespace base {
+class MessageLoopProxy;
+}
+
namespace fileapi {
+class FileSystemCallbackDispatcher;
+class FileSystemContext;
class FileSystemFileUtil;
+class FileSystemOperationInterface;
// An interface to provide mount-point-specific path-related utilities
// and specialized FileSystemFileUtil instance.
@@ -65,6 +73,19 @@ class FileSystemMountPointProvider {
// Returns the specialized FileSystemFileUtil for this mount point.
virtual FileSystemFileUtil* GetFileUtil() = 0;
+
+ // Returns a new instance of the specialized FileSystemOperation for this
+ // mount point based on the given triplet of |origin_url|, |file_system_type|
+ // and |virtual_path|.
+ // This method is usually dispatched by
+ // FileSystemContext::CreateFileSystemOperation.
+ virtual FileSystemOperationInterface* CreateFileSystemOperation(
+ const GURL& origin_url,
+ FileSystemType file_system_type,
+ const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy,
+ FileSystemContext* context) const = 0;
};
// An interface to control external file system access permissions.
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index 7189287..c0b922b 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -57,19 +57,6 @@ FileSystemOperation::ScopedQuotaUtilHelper::~ScopedQuotaUtilHelper() {
}
}
-FileSystemOperation::FileSystemOperation(
- scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
- scoped_refptr<base::MessageLoopProxy> proxy,
- FileSystemContext* file_system_context)
- : proxy_(proxy),
- dispatcher_(dispatcher.Pass()),
- operation_context_(file_system_context, NULL),
- peer_handle_(base::kNullProcessHandle) {
-#ifndef NDEBUG
- pending_operation_ = kOperationNone;
-#endif
-}
-
FileSystemOperation::~FileSystemOperation() {
if (file_writer_delegate_.get()) {
FileSystemOperationContext* c =
@@ -521,6 +508,10 @@ void FileSystemOperation::Cancel(
}
}
+FileSystemOperation* FileSystemOperation::AsFileSystemOperation() {
+ return this;
+}
+
void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
FilePath* platform_path) {
#ifndef NDEBUG
@@ -538,6 +529,19 @@ void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
delete this;
}
+FileSystemOperation::FileSystemOperation(
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ scoped_refptr<base::MessageLoopProxy> proxy,
+ FileSystemContext* file_system_context)
+ : proxy_(proxy),
+ dispatcher_(dispatcher.Pass()),
+ operation_context_(file_system_context, NULL),
+ peer_handle_(base::kNullProcessHandle) {
+#ifndef NDEBUG
+ pending_operation_ = kOperationNone;
+#endif
+}
+
void FileSystemOperation::GetUsageAndQuotaThenCallback(
const GURL& origin_url,
const quota::QuotaManager::GetUsageAndQuotaCallback& callback) {
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index f8785e4..550b54b 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -43,9 +43,6 @@ class FileSystemOperationTest;
// FileSystemOperation implementation for local file systems.
class FileSystemOperation : public FileSystemOperationInterface {
public:
- FileSystemOperation(scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
- scoped_refptr<base::MessageLoopProxy> proxy,
- FileSystemContext* file_system_context);
virtual ~FileSystemOperation();
// FileSystemOperation overrides.
@@ -77,6 +74,7 @@ class FileSystemOperation : public FileSystemOperationInterface {
base::ProcessHandle peer_handle) OVERRIDE;
virtual void Cancel(
scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) OVERRIDE;
+ virtual FileSystemOperation* AsFileSystemOperation() OVERRIDE;
// Synchronously gets the platform path for the given |path|.
void SyncGetPlatformPath(const GURL& path, FilePath* platform_path);
@@ -84,6 +82,16 @@ class FileSystemOperation : public FileSystemOperationInterface {
private:
class ScopedQuotaUtilHelper;
+ // Only MountPointProviders or testing class can create a
+ // new operation directly.
+ friend class SandboxMountPointProvider;
+ friend class CrosMountPointProvider;
+ friend class FileSystemTestHelper;
+
+ FileSystemOperation(scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ scoped_refptr<base::MessageLoopProxy> proxy,
+ FileSystemContext* file_system_context);
+
FileSystemContext* file_system_context() const {
return operation_context_.file_system_context();
}
diff --git a/webkit/fileapi/file_system_operation_interface.h b/webkit/fileapi/file_system_operation_interface.h
index ef75e4c..6a8a894 100644
--- a/webkit/fileapi/file_system_operation_interface.h
+++ b/webkit/fileapi/file_system_operation_interface.h
@@ -21,6 +21,7 @@ class GURL;
namespace fileapi {
class FileSystemCallbackDispatcher;
+class FileSystemOperation;
// The interface class for FileSystemOperation implementations.
//
@@ -145,6 +146,11 @@ class FileSystemOperationInterface {
const GURL& path,
int file_flags,
base::ProcessHandle peer_handle) = 0;
+
+ // For downcasting to FileSystemOperation.
+ // TODO(kinuko): this hack should go away once appropriate upload-stream
+ // handling based on element types is supported.
+ virtual FileSystemOperation* AsFileSystemOperation() = 0;
};
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_url_request_job.cc b/webkit/fileapi/file_system_url_request_job.cc
index a617d6a..d01dc40 100644
--- a/webkit/fileapi/file_system_url_request_job.cc
+++ b/webkit/fileapi/file_system_url_request_job.cc
@@ -23,6 +23,7 @@
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
+#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_util.h"
@@ -219,12 +220,19 @@ int FileSystemURLRequestJob::GetResponseCode() const {
}
void FileSystemURLRequestJob::StartAsync() {
- if (request_) {
- (new FileSystemOperation(CallbackDispatcher::Create(this),
- file_thread_proxy_,
- file_system_context_)
- )->GetMetadata(request_->url());
+ if (!request_)
+ return;
+ FileSystemOperationInterface* operation =
+ file_system_context_->CreateFileSystemOperation(
+ request_->url(),
+ CallbackDispatcher::Create(this),
+ file_thread_proxy_);
+ if (!operation) {
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
+ net::ERR_INVALID_URL));
+ return;
}
+ operation->GetMetadata(request_->url());
}
void FileSystemURLRequestJob::DidGetMetadata(
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index c0b65f2..1b2dc96 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -16,6 +16,7 @@
#include "base/metrics/histogram.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_options.h"
@@ -410,6 +411,17 @@ FileSystemFileUtil* SandboxMountPointProvider::GetFileUtil() {
return sandbox_file_util_.get();
}
+FileSystemOperationInterface*
+SandboxMountPointProvider::CreateFileSystemOperation(
+ const GURL& origin_url,
+ FileSystemType file_system_type,
+ const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy,
+ FileSystemContext* context) const {
+ return new FileSystemOperation(dispatcher.Pass(), file_proxy, context);
+}
+
FilePath SandboxMountPointProvider::old_base_path() const {
return profile_path_.Append(kOldFileSystemDirectory);
}
diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h
index 2ee584e..b00754d 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.h
+++ b/webkit/fileapi/sandbox_mount_point_provider.h
@@ -85,6 +85,13 @@ class SandboxMountPointProvider
virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE;
virtual std::vector<FilePath> GetRootDirectories() const OVERRIDE;
virtual FileSystemFileUtil* GetFileUtil() OVERRIDE;
+ virtual FileSystemOperationInterface* CreateFileSystemOperation(
+ const GURL& origin_url,
+ FileSystemType file_system_type,
+ const FilePath& virtual_path,
+ scoped_ptr<FileSystemCallbackDispatcher> dispatcher,
+ base::MessageLoopProxy* file_proxy,
+ FileSystemContext* context) const OVERRIDE;
FilePath old_base_path() const;
FilePath new_base_path() const;
diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc
index 8eb34fb..4dfb1ac 100644
--- a/webkit/tools/test_shell/simple_file_system.cc
+++ b/webkit/tools/test_shell/simple_file_system.cc
@@ -20,7 +20,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
-#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/mock_file_system_options.h"
#include "webkit/glue/webkit_glue.h"
@@ -42,7 +42,7 @@ using WebKit::WebVector;
using fileapi::FileSystemCallbackDispatcher;
using fileapi::FileSystemContext;
-using fileapi::FileSystemOperation;
+using fileapi::FileSystemOperationInterface;
namespace {
@@ -179,53 +179,53 @@ void SimpleFileSystem::OpenFileSystem(
void SimpleFileSystem::move(
const WebURL& src_path,
const WebURL& dest_path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path));
+ GetNewOperation(src_path, callbacks)->Move(GURL(src_path), GURL(dest_path));
}
void SimpleFileSystem::copy(
const WebURL& src_path, const WebURL& dest_path,
WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path));
+ GetNewOperation(src_path, callbacks)->Copy(GURL(src_path), GURL(dest_path));
}
void SimpleFileSystem::remove(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Remove(path, false /* recursive */);
+ GetNewOperation(path, callbacks)->Remove(path, false /* recursive */);
}
void SimpleFileSystem::removeRecursively(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->Remove(path, true /* recursive */);
+ GetNewOperation(path, callbacks)->Remove(path, true /* recursive */);
}
void SimpleFileSystem::readMetadata(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->GetMetadata(path);
+ GetNewOperation(path, callbacks)->GetMetadata(path);
}
void SimpleFileSystem::createFile(
const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->CreateFile(path, exclusive);
+ GetNewOperation(path, callbacks)->CreateFile(path, exclusive);
}
void SimpleFileSystem::createDirectory(
const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->CreateDirectory(path, exclusive, false);
+ GetNewOperation(path, callbacks)->CreateDirectory(path, exclusive, false);
}
void SimpleFileSystem::fileExists(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->FileExists(path);
+ GetNewOperation(path, callbacks)->FileExists(path);
}
void SimpleFileSystem::directoryExists(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->DirectoryExists(path);
+ GetNewOperation(path, callbacks)->DirectoryExists(path);
}
void SimpleFileSystem::readDirectory(
const WebURL& path, WebFileSystemCallbacks* callbacks) {
- GetNewOperation(callbacks)->ReadDirectory(path);
+ GetNewOperation(path, callbacks)->ReadDirectory(path);
}
WebFileWriter* SimpleFileSystem::createFileWriter(
@@ -233,11 +233,10 @@ WebFileWriter* SimpleFileSystem::createFileWriter(
return new SimpleFileWriter(path, client, file_system_context_.get());
}
-FileSystemOperation* SimpleFileSystem::GetNewOperation(
- WebFileSystemCallbacks* callbacks) {
- FileSystemOperation* operation = new FileSystemOperation(
+FileSystemOperationInterface* SimpleFileSystem::GetNewOperation(
+ const WebURL& url, WebFileSystemCallbacks* callbacks) {
+ return file_system_context_->CreateFileSystemOperation(
+ GURL(url),
SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks),
- base::MessageLoopProxy::current(),
- file_system_context_.get());
- return operation;
+ base::MessageLoopProxy::current());
}
diff --git a/webkit/tools/test_shell/simple_file_system.h b/webkit/tools/test_shell/simple_file_system.h
index 90693ff..82c2e01 100644
--- a/webkit/tools/test_shell/simple_file_system.h
+++ b/webkit/tools/test_shell/simple_file_system.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -21,7 +21,7 @@ class WebURL;
namespace fileapi {
class FileSystemContext;
-class FileSystemOperation;
+class FileSystemOperationInterface;
}
class SimpleFileSystem
@@ -81,8 +81,8 @@ class SimpleFileSystem
private:
// Helpers.
- fileapi::FileSystemOperation* GetNewOperation(
- WebKit::WebFileSystemCallbacks* callbacks);
+ fileapi::FileSystemOperationInterface* GetNewOperation(
+ const WebKit::WebURL& path, WebKit::WebFileSystemCallbacks* callbacks);
// A temporary directory for FileSystem API.
ScopedTempDir file_system_dir_;
diff --git a/webkit/tools/test_shell/simple_file_writer.cc b/webkit/tools/test_shell/simple_file_writer.cc
index 169106b..cdd36b1 100644
--- a/webkit/tools/test_shell/simple_file_writer.cc
+++ b/webkit/tools/test_shell/simple_file_writer.cc
@@ -10,13 +10,13 @@
#include "net/url_request/url_request_context.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
-#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_operation_interface.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
using fileapi::FileSystemCallbackDispatcher;
using fileapi::FileSystemContext;
-using fileapi::FileSystemOperation;
+using fileapi::FileSystemOperationInterface;
using fileapi::WebFileWriterBase;
using WebKit::WebFileWriterClient;
using WebKit::WebString;
@@ -52,7 +52,7 @@ class SimpleFileWriter::IOThreadProxy
return;
}
DCHECK(!operation_);
- operation_ = GetNewOperation();
+ operation_ = GetNewOperation(path);
operation_->Truncate(path, offset);
}
@@ -65,7 +65,7 @@ class SimpleFileWriter::IOThreadProxy
}
DCHECK(request_context_);
DCHECK(!operation_);
- operation_ = GetNewOperation();
+ operation_ = GetNewOperation(path);
operation_->Write(request_context_, path, blob_url, offset);
}
@@ -134,10 +134,10 @@ class SimpleFileWriter::IOThreadProxy
scoped_refptr<IOThreadProxy> proxy_;
};
- FileSystemOperation* GetNewOperation() {
+ FileSystemOperationInterface* GetNewOperation(const GURL& path) {
// The FileSystemOperation takes ownership of the CallbackDispatcher.
- return new FileSystemOperation(CallbackDispatcher::Create(this),
- io_thread_, file_system_context_.get());
+ return file_system_context_->CreateFileSystemOperation(
+ path, CallbackDispatcher::Create(this), io_thread_);
}
void DidSucceed() {
@@ -185,7 +185,7 @@ class SimpleFileWriter::IOThreadProxy
base::WeakPtr<SimpleFileWriter> simple_writer_;
// Only used on the io thread.
- FileSystemOperation* operation_;
+ FileSystemOperationInterface* operation_;
scoped_refptr<FileSystemContext> file_system_context_;
};