| Index: ppapi/shared_impl/tracked_callback.h
|
| diff --git a/ppapi/shared_impl/tracked_callback.h b/ppapi/shared_impl/tracked_callback.h
|
| index a75bded182624d876b64aa0e305473f34504d7ba..5286b51c6a375f5fd07ca1a24a69ba07e7d6f720 100644
|
| --- a/ppapi/shared_impl/tracked_callback.h
|
| +++ b/ppapi/shared_impl/tracked_callback.h
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -10,8 +10,11 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| +#include "base/synchronization/condition_variable.h"
|
| #include "ppapi/c/pp_completion_callback.h"
|
| +#include "ppapi/c/pp_instance.h"
|
| #include "ppapi/c/pp_resource.h"
|
| #include "ppapi/shared_impl/ppapi_shared_export.h"
|
|
|
| @@ -20,6 +23,13 @@ namespace ppapi {
|
| class CallbackTracker;
|
| class Resource;
|
|
|
| +namespace thunk {
|
| +namespace subtle {
|
| +// For a friend declaration below.
|
| +class EnterBase;
|
| +}
|
| +}
|
| +
|
| // |TrackedCallback| represents a tracked Pepper callback (from the browser to
|
| // the plugin), typically still pending. Such callbacks have the standard Pepper
|
| // callback semantics. Execution (i.e., completion) of callbacks happens through
|
| @@ -51,9 +61,9 @@ class PPAPI_SHARED_EXPORT TrackedCallback
|
| : public base::RefCountedThreadSafe<TrackedCallback> {
|
| public:
|
| // Create a tracked completion callback and register it with the tracker. The
|
| - // resource pointer is not stored.
|
| - TrackedCallback(Resource* resource,
|
| - const PP_CompletionCallback& callback);
|
| + // resource pointer is not stored. If |resource| is NULL, this callback will
|
| + // not be added to the callback tracker.
|
| + TrackedCallback(Resource* resource, const PP_CompletionCallback& callback);
|
|
|
| // These run the callback in an abortive manner, or post a task to do so (but
|
| // immediately marking the callback as to be aborted).
|
| @@ -66,6 +76,9 @@ class PPAPI_SHARED_EXPORT TrackedCallback
|
| //
|
| // See also ClearAndRun().
|
| void Run(int32_t result);
|
| + void PostRun(int32_t result);
|
| +
|
| + void BlockUntilRun();
|
|
|
| // Returns the ID of the resource which "owns" the callback, or 0 if the
|
| // callback is not associated with any resource.
|
| @@ -88,7 +101,7 @@ class PPAPI_SHARED_EXPORT TrackedCallback
|
|
|
| // Runs the given callback, clearing the given scoped_refptr before execution.
|
| // This is useful for cases where there can be only one pending callback, and
|
| - // the presence of the callback indicates is one is pending. Such code would
|
| + // the presence of the callback indicates one is pending. Such code would
|
| // normally want to clear it before execution so the plugin can issue a new
|
| // request.
|
| static void ClearAndRun(scoped_refptr<TrackedCallback>* callback,
|
| @@ -97,20 +110,43 @@ class PPAPI_SHARED_EXPORT TrackedCallback
|
| // Same as ClearAndRun except it calls Abort().
|
| static void ClearAndAbort(scoped_refptr<TrackedCallback>* callback);
|
|
|
| + protected:
|
| + bool is_blocking() {
|
| + return !callback_.func;
|
| + }
|
| + bool is_required() {
|
| + return (callback_.func &&
|
| + !(callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL));
|
| + }
|
| + bool is_optional() {
|
| + return (callback_.func &&
|
| + (callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL));
|
| + }
|
| +
|
| private:
|
| - // This class is ref counted.
|
| - friend class base::RefCountedThreadSafe<TrackedCallback>;
|
| - virtual ~TrackedCallback();
|
| + // TrackedCallback and EnterBase manage dealing with how to invoke callbacks
|
| + // appropriately. Pepper interface implementations and proxies should not have
|
| + // to check the type of callback, block, or mark them complete explicitly.
|
| + friend class ppapi::thunk::subtle::EnterBase;
|
| +
|
| + // Block until the associated operation has completed. Returns the result.
|
| + // This must only be called on a non-main thread on a blocking callback.
|
| + int32_t BlockUntilComplete();
|
|
|
| // Mark this object as complete and remove it from the tracker. This must only
|
| // be called once. Note that running this may result in this object being
|
| // deleted (so keep a reference if it'll still be needed).
|
| void MarkAsCompleted();
|
|
|
| - // Factory used by |PostAbort()|. Note that it's safe to cancel any pending
|
| - // posted aborts on destruction -- before it's destroyed, the "owning"
|
| - // |CallbackTracker| must have gone through and done (synchronous) |Abort()|s.
|
| - base::WeakPtrFactory<TrackedCallback> abort_impl_factory_;
|
| + // This class is ref counted.
|
| + friend class base::RefCountedThreadSafe<TrackedCallback>;
|
| + virtual ~TrackedCallback();
|
| +
|
| + // Factory used by |PostAbort()| and |PostRun()|. Note that it's safe to
|
| + // cancel any pending posted tasks on destruction -- before it's destroyed,
|
| + // the "owning" |CallbackTracker| must have gone through and done
|
| + // (synchronous) |Abort()|s.
|
| + base::WeakPtrFactory<TrackedCallback> weak_ptr_factory_;
|
|
|
| scoped_refptr<CallbackTracker> tracker_;
|
| PP_Resource resource_id_;
|
| @@ -118,6 +154,12 @@ class PPAPI_SHARED_EXPORT TrackedCallback
|
| bool aborted_;
|
| PP_CompletionCallback callback_;
|
|
|
| + int32_t result_for_blocked_callback_;
|
| + // Used for pausing/waking the blocked thread if this is a blocking completion
|
| + // callback. Note that in-process, there is no lock, blocking callbacks are
|
| + // not allowed, and therefore this pointer will be NULL.
|
| + scoped_ptr<base::ConditionVariable> operation_completed_condvar_;
|
| +
|
| DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback);
|
| };
|
|
|
|
|