| Index: ppapi/shared_impl/callback_tracker.cc
|
| ===================================================================
|
| --- ppapi/shared_impl/callback_tracker.cc (revision 115831)
|
| +++ ppapi/shared_impl/callback_tracker.cc (working copy)
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "webkit/plugins/ppapi/callbacks.h"
|
| +#include "ppapi/shared_impl/callback_tracker.h"
|
|
|
| #include <algorithm>
|
|
|
| @@ -11,9 +11,8 @@
|
| #include "base/logging.h"
|
| #include "base/message_loop.h"
|
| #include "ppapi/c/pp_completion_callback.h"
|
| -#include "ppapi/c/pp_errors.h"
|
| +#include "ppapi/shared_impl/tracked_callback.h"
|
|
|
| -namespace webkit {
|
| namespace ppapi {
|
|
|
| // CallbackTracker -------------------------------------------------------------
|
| @@ -73,85 +72,4 @@
|
| pending_callbacks_.erase(map_it);
|
| }
|
|
|
| -// TrackedCallback -------------------------------------------------------------
|
| -
|
| -TrackedCallback::TrackedCallback(const scoped_refptr<CallbackTracker>& tracker,
|
| - PP_Resource resource_id)
|
| - : ALLOW_THIS_IN_INITIALIZER_LIST(abort_impl_factory_(this)),
|
| - tracker_(tracker),
|
| - resource_id_(resource_id),
|
| - completed_(false),
|
| - aborted_(false) {
|
| - tracker_->Add(make_scoped_refptr(this));
|
| -}
|
| -
|
| -void TrackedCallback::Abort() {
|
| - if (!completed()) {
|
| - aborted_ = true;
|
| - AbortImpl();
|
| - }
|
| -}
|
| -
|
| -void TrackedCallback::PostAbort() {
|
| - if (!completed()) {
|
| - aborted_ = true;
|
| - // Post a task for the abort (only if necessary).
|
| - if (!abort_impl_factory_.HasWeakPtrs()) {
|
| - MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&TrackedCallback::AbortImpl,
|
| - abort_impl_factory_.GetWeakPtr()));
|
| - }
|
| - }
|
| -}
|
| -
|
| -TrackedCallback::~TrackedCallback() {
|
| - // The tracker must ensure that the callback is completed (maybe abortively).
|
| - DCHECK(completed_);
|
| -}
|
| -
|
| -void TrackedCallback::MarkAsCompleted() {
|
| - DCHECK(!completed());
|
| -
|
| - // We will be removed; maintain a reference to ensure we won't be deleted
|
| - // until we're done.
|
| - scoped_refptr<TrackedCallback> thiz = this;
|
| - completed_ = true;
|
| - tracker_->Remove(thiz);
|
| - tracker_ = NULL;
|
| -}
|
| -
|
| -// TrackedCompletionCallback ---------------------------------------------------
|
| -
|
| -TrackedCompletionCallback::TrackedCompletionCallback(
|
| - const scoped_refptr<CallbackTracker>& tracker,
|
| - PP_Resource resource_id,
|
| - const PP_CompletionCallback& callback)
|
| - : TrackedCallback(tracker, resource_id),
|
| - callback_(callback) {
|
| -}
|
| -
|
| -void TrackedCompletionCallback::Run(int32_t result) {
|
| - if (!completed()) {
|
| - // Cancel any pending calls.
|
| - abort_impl_factory_.InvalidateWeakPtrs();
|
| -
|
| - // Copy |callback_| and look at |aborted()| now, since |MarkAsCompleted()|
|
| - // may delete us.
|
| - PP_CompletionCallback callback = callback_;
|
| - if (aborted())
|
| - result = PP_ERROR_ABORTED;
|
| -
|
| - // Do this before running the callback in case of reentrancy (which
|
| - // shouldn't happen, but avoid strange failures).
|
| - MarkAsCompleted();
|
| - PP_RunCompletionCallback(&callback, result);
|
| - }
|
| -}
|
| -
|
| -void TrackedCompletionCallback::AbortImpl() {
|
| - Run(PP_ERROR_ABORTED);
|
| -}
|
| -
|
| } // namespace ppapi
|
| -} // namespace webkit
|
|
|