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