Index: ppapi/shared_impl/resource_tracker.cc |
diff --git a/ppapi/shared_impl/resource_tracker.cc b/ppapi/shared_impl/resource_tracker.cc |
index f7e22eb1c40e8e58f749d004992aaa2dcb110607..275a1e5140d5bc3c91cd69dece05162b0c814b96 100644 |
--- a/ppapi/shared_impl/resource_tracker.cc |
+++ b/ppapi/shared_impl/resource_tracker.cc |
@@ -15,17 +15,25 @@ |
namespace ppapi { |
-ResourceTracker::ResourceTracker() |
+ResourceTracker::ResourceTracker(ThreadMode thread_mode) |
: last_resource_value_(0), |
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
+ if (thread_mode == SINGLE_THREADED) |
+ thread_checker_.reset(new base::ThreadChecker); |
} |
ResourceTracker::~ResourceTracker() { |
} |
-Resource* ResourceTracker::GetResource(PP_Resource res) const { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+void ResourceTracker::CheckThreadingPreconditions() const { |
+ DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); |
+#ifndef NDEBUG |
ProxyLock::AssertAcquired(); |
+#endif |
+} |
+ |
+Resource* ResourceTracker::GetResource(PP_Resource res) const { |
+ CheckThreadingPreconditions(); |
ResourceMap::const_iterator i = live_resources_.find(res); |
if (i == live_resources_.end()) |
return NULL; |
@@ -33,7 +41,7 @@ Resource* ResourceTracker::GetResource(PP_Resource res) const { |
} |
void ResourceTracker::AddRefResource(PP_Resource res) { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE)) |
<< res << " is not a PP_Resource."; |
ResourceMap::iterator i = live_resources_.find(res); |
@@ -55,7 +63,7 @@ void ResourceTracker::AddRefResource(PP_Resource res) { |
} |
void ResourceTracker::ReleaseResource(PP_Resource res) { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
DLOG_IF(ERROR, !CheckIdType(res, PP_ID_TYPE_RESOURCE)) |
<< res << " is not a PP_Resource."; |
ResourceMap::iterator i = live_resources_.find(res); |
@@ -86,7 +94,7 @@ void ResourceTracker::ReleaseResourceSoon(PP_Resource res) { |
} |
void ResourceTracker::DidCreateInstance(PP_Instance instance) { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
// Due to the infrastructure of some tests, the instance is registered |
// twice in a few cases. It would be nice not to do that and assert here |
// instead. |
@@ -96,7 +104,7 @@ void ResourceTracker::DidCreateInstance(PP_Instance instance) { |
} |
void ResourceTracker::DidDeleteInstance(PP_Instance instance) { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
InstanceMap::iterator found_instance = instance_map_.find(instance); |
// Due to the infrastructure of some tests, the instance is unregistered |
@@ -151,7 +159,7 @@ void ResourceTracker::DidDeleteInstance(PP_Instance instance) { |
} |
int ResourceTracker::GetLiveObjectsForInstance(PP_Instance instance) const { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
InstanceMap::const_iterator found = instance_map_.find(instance); |
if (found == instance_map_.end()) |
return 0; |
@@ -159,7 +167,7 @@ int ResourceTracker::GetLiveObjectsForInstance(PP_Instance instance) const { |
} |
PP_Resource ResourceTracker::AddResource(Resource* object) { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
// If the plugin manages to create too many resources, don't do crazy stuff. |
if (last_resource_value_ == kMaxPPId) |
return 0; |
@@ -191,7 +199,7 @@ PP_Resource ResourceTracker::AddResource(Resource* object) { |
} |
void ResourceTracker::RemoveResource(Resource* object) { |
- CHECK(thread_checker_.CalledOnValidThread()); |
+ CheckThreadingPreconditions(); |
PP_Resource pp_resource = object->pp_resource(); |
InstanceMap::iterator found = instance_map_.find(object->pp_instance()); |
if (found != instance_map_.end()) |