Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1888)

Unified Diff: content/public/browser/browser_thread.h

Issue 491103004: Support scoped_ptr in BrowserThread::DeleteOnThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thu Aug 21 03:07:17 PDT 2014 Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/media/media_stream_ui_proxy.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/browser/browser_thread.h
diff --git a/content/public/browser/browser_thread.h b/content/public/browser/browser_thread.h
index 6c83633e1f545a067b03b1892103323d40c3186f..a9591e9516aeea36ccf961ec4a5ffb9fa56a1316 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> { };
« no previous file with comments | « content/browser/renderer_host/media/media_stream_ui_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698