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

Side by Side Diff: base/message_loop_proxy_impl.cc

Issue 1837003: Created a stock implementation of the MessageLoopProxy interface than can be ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Rearranged header files Created 10 years, 7 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_impl.h ('k') | base/message_loop_proxy_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #include "base/message_loop_proxy_impl.h"
6
7 namespace base {
8
9 MessageLoopProxyImpl::MessageLoopProxyImpl()
10 : target_message_loop_(MessageLoop::current()) {
11 target_message_loop_->AddDestructionObserver(this);
12 }
13
14 MessageLoopProxyImpl::~MessageLoopProxyImpl() {
15 AutoLock lock(message_loop_lock_);
16 // If the target message loop still exists, the d'tor WILL execute on the
17 // target loop.
18 if (target_message_loop_) {
19 DCHECK(MessageLoop::current() == target_message_loop_);
20 MessageLoop::current()->RemoveDestructionObserver(this);
21 }
22 }
23
24 // MessageLoopProxy implementation
25 bool MessageLoopProxyImpl::PostTask(const tracked_objects::Location& from_here,
26 Task* task) {
27 return PostTaskHelper(from_here, task, 0, true);
28 }
29
30 bool MessageLoopProxyImpl::PostDelayedTask(
31 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
32 return PostTaskHelper(from_here, task, delay_ms, true);
33 }
34
35 bool MessageLoopProxyImpl::PostNonNestableTask(
36 const tracked_objects::Location& from_here, Task* task) {
37 return PostTaskHelper(from_here, task, 0, false);
38 }
39
40 bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
41 const tracked_objects::Location& from_here,
42 Task* task,
43 int64 delay_ms) {
44 return PostTaskHelper(from_here, task, delay_ms, false);
45 }
46
47 bool MessageLoopProxyImpl::BelongsToCurrentThread() {
48 AutoLock lock(message_loop_lock_);
49 return (target_message_loop_ &&
50 (MessageLoop::current() == target_message_loop_));
51 }
52
53 bool MessageLoopProxyImpl::PostTaskHelper(
54 const tracked_objects::Location& from_here, Task* task, int64 delay_ms,
55 bool nestable) {
56 bool ret = false;
57 {
58 AutoLock lock(message_loop_lock_);
59 if (target_message_loop_) {
60 if (nestable) {
61 target_message_loop_->PostDelayedTask(from_here, task, delay_ms);
62 } else {
63 target_message_loop_->PostNonNestableDelayedTask(from_here, task,
64 delay_ms);
65 }
66 ret = true;
67 }
68 }
69 if (!ret)
70 delete task;
71 return ret;
72 }
73
74 void MessageLoopProxyImpl::OnDestruct() {
75 bool delete_later = false;
76 {
77 AutoLock lock(message_loop_lock_);
78 if (target_message_loop_ &&
79 (MessageLoop::current() != target_message_loop_)) {
80 target_message_loop_->DeleteSoon(FROM_HERE, this);
81 delete_later = true;
82 }
83 }
84 if (!delete_later)
85 delete this;
86 }
87
88 // MessageLoop::DestructionObserver implementation
89 void MessageLoopProxyImpl::WillDestroyCurrentMessageLoop() {
90 AutoLock lock(message_loop_lock_);
91 target_message_loop_ = NULL;
92 }
93
94 scoped_refptr<MessageLoopProxy>
95 MessageLoopProxy::CreateForCurrentThread() {
96 scoped_refptr<MessageLoopProxy> ret = new MessageLoopProxyImpl();
97 return ret;
98 }
99
100 } // namespace base
101
OLDNEW
« no previous file with comments | « base/message_loop_proxy_impl.h ('k') | base/message_loop_proxy_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698