summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-21 01:06:55 +0000
committernhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-21 01:06:55 +0000
commit8355b7629254490bf8aa89d9fd5779f4559ac168 (patch)
tree10f982d6b45befc8531390fa2d1795e8628ad278
parent4e16817c5d3145408ea306ae1c6bf2f1d5a8421f (diff)
downloadchromium_src-8355b7629254490bf8aa89d9fd5779f4559ac168.zip
chromium_src-8355b7629254490bf8aa89d9fd5779f4559ac168.tar.gz
chromium_src-8355b7629254490bf8aa89d9fd5779f4559ac168.tar.bz2
[Retry] SyncFS: Support resolveLocalFileSystemURL on SyncFileSystem
Original review: https://codereview.chromium.org/23856002/ window.resolveLocalFileSystemURL is originally defined only for FileSystem API, but it'd be nice if it works on SyncFileSystem in a similar way. For that this change adds new IPC messages and interfaces. Blink side change depends on this: https://codereview.chromium.org/23537011/ BUG=177137,294502 TEST=manual (Get FileSystemURL for a file on SyncFS, and then resolve it) TEST=unit_tests TEST=run_webkit_tests.sh http/tests/filesystem/\* TEST=run_webkit_tests.sh http/tests/inspector/filesystem/\* TBR=tsepez@chromium.org NOTRY=true Review URL: https://chromiumcodereview.appspot.com/23526076 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224542 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync_file_system/local/local_file_sync_context.cc2
-rw-r--r--chrome/browser/sync_file_system/local/sync_file_system_backend.cc6
-rw-r--r--chrome/browser/sync_file_system/sync_file_system_service_factory.cc5
-rw-r--r--chrome/browser/sync_file_system/syncable_file_system_util_unittest.cc38
-rw-r--r--content/browser/fileapi/fileapi_message_filter.cc40
-rw-r--r--content/browser/fileapi/fileapi_message_filter.h10
-rw-r--r--content/child/fileapi/file_system_dispatcher.cc38
-rw-r--r--content/child/fileapi/file_system_dispatcher.h12
-rw-r--r--content/child/fileapi/webfilesystem_impl.cc36
-rw-r--r--content/child/fileapi/webfilesystem_impl.h3
-rw-r--r--content/common/fileapi/file_system_messages.h17
-rw-r--r--webkit/browser/fileapi/file_system_context.cc68
-rw-r--r--webkit/browser/fileapi/file_system_context.h25
-rw-r--r--webkit/common/fileapi/file_system_info.cc24
-rw-r--r--webkit/common/fileapi/file_system_info.h31
-rw-r--r--webkit/common/fileapi/file_system_util.cc2
-rw-r--r--webkit/storage_common.gyp2
17 files changed, 306 insertions, 53 deletions
diff --git a/chrome/browser/sync_file_system/local/local_file_sync_context.cc b/chrome/browser/sync_file_system/local/local_file_sync_context.cc
index 8e45cf2..b4f3a03 100644
--- a/chrome/browser/sync_file_system/local/local_file_sync_context.cc
+++ b/chrome/browser/sync_file_system/local/local_file_sync_context.cc
@@ -507,8 +507,6 @@ void LocalFileSyncContext::InitializeFileSystemContextOnIOThread(
SyncFileSystemBackend::GetBackend(file_system_context);
DCHECK(backend);
if (!backend->change_tracker()) {
- // First registers the service name.
- RegisterSyncableFileSystem();
// Create and initialize LocalFileChangeTracker and call back this method
// later again.
std::set<GURL>* origins_with_changes = new std::set<GURL>;
diff --git a/chrome/browser/sync_file_system/local/sync_file_system_backend.cc b/chrome/browser/sync_file_system/local/sync_file_system_backend.cc
index 1c9eef5..199c233 100644
--- a/chrome/browser/sync_file_system/local/sync_file_system_backend.cc
+++ b/chrome/browser/sync_file_system/local/sync_file_system_backend.cc
@@ -66,9 +66,15 @@ SyncFileSystemBackend::SyncFileSystemBackend(Profile* profile)
DCHECK(CalledOnUIThread());
if (profile)
profile_holder_.reset(new ProfileHolder(profile));
+
+ // Register the service name here to enable to crack an URL on SyncFileSystem
+ // even if SyncFileSystemService has not started yet.
+ RegisterSyncableFileSystem();
}
SyncFileSystemBackend::~SyncFileSystemBackend() {
+ RevokeSyncableFileSystem();
+
if (change_tracker_) {
GetDelegate()->file_task_runner()->DeleteSoon(
FROM_HERE, change_tracker_.release());
diff --git a/chrome/browser/sync_file_system/sync_file_system_service_factory.cc b/chrome/browser/sync_file_system/sync_file_system_service_factory.cc
index 2adb67c..a49355a 100644
--- a/chrome/browser/sync_file_system/sync_file_system_service_factory.cc
+++ b/chrome/browser/sync_file_system/sync_file_system_service_factory.cc
@@ -71,8 +71,6 @@ SyncFileSystemServiceFactory::BuildServiceInstanceFor(
remote_file_service = mock_remote_file_service_.Pass();
} else if (CommandLine::ForCurrentProcess()->HasSwitch(
kEnableSyncFileSystemV2)) {
- RegisterSyncableFileSystem();
-
GURL base_drive_url(
google_apis::DriveApiUrlGenerator::kBaseUrlForProduction);
GURL base_download_url(
@@ -114,9 +112,6 @@ SyncFileSystemServiceFactory::BuildServiceInstanceFor(
sync_engine->Initialize();
remote_file_service = sync_engine.PassAs<RemoteFileSyncService>();
} else {
- // FileSystem needs to be registered before DriveFileSyncService runs
- // its initialization code.
- RegisterSyncableFileSystem();
remote_file_service =
DriveFileSyncService::Create(profile).PassAs<RemoteFileSyncService>();
}
diff --git a/chrome/browser/sync_file_system/syncable_file_system_util_unittest.cc b/chrome/browser/sync_file_system/syncable_file_system_util_unittest.cc
index b3804b4..31bc00d 100644
--- a/chrome/browser/sync_file_system/syncable_file_system_util_unittest.cc
+++ b/chrome/browser/sync_file_system/syncable_file_system_util_unittest.cc
@@ -112,44 +112,6 @@ TEST(SyncableFileSystemUtilTest,
RevokeSyncableFileSystem();
}
-TEST(SyncableFileSystemUtilTest, SerializeBeforeOpenFileSystem) {
- ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
- const std::string serialized = kSyncableFileSystemRootURI +
- CreateNormalizedFilePath(kPath).AsUTF8Unsafe();
- FileSystemURL deserialized;
- base::MessageLoop message_loop;
-
- // Setting up a full syncable filesystem environment.
- CannedSyncableFileSystem file_system(GURL(kOrigin),
- base::MessageLoopProxy::current().get(),
- base::MessageLoopProxy::current().get());
- file_system.SetUp();
- scoped_refptr<LocalFileSyncContext> sync_context =
- new LocalFileSyncContext(base::FilePath(),
- base::MessageLoopProxy::current().get(),
- base::MessageLoopProxy::current().get());
-
- // Before calling initialization we would not be able to get a valid
- // deserialized URL.
- EXPECT_FALSE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
- EXPECT_FALSE(deserialized.is_valid());
-
- ASSERT_EQ(sync_file_system::SYNC_STATUS_OK,
- file_system.MaybeInitializeFileSystemContext(sync_context.get()));
-
- // After initialization this should be ok (even before opening the file
- // system).
- EXPECT_TRUE(DeserializeSyncableFileSystemURL(serialized, &deserialized));
- EXPECT_TRUE(deserialized.is_valid());
-
- // Shutting down.
- file_system.TearDown();
- RevokeSyncableFileSystem();
- sync_context->ShutdownOnUIThread();
- sync_context = NULL;
- base::MessageLoop::current()->RunUntilIdle();
-}
-
TEST(SyncableFileSystemUtilTest, SyncableFileSystemURL_IsParent) {
RegisterSyncableFileSystem();
diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc
index ef5f248..1a79ea2 100644
--- a/content/browser/fileapi/fileapi_message_filter.cc
+++ b/content/browser/fileapi/fileapi_message_filter.cc
@@ -38,6 +38,7 @@
#include "webkit/common/blob/blob_data.h"
#include "webkit/common/blob/shareable_file_reference.h"
#include "webkit/common/fileapi/directory_entry.h"
+#include "webkit/common/fileapi/file_system_info.h"
#include "webkit/common/fileapi/file_system_types.h"
#include "webkit/common/fileapi/file_system_util.h"
@@ -168,6 +169,7 @@ bool FileAPIMessageFilter::OnMessageReceived(
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(FileAPIMessageFilter, message, *message_was_ok)
IPC_MESSAGE_HANDLER(FileSystemHostMsg_Open, OnOpen)
+ IPC_MESSAGE_HANDLER(FileSystemHostMsg_ResolveURL, OnResolveURL)
IPC_MESSAGE_HANDLER(FileSystemHostMsg_DeleteFileSystem, OnDeleteFileSystem)
IPC_MESSAGE_HANDLER(FileSystemHostMsg_Move, OnMove)
IPC_MESSAGE_HANDLER(FileSystemHostMsg_Copy, OnCopy)
@@ -250,6 +252,23 @@ void FileAPIMessageFilter::OnOpen(
&FileAPIMessageFilter::DidOpenFileSystem, this, request_id));
}
+void FileAPIMessageFilter::OnResolveURL(
+ int request_id,
+ const GURL& filesystem_url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ FileSystemURL url(context_->CrackURL(filesystem_url));
+ if (!ValidateFileSystemURL(request_id, url))
+ return;
+ if (!security_policy_->CanReadFileSystemFile(process_id_, url)) {
+ Send(new FileSystemMsg_DidFail(request_id,
+ base::PLATFORM_FILE_ERROR_SECURITY));
+ return;
+ }
+
+ context_->ResolveURL(url, base::Bind(
+ &FileAPIMessageFilter::DidResolveURL, this, request_id));
+}
+
void FileAPIMessageFilter::OnDeleteFileSystem(
int request_id,
const GURL& origin_url,
@@ -873,18 +892,35 @@ void FileAPIMessageFilter::DidWrite(int request_id,
void FileAPIMessageFilter::DidOpenFileSystem(int request_id,
base::PlatformFileError result,
- const std::string& name,
+ const std::string& filesystem_name,
const GURL& root) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (result == base::PLATFORM_FILE_OK) {
DCHECK(root.is_valid());
- Send(new FileSystemMsg_DidOpenFileSystem(request_id, name, root));
+ Send(new FileSystemMsg_DidOpenFileSystem(
+ request_id, filesystem_name, root));
} else {
Send(new FileSystemMsg_DidFail(request_id, result));
}
// For OpenFileSystem we do not create a new operation, so no unregister here.
}
+void FileAPIMessageFilter::DidResolveURL(int request_id,
+ base::PlatformFileError result,
+ const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (result == base::PLATFORM_FILE_OK) {
+ DCHECK(info.root_url.is_valid());
+ Send(new FileSystemMsg_DidResolveURL(
+ request_id, info, file_path, is_directory));
+ } else {
+ Send(new FileSystemMsg_DidFail(request_id, result));
+ }
+ // For ResolveURL we do not create a new operation, so no unregister here.
+}
+
void FileAPIMessageFilter::DidDeleteFileSystem(
int request_id,
base::PlatformFileError result) {
diff --git a/content/browser/fileapi/fileapi_message_filter.h b/content/browser/fileapi/fileapi_message_filter.h
index d1d7373..e9a707f 100644
--- a/content/browser/fileapi/fileapi_message_filter.h
+++ b/content/browser/fileapi/fileapi_message_filter.h
@@ -37,6 +37,7 @@ class FileSystemURL;
class FileSystemContext;
class FileSystemOperationRunner;
struct DirectoryEntry;
+struct FileSystemInfo;
}
namespace net {
@@ -93,6 +94,8 @@ class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter {
fileapi::FileSystemType type,
int64 requested_size,
bool create);
+ void OnResolveURL(int request_id,
+ const GURL& filesystem_url);
void OnDeleteFileSystem(int request_id,
const GURL& origin_url,
fileapi::FileSystemType type);
@@ -201,8 +204,13 @@ class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter {
bool complete);
void DidOpenFileSystem(int request_id,
base::PlatformFileError result,
- const std::string& name,
+ const std::string& filesystem_name,
const GURL& root);
+ void DidResolveURL(int request_id,
+ base::PlatformFileError result,
+ const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory);
void DidDeleteFileSystem(int request_id,
base::PlatformFileError result);
void DidCreateSnapshot(
diff --git a/content/child/fileapi/file_system_dispatcher.cc b/content/child/fileapi/file_system_dispatcher.cc
index c564f8d..fa73ad1 100644
--- a/content/child/fileapi/file_system_dispatcher.cc
+++ b/content/child/fileapi/file_system_dispatcher.cc
@@ -10,6 +10,7 @@
#include "base/process/process.h"
#include "content/child/child_thread.h"
#include "content/common/fileapi/file_system_messages.h"
+#include "webkit/common/fileapi/file_system_info.h"
namespace content {
@@ -20,6 +21,7 @@ class FileSystemDispatcher::CallbackDispatcher {
typedef FileSystemDispatcher::MetadataCallback MetadataCallback;
typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback;
typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback;
+ typedef FileSystemDispatcher::ResolveURLCallback ResolveURLCallback;
typedef FileSystemDispatcher::WriteCallback WriteCallback;
typedef FileSystemDispatcher::OpenFileCallback OpenFileCallback;
@@ -57,6 +59,13 @@ class FileSystemDispatcher::CallbackDispatcher {
dispatcher->error_callback_ = error_callback;
return dispatcher;
}
+ static CallbackDispatcher* Create(const ResolveURLCallback& callback,
+ const StatusCallback& error_callback) {
+ CallbackDispatcher* dispatcher = new CallbackDispatcher;
+ dispatcher->resolve_callback_ = callback;
+ dispatcher->error_callback_ = error_callback;
+ return dispatcher;
+ }
static CallbackDispatcher* Create(const WriteCallback& callback,
const StatusCallback& error_callback) {
CallbackDispatcher* dispatcher = new CallbackDispatcher;
@@ -105,6 +114,12 @@ class FileSystemDispatcher::CallbackDispatcher {
filesystem_callback_.Run(name, root);
}
+ void DidResolveURL(const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory) {
+ resolve_callback_.Run(info, file_path, is_directory);
+ }
+
void DidWrite(int64 bytes, bool complete) {
write_callback_.Run(bytes, complete);
}
@@ -123,6 +138,7 @@ class FileSystemDispatcher::CallbackDispatcher {
CreateSnapshotFileCallback snapshot_callback_;
ReadDirectoryCallback directory_callback_;
OpenFileSystemCallback filesystem_callback_;
+ ResolveURLCallback resolve_callback_;
WriteCallback write_callback_;
OpenFileCallback open_callback_;
@@ -150,6 +166,7 @@ bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg)
IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFileSystem, OnDidOpenFileSystem)
+ IPC_MESSAGE_HANDLER(FileSystemMsg_DidResolveURL, OnDidResolveURL)
IPC_MESSAGE_HANDLER(FileSystemMsg_DidSucceed, OnDidSucceed)
IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadDirectory, OnDidReadDirectory)
IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadMetadata, OnDidReadMetadata)
@@ -174,6 +191,16 @@ void FileSystemDispatcher::OpenFileSystem(
request_id, origin_url, type, size, create));
}
+void FileSystemDispatcher::ResolveURL(
+ const GURL& filesystem_url,
+ const ResolveURLCallback& success_callback,
+ const StatusCallback& error_callback) {
+ int request_id = dispatchers_.Add(
+ CallbackDispatcher::Create(success_callback, error_callback));
+ ChildThread::current()->Send(new FileSystemHostMsg_ResolveURL(
+ request_id, filesystem_url));
+}
+
void FileSystemDispatcher::DeleteFileSystem(
const GURL& origin_url,
fileapi::FileSystemType type,
@@ -362,6 +389,17 @@ void FileSystemDispatcher::OnDidOpenFileSystem(int request_id,
dispatchers_.Remove(request_id);
}
+void FileSystemDispatcher::OnDidResolveURL(int request_id,
+ const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory) {
+ DCHECK(info.root_url.is_valid());
+ CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
+ DCHECK(dispatcher);
+ dispatcher->DidResolveURL(info, file_path, is_directory);
+ dispatchers_.Remove(request_id);
+}
+
void FileSystemDispatcher::OnDidSucceed(int request_id) {
CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
DCHECK(dispatcher);
diff --git a/content/child/fileapi/file_system_dispatcher.h b/content/child/fileapi/file_system_dispatcher.h
index f3957c3..72ecee6 100644
--- a/content/child/fileapi/file_system_dispatcher.h
+++ b/content/child/fileapi/file_system_dispatcher.h
@@ -24,6 +24,7 @@ struct PlatformFileInfo;
namespace fileapi {
struct DirectoryEntry;
+struct FileSystemInfo;
}
class GURL;
@@ -49,6 +50,10 @@ class FileSystemDispatcher : public IPC::Listener {
const std::string& name,
const GURL& root)> OpenFileSystemCallback;
typedef base::Callback<void(
+ const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory)> ResolveURLCallback;
+ typedef base::Callback<void(
int64 bytes,
bool complete)> WriteCallback;
typedef base::Callback<void(
@@ -68,6 +73,9 @@ class FileSystemDispatcher : public IPC::Listener {
bool create,
const OpenFileSystemCallback& success_callback,
const StatusCallback& error_callback);
+ void ResolveURL(const GURL& filesystem_url,
+ const ResolveURLCallback& success_callback,
+ const StatusCallback& error_callback);
void DeleteFileSystem(const GURL& origin_url,
fileapi::FileSystemType type,
const StatusCallback& callback);
@@ -144,6 +152,10 @@ class FileSystemDispatcher : public IPC::Listener {
void OnDidOpenFileSystem(int request_id,
const std::string& name,
const GURL& root);
+ void OnDidResolveURL(int request_id,
+ const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory);
void OnDidSucceed(int request_id);
void OnDidReadMetadata(int request_id,
const base::PlatformFileInfo& file_info);
diff --git a/content/child/fileapi/webfilesystem_impl.cc b/content/child/fileapi/webfilesystem_impl.cc
index ac91214..ae3be406 100644
--- a/content/child/fileapi/webfilesystem_impl.cc
+++ b/content/child/fileapi/webfilesystem_impl.cc
@@ -154,6 +154,21 @@ void OpenFileSystemCallbackAdapter(
MakeTuple(UTF8ToUTF16(name), root));
}
+void ResolveURLCallbackAdapter(
+ int thread_id, int callbacks_id,
+ WaitableCallbackResults* waitable_results,
+ const fileapi::FileSystemInfo& info,
+ const base::FilePath& file_path, bool is_directory) {
+ base::FilePath normalized_path(
+ fileapi::VirtualPath::GetNormalizedFilePath(file_path));
+ CallbackFileSystemCallbacks(
+ thread_id, callbacks_id, waitable_results,
+ &WebFileSystemCallbacks::didResolveURL,
+ MakeTuple(UTF8ToUTF16(info.name), info.root_url,
+ static_cast<WebKit::WebFileSystemType>(info.mount_type),
+ normalized_path.AsUTF16Unsafe(), is_directory));
+}
+
void StatusCallbackAdapter(int thread_id, int callbacks_id,
WaitableCallbackResults* waitable_results,
base::PlatformFileError error) {
@@ -332,6 +347,25 @@ void WebFileSystemImpl::openFileSystem(
make_scoped_ptr(waitable_results));
}
+void WebFileSystemImpl::resolveURL(
+ const WebKit::WebURL& filesystem_url,
+ WebFileSystemCallbacks callbacks) {
+ int callbacks_id = RegisterCallbacks(callbacks);
+ WaitableCallbackResults* waitable_results =
+ WaitableCallbackResults::MaybeCreate(callbacks);
+ CallDispatcherOnMainThread(
+ main_thread_loop_.get(),
+ &FileSystemDispatcher::ResolveURL,
+ MakeTuple(GURL(filesystem_url),
+ base::Bind(&ResolveURLCallbackAdapter,
+ CurrentWorkerId(), callbacks_id,
+ base::Unretained(waitable_results)),
+ base::Bind(&StatusCallbackAdapter,
+ CurrentWorkerId(), callbacks_id,
+ base::Unretained(waitable_results))),
+ make_scoped_ptr(waitable_results));
+}
+
void WebFileSystemImpl::deleteFileSystem(
const WebKit::WebURL& storage_partition,
WebKit::WebFileSystemType type,
@@ -481,7 +515,7 @@ void WebFileSystemImpl::fileExists(
MakeTuple(GURL(path), false /* directory */,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
-base::Unretained(waitable_results))),
+ base::Unretained(waitable_results))),
make_scoped_ptr(waitable_results));
}
diff --git a/content/child/fileapi/webfilesystem_impl.h b/content/child/fileapi/webfilesystem_impl.h
index 7550545..8f390ff 100644
--- a/content/child/fileapi/webfilesystem_impl.h
+++ b/content/child/fileapi/webfilesystem_impl.h
@@ -54,6 +54,9 @@ class WebFileSystemImpl
const WebKit::WebFileSystemType type,
bool create,
WebKit::WebFileSystemCallbacks);
+ virtual void resolveURL(
+ const WebKit::WebURL& filesystem_url,
+ WebKit::WebFileSystemCallbacks) OVERRIDE;
virtual void deleteFileSystem(
const WebKit::WebURL& storage_partition,
const WebKit::WebFileSystemType type,
diff --git a/content/common/fileapi/file_system_messages.h b/content/common/fileapi/file_system_messages.h
index e277e33..191bf9d 100644
--- a/content/common/fileapi/file_system_messages.h
+++ b/content/common/fileapi/file_system_messages.h
@@ -9,6 +9,7 @@
#include "ipc/ipc_platform_file.h"
#include "url/gurl.h"
#include "webkit/common/fileapi/directory_entry.h"
+#include "webkit/common/fileapi/file_system_info.h"
#include "webkit/common/fileapi/file_system_types.h"
#include "webkit/common/quota/quota_types.h"
@@ -21,6 +22,12 @@ IPC_STRUCT_TRAITS_BEGIN(fileapi::DirectoryEntry)
IPC_STRUCT_TRAITS_MEMBER(is_directory)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(fileapi::FileSystemInfo)
+ IPC_STRUCT_TRAITS_MEMBER(name)
+ IPC_STRUCT_TRAITS_MEMBER(root_url)
+ IPC_STRUCT_TRAITS_MEMBER(mount_type)
+IPC_STRUCT_TRAITS_END()
+
IPC_ENUM_TRAITS(fileapi::FileSystemType)
IPC_ENUM_TRAITS(quota::QuotaLimitType)
@@ -33,6 +40,11 @@ IPC_MESSAGE_CONTROL3(FileSystemMsg_DidOpenFileSystem,
GURL /* root_url */)
// WebFileSystem response messages.
+IPC_MESSAGE_CONTROL4(FileSystemMsg_DidResolveURL,
+ int /* request_id */,
+ fileapi::FileSystemInfo /* filesystem_info */,
+ base::FilePath /* file_path */,
+ bool /* is_directory */)
IPC_MESSAGE_CONTROL1(FileSystemMsg_DidSucceed,
int /* request_id */)
IPC_MESSAGE_CONTROL2(FileSystemMsg_DidReadMetadata,
@@ -69,6 +81,11 @@ IPC_MESSAGE_CONTROL5(FileSystemHostMsg_Open,
int64 /* requested_size */,
bool /* create */)
+// WevFrameClient::resolveURL() message.
+IPC_MESSAGE_CONTROL2(FileSystemHostMsg_ResolveURL,
+ int /* request_id */,
+ GURL /* filesystem_url */)
+
// WebFrameClient::deleteFileSystem() message.
IPC_MESSAGE_CONTROL3(FileSystemHostMsg_DeleteFileSystem,
int /* request_id */,
diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc
index 26a48d4..0888661 100644
--- a/webkit/browser/fileapi/file_system_context.cc
+++ b/webkit/browser/fileapi/file_system_context.cc
@@ -27,6 +27,7 @@
#include "webkit/browser/fileapi/test_file_system_backend.h"
#include "webkit/browser/quota/quota_manager.h"
#include "webkit/browser/quota/special_storage_policy.h"
+#include "webkit/common/fileapi/file_system_info.h"
#include "webkit/common/fileapi/file_system_util.h"
using quota::QuotaClient;
@@ -49,6 +50,19 @@ void DidOpenFileSystem(
callback.Run(error, filesystem_name, filesystem_root);
}
+void DidGetMetadataForResolveURL(
+ const base::FilePath& path,
+ const FileSystemContext::ResolveURLCallback& callback,
+ const FileSystemInfo& info,
+ base::PlatformFileError error,
+ const base::PlatformFileInfo& file_info) {
+ if (error != base::PLATFORM_FILE_OK) {
+ callback.Run(error, FileSystemInfo(), base::FilePath(), false);
+ return;
+ }
+ callback.Run(error, info, path, file_info.is_directory);
+}
+
} // namespace
// static
@@ -275,6 +289,26 @@ void FileSystemContext::OpenFileSystem(
base::Bind(&DidOpenFileSystem, callback));
}
+void FileSystemContext::ResolveURL(
+ const FileSystemURL& url,
+ const ResolveURLCallback& callback) {
+ DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
+ DCHECK(!callback.is_null());
+
+ FileSystemBackend* backend = GetFileSystemBackend(url.type());
+ if (!backend) {
+ callback.Run(base::PLATFORM_FILE_ERROR_SECURITY,
+ FileSystemInfo(), base::FilePath(), false);
+ return;
+ }
+
+ backend->OpenFileSystem(
+ url.origin(), url.type(),
+ OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
+ base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL,
+ this, url, callback));
+}
+
void FileSystemContext::DeleteFileSystem(
const GURL& origin_url,
FileSystemType type,
@@ -424,8 +458,7 @@ FileSystemURL FileSystemContext::CrackFileSystemURL(
return current;
}
-void FileSystemContext::RegisterBackend(
- FileSystemBackend* backend) {
+void FileSystemContext::RegisterBackend(FileSystemBackend* backend) {
const FileSystemType mount_types[] = {
kFileSystemTypeTemporary,
kFileSystemTypePersistent,
@@ -452,4 +485,35 @@ void FileSystemContext::RegisterBackend(
}
}
+void FileSystemContext::DidOpenFileSystemForResolveURL(
+ const FileSystemURL& url,
+ const FileSystemContext::ResolveURLCallback& callback,
+ const GURL& filesystem_root,
+ const std::string& filesystem_name,
+ base::PlatformFileError error) {
+ DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
+
+ if (error != base::PLATFORM_FILE_OK) {
+ callback.Run(error, FileSystemInfo(), base::FilePath(), false);
+ return;
+ }
+
+ fileapi::FileSystemInfo info(
+ filesystem_name, filesystem_root, url.mount_type());
+
+ // Extract the virtual path not containing a filesystem type part from |url|.
+ base::FilePath parent =
+ base::FilePath::FromUTF8Unsafe(filesystem_root.path());
+ base::FilePath child = base::FilePath::FromUTF8Unsafe(url.ToGURL().path());
+ base::FilePath path;
+
+ if (parent != child) {
+ bool result = parent.AppendRelativePath(child, &path);
+ DCHECK(result);
+ }
+
+ operation_runner()->GetMetadata(
+ url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info));
+}
+
} // namespace fileapi
diff --git a/webkit/browser/fileapi/file_system_context.h b/webkit/browser/fileapi/file_system_context.h
index 9762b68..21a31b8 100644
--- a/webkit/browser/fileapi/file_system_context.h
+++ b/webkit/browser/fileapi/file_system_context.h
@@ -49,8 +49,8 @@ class CopyOrMoveFileValidatorFactory;
class ExternalFileSystemBackend;
class ExternalMountPoints;
class FileStreamWriter;
-class FileSystemFileUtil;
class FileSystemBackend;
+class FileSystemFileUtil;
class FileSystemOperation;
class FileSystemOperationRunner;
class FileSystemOptions;
@@ -61,6 +61,7 @@ class MountPoints;
class SandboxFileSystemBackend;
struct DefaultContextDeleter;
+struct FileSystemInfo;
// This class keeps and provides a file system context for FileSystem API.
// An instance of this class is created and owned by profile.
@@ -154,6 +155,12 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
const std::string& name,
const GURL& root)> OpenFileSystemCallback;
+ // Used for ResolveURL.
+ typedef base::Callback<void(base::PlatformFileError result,
+ const FileSystemInfo& info,
+ const base::FilePath& file_path,
+ bool is_directory)> ResolveURLCallback;
+
// Used for DeleteFileSystem.
typedef base::Callback<void(base::PlatformFileError result)>
DeleteFileSystemCallback;
@@ -169,8 +176,15 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
OpenFileSystemMode mode,
const OpenFileSystemCallback& callback);
+ // Opens the filesystem for the given |url| as read-only, and then checks the
+ // existence of the file entry referred by the URL. This should be called on
+ // the IO thread.
+ void ResolveURL(
+ const FileSystemURL& url,
+ const ResolveURLCallback& callback);
+
// Deletes the filesystem for the given |origin_url| and |type|. This should
- // be called on the IO Thread.
+ // be called on the IO thread.
void DeleteFileSystem(
const GURL& origin_url,
FileSystemType type,
@@ -274,6 +288,13 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
// the constructor.
void RegisterBackend(FileSystemBackend* backend);
+ void DidOpenFileSystemForResolveURL(
+ const FileSystemURL& url,
+ const ResolveURLCallback& callback,
+ const GURL& filesystem_root,
+ const std::string& filesystem_name,
+ base::PlatformFileError error);
+
// Returns a FileSystemBackend, used only by test code.
SandboxFileSystemBackend* sandbox_backend() const {
return sandbox_backend_.get();
diff --git a/webkit/common/fileapi/file_system_info.cc b/webkit/common/fileapi/file_system_info.cc
new file mode 100644
index 0000000..269c021
--- /dev/null
+++ b/webkit/common/fileapi/file_system_info.cc
@@ -0,0 +1,24 @@
+// Copyright 2013 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/common/fileapi/file_system_info.h"
+
+namespace fileapi {
+
+FileSystemInfo::FileSystemInfo()
+ : mount_type(fileapi::kFileSystemTypeTemporary) {
+}
+
+FileSystemInfo::FileSystemInfo(const std::string& name,
+ const GURL& root_url,
+ fileapi::FileSystemType mount_type)
+ : name(name),
+ root_url(root_url),
+ mount_type(mount_type) {
+}
+
+FileSystemInfo::~FileSystemInfo() {
+}
+
+} // namespace fileapi
diff --git a/webkit/common/fileapi/file_system_info.h b/webkit/common/fileapi/file_system_info.h
new file mode 100644
index 0000000..b71739a
--- /dev/null
+++ b/webkit/common/fileapi/file_system_info.h
@@ -0,0 +1,31 @@
+// Copyright 2013 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.
+
+#ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_
+#define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_
+
+#include "url/gurl.h"
+#include "webkit/common/fileapi/file_system_types.h"
+#include "webkit/common/webkit_storage_common_export.h"
+
+namespace fileapi {
+
+// This struct is used to send the necessary information for Blink to create a
+// DOMFileSystem. Since Blink side only uses mount_type (rather than
+// detailed/cracked filesystem type) this only contains mount_type but not type.
+struct WEBKIT_STORAGE_COMMON_EXPORT FileSystemInfo {
+ FileSystemInfo();
+ FileSystemInfo(const std::string& filesystem_name,
+ const GURL& root_url,
+ fileapi::FileSystemType mount_type);
+ ~FileSystemInfo();
+
+ std::string name;
+ GURL root_url;
+ fileapi::FileSystemType mount_type;
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_
diff --git a/webkit/common/fileapi/file_system_util.cc b/webkit/common/fileapi/file_system_util.cc
index bc9aba7..6229bc2 100644
--- a/webkit/common/fileapi/file_system_util.cc
+++ b/webkit/common/fileapi/file_system_util.cc
@@ -296,6 +296,8 @@ WebKit::WebFileError PlatformFileErrorToWebFileError(
return WebKit::WebFileErrorSecurity;
case base::PLATFORM_FILE_ERROR_NO_SPACE:
return WebKit::WebFileErrorQuotaExceeded;
+ case base::PLATFORM_FILE_ERROR_INVALID_URL:
+ return WebKit::WebFileErrorEncoding;
default:
return WebKit::WebFileErrorInvalidModification;
}
diff --git a/webkit/storage_common.gyp b/webkit/storage_common.gyp
index 01e8f23..a77d4c5 100644
--- a/webkit/storage_common.gyp
+++ b/webkit/storage_common.gyp
@@ -32,6 +32,8 @@
'common/database/database_identifier.cc',
'common/fileapi/directory_entry.cc',
'common/fileapi/directory_entry.h',
+ 'common/fileapi/file_system_info.cc',
+ 'common/fileapi/file_system_info.h',
'common/fileapi/file_system_types.h',
'common/fileapi/file_system_util.cc',
'common/fileapi/file_system_util.h',