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

Side by Side Diff: remoting/base/plugin_message_loop_proxy.cc

Issue 9427023: Add functions to expand PostDelayedTask interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add function implementations in derived classes. 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
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 "remoting/base/plugin_message_loop_proxy.h" 5 #include "remoting/base/plugin_message_loop_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 8
9 namespace remoting { 9 namespace remoting {
10 10
(...skipping 10 matching lines...) Expand all
21 if (delegate_) { 21 if (delegate_) {
22 DCHECK(BelongsToCurrentThread()); 22 DCHECK(BelongsToCurrentThread());
23 delegate_ = NULL; 23 delegate_ = NULL;
24 } 24 }
25 } 25 }
26 26
27 bool PluginMessageLoopProxy::PostDelayedTask( 27 bool PluginMessageLoopProxy::PostDelayedTask(
28 const tracked_objects::Location& from_here, 28 const tracked_objects::Location& from_here,
29 const base::Closure& task, 29 const base::Closure& task,
30 int64 delay_ms) { 30 int64 delay_ms) {
31 return PostDelayedTask(
32 from_here, task, base::TimeDelta::FromMilliseconds(delay_ms));
33 }
34
35 bool PluginMessageLoopProxy::PostDelayedTask(
36 const tracked_objects::Location& from_here,
37 const base::Closure& task,
38 base::TimeDelta delay) {
31 base::AutoLock auto_lock(lock_); 39 base::AutoLock auto_lock(lock_);
32 if (!delegate_) 40 if (!delegate_)
33 return false; 41 return false;
34 42
35 base::Closure* springpad_closure = new base::Closure(base::Bind( 43 base::Closure* springpad_closure = new base::Closure(base::Bind(
36 &PluginMessageLoopProxy::RunClosureIf, this, task)); 44 &PluginMessageLoopProxy::RunClosureIf, this, task));
37 return delegate_->RunOnPluginThread( 45 return delegate_->RunOnPluginThread(
38 delay_ms, &PluginMessageLoopProxy::TaskSpringboard, springpad_closure); 46 delay.InMilliseconds(),
jar (doing other things) 2012/02/25 02:00:22 Is this transition (to using TimeDelta) a future C
47 &PluginMessageLoopProxy::TaskSpringboard, springpad_closure);
39 } 48 }
40 49
41 bool PluginMessageLoopProxy::PostNonNestableDelayedTask( 50 bool PluginMessageLoopProxy::PostNonNestableDelayedTask(
42 const tracked_objects::Location& from_here, 51 const tracked_objects::Location& from_here,
43 const base::Closure& task, 52 const base::Closure& task,
44 int64 delay_ms) { 53 int64 delay_ms) {
45 // All tasks running on this message loop are non-nestable. 54 // All tasks running on this message loop are non-nestable.
46 return PostDelayedTask(from_here, task, delay_ms); 55 return PostDelayedTask(from_here, task, delay_ms);
47 } 56 }
48 57
58 bool PluginMessageLoopProxy::PostNonNestableDelayedTask(
59 const tracked_objects::Location& from_here,
60 const base::Closure& task,
61 base::TimeDelta delay) {
62 // All tasks running on this message loop are non-nestable.
63 return PostDelayedTask(from_here, task, delay);
64 }
65
49 bool PluginMessageLoopProxy::RunsTasksOnCurrentThread() const { 66 bool PluginMessageLoopProxy::RunsTasksOnCurrentThread() const {
50 // In pepper plugins ideally we should use pp::Core::IsMainThread, 67 // In pepper plugins ideally we should use pp::Core::IsMainThread,
51 // but it is problematic because we would need to keep reference to 68 // but it is problematic because we would need to keep reference to
52 // Core somewhere, e.g. make the delegate ref-counted. 69 // Core somewhere, e.g. make the delegate ref-counted.
53 return base::PlatformThread::CurrentId() == plugin_thread_id_; 70 return base::PlatformThread::CurrentId() == plugin_thread_id_;
54 } 71 }
55 72
56 // static 73 // static
57 void PluginMessageLoopProxy::TaskSpringboard(void* data) { 74 void PluginMessageLoopProxy::TaskSpringboard(void* data) {
58 base::Closure* task = reinterpret_cast<base::Closure*>(data); 75 base::Closure* task = reinterpret_cast<base::Closure*>(data);
59 task->Run(); 76 task->Run();
60 delete task; 77 delete task;
61 } 78 }
62 79
63 void PluginMessageLoopProxy::RunClosureIf(const base::Closure& task) { 80 void PluginMessageLoopProxy::RunClosureIf(const base::Closure& task) {
64 // |delegate_| can be changed only from our thread, so it's safe to 81 // |delegate_| can be changed only from our thread, so it's safe to
65 // access it without acquiring |lock_|. 82 // access it without acquiring |lock_|.
66 if (delegate_) 83 if (delegate_)
67 task.Run(); 84 task.Run();
68 } 85 }
69 86
70 } // namespace remoting 87 } // namespace remoting
OLDNEW
« content/browser/browser_thread_impl.cc ('K') | « remoting/base/plugin_message_loop_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698