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

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

Issue 174213003: PPAPI: Use clang-format on ppapi/shared_impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove DEPS Created 6 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 "ppapi/shared_impl/thread_aware_callback.h" 5 #include "ppapi/shared_impl/thread_aware_callback.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ppapi/shared_impl/ppapi_globals.h" 9 #include "ppapi/shared_impl/ppapi_globals.h"
10 #include "ppapi/shared_impl/ppb_message_loop_shared.h" 10 #include "ppapi/shared_impl/ppb_message_loop_shared.h"
11 11
12 namespace ppapi { 12 namespace ppapi {
13 namespace internal { 13 namespace internal {
14 14
15 class ThreadAwareCallbackBase::Core : public base::RefCountedThreadSafe<Core> { 15 class ThreadAwareCallbackBase::Core : public base::RefCountedThreadSafe<Core> {
16 public: 16 public:
17 Core() : aborted_(false) { 17 Core() : aborted_(false) {}
18 }
19 18
20 void MarkAsAborted() { aborted_ = true; } 19 void MarkAsAborted() { aborted_ = true; }
21 20
22 void RunIfNotAborted(const base::Closure& closure) { 21 void RunIfNotAborted(const base::Closure& closure) {
23 if (!aborted_) 22 if (!aborted_)
24 CallWhileUnlocked(closure); 23 CallWhileUnlocked(closure);
25 } 24 }
26 25
27 private: 26 private:
28 friend class base::RefCountedThreadSafe<Core>; 27 friend class base::RefCountedThreadSafe<Core>;
29 ~Core() { 28 ~Core() {}
30 }
31 29
32 bool aborted_; 30 bool aborted_;
33 }; 31 };
34 32
35 ThreadAwareCallbackBase::ThreadAwareCallbackBase() 33 ThreadAwareCallbackBase::ThreadAwareCallbackBase()
36 : target_loop_(PpapiGlobals::Get()->GetCurrentMessageLoop()), 34 : target_loop_(PpapiGlobals::Get()->GetCurrentMessageLoop()),
37 core_(new Core()) { 35 core_(new Core()) {
38 DCHECK(target_loop_.get()); 36 DCHECK(target_loop_.get());
39 } 37 }
40 38
41 ThreadAwareCallbackBase::~ThreadAwareCallbackBase() { 39 ThreadAwareCallbackBase::~ThreadAwareCallbackBase() { core_->MarkAsAborted(); }
42 core_->MarkAsAborted();
43 }
44 40
45 // static 41 // static
46 bool ThreadAwareCallbackBase::HasTargetLoop() { 42 bool ThreadAwareCallbackBase::HasTargetLoop() {
47 return !!PpapiGlobals::Get()->GetCurrentMessageLoop(); 43 return !!PpapiGlobals::Get()->GetCurrentMessageLoop();
48 } 44 }
49 45
50 void ThreadAwareCallbackBase::InternalRunOnTargetThread( 46 void ThreadAwareCallbackBase::InternalRunOnTargetThread(
51 const base::Closure& closure) { 47 const base::Closure& closure) {
52 if (target_loop_.get() != PpapiGlobals::Get()->GetCurrentMessageLoop()) { 48 if (target_loop_.get() != PpapiGlobals::Get()->GetCurrentMessageLoop()) {
53 target_loop_->PostClosure( 49 target_loop_->PostClosure(
54 FROM_HERE, 50 FROM_HERE,
55 RunWhileLocked(base::Bind(&Core::RunIfNotAborted, core_, closure)), 51 RunWhileLocked(base::Bind(&Core::RunIfNotAborted, core_, closure)),
56 0); 52 0);
57 } else { 53 } else {
58 CallWhileUnlocked(closure); 54 CallWhileUnlocked(closure);
59 } 55 }
60 } 56 }
61 57
62 } // namespace internal 58 } // namespace internal
63 } // namespace ppapi 59 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/thread_aware_callback.h ('k') | ppapi/shared_impl/thread_aware_callback_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698