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

Side by Side Diff: chrome/browser/profiles/refcounted_profile_keyed_service.h

Issue 9703038: Profiles: Really fix refcounted services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgot to save a file. >_< Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_ 5 #ifndef CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_
6 #define CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_ 6 #define CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "chrome/browser/profiles/profile_keyed_base.h"
10 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
11 10
12 class RefcountedProfileKeyedService; 11 class RefcountedProfileKeyedService;
13 12
14 namespace impl { 13 namespace impl {
15 14
16 struct RefcountedProfileKeyedServiceTraits { 15 struct RefcountedProfileKeyedServiceTraits {
17 static void Destruct(const RefcountedProfileKeyedService* obj); 16 static void Destruct(const RefcountedProfileKeyedService* obj);
18 }; 17 };
19 18
20 } // namespace impl 19 } // namespace impl
21 20
22 // Base class for refcounted objects that hang off the Profile. 21 // Base class for refcounted objects that hang off the Profile.
23 // 22 //
24 // The two pass shutdown described in ProfileKeyedService works a bit 23 // The two pass shutdown described in ProfileKeyedService works a bit
25 // differently because there could be outstanding references on other 24 // differently because there could be outstanding references on other
26 // threads. ShutdownOnUIThread() will be called on the UI thread, and then the 25 // threads. ShutdownOnUIThread() will be called on the UI thread, and then the
27 // destructor will run when the last reference is dropped, which may or may not 26 // destructor will run when the last reference is dropped, which may or may not
28 // be after the corresponding Profile has been destroyed. 27 // be after the corresponding Profile has been destroyed.
29 // 28 //
30 // Optionally, if you initialize your service with the constructor that takes a 29 // Optionally, if you initialize your service with the constructor that takes a
31 // thread ID, your service will be deleted on that thread. We can't use 30 // thread ID, your service will be deleted on that thread. We can't use
32 // content::DeleteOnThread<> directly because RefcountedProfileKeyedService 31 // content::DeleteOnThread<> directly because RefcountedProfileKeyedService
33 // must be one type that RefcountedProfileKeyedServiceFactory can use. 32 // must be one type that RefcountedProfileKeyedServiceFactory can use.
34 class RefcountedProfileKeyedService 33 class RefcountedProfileKeyedService
35 : public ProfileKeyedBase, 34 : public base::RefCountedThreadSafe<
36 public base::RefCountedThreadSafe<
37 RefcountedProfileKeyedService, 35 RefcountedProfileKeyedService,
38 impl::RefcountedProfileKeyedServiceTraits> { 36 impl::RefcountedProfileKeyedServiceTraits> {
39 public: 37 public:
40 // Unlike ProfileKeyedService, ShutdownOnUI is not optional. You must do 38 // Unlike ProfileKeyedService, ShutdownOnUI is not optional. You must do
41 // something to drop references during the first pass Shutdown() because this 39 // something to drop references during the first pass Shutdown() because this
42 // is the only point where you are guaranteed that something is running on 40 // is the only point where you are guaranteed that something is running on
43 // the UI thread. The PKSF framework will ensure that this is only called on 41 // the UI thread. The PKSF framework will ensure that this is only called on
44 // the UI thread; you do not need to check for that yourself. 42 // the UI thread; you do not need to check for that yourself.
45 virtual void ShutdownOnUIThread() = 0; 43 virtual void ShutdownOnUIThread() = 0;
46 44
(...skipping 14 matching lines...) Expand all
61 59
62 private: 60 private:
63 friend struct impl::RefcountedProfileKeyedServiceTraits; 61 friend struct impl::RefcountedProfileKeyedServiceTraits;
64 62
65 // Do we have to delete this object on a specific thread? 63 // Do we have to delete this object on a specific thread?
66 bool requires_destruction_on_thread_; 64 bool requires_destruction_on_thread_;
67 content::BrowserThread::ID thread_id_; 65 content::BrowserThread::ID thread_id_;
68 }; 66 };
69 67
70 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_ 68 #endif // CHROME_BROWSER_PROFILES_REFCOUNTED_PROFILE_KEYED_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698