diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 14:40:10 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 14:40:10 +0000 |
commit | 09dcdf81040085f81965fb92bd8ebc95d8a94189 (patch) | |
tree | f2b978154aaddf0e8d796eeffcab5217d72de722 /content/child | |
parent | e0532fb04c1412a3370c1cc7c166ca475d6c6e48 (diff) | |
download | chromium_src-09dcdf81040085f81965fb92bd8ebc95d8a94189.zip chromium_src-09dcdf81040085f81965fb92bd8ebc95d8a94189.tar.gz chromium_src-09dcdf81040085f81965fb92bd8ebc95d8a94189.tar.bz2 |
Make WebFileSystemCallbacks not self-destruct
It's multi-sided patch, so again it has ugly ifdefs.
Corresponding blink patch:
https://codereview.chromium.org/23704004/
BUG=257349
TEST=try, both with and without Blink patch
Review URL: https://chromiumcodereview.appspot.com/23762002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/child')
-rw-r--r-- | content/child/fileapi/webfilesystem_impl.cc | 93 | ||||
-rw-r--r-- | content/child/fileapi/webfilesystem_impl.h | 51 | ||||
-rw-r--r-- | content/child/fileapi/webfilewriter_base.cc | 4 | ||||
-rw-r--r-- | content/child/fileapi/webfilewriter_base.h | 2 | ||||
-rw-r--r-- | content/child/fileapi/webfilewriter_base_unittest.cc | 4 |
5 files changed, 91 insertions, 63 deletions
diff --git a/content/child/fileapi/webfilesystem_impl.cc b/content/child/fileapi/webfilesystem_impl.cc index b811c27..2c3de4d 100644 --- a/content/child/fileapi/webfilesystem_impl.cc +++ b/content/child/fileapi/webfilesystem_impl.cc @@ -16,9 +16,9 @@ #include "content/child/fileapi/webfilewriter_impl.h" #include "content/common/fileapi/file_system_messages.h" #include "third_party/WebKit/public/platform/WebFileInfo.h" +#include "third_party/WebKit/public/platform/WebFileSystemCallbacks.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/web/WebFileSystemCallbacks.h" #include "url/gurl.h" #include "webkit/child/worker_task_runner.h" #include "webkit/common/fileapi/directory_entry.h" @@ -37,14 +37,23 @@ namespace content { namespace { +// TODO(kinuko): Remove this hack after the two-sided patch lands. +WebFileSystemCallbacks* Wrapper(WebFileSystemCallbacksType& cb) { +#ifdef NON_SELFDESTRUCT_WEBFILESYSTEMCALLBACKS + return &cb; +#else + return cb; +#endif +} + base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky g_webfilesystem_tls = LAZY_INSTANCE_INITIALIZER; class WaitableCallbackResults { public: static WaitableCallbackResults* MaybeCreate( - WebKit::WebFileSystemCallbacks* callbacks) { - if (callbacks->shouldBlockUntilCompletion()) + WebFileSystemCallbacksType callbacks) { + if (Wrapper(callbacks)->shouldBlockUntilCompletion()) return new WaitableCallbackResults; return NULL; } @@ -110,10 +119,9 @@ void RunCallbacks(int callbacks_id, Method method, const Params& params) { WebFileSystemImpl::ThreadSpecificInstance(NULL); if (!filesystem) return; - WebFileSystemCallbacks* callbacks = + WebFileSystemCallbacksType callbacks = filesystem->GetAndUnregisterCallbacks(callbacks_id); - DCHECK(callbacks); - DispatchToMethod(callbacks, method, params); + DispatchToMethod(Wrapper(callbacks), method, params); } void DispatchResultsClosure(int thread_id, int callbacks_id, @@ -208,17 +216,17 @@ void DidCreateFileWriter( if (!filesystem) return; - WebFileSystemCallbacks* callbacks = + WebFileSystemCallbacksType callbacks = filesystem->GetAndUnregisterCallbacks(callbacks_id); - DCHECK(callbacks); if (file_info.is_directory || file_info.size < 0) { - callbacks->didFail(WebKit::WebFileErrorInvalidState); + Wrapper(callbacks)->didFail(WebKit::WebFileErrorInvalidState); return; } - WebFileWriterImpl::Type type = callbacks->shouldBlockUntilCompletion() ? - WebFileWriterImpl::TYPE_SYNC : WebFileWriterImpl::TYPE_ASYNC; - callbacks->didCreateFileWriter( + WebFileWriterImpl::Type type = + Wrapper(callbacks)->shouldBlockUntilCompletion() ? + WebFileWriterImpl::TYPE_SYNC : WebFileWriterImpl::TYPE_ASYNC; + Wrapper(callbacks)->didCreateFileWriter( new WebFileWriterImpl(path, client, type, main_thread_loop), file_info.size); } @@ -247,14 +255,13 @@ void DidCreateSnapshotFile( if (!filesystem) return; - WebFileSystemCallbacks* callbacks = + WebFileSystemCallbacksType callbacks = filesystem->GetAndUnregisterCallbacks(callbacks_id); - DCHECK(callbacks); WebFileInfo web_file_info; webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); web_file_info.platformPath = platform_path.AsUTF16Unsafe(); - callbacks->didCreateSnapshotFile(web_file_info); + Wrapper(callbacks)->didCreateSnapshotFile(web_file_info); // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes // non-bridge model. @@ -298,16 +305,18 @@ void WebFileSystemImpl::DeleteThreadSpecificInstance() { } WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) - : main_thread_loop_(main_thread_loop) { + : main_thread_loop_(main_thread_loop), + next_callbacks_id_(0) { g_webfilesystem_tls.Pointer()->Set(this); } WebFileSystemImpl::~WebFileSystemImpl() { - IDMap<WebFileSystemCallbacks>::iterator iter(&callbacks_); - while (!iter.IsAtEnd()) { - iter.GetCurrentValue()->didFail(WebKit::WebFileErrorAbort); - iter.Advance(); +#if !defined(NON_SELFDESTRUCT_WEBFILESYSTEMCALLBACKS) + for (CallbacksMap::iterator iter = callbacks_.begin(); + iter != callbacks_.end(); ++iter) { + iter->second->didFail(WebKit::WebFileErrorAbort); } +#endif g_webfilesystem_tls.Pointer()->Set(NULL); } @@ -319,7 +328,7 @@ void WebFileSystemImpl::openFileSystem( const WebKit::WebURL& storage_partition, WebKit::WebFileSystemType type, bool create, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -341,7 +350,7 @@ void WebFileSystemImpl::openFileSystem( void WebFileSystemImpl::deleteFileSystem( const WebKit::WebURL& storage_partition, WebKit::WebFileSystemType type, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -359,7 +368,7 @@ void WebFileSystemImpl::deleteFileSystem( void WebFileSystemImpl::move( const WebKit::WebURL& src_path, const WebKit::WebURL& dest_path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -376,7 +385,7 @@ void WebFileSystemImpl::move( void WebFileSystemImpl::copy( const WebKit::WebURL& src_path, const WebKit::WebURL& dest_path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -392,7 +401,7 @@ void WebFileSystemImpl::copy( void WebFileSystemImpl::remove( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -408,7 +417,7 @@ void WebFileSystemImpl::remove( void WebFileSystemImpl::removeRecursively( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -424,7 +433,7 @@ void WebFileSystemImpl::removeRecursively( void WebFileSystemImpl::readMetadata( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -444,7 +453,7 @@ void WebFileSystemImpl::readMetadata( void WebFileSystemImpl::createFile( const WebKit::WebURL& path, bool exclusive, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -461,7 +470,7 @@ void WebFileSystemImpl::createFile( void WebFileSystemImpl::createDirectory( const WebKit::WebURL& path, bool exclusive, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -477,7 +486,7 @@ void WebFileSystemImpl::createDirectory( void WebFileSystemImpl::fileExists( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -493,7 +502,7 @@ base::Unretained(waitable_results))), void WebFileSystemImpl::directoryExists( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -509,7 +518,7 @@ void WebFileSystemImpl::directoryExists( void WebFileSystemImpl::readDirectory( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -536,7 +545,7 @@ WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( void WebFileSystemImpl::createFileWriter( const WebURL& path, WebKit::WebFileWriterClient* client, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -556,7 +565,7 @@ void WebFileSystemImpl::createFileWriter( void WebFileSystemImpl::createSnapshotFileAndReadMetadata( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks* callbacks) { + WebFileSystemCallbacksType callbacks) { int callbacks_id = RegisterCallbacks(callbacks); WaitableCallbackResults* waitable_results = WaitableCallbackResults::MaybeCreate(callbacks); @@ -574,14 +583,20 @@ void WebFileSystemImpl::createSnapshotFileAndReadMetadata( make_scoped_ptr(waitable_results)); } -int WebFileSystemImpl::RegisterCallbacks(WebFileSystemCallbacks* callbacks) { - return callbacks_.Add(callbacks); +int WebFileSystemImpl::RegisterCallbacks(WebFileSystemCallbacksType callbacks) { + DCHECK(CalledOnValidThread()); + int id = next_callbacks_id_++; + callbacks_[id] = callbacks; + return id; } -WebFileSystemCallbacks* WebFileSystemImpl::GetAndUnregisterCallbacks( +WebFileSystemCallbacksType WebFileSystemImpl::GetAndUnregisterCallbacks( int callbacks_id) { - WebFileSystemCallbacks* callbacks = callbacks_.Lookup(callbacks_id); - callbacks_.Remove(callbacks_id); + DCHECK(CalledOnValidThread()); + CallbacksMap::iterator found = callbacks_.find(callbacks_id); + DCHECK(found != callbacks_.end()); + WebFileSystemCallbacksType callbacks = found->second; + callbacks_.erase(found); return callbacks; } diff --git a/content/child/fileapi/webfilesystem_impl.h b/content/child/fileapi/webfilesystem_impl.h index d439158..f800ff9 100644 --- a/content/child/fileapi/webfilesystem_impl.h +++ b/content/child/fileapi/webfilesystem_impl.h @@ -5,9 +5,10 @@ #ifndef CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ #define CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ +#include <map> + #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/id_map.h" #include "base/memory/ref_counted.h" #include "base/threading/non_thread_safe.h" #include "third_party/WebKit/public/platform/WebFileSystem.h" @@ -23,6 +24,13 @@ class WebFileWriter; class WebFileWriterClient; } +// TODO(kinuko): Remove this hack after the two-sided patch lands. +#ifdef NON_SELFDESTRUCT_WEBFILESYSTEMCALLBACKS + typedef WebKit::WebFileSystemCallbacks WebFileSystemCallbacksType; +#else + typedef WebKit::WebFileSystemCallbacks* WebFileSystemCallbacksType; +#endif + namespace content { class WebFileSystemImpl @@ -52,62 +60,67 @@ class WebFileSystemImpl const WebKit::WebURL& storage_partition, const WebKit::WebFileSystemType type, bool create, - WebKit::WebFileSystemCallbacks*); + WebFileSystemCallbacksType); virtual void deleteFileSystem( const WebKit::WebURL& storage_partition, const WebKit::WebFileSystemType type, - WebKit::WebFileSystemCallbacks*); + WebFileSystemCallbacksType); virtual void move( const WebKit::WebURL& src_path, const WebKit::WebURL& dest_path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void copy( const WebKit::WebURL& src_path, const WebKit::WebURL& dest_path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void remove( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void removeRecursively( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void readMetadata( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void createFile( const WebKit::WebURL& path, bool exclusive, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void createDirectory( const WebKit::WebURL& path, bool exclusive, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void fileExists( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void directoryExists( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void readDirectory( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual WebKit::WebFileWriter* createFileWriter( - const WebKit::WebURL& path, WebKit::WebFileWriterClient*) OVERRIDE; + const WebKit::WebURL& path, + WebKit::WebFileWriterClient*); virtual void createFileWriter( const WebKit::WebURL& path, WebKit::WebFileWriterClient*, - WebKit::WebFileSystemCallbacks*) OVERRIDE; + WebFileSystemCallbacksType) OVERRIDE; virtual void createSnapshotFileAndReadMetadata( const WebKit::WebURL& path, - WebKit::WebFileSystemCallbacks*); + WebFileSystemCallbacksType); - int RegisterCallbacks(WebKit::WebFileSystemCallbacks* callbacks); - WebKit::WebFileSystemCallbacks* GetAndUnregisterCallbacks( + int RegisterCallbacks(WebFileSystemCallbacksType callbacks); + WebFileSystemCallbacksType GetAndUnregisterCallbacks( int callbacks_id); private: + typedef std::map<int, WebFileSystemCallbacksType> CallbacksMap; + scoped_refptr<base::MessageLoopProxy> main_thread_loop_; - IDMap<WebKit::WebFileSystemCallbacks> callbacks_; + + CallbacksMap callbacks_; + int next_callbacks_id_; DISALLOW_COPY_AND_ASSIGN(WebFileSystemImpl); }; diff --git a/content/child/fileapi/webfilewriter_base.cc b/content/child/fileapi/webfilewriter_base.cc index fd0a207..2d0707a 100644 --- a/content/child/fileapi/webfilewriter_base.cc +++ b/content/child/fileapi/webfilewriter_base.cc @@ -5,9 +5,9 @@ #include "content/child/fileapi/webfilewriter_base.h" #include "base/logging.h" +#include "third_party/WebKit/public/platform/WebFileError.h" +#include "third_party/WebKit/public/platform/WebFileWriterClient.h" #include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/web/WebFileError.h" -#include "third_party/WebKit/public/web/WebFileWriterClient.h" #include "webkit/common/fileapi/file_system_util.h" using fileapi::PlatformFileErrorToWebFileError; diff --git a/content/child/fileapi/webfilewriter_base.h b/content/child/fileapi/webfilewriter_base.h index d3873dc..d7e220e 100644 --- a/content/child/fileapi/webfilewriter_base.h +++ b/content/child/fileapi/webfilewriter_base.h @@ -7,7 +7,7 @@ #include "base/platform_file.h" #include "content/common/content_export.h" -#include "third_party/WebKit/public/web/WebFileWriter.h" +#include "third_party/WebKit/public/platform/WebFileWriter.h" #include "url/gurl.h" namespace WebKit { diff --git a/content/child/fileapi/webfilewriter_base_unittest.cc b/content/child/fileapi/webfilewriter_base_unittest.cc index 92150813..76fd974 100644 --- a/content/child/fileapi/webfilewriter_base_unittest.cc +++ b/content/child/fileapi/webfilewriter_base_unittest.cc @@ -9,9 +9,9 @@ #include "base/message_loop/message_loop.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/public/platform/WebFileError.h" +#include "third_party/WebKit/public/platform/WebFileWriterClient.h" #include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/web/WebFileError.h" -#include "third_party/WebKit/public/web/WebFileWriterClient.h" #include "url/gurl.h" namespace content { |