| 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 void TrackedCallback::ClearAndRun(scoped_refptr<TrackedCallback>* callback, |
| 78 int32_t result) { |
| 79 scoped_refptr<TrackedCallback> temp; |
| 80 temp.swap(*callback); |
| 81 temp->Run(result); |
| 82 } |
| 83 |
| 84 // static |
| 85 void TrackedCallback::ClearAndAbort(scoped_refptr<TrackedCallback>* callback) { |
| 86 scoped_refptr<TrackedCallback> temp; |
| 87 temp.swap(*callback); |
| 88 temp->Abort(); |
| 89 } |
| 90 |
| 76 void TrackedCallback::MarkAsCompleted() { | 91 void TrackedCallback::MarkAsCompleted() { |
| 77 DCHECK(!completed()); | 92 DCHECK(!completed()); |
| 78 | 93 |
| 79 // We will be removed; maintain a reference to ensure we won't be deleted | 94 // We will be removed; maintain a reference to ensure we won't be deleted |
| 80 // until we're done. | 95 // until we're done. |
| 81 scoped_refptr<TrackedCallback> thiz = this; | 96 scoped_refptr<TrackedCallback> thiz = this; |
| 82 completed_ = true; | 97 completed_ = true; |
| 83 tracker_->Remove(thiz); | 98 tracker_->Remove(thiz); |
| 84 tracker_ = NULL; | 99 tracker_ = NULL; |
| 85 } | 100 } |
| 86 | 101 |
| 87 } // namespace ppapi | 102 } // namespace ppapi |
| OLD | NEW |