OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
| 6 |
| 7 #include <set> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "third_party/ppapi/c/pp_resource.h" |
| 11 #include "webkit/glue/plugins/pepper_resource.h" |
| 12 |
| 13 namespace pepper { |
| 14 |
| 15 ResourceTracker::ResourceTracker() { |
| 16 } |
| 17 |
| 18 ResourceTracker::~ResourceTracker() { |
| 19 } |
| 20 |
| 21 // static |
| 22 ResourceTracker* ResourceTracker::Get() { |
| 23 return Singleton<ResourceTracker>::get(); |
| 24 } |
| 25 |
| 26 Resource* ResourceTracker::GetResource(PP_Resource res) const { |
| 27 AutoLock lock(lock_); |
| 28 Resource* resource = reinterpret_cast<Resource*>(res.id); |
| 29 if (live_resources_.find(resource) == live_resources_.end()) |
| 30 return NULL; |
| 31 return resource; |
| 32 } |
| 33 |
| 34 void ResourceTracker::AddResource(Resource* resource) { |
| 35 AutoLock lock(lock_); |
| 36 DCHECK(live_resources_.find(resource) == live_resources_.end()); |
| 37 live_resources_.insert(resource); |
| 38 } |
| 39 |
| 40 void ResourceTracker::DeleteResource(Resource* resource) { |
| 41 AutoLock lock(lock_); |
| 42 ResourceSet::iterator found = live_resources_.find(resource); |
| 43 if (found == live_resources_.end()) { |
| 44 NOTREACHED(); |
| 45 return; |
| 46 } |
| 47 live_resources_.erase(found); |
| 48 } |
| 49 |
| 50 } // namespace pepper |
OLD | NEW |