| OLD | NEW |
| 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 "webkit/plugins/ppapi/host_globals.h" | 5 #include "webkit/plugins/ppapi/host_globals.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 DCHECK(!host_globals_); | 44 DCHECK(!host_globals_); |
| 45 host_globals_ = this; | 45 host_globals_ = this; |
| 46 } | 46 } |
| 47 | 47 |
| 48 HostGlobals::~HostGlobals() { | 48 HostGlobals::~HostGlobals() { |
| 49 DCHECK(host_globals_ == this); | 49 DCHECK(host_globals_ == this); |
| 50 host_globals_ = NULL; | 50 host_globals_ = NULL; |
| 51 } | 51 } |
| 52 | 52 |
| 53 ::ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { | 53 ::ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { |
| 54 return &host_resource_tracker_; | 54 return &resource_tracker_; |
| 55 } | 55 } |
| 56 | 56 |
| 57 ::ppapi::VarTracker* HostGlobals::GetVarTracker() { | 57 ::ppapi::VarTracker* HostGlobals::GetVarTracker() { |
| 58 return &host_var_tracker_; | 58 return &host_var_tracker_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 ::ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( | 61 ::ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( |
| 62 PP_Instance instance) { | 62 PP_Instance instance) { |
| 63 std::map<PP_Instance, linked_ptr<InstanceData> >::iterator found = | 63 std::map<PP_Instance, linked_ptr<InstanceData> >::iterator found = |
| 64 instance_map_.find(instance); | 64 instance_map_.find(instance); |
| 65 if (found == instance_map_.end()) | 65 if (found == instance_map_.end()) |
| 66 return NULL; | 66 return NULL; |
| 67 | 67 |
| 68 return found->second->instance->module()->GetNewCallbackTracker(); | 68 return found->second->instance->module()->GetCallbackTracker(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ::ppapi::FunctionGroupBase* HostGlobals::GetFunctionAPI(PP_Instance pp_instance, | 71 ::ppapi::FunctionGroupBase* HostGlobals::GetFunctionAPI(PP_Instance pp_instance, |
| 72 ::ppapi::ApiID id) { | 72 ::ppapi::ApiID id) { |
| 73 // Get the instance object. This also ensures that the instance data is in | 73 // Get the instance object. This also ensures that the instance data is in |
| 74 // the map, since we need it below. | 74 // the map, since we need it below. |
| 75 PluginInstance* instance = GetInstance(pp_instance); | 75 PluginInstance* instance = GetInstance(pp_instance); |
| 76 if (!instance) | 76 if (!instance) |
| 77 return NULL; | 77 return NULL; |
| 78 | 78 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 do { | 166 do { |
| 167 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), | 167 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), |
| 168 ::ppapi::PP_ID_TYPE_INSTANCE); | 168 ::ppapi::PP_ID_TYPE_INSTANCE); |
| 169 } while (!new_instance || | 169 } while (!new_instance || |
| 170 instance_map_.find(new_instance) != instance_map_.end() || | 170 instance_map_.find(new_instance) != instance_map_.end() || |
| 171 !instance->module()->ReserveInstanceID(new_instance)); | 171 !instance->module()->ReserveInstanceID(new_instance)); |
| 172 | 172 |
| 173 instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); | 173 instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); |
| 174 instance_map_[new_instance]->instance = instance; | 174 instance_map_[new_instance]->instance = instance; |
| 175 | 175 |
| 176 host_resource_tracker_.DidCreateInstance(new_instance); | 176 resource_tracker_.DidCreateInstance(new_instance); |
| 177 return new_instance; | 177 return new_instance; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void HostGlobals::InstanceDeleted(PP_Instance instance) { | 180 void HostGlobals::InstanceDeleted(PP_Instance instance) { |
| 181 host_resource_tracker_.DidDeleteInstance(instance); | 181 resource_tracker_.DidDeleteInstance(instance); |
| 182 host_var_tracker_.ForceFreeNPObjectsForInstance(instance); | 182 host_var_tracker_.ForceFreeNPObjectsForInstance(instance); |
| 183 instance_map_.erase(instance); | 183 instance_map_.erase(instance); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void HostGlobals::InstanceCrashed(PP_Instance instance) { | 186 void HostGlobals::InstanceCrashed(PP_Instance instance) { |
| 187 host_resource_tracker_.DidDeleteInstance(instance); | 187 resource_tracker_.DidDeleteInstance(instance); |
| 188 host_var_tracker_.ForceFreeNPObjectsForInstance(instance); | 188 host_var_tracker_.ForceFreeNPObjectsForInstance(instance); |
| 189 } | 189 } |
| 190 | 190 |
| 191 PluginInstance* HostGlobals::GetInstance(PP_Instance instance) { | 191 PluginInstance* HostGlobals::GetInstance(PP_Instance instance) { |
| 192 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) | 192 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) |
| 193 << instance << " is not a PP_Instance."; | 193 << instance << " is not a PP_Instance."; |
| 194 InstanceMap::iterator found = instance_map_.find(instance); | 194 InstanceMap::iterator found = instance_map_.find(instance); |
| 195 if (found == instance_map_.end()) | 195 if (found == instance_map_.end()) |
| 196 return NULL; | 196 return NULL; |
| 197 return found->second->instance; | 197 return found->second->instance; |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace ppapi | 200 } // namespace ppapi |
| 201 } // namespace webkit | 201 } // namespace webkit |
| OLD | NEW |