| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 5 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "third_party/ppapi/c/pp_resource.h" | 11 #include "third_party/ppapi/c/pp_resource.h" |
| 12 #include "webkit/glue/plugins/pepper_resource.h" | 12 #include "webkit/glue/plugins/pepper_resource.h" |
| 13 | 13 |
| 14 namespace pepper { | 14 namespace pepper { |
| 15 | 15 |
| 16 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { | 16 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { |
| 17 ResourceMap::const_iterator result = live_resources_.find(res); | 17 ResourceMap::const_iterator result = live_resources_.find(res); |
| 18 if (result == live_resources_.end()) { | 18 if (result == live_resources_.end()) { |
| 19 return scoped_refptr<Resource>(); | 19 return scoped_refptr<Resource>(); |
| 20 } | 20 } |
| 21 return result->second.first; | 21 return result->second.first; |
| 22 } | 22 } |
| 23 | 23 |
| 24 ResourceTracker::ResourceTracker() |
| 25 : last_id_(0) { |
| 26 } |
| 27 |
| 28 ResourceTracker::~ResourceTracker() { |
| 29 } |
| 30 |
| 24 PP_Resource ResourceTracker::AddResource(Resource* resource) { | 31 PP_Resource ResourceTracker::AddResource(Resource* resource) { |
| 25 // If the plugin manages to create 4B resources... | 32 // If the plugin manages to create 4B resources... |
| 26 if (last_id_ == std::numeric_limits<PP_Resource>::max()) { | 33 if (last_id_ == std::numeric_limits<PP_Resource>::max()) { |
| 27 return 0; | 34 return 0; |
| 28 } | 35 } |
| 29 // Add the resource with plugin use-count 1. | 36 // Add the resource with plugin use-count 1. |
| 30 ++last_id_; | 37 ++last_id_; |
| 31 live_resources_.insert(std::make_pair(last_id_, std::make_pair(resource, 1))); | 38 live_resources_.insert(std::make_pair(last_id_, std::make_pair(resource, 1))); |
| 32 return last_id_; | 39 return last_id_; |
| 33 } | 40 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // module->resource lookup to free resources when a module is unloaded. In | 73 // module->resource lookup to free resources when a module is unloaded. In |
| 67 // this case, this function can be implemented using that system. | 74 // this case, this function can be implemented using that system. |
| 68 uint32 count = 0; | 75 uint32 count = 0; |
| 69 for (ResourceMap::const_iterator i = live_resources_.begin(); | 76 for (ResourceMap::const_iterator i = live_resources_.begin(); |
| 70 i != live_resources_.end(); ++i) | 77 i != live_resources_.end(); ++i) |
| 71 count++; | 78 count++; |
| 72 return count; | 79 return count; |
| 73 } | 80 } |
| 74 | 81 |
| 75 } // namespace pepper | 82 } // namespace pepper |
| OLD | NEW |