summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/resource_tracker.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/shared_impl/resource_tracker.cc')
-rw-r--r--ppapi/shared_impl/resource_tracker.cc26
1 files changed, 16 insertions, 10 deletions
diff --git a/ppapi/shared_impl/resource_tracker.cc b/ppapi/shared_impl/resource_tracker.cc
index a448ce4..a46c823 100644
--- a/ppapi/shared_impl/resource_tracker.cc
+++ b/ppapi/shared_impl/resource_tracker.cc
@@ -15,17 +15,23 @@
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());
ProxyLock::AssertAcquired();
+}
+
+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 +39,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 +61,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 +92,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 +102,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 +157,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 +165,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 +197,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())