summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles/refcounted_profile_keyed_service.h
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 01:44:28 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 01:44:28 +0000
commit773040599d303c26919a020017102ddc8b7b1fd7 (patch)
tree66133d2d82905884ed52008846f26efb1a1bc9fc /chrome/browser/profiles/refcounted_profile_keyed_service.h
parent920a2bbcd3dd45042407af43ac7fa2fb21dc5ca5 (diff)
downloadchromium_src-773040599d303c26919a020017102ddc8b7b1fd7.zip
chromium_src-773040599d303c26919a020017102ddc8b7b1fd7.tar.gz
chromium_src-773040599d303c26919a020017102ddc8b7b1fd7.tar.bz2
Profiles: Mark the factories as NonThreadSafe and allow services to be deleted on certain threads.
BUG=116892, 116887 Review URL: http://codereview.chromium.org/9617023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles/refcounted_profile_keyed_service.h')
-rw-r--r--chrome/browser/profiles/refcounted_profile_keyed_service.h40
1 files changed, 38 insertions, 2 deletions
diff --git a/chrome/browser/profiles/refcounted_profile_keyed_service.h b/chrome/browser/profiles/refcounted_profile_keyed_service.h
index 562e113..c010118 100644
--- a/chrome/browser/profiles/refcounted_profile_keyed_service.h
+++ b/chrome/browser/profiles/refcounted_profile_keyed_service.h
@@ -7,6 +7,17 @@
#include "base/memory/ref_counted.h"
#include "chrome/browser/profiles/profile_keyed_base.h"
+#include "content/public/browser/browser_thread.h"
+
+class RefcountedProfileKeyedService;
+
+namespace impl {
+
+struct RefcountedProfileKeyedServiceTraits {
+ static void Destruct(const RefcountedProfileKeyedService* obj);
+};
+
+} // namespace impl
// Base class for refcounted objects that hang off the Profile.
//
@@ -15,9 +26,16 @@
// threads. ShutdownOnUIThread() will be called on the UI thread, and then the
// destructor will run when the last reference is dropped, which may or may not
// be after the corresponding Profile has been destroyed.
+//
+// Optionally, if you initialize your service with the constructor that takes a
+// thread ID, your service will be deleted on that thread. We can't use
+// content::DeleteOnThread<> directly because RefcountedProfileKeyedService
+// must be one type that RefcountedProfileKeyedServiceFactory can use.
class RefcountedProfileKeyedService
: public ProfileKeyedBase,
- public base::RefCountedThreadSafe<RefcountedProfileKeyedService> {
+ public base::RefCountedThreadSafe<
+ RefcountedProfileKeyedService,
+ impl::RefcountedProfileKeyedServiceTraits> {
public:
// Unlike ProfileKeyedService, ShutdownOnUI is not optional. You must do
// something to drop references during the first pass Shutdown() because this
@@ -26,8 +44,26 @@ class RefcountedProfileKeyedService
// the UI thread; you do not need to check for that yourself.
virtual void ShutdownOnUIThread() = 0;
- // This second pass can happen anywhere.
+ // The second pass destruction can happen anywhere unless you specify which
+ // thread this service must be destroyed on by using the second constructor.
virtual ~RefcountedProfileKeyedService();
+
+ protected:
+ // If you want your service deleted wherever, use the default constructor.
+ RefcountedProfileKeyedService();
+
+ // If you need your service to be deleted on a specific thread (for example,
+ // you're converting a service that used content::DeleteOnThread<IO>), then
+ // use this constructor with the ID of the thread.
+ explicit RefcountedProfileKeyedService(
+ const content::BrowserThread::ID thread_id);
+
+ private:
+ friend struct impl::RefcountedProfileKeyedServiceTraits;
+
+ // Do we have to delete this object on a specific thread?
+ bool requires_destruction_on_thread_;
+ content::BrowserThread::ID thread_id_;
};
#endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_