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

Side by Side Diff: base/message_loop_proxy_impl.cc

Issue 9427023: Add functions to expand PostDelayedTask interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add fix to RunOnPluginThread() in host_plugin.cc Created 8 years, 10 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 | « base/message_loop_proxy_impl.h ('k') | base/sequenced_task_runner.h » ('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) 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 #include "base/message_loop_proxy_impl.h" 5 #include "base/message_loop_proxy_impl.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/threading/thread_restrictions.h" 8 #include "base/threading/thread_restrictions.h"
9 9
10 namespace base { 10 namespace base {
11 11
12 MessageLoopProxyImpl::~MessageLoopProxyImpl() { 12 MessageLoopProxyImpl::~MessageLoopProxyImpl() {
13 } 13 }
14 14
15 // This function will be removed later in the fixing of CR Bug #108171.
16 bool MessageLoopProxyImpl::PostDelayedTask(
17 const tracked_objects::Location& from_here,
18 const base::Closure& task,
19 int64 delay_ms) {
20 return PostDelayedTask(
21 from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
22 }
23
24 // This function will be removed later in the fixing of CR Bug #108171.
25 bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
26 const tracked_objects::Location& from_here,
27 const base::Closure& task,
28 int64 delay_ms) {
29 return PostNonNestableDelayedTask(
30 from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
31 }
32
15 bool MessageLoopProxyImpl::PostDelayedTask( 33 bool MessageLoopProxyImpl::PostDelayedTask(
16 const tracked_objects::Location& from_here, 34 const tracked_objects::Location& from_here,
17 const base::Closure& task, 35 const base::Closure& task,
18 int64 delay_ms) { 36 base::TimeDelta delay) {
19 return PostTaskHelper(from_here, task, delay_ms, true); 37 return PostTaskHelper(from_here, task, delay, true);
20 } 38 }
21 39
22 bool MessageLoopProxyImpl::PostNonNestableDelayedTask( 40 bool MessageLoopProxyImpl::PostNonNestableDelayedTask(
23 const tracked_objects::Location& from_here, 41 const tracked_objects::Location& from_here,
24 const base::Closure& task, 42 const base::Closure& task,
25 int64 delay_ms) { 43 base::TimeDelta delay) {
26 return PostTaskHelper(from_here, task, delay_ms, false); 44 return PostTaskHelper(from_here, task, delay, false);
27 } 45 }
28 46
29 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const { 47 bool MessageLoopProxyImpl::RunsTasksOnCurrentThread() const {
30 // We shouldn't use MessageLoop::current() since it uses LazyInstance which 48 // We shouldn't use MessageLoop::current() since it uses LazyInstance which
31 // may be deleted by ~AtExitManager when a WorkerPool thread calls this 49 // may be deleted by ~AtExitManager when a WorkerPool thread calls this
32 // function. 50 // function.
33 // http://crbug.com/63678 51 // http://crbug.com/63678
34 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; 52 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
35 AutoLock lock(message_loop_lock_); 53 AutoLock lock(message_loop_lock_);
36 return (target_message_loop_ && 54 return (target_message_loop_ &&
(...skipping 24 matching lines...) Expand all
61 if (!delete_later) 79 if (!delete_later)
62 delete this; 80 delete this;
63 } 81 }
64 82
65 MessageLoopProxyImpl::MessageLoopProxyImpl() 83 MessageLoopProxyImpl::MessageLoopProxyImpl()
66 : target_message_loop_(MessageLoop::current()) { 84 : target_message_loop_(MessageLoop::current()) {
67 } 85 }
68 86
69 bool MessageLoopProxyImpl::PostTaskHelper( 87 bool MessageLoopProxyImpl::PostTaskHelper(
70 const tracked_objects::Location& from_here, const base::Closure& task, 88 const tracked_objects::Location& from_here, const base::Closure& task,
71 int64 delay_ms, bool nestable) { 89 base::TimeDelta delay, bool nestable) {
72 AutoLock lock(message_loop_lock_); 90 AutoLock lock(message_loop_lock_);
73 if (target_message_loop_) { 91 if (target_message_loop_) {
74 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms);
75 if (nestable) { 92 if (nestable) {
76 target_message_loop_->PostDelayedTask(from_here, task, delay); 93 target_message_loop_->PostDelayedTask(from_here, task, delay);
77 } else { 94 } else {
78 target_message_loop_->PostNonNestableDelayedTask(from_here, task, delay); 95 target_message_loop_->PostNonNestableDelayedTask(from_here, task, delay);
79 } 96 }
80 return true; 97 return true;
81 } 98 }
82 return false; 99 return false;
83 } 100 }
84 101
85 scoped_refptr<MessageLoopProxy> 102 scoped_refptr<MessageLoopProxy>
86 MessageLoopProxy::current() { 103 MessageLoopProxy::current() {
87 MessageLoop* cur_loop = MessageLoop::current(); 104 MessageLoop* cur_loop = MessageLoop::current();
88 if (!cur_loop) 105 if (!cur_loop)
89 return NULL; 106 return NULL;
90 return cur_loop->message_loop_proxy(); 107 return cur_loop->message_loop_proxy();
91 } 108 }
92 109
93 } // namespace base 110 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop_proxy_impl.h ('k') | base/sequenced_task_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698