Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: ppapi/shared_impl/resource_tracker.cc

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix self-assignment Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/shared_impl/resource_tracker.h" 5 #include "ppapi/shared_impl/resource_tracker.h"
6 6
7 #include "ppapi/shared_impl/id_assignment.h" 7 #include "ppapi/shared_impl/id_assignment.h"
8 #include "ppapi/shared_impl/resource.h" 8 #include "ppapi/shared_impl/resource.h"
9 9
10 namespace ppapi { 10 namespace ppapi {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return static_cast<int>(found->second->resources.size()); 135 return static_cast<int>(found->second->resources.size());
136 } 136 }
137 137
138 PP_Resource ResourceTracker::AddResource(Resource* object) { 138 PP_Resource ResourceTracker::AddResource(Resource* object) {
139 // If the plugin manages to create too many resources, don't do crazy stuff. 139 // If the plugin manages to create too many resources, don't do crazy stuff.
140 if (last_resource_value_ == kMaxPPId) 140 if (last_resource_value_ == kMaxPPId)
141 return 0; 141 return 0;
142 142
143 // If you hit this somebody forgot to call DidCreateInstance or the resource 143 // If you hit this somebody forgot to call DidCreateInstance or the resource
144 // was created with an invalid PP_Instance. 144 // was created with an invalid PP_Instance.
145 DCHECK(instance_map_.find(object->pp_instance()) != instance_map_.end()); 145 //
146 // This is specifically a check even in release mode. When creating resources
147 // it can be easy to forget to validate the instance parameter. If somebody
148 // does forget, we don't want to introduce a vulnerability with invalid
149 // pointers floating around, so we die ASAP.
150 CHECK(instance_map_.find(object->pp_instance()) != instance_map_.end());
viettrungluu 2011/08/22 23:19:46 Hrm, this could conceivably be a fairly hot method
146 151
147 PP_Resource new_id = MakeTypedId(++last_resource_value_, PP_ID_TYPE_RESOURCE); 152 PP_Resource new_id = MakeTypedId(++last_resource_value_, PP_ID_TYPE_RESOURCE);
148 instance_map_[object->pp_instance()]->resources.insert(new_id); 153 instance_map_[object->pp_instance()]->resources.insert(new_id);
149 154
150 live_resources_[new_id] = ResourceAndRefCount(object, 0); 155 live_resources_[new_id] = ResourceAndRefCount(object, 0);
151 return new_id; 156 return new_id;
152 } 157 }
153 158
154 void ResourceTracker::RemoveResource(Resource* object) { 159 void ResourceTracker::RemoveResource(Resource* object) {
155 PP_Resource pp_resource = object->pp_resource(); 160 PP_Resource pp_resource = object->pp_resource();
156 if (object->pp_instance()) 161 if (object->pp_instance())
157 instance_map_[object->pp_instance()]->resources.erase(pp_resource); 162 instance_map_[object->pp_instance()]->resources.erase(pp_resource);
158 live_resources_.erase(pp_resource); 163 live_resources_.erase(pp_resource);
159 } 164 }
160 165
161 } // namespace ppapi 166 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698