OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/tracked_callback.h" | 5 #include "ppapi/shared_impl/tracked_callback.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "ppapi/c/pp_completion_callback.h" | 11 #include "ppapi/c/pp_completion_callback.h" |
12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/shared_impl/callback_tracker.h" | 13 #include "ppapi/shared_impl/callback_tracker.h" |
14 #include "ppapi/shared_impl/ppapi_globals.h" | 14 #include "ppapi/shared_impl/ppapi_globals.h" |
| 15 #include "ppapi/shared_impl/proxy_lock.h" |
15 #include "ppapi/shared_impl/resource.h" | 16 #include "ppapi/shared_impl/resource.h" |
16 | 17 |
17 namespace ppapi { | 18 namespace ppapi { |
18 | 19 |
19 // TrackedCallback ------------------------------------------------------------- | 20 // TrackedCallback ------------------------------------------------------------- |
20 | 21 |
21 // Note: don't keep a Resource* since it may go out of scope before us. | 22 // Note: don't keep a Resource* since it may go out of scope before us. |
22 TrackedCallback::TrackedCallback( | 23 TrackedCallback::TrackedCallback( |
23 Resource* resource, | 24 Resource* resource, |
24 const PP_CompletionCallback& callback) | 25 const PP_CompletionCallback& callback) |
(...skipping 17 matching lines...) Expand all Loading... |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 void TrackedCallback::PostAbort() { | 46 void TrackedCallback::PostAbort() { |
46 if (!completed()) { | 47 if (!completed()) { |
47 aborted_ = true; | 48 aborted_ = true; |
48 // Post a task for the abort (only if necessary). | 49 // Post a task for the abort (only if necessary). |
49 if (!abort_impl_factory_.HasWeakPtrs()) { | 50 if (!abort_impl_factory_.HasWeakPtrs()) { |
50 MessageLoop::current()->PostTask( | 51 MessageLoop::current()->PostTask( |
51 FROM_HERE, | 52 FROM_HERE, |
52 base::Bind(&TrackedCallback::Abort, | 53 RunWhileLocked(base::Bind(&TrackedCallback::Abort, |
53 abort_impl_factory_.GetWeakPtr())); | 54 abort_impl_factory_.GetWeakPtr()))); |
54 } | 55 } |
55 } | 56 } |
56 } | 57 } |
57 | 58 |
58 void TrackedCallback::Run(int32_t result) { | 59 void TrackedCallback::Run(int32_t result) { |
59 if (!completed()) { | 60 if (!completed()) { |
60 // Cancel any pending calls. | 61 // Cancel any pending calls. |
61 abort_impl_factory_.InvalidateWeakPtrs(); | 62 abort_impl_factory_.InvalidateWeakPtrs(); |
62 | 63 |
63 // Copy |callback_| and look at |aborted()| now, since |MarkAsCompleted()| | 64 // Copy |callback_| and look at |aborted()| now, since |MarkAsCompleted()| |
64 // may delete us. | 65 // may delete us. |
65 PP_CompletionCallback callback = callback_; | 66 PP_CompletionCallback callback = callback_; |
66 if (aborted()) | 67 if (aborted()) |
67 result = PP_ERROR_ABORTED; | 68 result = PP_ERROR_ABORTED; |
68 | 69 |
69 // Do this before running the callback in case of reentrancy (which | 70 // Do this before running the callback in case of reentrancy (which |
70 // shouldn't happen, but avoid strange failures). | 71 // shouldn't happen, but avoid strange failures). |
71 MarkAsCompleted(); | 72 MarkAsCompleted(); |
72 PP_RunCompletionCallback(&callback, result); | 73 CallWhileUnlocked(PP_RunCompletionCallback, &callback, result); |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 // static | 77 // static |
77 bool TrackedCallback::IsPending( | 78 bool TrackedCallback::IsPending( |
78 const scoped_refptr<TrackedCallback>& callback) { | 79 const scoped_refptr<TrackedCallback>& callback) { |
79 if (!callback.get()) | 80 if (!callback.get()) |
80 return false; | 81 return false; |
81 return !callback->completed(); | 82 return !callback->completed(); |
82 } | 83 } |
(...skipping 18 matching lines...) Expand all Loading... |
101 | 102 |
102 // We will be removed; maintain a reference to ensure we won't be deleted | 103 // We will be removed; maintain a reference to ensure we won't be deleted |
103 // until we're done. | 104 // until we're done. |
104 scoped_refptr<TrackedCallback> thiz = this; | 105 scoped_refptr<TrackedCallback> thiz = this; |
105 completed_ = true; | 106 completed_ = true; |
106 tracker_->Remove(thiz); | 107 tracker_->Remove(thiz); |
107 tracker_ = NULL; | 108 tracker_ = NULL; |
108 } | 109 } |
109 | 110 |
110 } // namespace ppapi | 111 } // namespace ppapi |
OLD | NEW |