| 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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if (aborted()) | 66 if (aborted()) |
| 67 result = PP_ERROR_ABORTED; | 67 result = PP_ERROR_ABORTED; |
| 68 | 68 |
| 69 // Do this before running the callback in case of reentrancy (which | 69 // Do this before running the callback in case of reentrancy (which |
| 70 // shouldn't happen, but avoid strange failures). | 70 // shouldn't happen, but avoid strange failures). |
| 71 MarkAsCompleted(); | 71 MarkAsCompleted(); |
| 72 PP_RunCompletionCallback(&callback, result); | 72 PP_RunCompletionCallback(&callback, result); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 // static |
| 77 bool TrackedCallback::IsPending( |
| 78 const scoped_refptr<TrackedCallback>& callback) { |
| 79 if (!callback.get()) |
| 80 return false; |
| 81 return !callback->completed(); |
| 82 } |
| 83 |
| 84 // static |
| 85 void TrackedCallback::ClearAndRun(scoped_refptr<TrackedCallback>* callback, |
| 86 int32_t result) { |
| 87 scoped_refptr<TrackedCallback> temp; |
| 88 temp.swap(*callback); |
| 89 temp->Run(result); |
| 90 } |
| 91 |
| 92 // static |
| 93 void TrackedCallback::ClearAndAbort(scoped_refptr<TrackedCallback>* callback) { |
| 94 scoped_refptr<TrackedCallback> temp; |
| 95 temp.swap(*callback); |
| 96 temp->Abort(); |
| 97 } |
| 98 |
| 76 void TrackedCallback::MarkAsCompleted() { | 99 void TrackedCallback::MarkAsCompleted() { |
| 77 DCHECK(!completed()); | 100 DCHECK(!completed()); |
| 78 | 101 |
| 79 // 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 |
| 80 // until we're done. | 103 // until we're done. |
| 81 scoped_refptr<TrackedCallback> thiz = this; | 104 scoped_refptr<TrackedCallback> thiz = this; |
| 82 completed_ = true; | 105 completed_ = true; |
| 83 tracker_->Remove(thiz); | 106 tracker_->Remove(thiz); |
| 84 tracker_ = NULL; | 107 tracker_ = NULL; |
| 85 } | 108 } |
| 86 | 109 |
| 87 } // namespace ppapi | 110 } // namespace ppapi |
| OLD | NEW |