diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-21 19:05:43 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-21 19:07:38 +0000 |
commit | 36c762beb87b90eb289ef81c1262674531735d73 (patch) | |
tree | 6edae08433cbb5517fcc4b15299c2646401ab358 | |
parent | 6db3123cc4ab6f11ad158f862780c49ba30aedc4 (diff) | |
download | chromium_src-36c762beb87b90eb289ef81c1262674531735d73.zip chromium_src-36c762beb87b90eb289ef81c1262674531735d73.tar.gz chromium_src-36c762beb87b90eb289ef81c1262674531735d73.tar.bz2 |
Support scoped_ptr in BrowserThread::DeleteOnThread.
Review URL: https://codereview.chromium.org/491103004
Cr-Commit-Position: refs/heads/master@{#291149}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291149 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 21 insertions, 16 deletions
diff --git a/chrome/browser/local_discovery/pwg_raster_converter.cc b/chrome/browser/local_discovery/pwg_raster_converter.cc index 9ae1d06..711c9ce 100644 --- a/chrome/browser/local_discovery/pwg_raster_converter.cc +++ b/chrome/browser/local_discovery/pwg_raster_converter.cc @@ -127,7 +127,7 @@ class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient { void RunCallbackOnUIThread(bool success); void OnFilesReadyOnUIThread(); - scoped_ptr<FileHandlers> files_; + scoped_ptr<FileHandlers, BrowserThread::DeleteOnFileThread> files_; printing::PdfRenderSettings settings_; printing::PwgRasterSettings bitmap_settings_; PWGRasterConverter::ResultCallback callback_; @@ -142,8 +142,6 @@ PwgUtilityProcessHostClient::PwgUtilityProcessHostClient( : settings_(settings), bitmap_settings_(bitmap_settings) {} PwgUtilityProcessHostClient::~PwgUtilityProcessHostClient() { - // Delete temp directory. - BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, files_.release()); } void PwgUtilityProcessHostClient::Convert( diff --git a/chrome/browser/printing/pdf_to_emf_converter.cc b/chrome/browser/printing/pdf_to_emf_converter.cc index 21800ee..4db648b 100644 --- a/chrome/browser/printing/pdf_to_emf_converter.cc +++ b/chrome/browser/printing/pdf_to_emf_converter.cc @@ -125,7 +125,7 @@ class PdfToEmfUtilityProcessHostClient double scale_factor); void OnFilesReadyOnUIThread(); - scoped_ptr<FileHandlers> files_; + scoped_ptr<FileHandlers, BrowserThread::DeleteOnFileThread> files_; printing::PdfRenderSettings settings_; PdfToEmfConverter::ResultCallback callback_; base::WeakPtr<content::UtilityProcessHost> utility_process_host_; @@ -138,8 +138,6 @@ PdfToEmfUtilityProcessHostClient::PdfToEmfUtilityProcessHostClient( : settings_(settings) {} PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() { - // Delete temp directory. - BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, files_.release()); } void PdfToEmfUtilityProcessHostClient::Convert( diff --git a/content/browser/renderer_host/media/media_stream_ui_proxy.cc b/content/browser/renderer_host/media/media_stream_ui_proxy.cc index 122bfa2..837577a 100644 --- a/content/browser/renderer_host/media/media_stream_ui_proxy.cc +++ b/content/browser/renderer_host/media/media_stream_ui_proxy.cc @@ -128,7 +128,6 @@ MediaStreamUIProxy::MediaStreamUIProxy( MediaStreamUIProxy::~MediaStreamUIProxy() { DCHECK_CURRENTLY_ON(BrowserThread::IO); - BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, core_.release()); } void MediaStreamUIProxy::RequestAccess( diff --git a/content/browser/renderer_host/media/media_stream_ui_proxy.h b/content/browser/renderer_host/media/media_stream_ui_proxy.h index fe1dde5..810a29a 100644 --- a/content/browser/renderer_host/media/media_stream_ui_proxy.h +++ b/content/browser/renderer_host/media/media_stream_ui_proxy.h @@ -9,6 +9,7 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "content/public/browser/browser_thread.h" #include "content/public/common/media_stream_request.h" namespace content { @@ -65,7 +66,7 @@ class CONTENT_EXPORT MediaStreamUIProxy { void OnWindowId(const WindowIdCallback& window_id_callback, gfx::NativeViewId* window_id); - scoped_ptr<Core> core_; + scoped_ptr<Core, content::BrowserThread::DeleteOnUIThread> core_; ResponseCallback response_callback_; base::Closure stop_callback_; diff --git a/content/public/browser/browser_thread.h b/content/public/browser/browser_thread.h index 6c83633..a9591e9 100644 --- a/content/public/browser/browser_thread.h +++ b/content/public/browser/browser_thread.h @@ -229,13 +229,14 @@ class CONTENT_EXPORT BrowserThread { // not deleted while unregistering. static void SetDelegate(ID identifier, BrowserThreadDelegate* delegate); - // Use these templates in conjuction with RefCountedThreadSafe when you want - // to ensure that an object is deleted on a specific thread. This is needed - // when an object can hop between threads (i.e. IO -> FILE -> IO), and thread - // switching delays can mean that the final IO tasks executes before the FILE - // task's stack unwinds. This would lead to the object destructing on the - // FILE thread, which often is not what you want (i.e. to unregister from - // NotificationService, to notify other objects on the creating thread etc). + // Use these templates in conjunction with RefCountedThreadSafe or scoped_ptr + // when you want to ensure that an object is deleted on a specific thread. + // This is needed when an object can hop between threads + // (i.e. IO -> FILE -> IO), and thread switching delays can mean that the + // final IO tasks executes before the FILE task's stack unwinds. + // This would lead to the object destructing on the FILE thread, which often + // is not what you want (i.e. to unregister from NotificationService, to + // notify other objects on the creating thread etc). template<ID thread> struct DeleteOnThread { template<typename T> @@ -252,9 +253,14 @@ class CONTENT_EXPORT BrowserThread { } } } + template <typename T> + inline void operator()(T* ptr) const { + enum { type_must_be_complete = sizeof(T) }; + Destruct(ptr); + } }; - // Sample usage: + // Sample usage with RefCountedThreadSafe: // class Foo // : public base::RefCountedThreadSafe< // Foo, BrowserThread::DeleteOnIOThread> { @@ -265,6 +271,9 @@ class CONTENT_EXPORT BrowserThread { // friend class base::DeleteHelper<Foo>; // // ~Foo(); + // + // Sample usage with scoped_ptr: + // scoped_ptr<Foo, BrowserThread::DeleteOnIOThread> ptr; struct DeleteOnUIThread : public DeleteOnThread<UI> { }; struct DeleteOnIOThread : public DeleteOnThread<IO> { }; struct DeleteOnFileThread : public DeleteOnThread<FILE> { }; |