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 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/basictypes.h" |
| 12 #include "base/lock.h" |
| 13 #include "base/ref_counted.h" |
| 14 #include "base/singleton.h" |
| 15 |
| 16 typedef struct _pp_Resource PP_Resource; |
| 17 |
| 18 namespace pepper { |
| 19 |
| 20 class Resource; |
| 21 |
| 22 // This class maintains a global list of all live pepper resources. It allows |
| 23 // us to check resource ID validity and to map them to a specific module. |
| 24 // |
| 25 // This object is threadsafe. |
| 26 class ResourceTracker { |
| 27 public: |
| 28 // Returns the pointer to the singleton object. |
| 29 static ResourceTracker* Get(); |
| 30 |
| 31 // The returned pointer will be NULL if there is no resource. |
| 32 Resource* GetResource(PP_Resource res) const; |
| 33 |
| 34 // Adds the given resource to the tracker and assigns it a resource ID. The |
| 35 // assigned resource ID will be returned. |
| 36 void AddResource(Resource* resource); |
| 37 |
| 38 void DeleteResource(Resource* resource); |
| 39 |
| 40 private: |
| 41 friend struct DefaultSingletonTraits<ResourceTracker>; |
| 42 |
| 43 ResourceTracker(); |
| 44 ~ResourceTracker(); |
| 45 |
| 46 // Hold this lock when accessing this object's members. |
| 47 mutable Lock lock_; |
| 48 |
| 49 typedef std::set<Resource*> ResourceSet; |
| 50 ResourceSet live_resources_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); |
| 53 }; |
| 54 |
| 55 } // namespace pepper |
| 56 |
| 57 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_ |
OLD | NEW |