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

Side by Side Diff: ppapi/shared_impl/thread_aware_callback.cc

Issue 11859015: Pepper: Introduce ThreadAwareCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and update tests accordingly. Created 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/shared_impl/thread_aware_callback.h"
6
7 #include "base/callback.h"
8 #include "ppapi/shared_impl/ppapi_globals.h"
9 #include "ppapi/shared_impl/ppb_message_loop_shared.h"
10
11 namespace ppapi {
12 namespace internal {
13
14 class ThreadAwareCallbackBase::Core : public base::RefCountedThreadSafe<Core> {
15 public:
16 Core() : aborted_(false) {
17 }
18
19 void MarkAsAborted() { aborted_ = true; }
20
21 void RunIfNotAborted(const base::Closure& closure) {
22 ProxyAutoLock auto_lock;
dmichael (off chromium) 2013/01/15 22:43:52 You could use "RunWhileLocked" where you Post this
yzshen1 2013/01/16 18:55:59 RunWhileLocked() adds another level of 'Bind', whi
dmichael (off chromium) 2013/01/16 19:21:00 I really don't think the Bind is a big deal; it's
yzshen1 2013/01/16 22:37:36 Done. Thanks for the feedback. :) On 2013/01/16 1
23
24 if (!aborted_)
25 CallWhileUnlocked(closure);
26 }
27
28 private:
29 friend class base::RefCountedThreadSafe<Core>;
30 ~Core() {
31 }
32
33 bool aborted_;
34 };
35
36 ThreadAwareCallbackBase::ThreadAwareCallbackBase()
37 : target_loop_(PpapiGlobals::Get()->GetCurrentMessageLoop()),
38 core_(new Core()) {
dmichael (off chromium) 2013/01/15 22:43:52 DCHECK(target_loop_); ? There's no guarantee that
yzshen1 2013/01/16 18:55:59 A DCHECK() won't help plugin developers who develo
dmichael (off chromium) 2013/01/16 19:21:00 Ah. I was assuming that the API that uses this wou
yzshen1 2013/01/16 22:37:36 Yeah, I like this idea. I have made changes accord
39 }
40
41 ThreadAwareCallbackBase::~ThreadAwareCallbackBase() {
42 core_->MarkAsAborted();
43 }
44
45 bool ThreadAwareCallbackBase::ShouldPostToTargetLoop() {
46 return target_loop_.get() &&
47 target_loop_ != PpapiGlobals::Get()->GetCurrentMessageLoop();
48 }
49
50 void ThreadAwareCallbackBase::RunIfNotAborted(
51 const base::Closure& closure) {
52 target_loop_->PostClosure(FROM_HERE,
53 base::Bind(&Core::RunIfNotAborted, core_, closure),
54 0);
55 }
56
57 } // namespace internal
58 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698