diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-16 14:19:27 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-16 14:19:27 +0000 |
commit | d2691960115fcc0333fda4fa390bba77cd54dee4 (patch) | |
tree | 6de6f151ef69cf6d256c78e2130ec160fff13ac4 | |
parent | 015eb6cca97452167afb969f6ca7965601dd72ac (diff) | |
download | chromium_src-d2691960115fcc0333fda4fa390bba77cd54dee4.zip chromium_src-d2691960115fcc0333fda4fa390bba77cd54dee4.tar.gz chromium_src-d2691960115fcc0333fda4fa390bba77cd54dee4.tar.bz2 |
Cleanup: Deprecate FileSystemCallbackDispatcher
Replace all FileSystemCallbackDispatcher* with our usual
base::Callback.
BUG=157537
TEST=existing tests
R=michaeln@chromium.org, tzik@chromium.org, yzshen@chromium.org
Review URL: https://codereview.chromium.org/14796018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200531 0039d316-1c4b-4281-b951-d872f2087c98
34 files changed, 607 insertions, 935 deletions
diff --git a/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc b/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc index fd3ffaa..39408c6 100644 --- a/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc +++ b/chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.cc @@ -18,7 +18,6 @@ #include "webkit/blob/local_file_stream_reader.h" #include "webkit/fileapi/async_file_util_adapter.h" #include "webkit/fileapi/copy_or_move_file_validator.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_stream_reader.h" #include "webkit/fileapi/file_system_operation_context.h" diff --git a/content/common/fileapi/file_system_dispatcher.cc b/content/common/fileapi/file_system_dispatcher.cc index c9726dc..9f725a6 100644 --- a/content/common/fileapi/file_system_dispatcher.cc +++ b/content/common/fileapi/file_system_dispatcher.cc @@ -4,21 +4,133 @@ #include "content/common/fileapi/file_system_dispatcher.h" +#include "base/callback.h" +#include "base/file_util.h" #include "base/process.h" #include "content/common/child_thread.h" #include "content/common/fileapi/file_system_messages.h" namespace content { +class FileSystemDispatcher::CallbackDispatcher { + public: + typedef CallbackDispatcher self; + typedef FileSystemDispatcher::StatusCallback StatusCallback; + typedef FileSystemDispatcher::MetadataCallback MetadataCallback; + typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback; + typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback; + typedef FileSystemDispatcher::WriteCallback WriteCallback; + typedef FileSystemDispatcher::OpenFileCallback OpenFileCallback; + + static CallbackDispatcher* Create(const StatusCallback& callback) { + CallbackDispatcher* dispatcher = new CallbackDispatcher; + dispatcher->status_callback_ = callback; + dispatcher->error_callback_ = callback; + return dispatcher; + } + static CallbackDispatcher* Create(const MetadataCallback& callback, + const StatusCallback& error_callback) { + CallbackDispatcher* dispatcher = new CallbackDispatcher; + dispatcher->metadata_callback_ = callback; + dispatcher->error_callback_ = error_callback; + return dispatcher; + } + static CallbackDispatcher* Create(const ReadDirectoryCallback& callback, + const StatusCallback& error_callback) { + CallbackDispatcher* dispatcher = new CallbackDispatcher; + dispatcher->directory_callback_ = callback; + dispatcher->error_callback_ = error_callback; + return dispatcher; + } + static CallbackDispatcher* Create(const OpenFileSystemCallback& callback, + const StatusCallback& error_callback) { + CallbackDispatcher* dispatcher = new CallbackDispatcher; + dispatcher->filesystem_callback_ = callback; + dispatcher->error_callback_ = error_callback; + return dispatcher; + } + static CallbackDispatcher* Create(const WriteCallback& callback, + const StatusCallback& error_callback) { + CallbackDispatcher* dispatcher = new CallbackDispatcher; + dispatcher->write_callback_ = callback; + dispatcher->error_callback_ = error_callback; + return dispatcher; + } + static CallbackDispatcher* Create(const OpenFileCallback& callback, + const StatusCallback& error_callback) { + CallbackDispatcher* dispatcher = new CallbackDispatcher; + dispatcher->open_callback_ = callback; + dispatcher->error_callback_ = error_callback; + return dispatcher; + } + + ~CallbackDispatcher() {} + + void DidSucceed() { + status_callback_.Run(base::PLATFORM_FILE_OK); + } + + void DidFail(base::PlatformFileError error_code) { + error_callback_.Run(error_code); + } + + void DidReadMetadata( + const base::PlatformFileInfo& file_info, + const base::FilePath& platform_path) { + metadata_callback_.Run(file_info, platform_path); + } + + void DidCreateSnapshotFile( + const base::PlatformFileInfo& file_info, + const base::FilePath& platform_path) { + metadata_callback_.Run(file_info, platform_path); + } + + void DidReadDirectory( + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more) { + directory_callback_.Run(entries, has_more); + } + + void DidOpenFileSystem(const std::string& name, + const GURL& root) { + filesystem_callback_.Run(name, root); + } + + void DidWrite(int64 bytes, bool complete) { + write_callback_.Run(bytes, complete); + } + + void DidOpenFile(base::PlatformFile file, + int file_open_id, + quota::QuotaLimitType quota_policy) { + open_callback_.Run(file, file_open_id, quota_policy); + } + + private: + CallbackDispatcher() {} + + StatusCallback status_callback_; + MetadataCallback metadata_callback_; + ReadDirectoryCallback directory_callback_; + OpenFileSystemCallback filesystem_callback_; + WriteCallback write_callback_; + OpenFileCallback open_callback_; + + StatusCallback error_callback_; + + DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher); +}; + FileSystemDispatcher::FileSystemDispatcher() { } FileSystemDispatcher::~FileSystemDispatcher() { // Make sure we fire all the remaining callbacks. - for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator + for (IDMap<CallbackDispatcher, IDMapOwnPointer>::iterator iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { int request_id = iter.GetCurrentKey(); - fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); + CallbackDispatcher* dispatcher = iter.GetCurrentValue(); DCHECK(dispatcher); dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); dispatchers_.Remove(request_id); @@ -45,8 +157,10 @@ bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { bool FileSystemDispatcher::OpenFileSystem( const GURL& origin_url, fileapi::FileSystemType type, long long size, bool create, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const OpenFileSystemCallback& success_callback, + const StatusCallback& error_callback) { + int request_id = dispatchers_.Add( + CallbackDispatcher::Create(success_callback, error_callback)); if (!ChildThread::current()->Send(new FileSystemHostMsg_Open( request_id, origin_url, type, size, create))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -59,8 +173,8 @@ bool FileSystemDispatcher::OpenFileSystem( bool FileSystemDispatcher::DeleteFileSystem( const GURL& origin_url, fileapi::FileSystemType type, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send(new FileSystemHostMsg_DeleteFileSystem( request_id, origin_url, type))) { dispatchers_.Remove(request_id); @@ -72,8 +186,8 @@ bool FileSystemDispatcher::DeleteFileSystem( bool FileSystemDispatcher::Move( const GURL& src_path, const GURL& dest_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send(new FileSystemHostMsg_Move( request_id, src_path, dest_path))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -86,8 +200,8 @@ bool FileSystemDispatcher::Move( bool FileSystemDispatcher::Copy( const GURL& src_path, const GURL& dest_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send(new FileSystemHostMsg_Copy( request_id, src_path, dest_path))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -100,8 +214,8 @@ bool FileSystemDispatcher::Copy( bool FileSystemDispatcher::Remove( const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send( new FileSystemMsg_Remove(request_id, path, recursive))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -113,8 +227,10 @@ bool FileSystemDispatcher::Remove( bool FileSystemDispatcher::ReadMetadata( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const MetadataCallback& success_callback, + const StatusCallback& error_callback) { + int request_id = dispatchers_.Add( + CallbackDispatcher::Create(success_callback, error_callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_ReadMetadata(request_id, path))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -129,8 +245,8 @@ bool FileSystemDispatcher::Create( bool exclusive, bool is_directory, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send(new FileSystemHostMsg_Create( request_id, path, exclusive, is_directory, recursive))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -143,8 +259,8 @@ bool FileSystemDispatcher::Create( bool FileSystemDispatcher::Exists( const GURL& path, bool is_directory, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_Exists(request_id, path, is_directory))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -156,8 +272,10 @@ bool FileSystemDispatcher::Exists( bool FileSystemDispatcher::ReadDirectory( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) { + int request_id = dispatchers_.Add( + CallbackDispatcher::Create(success_callback, error_callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_ReadDirectory(request_id, path))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -171,8 +289,8 @@ bool FileSystemDispatcher::Truncate( const GURL& path, int64 offset, int* request_id_out, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_Truncate(request_id, path, offset))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -189,8 +307,10 @@ bool FileSystemDispatcher::Write( const GURL& blob_url, int64 offset, int* request_id_out, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const WriteCallback& success_callback, + const StatusCallback& error_callback) { + int request_id = dispatchers_.Add( + CallbackDispatcher::Create(success_callback, error_callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_Write(request_id, path, blob_url, offset))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -204,8 +324,8 @@ bool FileSystemDispatcher::Write( bool FileSystemDispatcher::Cancel( int request_id_to_cancel, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send(new FileSystemHostMsg_CancelWrite( request_id, request_id_to_cancel))) { dispatchers_.Remove(request_id); // destroys |dispatcher| @@ -219,8 +339,8 @@ bool FileSystemDispatcher::TouchFile( const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const StatusCallback& callback) { + int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_TouchFile( request_id, path, last_access_time, last_modified_time))) { @@ -234,8 +354,10 @@ bool FileSystemDispatcher::TouchFile( bool FileSystemDispatcher::OpenFile( const GURL& file_path, int file_flags, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const OpenFileCallback& success_callback, + const StatusCallback& error_callback) { + int request_id = dispatchers_.Add( + CallbackDispatcher::Create(success_callback, error_callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_OpenFile( request_id, file_path, file_flags))) { @@ -253,8 +375,10 @@ bool FileSystemDispatcher::NotifyCloseFile(int file_open_id) { bool FileSystemDispatcher::CreateSnapshotFile( const GURL& file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - int request_id = dispatchers_.Add(dispatcher); + const CreateSnapshotFileCallback& success_callback, + const StatusCallback& error_callback) { + int request_id = dispatchers_.Add( + CallbackDispatcher::Create(success_callback, error_callback)); if (!ChildThread::current()->Send( new FileSystemHostMsg_CreateSnapshotFile( request_id, file_path))) { @@ -268,16 +392,14 @@ void FileSystemDispatcher::OnDidOpenFileSystem(int request_id, const std::string& name, const GURL& root) { DCHECK(root.is_valid()); - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidOpenFileSystem(name, root); dispatchers_.Remove(request_id); } void FileSystemDispatcher::OnDidSucceed(int request_id) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidSucceed(); dispatchers_.Remove(request_id); @@ -286,8 +408,7 @@ void FileSystemDispatcher::OnDidSucceed(int request_id) { void FileSystemDispatcher::OnDidReadMetadata( int request_id, const base::PlatformFileInfo& file_info, const base::FilePath& platform_path) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidReadMetadata(file_info, platform_path); dispatchers_.Remove(request_id); @@ -296,8 +417,7 @@ void FileSystemDispatcher::OnDidReadMetadata( void FileSystemDispatcher::OnDidCreateSnapshotFile( int request_id, const base::PlatformFileInfo& file_info, const base::FilePath& platform_path) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidCreateSnapshotFile(file_info, platform_path); dispatchers_.Remove(request_id); @@ -309,8 +429,7 @@ void FileSystemDispatcher::OnDidReadDirectory( int request_id, const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidReadDirectory(entries, has_more); dispatchers_.Remove(request_id); @@ -318,8 +437,7 @@ void FileSystemDispatcher::OnDidReadDirectory( void FileSystemDispatcher::OnDidFail( int request_id, base::PlatformFileError error_code) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidFail(error_code); dispatchers_.Remove(request_id); @@ -327,8 +445,7 @@ void FileSystemDispatcher::OnDidFail( void FileSystemDispatcher::OnDidWrite( int request_id, int64 bytes, bool complete) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidWrite(bytes, complete); if (complete) @@ -340,8 +457,7 @@ void FileSystemDispatcher::OnDidOpenFile( IPC::PlatformFileForTransit file, int file_open_id, quota::QuotaLimitType quota_policy) { - fileapi::FileSystemCallbackDispatcher* dispatcher = - dispatchers_.Lookup(request_id); + CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); DCHECK(dispatcher); dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file), file_open_id, diff --git a/content/common/fileapi/file_system_dispatcher.h b/content/common/fileapi/file_system_dispatcher.h index f38cd0d..4d01c6e 100644 --- a/content/common/fileapi/file_system_dispatcher.h +++ b/content/common/fileapi/file_system_dispatcher.h @@ -9,12 +9,12 @@ #include <vector> #include "base/basictypes.h" +#include "base/callback_forward.h" #include "base/files/file_util_proxy.h" #include "base/id_map.h" #include "base/process.h" #include "ipc/ipc_listener.h" #include "ipc/ipc_platform_file.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/fileapi/file_system_types.h" #include "webkit/quota/quota_types.h" @@ -32,6 +32,25 @@ namespace content { // per child process. Messages are dispatched on the main child thread. class FileSystemDispatcher : public IPC::Listener { public: + typedef base::Callback<void(base::PlatformFileError error)> StatusCallback; + typedef base::Callback<void( + const base::PlatformFileInfo& file_info, + const base::FilePath& platform_path)> MetadataCallback; + typedef MetadataCallback CreateSnapshotFileCallback; + typedef base::Callback<void( + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more)> ReadDirectoryCallback; + typedef base::Callback<void( + const std::string& name, + const GURL& root)> OpenFileSystemCallback; + typedef base::Callback<void( + int64 bytes, + bool complete)> WriteCallback; + typedef base::Callback<void( + base::PlatformFile file, + int file_open_id, + quota::QuotaLimitType quota_policy)> OpenFileCallback; + FileSystemDispatcher(); virtual ~FileSystemDispatcher(); @@ -42,60 +61,68 @@ class FileSystemDispatcher : public IPC::Listener { fileapi::FileSystemType type, long long size, bool create, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const OpenFileSystemCallback& success_callback, + const StatusCallback& error_callback); bool DeleteFileSystem(const GURL& origin_url, fileapi::FileSystemType type, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool Move(const GURL& src_path, const GURL& dest_path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool Copy(const GURL& src_path, const GURL& dest_path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool Remove(const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool ReadMetadata(const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const MetadataCallback& success_callback, + const StatusCallback& error_callback); bool Create(const GURL& path, bool exclusive, bool is_directory, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool Exists(const GURL& path, bool for_directory, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool ReadDirectory(const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback); bool Truncate(const GURL& path, int64 offset, int* request_id_out, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool Write(const GURL& path, const GURL& blob_url, int64 offset, int* request_id_out, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const WriteCallback& success_callback, + const StatusCallback& error_callback); bool Cancel(int request_id_to_cancel, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); bool TouchFile(const GURL& file_path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); // This returns a raw open PlatformFile, unlike the above, which are // self-contained operations. bool OpenFile(const GURL& file_path, int file_flags, // passed to FileUtilProxy::CreateOrOpen - fileapi::FileSystemCallbackDispatcher* dispatcher); + const OpenFileCallback& success_callback, + const StatusCallback& error_callback); // This must be paired with OpenFile, and called after finished using the // raw PlatformFile returned from OpenFile. bool NotifyCloseFile(int file_open_id); bool CreateSnapshotFile(const GURL& file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const CreateSnapshotFileCallback& success_callback, + const StatusCallback& error_callback); private: + class CallbackDispatcher; + // Message handlers. void OnDidOpenFileSystem(int request_id, const std::string& name, @@ -119,7 +146,7 @@ class FileSystemDispatcher : public IPC::Listener { int file_open_id, quota::QuotaLimitType quota_policy); - IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer> dispatchers_; + IDMap<CallbackDispatcher, IDMapOwnPointer> dispatchers_; DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher); }; diff --git a/content/common/fileapi/webfilesystem_callback_dispatcher.cc b/content/common/fileapi/webfilesystem_callback_adapters.cc index 24926c6..228371a 100644 --- a/content/common/fileapi/webfilesystem_callback_dispatcher.cc +++ b/content/common/fileapi/webfilesystem_callback_adapters.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 "content/common/fileapi/webfilesystem_callback_dispatcher.h" +#include "content/common/fileapi/webfilesystem_callback_adapters.h" #include <string> #include <vector> @@ -12,7 +12,6 @@ #include "base/utf_string_conversions.h" #include "googleurl/src/gurl.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" -#include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystem.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" #include "webkit/base/file_path_string_conversions.h" @@ -27,58 +26,52 @@ using WebKit::WebVector; namespace content { -WebFileSystemCallbackDispatcher::WebFileSystemCallbackDispatcher( - WebFileSystemCallbacks* callbacks) - : callbacks_(callbacks) { - DCHECK(callbacks_); +void FileStatusCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, + base::PlatformFileError error) { + if (error == base::PLATFORM_FILE_OK) + callbacks->didSucceed(); + else + callbacks->didFail(::fileapi::PlatformFileErrorToWebFileError(error)); } -void WebFileSystemCallbackDispatcher::DidSucceed() { - callbacks_->didSucceed(); -} - -void WebFileSystemCallbackDispatcher::DidReadMetadata( +void ReadMetadataCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, const base::PlatformFileInfo& file_info, const base::FilePath& platform_path) { WebFileInfo web_file_info; webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); web_file_info.platformPath = webkit_base::FilePathToWebString(platform_path); - callbacks_->didReadMetadata(web_file_info); + callbacks->didReadMetadata(web_file_info); } -void WebFileSystemCallbackDispatcher::DidCreateSnapshotFile( +void CreateSnapshotFileCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, const base::PlatformFileInfo& file_info, const base::FilePath& platform_path) { WebFileInfo web_file_info; webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); web_file_info.platformPath = webkit_base::FilePathToWebString(platform_path); - callbacks_->didCreateSnapshotFile(web_file_info); + callbacks->didCreateSnapshotFile(web_file_info); } -void WebFileSystemCallbackDispatcher::DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { +void ReadDirectoryCallbackAdapater( + WebKit::WebFileSystemCallbacks* callbacks, + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more) { WebVector<WebFileSystemEntry> file_system_entries(entries.size()); for (size_t i = 0; i < entries.size(); i++) { file_system_entries[i].name = webkit_base::FilePathStringToWebString(entries[i].name); file_system_entries[i].isDirectory = entries[i].is_directory; } - callbacks_->didReadDirectory(file_system_entries, has_more); + callbacks->didReadDirectory(file_system_entries, has_more); } -void WebFileSystemCallbackDispatcher::DidOpenFileSystem( +void OpenFileSystemCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, const std::string& name, const GURL& root) { - callbacks_->didOpenFileSystem(UTF8ToUTF16(name), root); -} - -void WebFileSystemCallbackDispatcher::DidFail( - base::PlatformFileError error_code) { - callbacks_->didFail( - fileapi::PlatformFileErrorToWebFileError(error_code)); -} - -void WebFileSystemCallbackDispatcher::DidWrite(int64 bytes, bool complete) { - NOTREACHED(); + callbacks->didOpenFileSystem(UTF8ToUTF16(name), root); } } // namespace content diff --git a/content/common/fileapi/webfilesystem_callback_adapters.h b/content/common/fileapi/webfilesystem_callback_adapters.h new file mode 100644 index 0000000..8f2c699 --- /dev/null +++ b/content/common/fileapi/webfilesystem_callback_adapters.h @@ -0,0 +1,45 @@ +// 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. + +#ifndef CONTENT_COMMON_FILEAPI_WEBFILESYSTEM_CALLBACK_ADAPTERS_H_ +#define CONTENT_COMMON_FILEAPI_WEBFILESYSTEM_CALLBACK_ADAPTERS_H_ + +#include "base/basictypes.h" +#include "base/files/file_util_proxy.h" +#include "base/platform_file.h" + +class GURL; + +namespace WebKit { +class WebFileSystemCallbacks; +} + +namespace content { + +void FileStatusCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, + base::PlatformFileError error); + +void ReadMetadataCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, + const base::PlatformFileInfo& file_info, + const base::FilePath& platform_path); + +void CreateSnapshotFileCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, + const base::PlatformFileInfo& file_info, + const base::FilePath& platform_path); + +void ReadDirectoryCallbackAdapater( + WebKit::WebFileSystemCallbacks* callbacks, + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more); + +void OpenFileSystemCallbackAdapter( + WebKit::WebFileSystemCallbacks* callbacks, + const std::string& name, const GURL& root); + +} // namespace content + +#endif // CONTENT_COMMON_FILEAPI_WEBFILESYSTEM_CALLBACK_ADAPTERS_H_ diff --git a/content/common/fileapi/webfilesystem_callback_dispatcher.h b/content/common/fileapi/webfilesystem_callback_dispatcher.h deleted file mode 100644 index ce2178b..0000000 --- a/content/common/fileapi/webfilesystem_callback_dispatcher.h +++ /dev/null @@ -1,48 +0,0 @@ -// 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. - -#ifndef CONTENT_COMMON_FILEAPI_WEBFILESYSTEM_CALLBACK_DISPATCHER_H_ -#define CONTENT_COMMON_FILEAPI_WEBFILESYSTEM_CALLBACK_DISPATCHER_H_ - -#include "base/basictypes.h" -#include "base/platform_file.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" - -class GURL; - -namespace WebKit { -class WebFileSystemCallbacks; -} - -namespace content { - -class WebFileSystemCallbackDispatcher - : public fileapi::FileSystemCallbackDispatcher { - public: - explicit WebFileSystemCallbackDispatcher( - WebKit::WebFileSystemCallbacks* callbacks); - - // FileSystemCallbackDispatcher implementation - virtual void DidSucceed() OVERRIDE; - virtual void DidReadMetadata( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) OVERRIDE; - virtual void DidCreateSnapshotFile( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) OVERRIDE; - virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, - bool has_more) OVERRIDE; - virtual void DidOpenFileSystem(const std::string&, - const GURL&) OVERRIDE; - virtual void DidFail(base::PlatformFileError) OVERRIDE; - virtual void DidWrite(int64 bytes, bool complete) OVERRIDE; - - private: - WebKit::WebFileSystemCallbacks* callbacks_; -}; - -} // namespace content - -#endif // CONTENT_COMMON_FILEAPI_WEBFILESYSTEM_CALLBACK_DISPATCHER_H_ diff --git a/content/common/fileapi/webfilesystem_impl.cc b/content/common/fileapi/webfilesystem_impl.cc index 0fcd7a3..479484b 100644 --- a/content/common/fileapi/webfilesystem_impl.cc +++ b/content/common/fileapi/webfilesystem_impl.cc @@ -4,9 +4,10 @@ #include "content/common/fileapi/webfilesystem_impl.h" +#include "base/bind.h" #include "content/common/child_thread.h" #include "content/common/fileapi/file_system_dispatcher.h" -#include "content/common/fileapi/webfilesystem_callback_dispatcher.h" +#include "content/common/fileapi/webfilesystem_callback_adapters.h" #include "content/common/fileapi/webfilewriter_impl.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" @@ -33,7 +34,7 @@ void WebFileSystemImpl::move(const WebURL& src_path, ChildThread::current()->file_system_dispatcher(); dispatcher->Move(GURL(src_path), GURL(dest_path), - new WebFileSystemCallbackDispatcher(callbacks)); + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::copy(const WebURL& src_path, @@ -43,33 +44,37 @@ void WebFileSystemImpl::copy(const WebURL& src_path, ChildThread::current()->file_system_dispatcher(); dispatcher->Copy(GURL(src_path), GURL(dest_path), - new WebFileSystemCallbackDispatcher(callbacks)); + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::remove(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->Remove(GURL(path), - false /* recursive */, - new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->Remove( + GURL(path), + false /* recursive */, + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::removeRecursively(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->Remove(GURL(path), - true /* recursive */, - new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->Remove( + GURL(path), + true /* recursive */, + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::readMetadata(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->ReadMetadata(GURL(path), - new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->ReadMetadata( + GURL(path), + base::Bind(&ReadMetadataCallbackAdapter, callbacks), + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::createFile(const WebURL& path, @@ -77,8 +82,9 @@ void WebFileSystemImpl::createFile(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->Create(GURL(path), exclusive, false, - false, new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->Create( + GURL(path), exclusive, false /* directory */, false /* recursive */, + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::createDirectory(const WebURL& path, @@ -86,32 +92,37 @@ void WebFileSystemImpl::createDirectory(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->Create(GURL(path), exclusive, true, - false, new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->Create( + GURL(path), exclusive, true /* directory */, false /* recursive */, + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::fileExists(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->Exists(GURL(path), false, - new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->Exists( + GURL(path), false /* directory */, + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::directoryExists(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->Exists(GURL(path), true, - new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->Exists( + GURL(path), true /* directory */, + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void WebFileSystemImpl::readDirectory(const WebURL& path, WebFileSystemCallbacks* callbacks) { FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); - dispatcher->ReadDirectory(GURL(path), - new WebFileSystemCallbackDispatcher(callbacks)); + dispatcher->ReadDirectory( + GURL(path), + base::Bind(&ReadDirectoryCallbackAdapater, callbacks), + base::Bind(&FileStatusCallbackAdapter, callbacks)); } WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( @@ -125,7 +136,9 @@ void WebFileSystemImpl::createSnapshotFileAndReadMetadata( FileSystemDispatcher* dispatcher = ChildThread::current()->file_system_dispatcher(); dispatcher->CreateSnapshotFile( - GURL(path), new WebFileSystemCallbackDispatcher(callbacks)); + GURL(path), + base::Bind(&CreateSnapshotFileCallbackAdapter, callbacks), + base::Bind(&FileStatusCallbackAdapter, callbacks)); } } // namespace content diff --git a/content/common/fileapi/webfilewriter_impl.cc b/content/common/fileapi/webfilewriter_impl.cc index ac685e1..fed77f5 100644 --- a/content/common/fileapi/webfilewriter_impl.cc +++ b/content/common/fileapi/webfilewriter_impl.cc @@ -4,60 +4,19 @@ #include "content/common/fileapi/webfilewriter_impl.h" +#include "base/bind.h" #include "content/common/child_thread.h" #include "content/common/fileapi/file_system_dispatcher.h" namespace content { + namespace { inline FileSystemDispatcher* GetFileSystemDispatcher() { return ChildThread::current()->file_system_dispatcher(); } -} - -class WebFileWriterImpl::CallbackDispatcher - : public fileapi::FileSystemCallbackDispatcher { - public: - explicit CallbackDispatcher( - const base::WeakPtr<WebFileWriterImpl>& writer) : writer_(writer) { - } - virtual ~CallbackDispatcher() { - } - virtual void DidReadMetadata( - const base::PlatformFileInfo&, - const base::FilePath&) OVERRIDE { - NOTREACHED(); - } - virtual void DidCreateSnapshotFile( - const base::PlatformFileInfo&, - const base::FilePath&) OVERRIDE { - NOTREACHED(); - } - virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, - bool has_more) OVERRIDE { - NOTREACHED(); - } - virtual void DidOpenFileSystem(const std::string& name, - const GURL& root) OVERRIDE { - NOTREACHED(); - } - virtual void DidSucceed() OVERRIDE { - if (writer_) - writer_->DidSucceed(); - } - virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { - if (writer_) - writer_->DidFail(error_code); - } - virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { - if (writer_) - writer_->DidWrite(bytes, complete); - } - private: - base::WeakPtr<WebFileWriterImpl> writer_; -}; +} // namespace WebFileWriterImpl::WebFileWriterImpl( const GURL& path, WebKit::WebFileWriterClient* client) @@ -70,20 +29,23 @@ WebFileWriterImpl::~WebFileWriterImpl() { void WebFileWriterImpl::DoTruncate(const GURL& path, int64 offset) { // The FileSystemDispatcher takes ownership of the CallbackDispatcher. - GetFileSystemDispatcher()->Truncate(path, offset, &request_id_, - new CallbackDispatcher(AsWeakPtr())); + GetFileSystemDispatcher()->Truncate( + path, offset, &request_id_, + base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr())); } void WebFileWriterImpl::DoWrite( const GURL& path, const GURL& blob_url, int64 offset) { GetFileSystemDispatcher()->Write( path, blob_url, offset, &request_id_, - new CallbackDispatcher(AsWeakPtr())); + base::Bind(&WebFileWriterImpl::DidWrite, AsWeakPtr()), + base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr())); } void WebFileWriterImpl::DoCancel() { - GetFileSystemDispatcher()->Cancel(request_id_, - new CallbackDispatcher(AsWeakPtr())); + GetFileSystemDispatcher()->Cancel( + request_id_, + base::Bind(&WebFileWriterImpl::DidFinish, AsWeakPtr())); } } // namespace content diff --git a/content/content_common.gypi b/content/content_common.gypi index d08f75e..cab1c9d 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -167,19 +167,19 @@ 'common/drag_messages.h', 'common/drag_traits.h', 'common/edit_command.h', + 'common/file_utilities_messages.h', 'common/fileapi/file_system_dispatcher.cc', 'common/fileapi/file_system_dispatcher.h', 'common/fileapi/file_system_messages.h', 'common/fileapi/webblob_messages.h', 'common/fileapi/webblobregistry_impl.cc', 'common/fileapi/webblobregistry_impl.h', - 'common/fileapi/webfilesystem_callback_dispatcher.cc', - 'common/fileapi/webfilesystem_callback_dispatcher.h', + 'common/fileapi/webfilesystem_callback_adapters.cc', + 'common/fileapi/webfilesystem_callback_adapters.h', 'common/fileapi/webfilesystem_impl.cc', 'common/fileapi/webfilesystem_impl.h', 'common/fileapi/webfilewriter_impl.cc', 'common/fileapi/webfilewriter_impl.h', - 'common/file_utilities_messages.h', 'common/find_match_rect_android.cc', 'common/find_match_rect_android.h', 'common/font_cache_dispatcher_win.cc', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index fe7c6a0..b3ee0bf 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -180,8 +180,6 @@ 'renderer/password_form_conversion_utils.cc', 'renderer/pepper/content_renderer_pepper_host_factory.cc', 'renderer/pepper/content_renderer_pepper_host_factory.h', - 'renderer/pepper/null_file_system_callback_dispatcher.cc', - 'renderer/pepper/null_file_system_callback_dispatcher.h', 'renderer/pepper/pepper_audio_input_host.cc', 'renderer/pepper/pepper_audio_input_host.h', 'renderer/pepper/pepper_broker_impl.cc', diff --git a/content/renderer/pepper/null_file_system_callback_dispatcher.cc b/content/renderer/pepper/null_file_system_callback_dispatcher.cc deleted file mode 100644 index 0c8d6a3..0000000 --- a/content/renderer/pepper/null_file_system_callback_dispatcher.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 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 "content/renderer/pepper/null_file_system_callback_dispatcher.h" - -#include "base/files/file_path.h" -#include "base/files/file_util_proxy.h" -#include "base/logging.h" -#include "googleurl/src/gurl.h" - -namespace content { - -void NullFileSystemCallbackDispatcher::DidSucceed() { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidReadMetadata( - const base::PlatformFileInfo& /* file_info */, - const base::FilePath& /* platform_path */) { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidCreateSnapshotFile( - const base::PlatformFileInfo& /* file_info */, - const base::FilePath& /* platform_path */) { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& /* entries */, - bool /* has_more */) { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidOpenFileSystem( - const std::string& /* name */, - const GURL& /* root */) { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidWrite(int64 /* bytes */, - bool /* complete */) { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidOpenFile( - base::PlatformFile /* file */, - int /* file_open_id */, - quota::QuotaLimitType /* quota_policy */) { - NOTREACHED(); -} - -void NullFileSystemCallbackDispatcher::DidFail( - base::PlatformFileError /* platform_error */) { - NOTREACHED(); -} - -} // namespace content diff --git a/content/renderer/pepper/null_file_system_callback_dispatcher.h b/content/renderer/pepper/null_file_system_callback_dispatcher.h deleted file mode 100644 index 1031948..0000000 --- a/content/renderer/pepper/null_file_system_callback_dispatcher.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 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 CONTENT_RENDERER_PEPPER_NULL_FILE_SYSTEM_CALLBACK_DISPATCHER_H_ -#define CONTENT_RENDERER_PEPPER_NULL_FILE_SYSTEM_CALLBACK_DISPATCHER_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/platform_file.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" -#include "webkit/quota/quota_types.h" - -class GURL; - -namespace base { -class FilePath; -class FileUtilProxy; -struct PlatformFileInfo; -} // namespace base - -namespace content { - -class NullFileSystemCallbackDispatcher - : public fileapi::FileSystemCallbackDispatcher { - public: - NullFileSystemCallbackDispatcher() {} - - virtual ~NullFileSystemCallbackDispatcher(){} - - virtual void DidSucceed() OVERRIDE; - virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) OVERRIDE; - virtual void DidCreateSnapshotFile( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) OVERRIDE; - virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, - bool has_more) OVERRIDE; - virtual void DidOpenFileSystem(const std::string& name, - const GURL& root) OVERRIDE; - virtual void DidWrite(int64 bytes, bool complete) OVERRIDE; - virtual void DidOpenFile(base::PlatformFile file, - int file_open_id, - quota::QuotaLimitType quota_policy) OVERRIDE; - virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(NullFileSystemCallbackDispatcher); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_PEPPER_NULL_FILE_SYSTEM_CALLBACK_DISPATCHER_H_ diff --git a/content/renderer/pepper/pepper_file_io_host.cc b/content/renderer/pepper/pepper_file_io_host.cc index 48dd502..d92dd69 100644 --- a/content/renderer/pepper/pepper_file_io_host.cc +++ b/content/renderer/pepper/pepper_file_io_host.cc @@ -11,7 +11,6 @@ #include "base/files/file_util_proxy.h" #include "content/public/common/content_client.h" #include "content/public/renderer/content_renderer_client.h" -#include "content/renderer/pepper/null_file_system_callback_dispatcher.h" #include "ppapi/c/pp_errors.h" #include "ppapi/host/dispatch_host_message.h" #include "ppapi/host/ppapi_host.h" @@ -19,7 +18,6 @@ #include "ppapi/shared_impl/file_type_conversion.h" #include "ppapi/shared_impl/time_conversion.h" #include "ppapi/thunk/enter.h" -#include "webkit/plugins/ppapi/file_callbacks.h" #include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" @@ -47,27 +45,6 @@ static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; -class PlatformGeneralCallbackTranslator - : public NullFileSystemCallbackDispatcher { - public: - explicit PlatformGeneralCallbackTranslator( - const PlatformGeneralCallback& callback) - : callback_(callback) {} - - virtual ~PlatformGeneralCallbackTranslator() {} - - virtual void DidSucceed() OVERRIDE { - callback_.Run(base::PLATFORM_FILE_OK); - } - - virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE { - callback_.Run(platform_error); - } - - private: - PlatformGeneralCallback callback_; -}; - int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) { // On the plugin side, some callbacks expect a parameter that means different // things depending on whether is negative or not. We translate for those @@ -222,10 +199,9 @@ int32_t PepperFileIOHost::OnHostMsgTouch( file_system_url_, PPTimeToTime(last_access_time), PPTimeToTime(last_modified_time), - new PlatformGeneralCallbackTranslator( - base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, - weak_factory_.GetWeakPtr(), - context->MakeReplyMessageContext())))) + base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, + weak_factory_.GetWeakPtr(), + context->MakeReplyMessageContext()))) return PP_ERROR_FAILED; state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); return PP_OK_COMPLETIONPENDING; @@ -327,10 +303,9 @@ int32_t PepperFileIOHost::OnHostMsgSetLength( if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { if (!plugin_delegate_->SetLength( file_system_url_, length, - new PlatformGeneralCallbackTranslator( - base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, - weak_factory_.GetWeakPtr(), - context->MakeReplyMessageContext())))) + base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, + weak_factory_.GetWeakPtr(), + context->MakeReplyMessageContext()))) return PP_ERROR_FAILED; } else { // TODO(nhiroki): fix a failure of FileIO.SetLength for an external diff --git a/content/renderer/pepper/pepper_file_system_host.cc b/content/renderer/pepper/pepper_file_system_host.cc index 13bff9a..ac36cd0 100644 --- a/content/renderer/pepper/pepper_file_system_host.cc +++ b/content/renderer/pepper/pepper_file_system_host.cc @@ -10,7 +10,6 @@ #include "content/common/fileapi/file_system_dispatcher.h" #include "content/public/renderer/render_view.h" #include "content/public/renderer/renderer_ppapi_host.h" -#include "content/renderer/pepper/null_file_system_callback_dispatcher.h" #include "ppapi/c/pp_errors.h" #include "ppapi/host/dispatch_host_message.h" #include "ppapi/host/ppapi_host.h" @@ -28,31 +27,6 @@ namespace content { namespace { -class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { - public: - explicit PlatformCallbackAdaptor( - const base::WeakPtr<PepperFileSystemHost>& weak_host) - : weak_host_(weak_host) {} - - virtual ~PlatformCallbackAdaptor() {} - - virtual void DidOpenFileSystem(const std::string& /* unused */, - const GURL& root) OVERRIDE { - if (weak_host_) - weak_host_->OpenFileSystemReply(PP_OK, root); - } - - virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE { - if (weak_host_) { - weak_host_->OpenFileSystemReply( - ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); - } - } - - private: - base::WeakPtr<PepperFileSystemHost> weak_host_; -}; - bool LooksLikeAGuid(const std::string& fsid) { const size_t kExpectedFsIdSize = 32; if (fsid.size() != kExpectedFsIdSize) @@ -97,13 +71,22 @@ int32_t PepperFileSystemHost::OnResourceMessageReceived( return PP_ERROR_FAILED; } -void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, - const GURL& root) { - opened_ = (pp_error == PP_OK); +void PepperFileSystemHost::DidOpenFileSystem( + const std::string& /* name_unused */, + const GURL& root) { + opened_ = true; root_url_ = root; + reply_context_.params.set_result(PP_OK); + host()->SendReply(reply_context_, PpapiPluginMsg_FileSystem_OpenReply()); + reply_context_ = ppapi::host::ReplyMessageContext(); +} + +void PepperFileSystemHost::DidFailOpenFileSystem( + base::PlatformFileError error) { + int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); + opened_ = (pp_error == PP_OK); reply_context_.params.set_result(pp_error); - host()->SendReply(reply_context_, - PpapiPluginMsg_FileSystem_OpenReply()); + host()->SendReply(reply_context_, PpapiPluginMsg_FileSystem_OpenReply()); reply_context_ = ppapi::host::ReplyMessageContext(); } @@ -142,7 +125,10 @@ int32_t PepperFileSystemHost::OnHostMsgOpen( GURL(plugin_instance->container()->element().document().url()). GetOrigin(), file_system_type, expected_size, true /* create */, - new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { + base::Bind(&PepperFileSystemHost::DidOpenFileSystem, + weak_factory_.GetWeakPtr()), + base::Bind(&PepperFileSystemHost::DidFailOpenFileSystem, + weak_factory_.GetWeakPtr()))) { return PP_ERROR_FAILED; } diff --git a/content/renderer/pepper/pepper_file_system_host.h b/content/renderer/pepper/pepper_file_system_host.h index 90ba4e0..6a9101a 100644 --- a/content/renderer/pepper/pepper_file_system_host.h +++ b/content/renderer/pepper/pepper_file_system_host.h @@ -36,11 +36,11 @@ class PepperFileSystemHost : bool IsOpened() const { return opened_; } GURL GetRootUrl() const { return root_url_; } - // It's public only to allow PlatformCallbackAdaptor to access. - void OpenFileSystemReply(int32_t pp_error, - const GURL& root); - private: + // Callback for OpenFileSystem. + void DidOpenFileSystem(const std::string& name_unused, const GURL& root); + void DidFailOpenFileSystem(base::PlatformFileError error); + int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, int64_t expected_size); int32_t OnHostMsgInitIsolatedFileSystem( diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index a3625b8..c38968f 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -90,7 +90,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "ui/gfx/size.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/plugins/npapi/webplugin.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -268,70 +267,34 @@ void DoNotifyCloseFile(int file_open_id, base::PlatformFileError /* unused */) { file_open_id); } -class AsyncOpenFileSystemURLCallbackTranslator - : public fileapi::FileSystemCallbackDispatcher { - public: - AsyncOpenFileSystemURLCallbackTranslator( - const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& - callback) - : callback_(callback) { - } - - virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} - - virtual void DidSucceed() OVERRIDE { - NOTREACHED(); - } - virtual void DidReadMetadata( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) OVERRIDE { - NOTREACHED(); - } - virtual void DidCreateSnapshotFile( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) OVERRIDE { - NOTREACHED(); - } - virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, - bool has_more) OVERRIDE { - NOTREACHED(); - } - virtual void DidOpenFileSystem(const std::string& name, - const GURL& root) OVERRIDE { - NOTREACHED(); - } - - virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { - base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; - callback_.Run(error_code, - base::PassPlatformFile(&invalid_file), - quota::kQuotaLimitTypeUnknown, - webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); - } - - virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { - NOTREACHED(); - } - - virtual void DidOpenFile(base::PlatformFile file, - int file_open_id, - quota::QuotaLimitType quota_policy) OVERRIDE { - callback_.Run(base::PLATFORM_FILE_OK, - base::PassPlatformFile(&file), - quota_policy, - base::Bind(&DoNotifyCloseFile, file_open_id)); - // Make sure we won't leak file handle if the requester has died. - if (file != base::kInvalidPlatformFileValue) { - base::FileUtilProxy::Close( - RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, - base::Bind(&DoNotifyCloseFile, file_open_id)); - } +void DidOpenFileSystemURL( + const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& + callback, + base::PlatformFile file, + int file_open_id, + quota::QuotaLimitType quota_policy) { + callback.Run(base::PLATFORM_FILE_OK, + base::PassPlatformFile(&file), + quota_policy, + base::Bind(&DoNotifyCloseFile, file_open_id)); + // Make sure we won't leak file handle if the requester has died. + if (file != base::kInvalidPlatformFileValue) { + base::FileUtilProxy::Close( + RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, + base::Bind(&DoNotifyCloseFile, file_open_id)); } +} - private: - webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback callback_; -}; +void DidFailOpenFileSystemURL( + const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& + callback, + base::PlatformFileError error_code) { + base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; + callback.Run(error_code, + base::PassPlatformFile(&invalid_file), + quota::kQuotaLimitTypeUnknown, + webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); +} void CreateHostForInProcessModule(RenderViewImpl* render_view, webkit::ppapi::PluginModule* module, @@ -1060,73 +1023,78 @@ GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( bool PepperPluginDelegateImpl::MakeDirectory( const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); return file_system_dispatcher->Create( - path, false, true, recursive, dispatcher); + path, false, true, recursive, callback); } bool PepperPluginDelegateImpl::Query( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const MetadataCallback& success_callback, + const StatusCallback& error_callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->ReadMetadata(path, dispatcher); + return file_system_dispatcher->ReadMetadata( + path, success_callback, error_callback); } bool PepperPluginDelegateImpl::ReadDirectoryEntries( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->ReadDirectory(path, dispatcher); + return file_system_dispatcher->ReadDirectory( + path, success_callback, error_callback); } bool PepperPluginDelegateImpl::Touch( const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); return file_system_dispatcher->TouchFile(path, last_access_time, - last_modified_time, dispatcher); + last_modified_time, callback); } bool PepperPluginDelegateImpl::SetLength( const GURL& path, int64_t length, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->Truncate(path, length, NULL, dispatcher); + return file_system_dispatcher->Truncate(path, length, NULL, callback); } bool PepperPluginDelegateImpl::Delete( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->Remove(path, false /* recursive */, - dispatcher); + return file_system_dispatcher->Remove(path, false /* recursive */, callback); } bool PepperPluginDelegateImpl::Rename( const GURL& file_path, const GURL& new_file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->Move(file_path, new_file_path, dispatcher); + return file_system_dispatcher->Move(file_path, new_file_path, callback); } bool PepperPluginDelegateImpl::ReadDirectory( const GURL& directory_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) { FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); + return file_system_dispatcher->ReadDirectory( + directory_path, success_callback, error_callback); } void PepperPluginDelegateImpl::QueryAvailableSpace( @@ -1151,9 +1119,10 @@ bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( FileSystemDispatcher* file_system_dispatcher = ChildThread::current()->file_system_dispatcher(); - return file_system_dispatcher->OpenFile(path, flags, - new AsyncOpenFileSystemURLCallbackTranslator( - callback)); + return file_system_dispatcher->OpenFile( + path, flags, + base::Bind(&DidOpenFileSystemURL, callback), + base::Bind(&DidFailOpenFileSystemURL, callback)); } void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h index c694d54..40dabee 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h @@ -215,32 +215,35 @@ class PepperPluginDelegateImpl virtual bool MakeDirectory( const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const StatusCallback& callback) OVERRIDE; virtual bool Query( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const MetadataCallback& success_callback, + const StatusCallback& error_callback) OVERRIDE; virtual bool ReadDirectoryEntries( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) OVERRIDE; virtual bool Touch( const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const StatusCallback& callback) OVERRIDE; virtual bool SetLength( const GURL& path, int64_t length, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const StatusCallback& callback) OVERRIDE; virtual bool Delete( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const StatusCallback& callback) OVERRIDE; virtual bool Rename( const GURL& file_path, const GURL& new_file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const StatusCallback& callback) OVERRIDE; virtual bool ReadDirectory( const GURL& directory_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE; + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) OVERRIDE; virtual void QueryAvailableSpace( const GURL& origin, quota::StorageType type, diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 89dc702..079a5cf7 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -33,7 +33,7 @@ #include "content/common/database_messages.h" #include "content/common/drag_messages.h" #include "content/common/fileapi/file_system_dispatcher.h" -#include "content/common/fileapi/webfilesystem_callback_dispatcher.h" +#include "content/common/fileapi/webfilesystem_callback_adapters.h" #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" #include "content/common/input_messages.h" #include "content/common/java_bridge_messages.h" @@ -4232,7 +4232,9 @@ void RenderViewImpl::openFileSystem( ChildThread::current()->file_system_dispatcher()->OpenFileSystem( GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), - size, create, new WebFileSystemCallbackDispatcher(callbacks)); + size, create, + base::Bind(&OpenFileSystemCallbackAdapter, callbacks), + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void RenderViewImpl::deleteFileSystem( @@ -4251,7 +4253,7 @@ void RenderViewImpl::deleteFileSystem( ChildThread::current()->file_system_dispatcher()->DeleteFileSystem( GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), - new WebFileSystemCallbackDispatcher(callbacks)); + base::Bind(&FileStatusCallbackAdapter, callbacks)); } void RenderViewImpl::queryStorageUsageAndQuota( diff --git a/content/worker/websharedworkerclient_proxy.cc b/content/worker/websharedworkerclient_proxy.cc index 4db74b8..d079171 100644 --- a/content/worker/websharedworkerclient_proxy.cc +++ b/content/worker/websharedworkerclient_proxy.cc @@ -8,7 +8,7 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "content/common/fileapi/file_system_dispatcher.h" -#include "content/common/fileapi/webfilesystem_callback_dispatcher.h" +#include "content/common/fileapi/webfilesystem_callback_adapters.h" #include "content/common/quota_dispatcher.h" #include "content/common/webmessageportchannel_impl.h" #include "content/common/worker_messages.h" @@ -168,7 +168,9 @@ void WebSharedWorkerClientProxy::openFileSystem( WebKit::WebFileSystemCallbacks* callbacks) { ChildThread::current()->file_system_dispatcher()->OpenFileSystem( stub_->url().GetOrigin(), static_cast<fileapi::FileSystemType>(type), - size, create, new WebFileSystemCallbackDispatcher(callbacks)); + size, create, + base::Bind(&OpenFileSystemCallbackAdapter, callbacks), + base::Bind(&FileStatusCallbackAdapter, callbacks)); } bool WebSharedWorkerClientProxy::allowIndexedDB(const WebKit::WebString& name) { diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.cc b/webkit/chromeos/fileapi/remote_file_system_operation.cc index 153657c..d764266 100644 --- a/webkit/chromeos/fileapi/remote_file_system_operation.cc +++ b/webkit/chromeos/fileapi/remote_file_system_operation.cc @@ -11,7 +11,6 @@ #include "googleurl/src/gurl.h" #include "net/url_request/url_request_context.h" #include "webkit/chromeos/fileapi/remote_file_stream_writer.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_writer_delegate.h" diff --git a/webkit/fileapi/file_system_callback_dispatcher.cc b/webkit/fileapi/file_system_callback_dispatcher.cc deleted file mode 100644 index 3e040b3..0000000 --- a/webkit/fileapi/file_system_callback_dispatcher.cc +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -#include "webkit/fileapi/file_system_callback_dispatcher.h" - -#include "base/logging.h" - -namespace fileapi { - -FileSystemCallbackDispatcher::~FileSystemCallbackDispatcher() { -} - -void FileSystemCallbackDispatcher::DidOpenFile( - base::PlatformFile file, - int file_open_id, - quota::QuotaLimitType quota_policy) { - NOTREACHED(); - - if (file != base::kInvalidPlatformFileValue) - base::ClosePlatformFile(file); -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_system_callback_dispatcher.h b/webkit/fileapi/file_system_callback_dispatcher.h deleted file mode 100644 index 14e4196..0000000 --- a/webkit/fileapi/file_system_callback_dispatcher.h +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_CALLBACK_DISPATCHER_H_ -#define WEBKIT_FILEAPI_FILE_SYSTEM_CALLBACK_DISPATCHER_H_ - -#include <string> -#include <vector> - -#include "base/files/file_util_proxy.h" -#include "base/platform_file.h" -#include "base/process.h" -#include "webkit/quota/quota_types.h" -#include "webkit/storage/webkit_storage_export.h" - -class GURL; - -namespace fileapi { - -// This class mirrors the callbacks in -// third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h, -// but uses chromium types. -class WEBKIT_STORAGE_EXPORT FileSystemCallbackDispatcher { - public: - virtual ~FileSystemCallbackDispatcher(); - - // Callback for various operations that don't require return values. - virtual void DidSucceed() = 0; - - // Callback to report information for a file. - virtual void DidReadMetadata( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) = 0; - - // Callback to report information for a file and its actual file path. - virtual void DidCreateSnapshotFile( - const base::PlatformFileInfo& file_info, - const base::FilePath& platform_path) = 0; - - // Callback to report the contents of a directory. If the contents of - // the given directory are reported in one batch, then |entries| will have - // the list of all files/directories in the given directory, |has_more| will - // be false, and this callback will be called only once. If the contents of - // the given directory are reported in multiple chunks, then this callback - // will be called multiple times, |entries| will have only a subset of - // all contents (the subsets reported in any two calls are disjoint), and - // |has_more| will be true, except for the last chunk. - virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, - bool has_more) = 0; - - // Callback for opening a file system. Called with a name and root path for - // the FileSystem when the request is accepted. Used by WebFileSystem API. - virtual void DidOpenFileSystem(const std::string& name, - const GURL& root) = 0; - - // Called with an error code when a requested operation has failed. - virtual void DidFail(base::PlatformFileError error_code) = 0; - - // Callback for FileWriter's write() call. - virtual void DidWrite(int64 bytes, bool complete) = 0; - - // Callback for OpenFile. This isn't in WebFileSystemCallbacks, as it's just - // for Pepper. - // The method will be responsible for closing |file|. - virtual void DidOpenFile(base::PlatformFile file, - int file_open_id, - quota::QuotaLimitType quota_policy); -}; - -} // namespace fileapi - -#endif // WEBKIT_FILEAPI_FILE_SYSTEM_CALLBACK_DISPATCHER_H_ diff --git a/webkit/fileapi/isolated_mount_point_provider.cc b/webkit/fileapi/isolated_mount_point_provider.cc index 36d8879..7cba737 100644 --- a/webkit/fileapi/isolated_mount_point_provider.cc +++ b/webkit/fileapi/isolated_mount_point_provider.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/files/file_path.h" +#include "base/files/file_util_proxy.h" #include "base/logging.h" #include "base/message_loop_proxy.h" #include "base/platform_file.h" @@ -15,7 +16,6 @@ #include "webkit/blob/local_file_stream_reader.h" #include "webkit/fileapi/async_file_util_adapter.h" #include "webkit/fileapi/copy_or_move_file_validator.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_file_stream_reader.h" #include "webkit/fileapi/file_system_operation_context.h" diff --git a/webkit/fileapi/webfilewriter_base.cc b/webkit/fileapi/webfilewriter_base.cc index ca0239f..cd0bd757 100644 --- a/webkit/fileapi/webfilewriter_base.cc +++ b/webkit/fileapi/webfilewriter_base.cc @@ -63,6 +63,34 @@ void WebFileWriterBase::cancel() { DoCancel(); } +void WebFileWriterBase::DidFinish(base::PlatformFileError error_code) { + if (error_code == base::PLATFORM_FILE_OK) + DidSucceed(); + else + DidFail(error_code); +} + +void WebFileWriterBase::DidWrite(int64 bytes, bool complete) { + DCHECK(kOperationWrite == operation_); + switch (cancel_state_) { + case kCancelNotInProgress: + if (complete) + operation_ = kOperationNone; + client_->didWrite(bytes, complete); + break; + case kCancelSent: + // This is the success call of the write, which we'll eat, even though + // it succeeded before the cancel got there. We accepted the cancel call, + // so the write will eventually return an error. + if (complete) + cancel_state_ = kCancelReceivedWriteResponse; + break; + case kCancelReceivedWriteResponse: + default: + NOTREACHED(); + } +} + void WebFileWriterBase::DidSucceed() { // Write never gets a DidSucceed call, so this is either a cancel or truncate // response. @@ -115,27 +143,6 @@ void WebFileWriterBase::DidFail(base::PlatformFileError error_code) { } } -void WebFileWriterBase::DidWrite(int64 bytes, bool complete) { - DCHECK(kOperationWrite == operation_); - switch (cancel_state_) { - case kCancelNotInProgress: - if (complete) - operation_ = kOperationNone; - client_->didWrite(bytes, complete); - break; - case kCancelSent: - // This is the success call of the write, which we'll eat, even though - // it succeeded before the cancel got there. We accepted the cancel call, - // so the write will eventually return an error. - if (complete) - cancel_state_ = kCancelReceivedWriteResponse; - break; - case kCancelReceivedWriteResponse: - default: - NOTREACHED(); - } -} - void WebFileWriterBase::FinishCancel() { DCHECK(kCancelReceivedWriteResponse == cancel_state_); DCHECK(kOperationNone != operation_); diff --git a/webkit/fileapi/webfilewriter_base.h b/webkit/fileapi/webfilewriter_base.h index 60872e2..f7838e6 100644 --- a/webkit/fileapi/webfilewriter_base.h +++ b/webkit/fileapi/webfilewriter_base.h @@ -30,6 +30,13 @@ class WEBKIT_STORAGE_EXPORT WebFileWriterBase virtual void cancel(); protected: + // This calls DidSucceed() or DidFail() based on the value of |error_code|. + void DidFinish(base::PlatformFileError error_code); + + void DidWrite(int64 bytes, bool complete); + void DidSucceed(); + void DidFail(base::PlatformFileError error_code); + // Derived classes must provide these methods to asynchronously perform // the requested operation, and they must call the appropiate DidSomething // method upon completion and as progress is made in the Write case. @@ -38,10 +45,6 @@ class WEBKIT_STORAGE_EXPORT WebFileWriterBase int64 offset) = 0; virtual void DoCancel() = 0; - void DidSucceed(); - void DidFail(base::PlatformFileError error_code); - void DidWrite(int64 bytes, bool complete); - private: enum OperationType { kOperationNone, diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi index 4c3f288..3e6afc4 100644 --- a/webkit/fileapi/webkit_fileapi.gypi +++ b/webkit/fileapi/webkit_fileapi.gypi @@ -17,8 +17,6 @@ '../fileapi/file_permission_policy.cc', '../fileapi/file_permission_policy.h', '../fileapi/file_stream_writer.h', - '../fileapi/file_system_callback_dispatcher.cc', - '../fileapi/file_system_callback_dispatcher.h', '../fileapi/file_system_context.cc', '../fileapi/file_system_context.h', '../fileapi/file_system_dir_url_request_job.cc', diff --git a/webkit/plugins/ppapi/file_callbacks.cc b/webkit/plugins/ppapi/file_callbacks.cc deleted file mode 100644 index d75def9..0000000 --- a/webkit/plugins/ppapi/file_callbacks.cc +++ /dev/null @@ -1,147 +0,0 @@ -// 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. - -#include "webkit/plugins/ppapi/file_callbacks.h" - -#include "base/logging.h" -#include "base/utf_string_conversions.h" -#include "ppapi/c/pp_file_info.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/ppb_file_system.h" -#include "ppapi/shared_impl/file_type_conversion.h" -#include "ppapi/shared_impl/ppb_file_ref_shared.h" -#include "ppapi/shared_impl/time_conversion.h" -#include "ppapi/shared_impl/tracked_callback.h" -#include "webkit/fileapi/file_system_types.h" -#include "webkit/fileapi/file_system_util.h" -#include "webkit/plugins/ppapi/plugin_module.h" -#include "webkit/plugins/ppapi/ppb_file_ref_impl.h" - -using ppapi::Resource; -using ppapi::TimeToPPTime; -using ppapi::TrackedCallback; - -namespace webkit { -namespace ppapi { - -FileCallbacks::FileCallbacks( - Resource* resource, - scoped_refptr<TrackedCallback> callback) - : callback_(callback), - file_system_type_(PP_FILESYSTEMTYPE_INVALID), - read_entries_dir_ref_(NULL) { -} - -FileCallbacks::FileCallbacks( - Resource* resource, - scoped_refptr<TrackedCallback> callback, - linked_ptr<PP_FileInfo> info, - PP_FileSystemType file_system_type) - : callback_(callback), - info_(info), - file_system_type_(file_system_type), - read_entries_dir_ref_(NULL) { -} - -FileCallbacks::FileCallbacks( - ::ppapi::Resource* resource, - scoped_refptr< ::ppapi::TrackedCallback> callback, - const ReadDirectoryEntriesParams& params) - : callback_(callback), - file_system_type_(PP_FILESYSTEMTYPE_INVALID), - read_entries_dir_ref_(params.dir_ref), - read_entries_files_(params.files), - read_entries_file_types_(params.file_types) { -} - -FileCallbacks::~FileCallbacks() {} - -void FileCallbacks::DidSucceed() { - if (callback_->completed()) - return; - - callback_->Run(PP_OK); -} - -void FileCallbacks::DidReadMetadata( - const base::PlatformFileInfo& file_info, - const base::FilePath& unused) { - if (callback_->completed()) - return; - - DCHECK(info_.get()); - info_->size = file_info.size; - info_->creation_time = TimeToPPTime(file_info.creation_time); - info_->last_access_time = TimeToPPTime(file_info.last_accessed); - info_->last_modified_time = TimeToPPTime(file_info.last_modified); - info_->system_type = file_system_type_; - if (file_info.is_directory) - info_->type = PP_FILETYPE_DIRECTORY; - else - info_->type = PP_FILETYPE_REGULAR; - - callback_->Run(PP_OK); -} - -void FileCallbacks::DidCreateSnapshotFile( - const base::PlatformFileInfo& file_info, - const base::FilePath& path) { - NOTREACHED(); -} - -void FileCallbacks::DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { - if (callback_->completed()) - return; - - // The current filesystem backend always returns false. - DCHECK(!has_more); - - DCHECK(read_entries_dir_ref_); - DCHECK(read_entries_files_.get()); - DCHECK(read_entries_file_types_.get()); - - std::string dir_path = read_entries_dir_ref_->GetCreateInfo().path; - if (dir_path.empty() || dir_path[dir_path.size() - 1] != '/') - dir_path += '/'; - - for (size_t i = 0; i < entries.size(); ++i) { - const base::FileUtilProxy::Entry& entry = entries[i]; - scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal( - read_entries_dir_ref_->pp_instance(), - read_entries_dir_ref_->file_system_resource(), - dir_path + fileapi::FilePathToString(base::FilePath(entry.name)))); - read_entries_files_->push_back(file_ref->GetCreateInfo()); - read_entries_file_types_->push_back( - entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); - // Add a ref count on behalf of the plugin side. - file_ref->GetReference(); - } - CHECK_EQ(read_entries_files_->size(), read_entries_file_types_->size()); - - callback_->Run(PP_OK); -} - -void FileCallbacks::DidOpenFileSystem(const std::string&, - const GURL& root_url) { - NOTREACHED(); -} - -void FileCallbacks::DidFail(base::PlatformFileError error_code) { - RunCallback(error_code); -} - -void FileCallbacks::DidWrite(int64 bytes, bool complete) { - NOTREACHED(); -} - -void FileCallbacks::RunCallback(base::PlatformFileError error_code) { - if (callback_->completed()) - return; - - callback_->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/file_callbacks.h b/webkit/plugins/ppapi/file_callbacks.h deleted file mode 100644 index 2df1c24..0000000 --- a/webkit/plugins/ppapi/file_callbacks.h +++ /dev/null @@ -1,94 +0,0 @@ -// 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. - -#ifndef WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_ -#define WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_ - -#include <string> -#include <vector> - -#include "base/memory/linked_ptr.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "base/platform_file.h" -#include "googleurl/src/gurl.h" -#include "ppapi/c/pp_array_output.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_file_info.h" -#include "ppapi/c/pp_resource.h" -#include "webkit/fileapi/file_system_callback_dispatcher.h" - -struct PP_FileInfo; - -namespace base { -class FilePath; -} - -namespace ppapi { -class Resource; -class TrackedCallback; -struct PPB_FileRef_CreateInfo; -} - -namespace webkit { -namespace ppapi { - -class PPB_FileRef_Impl; - -// Instances of this class are deleted by FileSystemDispatcher. -class FileCallbacks : public fileapi::FileSystemCallbackDispatcher { - typedef std::vector< ::ppapi::PPB_FileRef_CreateInfo> CreateInfos; - typedef std::vector<PP_FileType> FileTypes; - - public: - // Doesn't take the ownership of members. - struct ReadDirectoryEntriesParams { - PPB_FileRef_Impl* dir_ref; - linked_ptr<CreateInfos> files; - linked_ptr<FileTypes> file_types; - }; - - FileCallbacks(::ppapi::Resource* resource, - scoped_refptr< ::ppapi::TrackedCallback> callback); - FileCallbacks(::ppapi::Resource* resource, - scoped_refptr< ::ppapi::TrackedCallback> callback, - linked_ptr<PP_FileInfo> info, - PP_FileSystemType file_system_type); - FileCallbacks(::ppapi::Resource* resource, - scoped_refptr< ::ppapi::TrackedCallback> callback, - const ReadDirectoryEntriesParams& params); - virtual ~FileCallbacks(); - - // FileSystemCallbackDispatcher implementation. - virtual void DidSucceed(); - virtual void DidReadMetadata( - const base::PlatformFileInfo& file_info, - const base::FilePath& unused); - virtual void DidCreateSnapshotFile( - const base::PlatformFileInfo& file_info, - const base::FilePath& path); - virtual void DidReadDirectory( - const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more); - virtual void DidOpenFileSystem(const std::string&, - const GURL& root_url); - virtual void DidFail(base::PlatformFileError error_code); - virtual void DidWrite(int64 bytes, bool complete); - - scoped_refptr< ::ppapi::TrackedCallback> GetTrackedCallback() const; - - private: - void RunCallback(base::PlatformFileError error_code); - - scoped_refptr< ::ppapi::TrackedCallback> callback_; - linked_ptr<PP_FileInfo> info_; - PP_FileSystemType file_system_type_; - PPB_FileRef_Impl* read_entries_dir_ref_; - linked_ptr<CreateInfos> read_entries_files_; - linked_ptr<FileTypes> read_entries_file_types_; -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_FILE_CALLBACKS_H_ diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index feccd2f..de24b2f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -173,30 +173,24 @@ GURL MockPluginDelegate::GetFileSystemRootUrl( return GURL(); } -bool MockPluginDelegate::OpenFileSystem( - const GURL& origin_url, - fileapi::FileSystemType type, - long long size, - fileapi::FileSystemCallbackDispatcher* dispatcher) { - return false; -} - bool MockPluginDelegate::MakeDirectory( const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { return false; } bool MockPluginDelegate::Query( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const MetadataCallback& success_callback, + const StatusCallback& error_callback) { return false; } bool MockPluginDelegate::ReadDirectoryEntries( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) { return false; } @@ -204,33 +198,34 @@ bool MockPluginDelegate::Touch( const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { return false; } bool MockPluginDelegate::SetLength( const GURL& path, int64_t length, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { return false; } bool MockPluginDelegate::Delete( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { return false; } bool MockPluginDelegate::Rename( const GURL& file_path, const GURL& new_file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const StatusCallback& callback) { return false; } bool MockPluginDelegate::ReadDirectory( const GURL& directory_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) { + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) { return false; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index d343c2a..a3a35b0 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -77,35 +77,33 @@ class MockPluginDelegate : public PluginDelegate { PP_Resource resource) const; virtual GURL GetFileSystemRootUrl(PP_Instance instance, PP_Resource resource) const; - virtual bool OpenFileSystem( - const GURL& origin_url, - fileapi::FileSystemType type, - long long size, - fileapi::FileSystemCallbackDispatcher* dispatcher); virtual bool MakeDirectory( const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); virtual bool Query(const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const MetadataCallback& success_callback, + const StatusCallback& error_callback); virtual bool ReadDirectoryEntries( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback); virtual bool Touch(const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); virtual bool SetLength(const GURL& path, int64_t length, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); virtual bool Delete(const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); virtual bool Rename(const GURL& file_path, const GURL& new_file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const StatusCallback& callback); virtual bool ReadDirectory( const GURL& directory_path, - fileapi::FileSystemCallbackDispatcher* dispatcher); + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback); virtual void QueryAvailableSpace(const GURL& origin, quota::StorageType type, const AvailableSpaceCallback& callback); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index f48e94e..ccd9e3f 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -9,6 +9,7 @@ #include <vector> #include "base/callback.h" +#include "base/files/file_util_proxy.h" #include "base/memory/ref_counted.h" #include "base/message_loop_proxy.h" #include "base/platform_file.h" @@ -53,10 +54,6 @@ class MessageLoopProxy; class Time; } -namespace fileapi { -class FileSystemCallbackDispatcher; -} - namespace gfx { class Point; } @@ -501,30 +498,42 @@ class PluginDelegate { int flags, const AsyncOpenFileSystemURLCallback& callback) = 0; + // Callback typedefs for FileSystem related methods. + typedef base::Callback<void (base::PlatformFileError)> StatusCallback; + typedef base::Callback<void( + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more)> ReadDirectoryCallback; + typedef base::Callback<void( + const base::PlatformFileInfo& file_info, + const base::FilePath& platform_path)> MetadataCallback; + virtual bool MakeDirectory( const GURL& path, bool recursive, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const StatusCallback& callback) = 0; virtual bool Query(const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const MetadataCallback& success_callback, + const StatusCallback& error_callback) = 0; virtual bool ReadDirectoryEntries( const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) = 0; virtual bool Touch(const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const StatusCallback& callback) = 0; virtual bool SetLength(const GURL& path, int64_t length, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const StatusCallback& callback) = 0; virtual bool Delete(const GURL& path, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const StatusCallback& callback) = 0; virtual bool Rename(const GURL& file_path, const GURL& new_file_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const StatusCallback& callback) = 0; virtual bool ReadDirectory( const GURL& directory_path, - fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; + const ReadDirectoryCallback& success_callback, + const StatusCallback& error_callback) = 0; // For quota handlings for FileIO API. typedef base::Callback<void (int64)> AvailableSpaceCallback; diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index d6c7ce8..e57169c 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -15,8 +15,8 @@ #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_file_system_api.h" +#include "webkit/fileapi/file_system_util.h" #include "webkit/plugins/ppapi/common.h" -#include "webkit/plugins/ppapi/file_callbacks.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -90,6 +90,29 @@ std::string GetNameForVirtualFilePath(const std::string& path) { void IgnoreCloseCallback(base::PlatformFileError error_code) { } +void PlatformFileInfoToPPFileInfo( + const base::PlatformFileInfo& file_info, + PP_FileSystemType file_system_type, + PP_FileInfo* info) { + DCHECK(info); + + info->size = file_info.size; + info->system_type = file_system_type; + info->creation_time = ::ppapi::TimeToPPTime(file_info.creation_time); + info->last_access_time = ::ppapi::TimeToPPTime(file_info.last_accessed); + info->last_modified_time = ::ppapi::TimeToPPTime(file_info.last_modified); + + if (file_info.is_symbolic_link) { + // Only external filesystem may have symbolic link files. + DCHECK_EQ(PP_FILESYSTEMTYPE_EXTERNAL, file_system_type); + info->type = PP_FILETYPE_OTHER; + } else if (file_info.is_directory) { + info->type = PP_FILETYPE_DIRECTORY; + } else { + info->type = PP_FILETYPE_REGULAR; + } +} + void GetFileInfoCallback( scoped_refptr<base::TaskRunner> task_runner, base::PlatformFile file, @@ -104,21 +127,14 @@ void GetFileInfoCallback( return; int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); - if (pp_error != PP_OK) + if (pp_error != PP_OK) { callback->Run(pp_error); + return; + } - info->size = file_info.size; - if (file_info.is_symbolic_link) - info->type = PP_FILETYPE_OTHER; - else if (file_info.is_directory) - info->type = PP_FILETYPE_DIRECTORY; - else - info->type = PP_FILETYPE_REGULAR; + PlatformFileInfoToPPFileInfo( + file_info, PP_FILESYSTEMTYPE_EXTERNAL, info.get()); - info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; - info->creation_time = file_info.creation_time.ToDoubleT(); - info->last_access_time = file_info.last_accessed.ToDoubleT(); - info->last_modified_time = file_info.last_modified.ToDoubleT(); callback->Run(PP_OK); } @@ -131,8 +147,10 @@ void QueryCallback(scoped_refptr<base::TaskRunner> task_runner, return; int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); - if (pp_error != PP_OK) + if (pp_error != PP_OK) { callback->Run(pp_error); + return; + } base::PlatformFile file = passed_file.ReleaseValue(); if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( @@ -145,6 +163,65 @@ void QueryCallback(scoped_refptr<base::TaskRunner> task_runner, } } +void DidReadMetadata( + scoped_refptr< ::ppapi::TrackedCallback> callback, + linked_ptr<PP_FileInfo> info, + PP_FileSystemType file_system_type, + const base::PlatformFileInfo& file_info, + const base::FilePath& unused) { + if (!TrackedCallback::IsPending(callback)) + return; + + PlatformFileInfoToPPFileInfo(file_info, file_system_type, info.get()); + callback->Run(PP_OK); +} + +void DidReadDirectory( + scoped_refptr< ::ppapi::TrackedCallback> callback, + PPB_FileRef_Impl* dir_ref, + linked_ptr<std::vector< ::ppapi::PPB_FileRef_CreateInfo> > dir_files, + linked_ptr<std::vector<PP_FileType> > dir_file_types, + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more) { + if (!TrackedCallback::IsPending(callback)) + return; + + // The current filesystem backend always returns false. + DCHECK(!has_more); + + DCHECK(dir_ref); + DCHECK(dir_files.get()); + DCHECK(dir_file_types.get()); + + std::string dir_path = dir_ref->GetCreateInfo().path; + if (dir_path.empty() || dir_path[dir_path.size() - 1] != '/') + dir_path += '/'; + + for (size_t i = 0; i < entries.size(); ++i) { + const base::FileUtilProxy::Entry& entry = entries[i]; + scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal( + dir_ref->pp_instance(), + dir_ref->file_system_resource(), + dir_path + fileapi::FilePathToString(base::FilePath(entry.name)))); + dir_files->push_back(file_ref->GetCreateInfo()); + dir_file_types->push_back( + entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); + // Add a ref count on behalf of the plugin side. + file_ref->GetReference(); + } + CHECK_EQ(dir_files->size(), dir_file_types->size()); + + callback->Run(PP_OK); +} + +void DidFinishFileOperation( + scoped_refptr< ::ppapi::TrackedCallback> callback, + base::PlatformFileError error_code) { + if (callback->completed()) + return; + callback->Run(::ppapi::PlatformFileErrorToPepperError(error_code)); +} + } // namespace PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, @@ -250,7 +327,7 @@ int32_t PPB_FileRef_Impl::MakeDirectory( return PP_ERROR_FAILED; if (!plugin_instance->delegate()->MakeDirectory( GetFileSystemURL(), PP_ToBool(make_ancestors), - new FileCallbacks(this, callback))) + base::Bind(&DidFinishFileOperation, callback))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -268,7 +345,7 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, GetFileSystemURL(), PPTimeToTime(last_access_time), PPTimeToTime(last_modified_time), - new FileCallbacks(this, callback))) + base::Bind(&DidFinishFileOperation, callback))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -282,7 +359,7 @@ int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { return PP_ERROR_FAILED; if (!plugin_instance->delegate()->Delete( GetFileSystemURL(), - new FileCallbacks(this, callback))) + base::Bind(&DidFinishFileOperation, callback))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -306,7 +383,7 @@ int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, return PP_ERROR_FAILED; if (!plugin_instance->delegate()->Rename( GetFileSystemURL(), new_file_ref->GetFileSystemURL(), - new FileCallbacks(this, callback))) + base::Bind(&DidFinishFileOperation, callback))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -408,11 +485,12 @@ int32_t PPB_FileRef_Impl::QueryInHost( if (!delegate) return PP_ERROR_FAILED; + PP_FileSystemType file_system_type = + delegate->GetFileSystemType(pp_instance(), file_system_); if (!plugin_instance->delegate()->Query( GetFileSystemURL(), - new FileCallbacks(this, callback, info, - delegate->GetFileSystemType(pp_instance(), - file_system_)))) + base::Bind(&DidReadMetadata, callback, info, file_system_type), + base::Bind(&DidFinishFileOperation, callback))) return PP_ERROR_FAILED; } @@ -437,14 +515,13 @@ int32_t PPB_FileRef_Impl::ReadDirectoryEntriesInHost( if (!plugin_instance) return PP_ERROR_FAILED; - FileCallbacks::ReadDirectoryEntriesParams params; - params.dir_ref = this; - params.files = files; - params.file_types = file_types; - + // TODO(yzshen): Passing base::Unretained(this) to the callback could + // be dangerous. if (!plugin_instance->delegate()->ReadDirectoryEntries( GetFileSystemURL(), - new FileCallbacks(this, callback, params))) + base::Bind(&DidReadDirectory, + callback, base::Unretained(this), files, file_types), + base::Bind(&DidFinishFileOperation, callback))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h index 272b4a4..2da8903 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.h +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h @@ -16,7 +16,6 @@ #include "ppapi/shared_impl/ppb_file_ref_shared.h" #include "ppapi/shared_impl/scoped_pp_resource.h" #include "ppapi/shared_impl/var.h" -#include "webkit/plugins/ppapi/file_callbacks.h" #include "webkit/plugins/webkit_plugins_export.h" namespace webkit { diff --git a/webkit/plugins/webkit_plugins.gypi b/webkit/plugins/webkit_plugins.gypi index 05f87eb..a301783 100644 --- a/webkit/plugins/webkit_plugins.gypi +++ b/webkit/plugins/webkit_plugins.gypi @@ -126,8 +126,6 @@ '../plugins/ppapi/content_decryptor_delegate.h', '../plugins/ppapi/event_conversion.cc', '../plugins/ppapi/event_conversion.h', - '../plugins/ppapi/file_callbacks.cc', - '../plugins/ppapi/file_callbacks.h', '../plugins/ppapi/fullscreen_container.h', '../plugins/ppapi/gfx_conversion.h', '../plugins/ppapi/host_array_buffer_var.cc', |