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

Side by Side Diff: base/message_loop_helpers.h

Issue 9004051: Replace MessageLoop::DeleteSoon implementation with one that uses base::Bind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Apparently someone clever #defines Status Created 8 years, 11 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
« no previous file with comments | « base/message_loop.cc ('k') | base/message_loop_proxy.h » ('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) 2011 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_MESSAGE_LOOP_HELPERS_H_
6 #define BASE_MESSAGE_LOOP_HELPERS_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10
11 namespace tracked_objects {
12 class Location;
13 }
14
15 namespace base {
awong 2011/12/29 18:09:11 Add a newline here.
16 namespace subtle {
17 template <class T, class R> class DeleteHelperInternal;
18 }
19
20 // This is a template helper which uses a function indirection to erase T from
21 // the function signature while still remembering it so we can call the correct
22 // destructor. We use this trick so we don't need to include bind.h in a
23 // header file. We also embed the function in a class to make it easier for
24 // users of DeleteSoon to declare the helper as a friend.
25 template <class T>
26 class DeleteHelper {
27 private:
28 // TODO(dcheng): Move the return type back to a function template parameter.
29 template <class T2, class R> friend class subtle::DeleteHelperInternal;
30
31 static void DoDelete(const void* object) {
32 delete reinterpret_cast<const T*>(object);
33 }
34
35 DISALLOW_COPY_AND_ASSIGN(DeleteHelper);
36 };
37
38 namespace subtle {
39
40 // An internal MessageLoop-like class helper for DeleteHelper. We don't want to
41 // expose DoDelete directly since the void* argument makes it possible to pass
42 // an object of the wrong type to delete. Instead, we force callers to go
43 // through DeleteHelperInternal for type safety. MessageLoop-like classes which
44 // expose a DeleteSoon method should friend this class and implement a
45 // DeleteSoonInternal method with the following signature:
46 // bool(const tracked_objects::Location&,
47 // void(*deleter)(const void*),
48 // void* object)
49 // An implementation of DeleteSoonInternal should simply create a base::Closure
50 // from (deleter, object) and return the result of posting the task.
51 template <class T, class ReturnType>
52 class DeleteHelperInternal {
53 public:
54 template <class MessageLoopType>
55 static ReturnType DeleteOnMessageLoop(
56 MessageLoopType* message_loop,
57 const tracked_objects::Location& from_here,
58 const T* object) {
59 return message_loop->DeleteSoonInternal(from_here,
60 &DeleteHelper<T>::DoDelete,
61 object);
62 }
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(DeleteHelperInternal);
66 };
67
68 } // namespace subtle
69
70 } // namespace base
71
72 #endif // BASE_MESSAGE_LOOP_HELPERS_H_
OLDNEW
« no previous file with comments | « base/message_loop.cc ('k') | base/message_loop_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698