diff options
5 files changed, 51 insertions, 58 deletions
diff --git a/content/browser/fileapi/plugin_private_file_system_backend_unittest.cc b/content/browser/fileapi/plugin_private_file_system_backend_unittest.cc index a724688..0cc2f48 100644 --- a/content/browser/fileapi/plugin_private_file_system_backend_unittest.cc +++ b/content/browser/fileapi/plugin_private_file_system_backend_unittest.cc @@ -14,8 +14,10 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/browser/fileapi/async_file_test_helper.h" #include "webkit/browser/fileapi/file_system_context.h" +#include "webkit/browser/fileapi/isolated_context.h" #include "webkit/browser/fileapi/obfuscated_file_util.h" #include "webkit/browser/fileapi/plugin_private_file_system_backend.h" +#include "webkit/common/fileapi/file_system_util.h" namespace fileapi { @@ -25,18 +27,18 @@ const GURL kOrigin("http://www.example.com"); const std::string kPlugin1("plugin1"); const std::string kPlugin2("plugin2"); const FileSystemType kType = kFileSystemTypePluginPrivate; +const std::string kRootName = "pluginprivate"; -void DidOpenFileSystem(GURL* root_url_out, - std::string* filesystem_id_out, - base::PlatformFileError* error_out, - const GURL& root_url, - const std::string& filesystem_id, +void DidOpenFileSystem(base::PlatformFileError* error_out, base::PlatformFileError error) { - *root_url_out = root_url; - *filesystem_id_out = filesystem_id; *error_out = error; } +std::string RegisterFileSystem() { + return IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( + kType, kRootName, base::FilePath()); +} + } // namespace class PluginPrivateFileSystemBackendTest : public testing::Test { @@ -65,27 +67,31 @@ class PluginPrivateFileSystemBackendTest : public testing::Test { base::ScopedTempDir data_dir_; base::MessageLoop message_loop_; scoped_refptr<FileSystemContext> context_; + std::string filesystem_id_; }; TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { - GURL root_url; - std::string filesystem_id; + const std::string filesystem_id1 = RegisterFileSystem(); base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; - backend()->OpenPrivateFileSystem( - kOrigin, kType, kPlugin1, OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, - base::Bind(&DidOpenFileSystem, &root_url, &filesystem_id, &error)); + kOrigin, kType, filesystem_id1, kPlugin1, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&DidOpenFileSystem, &error)); base::RunLoop().RunUntilIdle(); ASSERT_EQ(base::PLATFORM_FILE_OK, error); // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. + const std::string filesystem_id2 = RegisterFileSystem(); error = base::PLATFORM_FILE_ERROR_FAILED; backend()->OpenPrivateFileSystem( - kOrigin, kType, kPlugin1, OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, - base::Bind(&DidOpenFileSystem, &root_url, &filesystem_id, &error)); + kOrigin, kType, filesystem_id2, kPlugin1, + OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, + base::Bind(&DidOpenFileSystem, &error)); base::RunLoop().RunUntilIdle(); ASSERT_EQ(base::PLATFORM_FILE_OK, error); + const GURL root_url( + GetIsolatedFileSystemRootURIString(kOrigin, filesystem_id1, kRootName)); FileSystemURL file = CreateURL(root_url, "foo"); base::FilePath platform_path; EXPECT_EQ(base::PLATFORM_FILE_OK, @@ -98,25 +104,28 @@ TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { } TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { - GURL root_url1, root_url2; - std::string filesystem_id1, filesystem_id2; - // Open filesystem for kPlugin1 and kPlugin2. + const std::string filesystem_id1 = RegisterFileSystem(); base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; backend()->OpenPrivateFileSystem( - kOrigin, kType, kPlugin1, OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, - base::Bind(&DidOpenFileSystem, &root_url1, &filesystem_id1, &error)); + kOrigin, kType, filesystem_id1, kPlugin1, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&DidOpenFileSystem, &error)); base::RunLoop().RunUntilIdle(); ASSERT_EQ(base::PLATFORM_FILE_OK, error); + const std::string filesystem_id2 = RegisterFileSystem(); error = base::PLATFORM_FILE_ERROR_FAILED; backend()->OpenPrivateFileSystem( - kOrigin, kType, kPlugin2, OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, - base::Bind(&DidOpenFileSystem, &root_url2, &filesystem_id2, &error)); + kOrigin, kType, filesystem_id2, kPlugin2, + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, + base::Bind(&DidOpenFileSystem, &error)); base::RunLoop().RunUntilIdle(); ASSERT_EQ(base::PLATFORM_FILE_OK, error); // Create 'foo' in kPlugin1. + const GURL root_url1( + GetIsolatedFileSystemRootURIString(kOrigin, filesystem_id1, kRootName)); FileSystemURL file1 = CreateURL(root_url1, "foo"); base::FilePath platform_path; EXPECT_EQ(base::PLATFORM_FILE_OK, @@ -125,6 +134,8 @@ TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); // See the same path is not available in kPlugin2. + const GURL root_url2( + GetIsolatedFileSystemRootURIString(kOrigin, filesystem_id2, kRootName)); FileSystemURL file2 = CreateURL(root_url2, "foo"); EXPECT_FALSE(AsyncFileTestHelper::FileExists( context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc index fd6ae4d..5bf8977 100644 --- a/webkit/browser/fileapi/file_system_context.cc +++ b/webkit/browser/fileapi/file_system_context.cc @@ -348,7 +348,7 @@ void FileSystemContext::ResolveURL( void FileSystemContext::DeleteFileSystem( const GURL& origin_url, FileSystemType type, - const DeleteFileSystemCallback& callback) { + const StatusCallback& callback) { DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); DCHECK(origin_url == origin_url.GetOrigin()); DCHECK(!callback.is_null()); @@ -439,12 +439,13 @@ bool FileSystemContext::CanServeURLRequest(const FileSystemURL& url) const { void FileSystemContext::OpenPluginPrivateFileSystem( const GURL& origin_url, FileSystemType type, + const std::string& filesystem_id, const std::string& plugin_id, OpenFileSystemMode mode, - const OpenPluginPrivateFileSystemCallback& callback) { + const StatusCallback& callback) { DCHECK(plugin_private_backend_); plugin_private_backend_->OpenPrivateFileSystem( - origin_url, type, plugin_id, mode, callback); + origin_url, type, filesystem_id, plugin_id, mode, callback); } FileSystemContext::~FileSystemContext() { diff --git a/webkit/browser/fileapi/file_system_context.h b/webkit/browser/fileapi/file_system_context.h index 745bdae..b7a4a94 100644 --- a/webkit/browser/fileapi/file_system_context.h +++ b/webkit/browser/fileapi/file_system_context.h @@ -174,15 +174,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext const base::FilePath& file_path, bool is_directory)> ResolveURLCallback; - // Used for DeleteFileSystem. - typedef base::Callback<void(base::PlatformFileError result)> - DeleteFileSystemCallback; - - // Used for OpenPluginPrivateFileSystem. - typedef base::Callback<void(const GURL& root, - const std::string& filesystem_id, - base::PlatformFileError result)> - OpenPluginPrivateFileSystemCallback; + // Used for DeleteFileSystem and OpenPluginPrivateFileSystem. + typedef base::Callback<void(base::PlatformFileError result)> StatusCallback; // Opens the filesystem for the given |origin_url| and |type|, and dispatches // |callback| on completion. @@ -207,7 +200,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext void DeleteFileSystem( const GURL& origin_url, FileSystemType type, - const DeleteFileSystemCallback& callback); + const StatusCallback& callback); // Creates new FileStreamReader instance to read a file pointed by the given // filesystem URL |url| starting from |offset|. |expected_modification_time| @@ -269,9 +262,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext void OpenPluginPrivateFileSystem( const GURL& origin_url, FileSystemType type, + const std::string& filesystem_id, const std::string& plugin_id, OpenFileSystemMode mode, - const OpenPluginPrivateFileSystemCallback& callback); + const StatusCallback& callback); private: typedef std::map<FileSystemType, FileSystemBackend*> diff --git a/webkit/browser/fileapi/plugin_private_file_system_backend.cc b/webkit/browser/fileapi/plugin_private_file_system_backend.cc index e701ce9..0426bd2 100644 --- a/webkit/browser/fileapi/plugin_private_file_system_backend.cc +++ b/webkit/browser/fileapi/plugin_private_file_system_backend.cc @@ -43,8 +43,8 @@ class PluginPrivateFileSystemBackend::FileSystemIDToPluginMap { void RegisterFileSystem(const std::string& filesystem_id, const std::string& plugin_id) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); - DCHECK(!filesystem_id.empty() && - !ContainsKey(map_, filesystem_id)) << filesystem_id; + DCHECK(!filesystem_id.empty()); + DCHECK(!ContainsKey(map_, filesystem_id)) << filesystem_id; map_[filesystem_id] = plugin_id; } @@ -77,9 +77,7 @@ base::PlatformFileError OpenFileSystemOnFileThread( const bool create = (mode == OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT); file_util->GetDirectoryForOriginAndType( origin_url, plugin_id, create, &error); - if (error != base::PLATFORM_FILE_OK) - IsolatedContext::GetInstance()->RevokeFileSystem(filesystem_id); - else + if (error == base::PLATFORM_FILE_OK) plugin_map->RegisterFileSystem(filesystem_id, plugin_id); return error; } @@ -119,32 +117,23 @@ PluginPrivateFileSystemBackend::~PluginPrivateFileSystemBackend() { void PluginPrivateFileSystemBackend::OpenPrivateFileSystem( const GURL& origin_url, FileSystemType type, + const std::string& filesystem_id, const std::string& plugin_id, OpenFileSystemMode mode, - const OpenPrivateFileSystemCallback& callback) { + const StatusCallback& callback) { if (!CanHandleType(type) || file_system_options_.is_incognito()) { base::MessageLoopProxy::current()->PostTask( - FROM_HERE, base::Bind(callback, GURL(), std::string(), - base::PLATFORM_FILE_ERROR_SECURITY)); + FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); return; } - // TODO(nhiroki,kinuko): This constant should be somehow shared. - const std::string name("PluginPrivate"); - std::string filesystem_id = - IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( - type, name, base::FilePath()); - PostTaskAndReplyWithResult( file_task_runner_.get(), FROM_HERE, base::Bind(&OpenFileSystemOnFileThread, obfuscated_file_util(), plugin_map_, origin_url, filesystem_id, plugin_id, mode), - base::Bind(callback, - GURL(GetIsolatedFileSystemRootURIString( - origin_url, filesystem_id, name)), - filesystem_id)); + callback); } bool PluginPrivateFileSystemBackend::CanHandleType(FileSystemType type) const { diff --git a/webkit/browser/fileapi/plugin_private_file_system_backend.h b/webkit/browser/fileapi/plugin_private_file_system_backend.h index 69d61c2..d41f4b7 100644 --- a/webkit/browser/fileapi/plugin_private_file_system_backend.h +++ b/webkit/browser/fileapi/plugin_private_file_system_backend.h @@ -31,10 +31,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT PluginPrivateFileSystemBackend public FileSystemQuotaUtil { public: class FileSystemIDToPluginMap; - typedef base::Callback<void(const GURL& root, - const std::string& filesystem_id, - base::PlatformFileError result)> - OpenPrivateFileSystemCallback; + typedef base::Callback<void(base::PlatformFileError result)> StatusCallback; PluginPrivateFileSystemBackend( base::SequencedTaskRunner* file_task_runner, @@ -52,9 +49,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT PluginPrivateFileSystemBackend void OpenPrivateFileSystem( const GURL& origin_url, FileSystemType type, + const std::string& filesystem_id, const std::string& plugin_id, OpenFileSystemMode mode, - const OpenPrivateFileSystemCallback& callback); + const StatusCallback& callback); // FileSystemBackend overrides. virtual bool CanHandleType(FileSystemType type) const OVERRIDE; |