diff options
Diffstat (limited to 'content')
-rw-r--r-- | content/child/fileapi/webfilesystem_impl.cc | 27 | ||||
-rw-r--r-- | content/child/fileapi/webfilesystem_impl.h | 17 | ||||
-rw-r--r-- | content/renderer/renderer_webkitplatformsupport_impl.cc | 9 | ||||
-rw-r--r-- | content/worker/worker_webkitplatformsupport_impl.cc | 9 |
4 files changed, 60 insertions, 2 deletions
diff --git a/content/child/fileapi/webfilesystem_impl.cc b/content/child/fileapi/webfilesystem_impl.cc index 052bce4..29a7780 100644 --- a/content/child/fileapi/webfilesystem_impl.cc +++ b/content/child/fileapi/webfilesystem_impl.cc @@ -43,6 +43,9 @@ class CallbacksMap; base::LazyInstance<base::ThreadLocalPointer<CallbacksMap> >::Leaky g_callbacks_map_tls = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky + g_webfilesystem_tls = LAZY_INSTANCE_INITIALIZER; + // TODO(kinuko): Integrate this into WebFileSystemImpl when blink side // becomes ready to make WebFileSystemImpl thread-local. class CallbacksMap : public WorkerTaskRunner::Observer { @@ -312,11 +315,33 @@ void CreateSnapshotFileCallbackAdapter( } // namespace -WebFileSystemImpl::~WebFileSystemImpl() { +WebFileSystemImpl* WebFileSystemImpl::ThreadSpecificInstance( + base::MessageLoopProxy* main_thread_loop) { + if (g_webfilesystem_tls.Pointer()->Get()) + return g_webfilesystem_tls.Pointer()->Get(); + WebFileSystemImpl* filesystem = new WebFileSystemImpl(main_thread_loop); + if (WorkerTaskRunner::Instance()->CurrentWorkerId()) + WorkerTaskRunner::Instance()->AddStopObserver(filesystem); + return filesystem; +} + +void WebFileSystemImpl::DeleteThreadSpecificInstance() { + DCHECK(!WorkerTaskRunner::Instance()->CurrentWorkerId()); + if (g_webfilesystem_tls.Pointer()->Get()) + delete g_webfilesystem_tls.Pointer()->Get(); } WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) : main_thread_loop_(main_thread_loop) { + g_webfilesystem_tls.Pointer()->Set(this); +} + +WebFileSystemImpl::~WebFileSystemImpl() { + g_webfilesystem_tls.Pointer()->Set(NULL); +} + +void WebFileSystemImpl::OnWorkerRunLoopStopped() { + delete this; } void WebFileSystemImpl::move( diff --git a/content/child/fileapi/webfilesystem_impl.h b/content/child/fileapi/webfilesystem_impl.h index d9a2584..3e88982 100644 --- a/content/child/fileapi/webfilesystem_impl.h +++ b/content/child/fileapi/webfilesystem_impl.h @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "third_party/WebKit/public/platform/WebFileSystem.h" +#include "webkit/child/worker_task_runner.h" namespace base { class MessageLoopProxy; @@ -22,11 +23,25 @@ class WebFileWriterClient; namespace content { -class WebFileSystemImpl : public WebKit::WebFileSystem { +class WebFileSystemImpl + : public WebKit::WebFileSystem, + public webkit_glue::WorkerTaskRunner::Observer { public: + // Returns thread-specific instance. + static WebFileSystemImpl* ThreadSpecificInstance( + base::MessageLoopProxy* main_thread_loop); + + // Deletes thread-specific instance (if exists). For workers it deletes + // itself in OnWorkerRunLoopStopped(), but for an instance created on the + // main thread this method must be called. + static void DeleteThreadSpecificInstance(); + explicit WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop); virtual ~WebFileSystemImpl(); + // webkit_glue::WorkerTaskRunner::Observer implementation. + virtual void OnWorkerRunLoopStopped() OVERRIDE; + // WebFileSystem implementation. virtual void move( const WebKit::WebURL& src_path, diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc index d5156a1..c9219ed 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc @@ -225,6 +225,10 @@ RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() } RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { +#ifdef USE_THREADLOCAL_WEBFILESYSTEM + // TODO(kinuko): Delete this ifdef after blink side switch's over. + WebFileSystemImpl::DeleteThreadSpecificInstance(); +#endif } //------------------------------------------------------------------------------ @@ -374,9 +378,14 @@ WebIDBFactory* RendererWebKitPlatformSupportImpl::idbFactory() { //------------------------------------------------------------------------------ WebFileSystem* RendererWebKitPlatformSupportImpl::fileSystem() { +#ifdef USE_THREADLOCAL_WEBFILESYSTEM + // TODO(kinuko): Delete this ifdef after blink side switch's over. + return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_.get()); +#else if (!web_file_system_) web_file_system_.reset(new WebFileSystemImpl(child_thread_loop_.get())); return web_file_system_.get(); +#endif } //------------------------------------------------------------------------------ diff --git a/content/worker/worker_webkitplatformsupport_impl.cc b/content/worker/worker_webkitplatformsupport_impl.cc index 144db959..a4de2c8 100644 --- a/content/worker/worker_webkitplatformsupport_impl.cc +++ b/content/worker/worker_webkitplatformsupport_impl.cc @@ -86,6 +86,10 @@ WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl( } WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() { +#ifdef USE_THREADLOCAL_WEBFILESYSTEM + // TODO(kinuko): Delete this ifdef after blink side switch's over. + WebFileSystemImpl::DeleteThreadSpecificInstance(); +#endif } WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() { @@ -98,9 +102,14 @@ WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() { } WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() { +#ifdef USE_THREADLOCAL_WEBFILESYSTEM + // TODO(kinuko): Delete this ifdef after blink side switch's over. + return WebFileSystemImpl::ThreadSpecificInstance(child_thread_loop_.get()); +#else if (!web_file_system_) web_file_system_.reset(new WebFileSystemImpl(child_thread_loop_.get())); return web_file_system_.get(); +#endif } WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() { |