| Index: ppapi/shared_impl/resource_tracker.h
|
| diff --git a/ppapi/shared_impl/resource_tracker.h b/ppapi/shared_impl/resource_tracker.h
|
| index f5f790c60acf838b657a185e5d972b7cc8781aa9..54e6daf2c1080c5d72c1ed063dd9ab532f0dbce6 100644
|
| --- a/ppapi/shared_impl/resource_tracker.h
|
| +++ b/ppapi/shared_impl/resource_tracker.h
|
| @@ -10,6 +10,7 @@
|
| #include "base/basictypes.h"
|
| #include "base/hash_tables.h"
|
| #include "base/memory/linked_ptr.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/threading/thread_checker.h"
|
| #include "base/threading/thread_checker_impl.h"
|
| @@ -23,7 +24,12 @@ class Resource;
|
|
|
| class PPAPI_SHARED_EXPORT ResourceTracker {
|
| public:
|
| - ResourceTracker();
|
| + // A SINGLE_THREADED ResourceTracker will use a thread-checker to make sure
|
| + // it's always invoked on the same thread on which it was constructed. A
|
| + // THREAD_SAFE ResourceTracker will check that the ProxyLock is held. See
|
| + // CheckThreadingPreconditions() for more details.
|
| + enum ThreadMode { SINGLE_THREADED, THREAD_SAFE };
|
| + explicit ResourceTracker(ThreadMode thread_mode);
|
| virtual ~ResourceTracker();
|
|
|
| // The returned pointer will be NULL if there is no resource. The reference
|
| @@ -53,6 +59,10 @@ class PPAPI_SHARED_EXPORT ResourceTracker {
|
| // This calls AddResource and RemoveResource.
|
| friend class Resource;
|
|
|
| + // On the host-side, make sure we are called on the right thread. On the
|
| + // plugin side, make sure we have the proxy lock.
|
| + void CheckThreadingPreconditions() const;
|
| +
|
| // Adds the given resource to the tracker, associating it with the instance
|
| // stored in the resource object. The new resource ID is returned, and the
|
| // resource will have 0 plugin refcount. This is called by the resource
|
| @@ -98,19 +108,11 @@ class PPAPI_SHARED_EXPORT ResourceTracker {
|
|
|
| base::WeakPtrFactory<ResourceTracker> weak_ptr_factory_;
|
|
|
| - // TODO(raymes): We won't need to do thread checks once pepper calls are
|
| - // allowed off of the main thread.
|
| - // See http://code.google.com/p/chromium/issues/detail?id=92909.
|
| -#ifdef ENABLE_PEPPER_THREADING
|
| - base::ThreadCheckerDoNothing thread_checker_;
|
| -#else
|
| - // TODO(raymes): We've seen plugins (Flash) creating resources from random
|
| - // threads. Let's always crash for now in this case. Once we have a handle
|
| - // over how common this is, we can change ThreadCheckerImpl->ThreadChecker
|
| - // so that we only crash in debug mode. See
|
| - // https://code.google.com/p/chromium/issues/detail?id=146415.
|
| - base::ThreadCheckerImpl thread_checker_;
|
| -#endif
|
| + // On the host side, we want to check that we are only called on the main
|
| + // thread. This is to protect us from accidentally using the tracker from
|
| + // other threads (especially the IO thread). On the plugin side, the tracker
|
| + // is protected by the proxy lock and is thread-safe, so this will be NULL.
|
| + scoped_ptr<base::ThreadChecker> thread_checker_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
|
| };
|
|
|