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

Side by Side Diff: base/message_loop_proxy_impl.h

Issue 7583053: Add MessageLoopProxy::current (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No need for MessageLoopProxy destruction observer. Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_loop_proxy.h ('k') | base/message_loop_proxy_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 BASE_MESSAGE_LOOP_PROXY_IMPL_H_ 5 #ifndef BASE_MESSAGE_LOOP_PROXY_IMPL_H_
6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_ 6 #define BASE_MESSAGE_LOOP_PROXY_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/base_export.h" 9 #include "base/base_export.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 // A stock implementation of MessageLoopProxy that takes in a MessageLoop 16 // A stock implementation of MessageLoopProxy that is created and managed by a
17 // and keeps track of its lifetime using the MessageLoop DestructionObserver. 17 // MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a
18 // For now a MessageLoopProxyImpl can only be created for the current thread. 18 // MessageLoop.
19 class BASE_EXPORT MessageLoopProxyImpl 19 class BASE_EXPORT MessageLoopProxyImpl
20 : public MessageLoopProxy, 20 : public MessageLoopProxy {
21 public MessageLoop::DestructionObserver {
22 public: 21 public:
23 virtual ~MessageLoopProxyImpl(); 22 virtual ~MessageLoopProxyImpl();
24 23
25 // MessageLoopProxy implementation 24 // MessageLoopProxy implementation
26 virtual bool PostTask(const tracked_objects::Location& from_here, 25 virtual bool PostTask(const tracked_objects::Location& from_here,
27 Task* task); 26 Task* task);
28 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, 27 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
29 Task* task, 28 Task* task,
30 int64 delay_ms); 29 int64 delay_ms);
31 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, 30 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here,
32 Task* task); 31 Task* task);
33 virtual bool PostNonNestableDelayedTask( 32 virtual bool PostNonNestableDelayedTask(
34 const tracked_objects::Location& from_here, 33 const tracked_objects::Location& from_here,
35 Task* task, 34 Task* task,
36 int64 delay_ms); 35 int64 delay_ms);
37 virtual bool PostTask(const tracked_objects::Location& from_here, 36 virtual bool PostTask(const tracked_objects::Location& from_here,
38 const base::Closure& task); 37 const base::Closure& task);
39 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, 38 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
40 const base::Closure& task, 39 const base::Closure& task,
41 int64 delay_ms); 40 int64 delay_ms);
42 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here, 41 virtual bool PostNonNestableTask(const tracked_objects::Location& from_here,
43 const base::Closure& task); 42 const base::Closure& task);
44 virtual bool PostNonNestableDelayedTask( 43 virtual bool PostNonNestableDelayedTask(
45 const tracked_objects::Location& from_here, 44 const tracked_objects::Location& from_here,
46 const base::Closure& task, 45 const base::Closure& task,
47 int64 delay_ms); 46 int64 delay_ms);
48 virtual bool BelongsToCurrentThread(); 47 virtual bool BelongsToCurrentThread();
49 48
50 // MessageLoop::DestructionObserver implementation
51 virtual void WillDestroyCurrentMessageLoop();
52
53 protected: 49 protected:
54 // Override OnDestruct so that we can delete the object on the target message 50 // Override OnDestruct so that we can delete the object on the target message
55 // loop if it still exists. 51 // loop if it still exists.
56 virtual void OnDestruct() const; 52 virtual void OnDestruct() const;
57 53
58 private: 54 private:
59 MessageLoopProxyImpl(); 55 MessageLoopProxyImpl();
56
57 // Called directly by MessageLoop::~MessageLoop.
58 virtual void WillDestroyCurrentMessageLoop();
59
60
60 // TODO(ajwong): Remove this after we've fully migrated to base::Closure. 61 // TODO(ajwong): Remove this after we've fully migrated to base::Closure.
61 bool PostTaskHelper(const tracked_objects::Location& from_here, 62 bool PostTaskHelper(const tracked_objects::Location& from_here,
62 Task* task, 63 Task* task,
63 int64 delay_ms, 64 int64 delay_ms,
64 bool nestable); 65 bool nestable);
65 bool PostTaskHelper(const tracked_objects::Location& from_here, 66 bool PostTaskHelper(const tracked_objects::Location& from_here,
66 const base::Closure& task, 67 const base::Closure& task,
67 int64 delay_ms, 68 int64 delay_ms,
68 bool nestable); 69 bool nestable);
69 70
70 // For the factory method to work 71 // Allow the messageLoop to create a MessageLoopProxyImpl.
71 friend class MessageLoopProxy; 72 friend class ::MessageLoop;
72 73
73 // The lock that protects access to target_message_loop_. 74 // The lock that protects access to target_message_loop_.
74 mutable base::Lock message_loop_lock_; 75 mutable base::Lock message_loop_lock_;
75 MessageLoop* target_message_loop_; 76 MessageLoop* target_message_loop_;
76 77
77 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl); 78 DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl);
78 }; 79 };
79 80
80 } // namespace base 81 } // namespace base
81 82
82 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_ 83 #endif // BASE_MESSAGE_LOOP_PROXY_IMPL_H_
OLDNEW
« no previous file with comments | « base/message_loop_proxy.h ('k') | base/message_loop_proxy_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698