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

Side by Side Diff: base/memory/ref_counted_delete_on_message_loop.h

Issue 16938006: Adds RefCountedDeleteOnMessageLoop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing include Created 7 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/webdata/web_data_service_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_
6 #define BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_
7
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop/message_loop_proxy.h"
12
13 namespace base {
14
15 // RefCountedDeleteOnMessageLoop is similar to RefCountedThreadSafe, and ensures
Mark Mentovai 2013/06/13 18:36:34 Fix the CL description to accurately reflect the n
16 // that the object will be deleted on a specified message loop.
17 //
18 // Sample usage:
19 // class Foo : public RefCountedDeleteOnMessageLoop<Foo> {
20 //
21 // Foo(const scoped_refptr<MessageLoopProxy>& loop)
22 // : RefCountedDeleteOnMessageLoop<Foo>(loop) {
23 // ...
24 // }
25 // ...
26 // private:
27 // friend class RefCountedDeleteOnMessageLoop<Foo>;
28 // friend class DeleteHelper<Foo>;
29 //
30 // ~Foo();
31 // };
32
33 template <class T>
34 class RefCountedDeleteOnMessageLoop
35 : public base::subtle::RefCountedThreadSafeBase {
Mark Mentovai 2013/06/13 18:36:34 You don’t need to say base:: anywhere because you’
36 public:
37 RefCountedDeleteOnMessageLoop(
38 const scoped_refptr<base::MessageLoopProxy>& proxy) : proxy_(proxy) {
39 DCHECK(proxy_);
40 }
41
42 void AddRef() const {
43 base::subtle::RefCountedThreadSafeBase::AddRef();
44 }
45
46 void Release() const {
47 if (base::subtle::RefCountedThreadSafeBase::Release())
48 DestructOnMessageLoop();
49 }
50
51 protected:
52 friend class DeleteHelper<RefCountedDeleteOnMessageLoop>;
53 ~RefCountedDeleteOnMessageLoop() {}
54
55 void DestructOnMessageLoop() const {
56 const T* t = static_cast<const T*>(this);
57 if (proxy_->BelongsToCurrentThread())
58 delete t;
59 else
60 proxy_->DeleteSoon(FROM_HERE, t);
61 }
62
63 scoped_refptr<base::MessageLoopProxy> proxy_;
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(RefCountedDeleteOnMessageLoop);
67 };
68
69 } // namespace base
70
71 #endif // BASE_MEMORY_REF_COUNTED_DELETE_ON_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/webdata/web_data_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698