OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "ppapi/shared_impl/callback_tracker.h" | 10 #include "ppapi/shared_impl/callback_tracker.h" |
11 #include "ppapi/shared_impl/id_assignment.h" | 11 #include "ppapi/shared_impl/id_assignment.h" |
12 #include "ppapi/shared_impl/ppapi_globals.h" | 12 #include "ppapi/shared_impl/ppapi_globals.h" |
13 #include "ppapi/shared_impl/proxy_lock.h" | 13 #include "ppapi/shared_impl/proxy_lock.h" |
14 #include "ppapi/shared_impl/resource.h" | 14 #include "ppapi/shared_impl/resource.h" |
15 | 15 |
16 namespace ppapi { | 16 namespace ppapi { |
17 | 17 |
18 ResourceTracker::ResourceTracker(ThreadMode thread_mode) | 18 ResourceTracker::ResourceTracker(ThreadMode thread_mode) |
19 : last_resource_value_(0), | 19 : last_resource_value_(0), weak_ptr_factory_(this) { |
20 weak_ptr_factory_(this) { | |
21 if (thread_mode == SINGLE_THREADED) | 20 if (thread_mode == SINGLE_THREADED) |
22 thread_checker_.reset(new base::ThreadChecker); | 21 thread_checker_.reset(new base::ThreadChecker); |
23 } | 22 } |
24 | 23 |
25 ResourceTracker::~ResourceTracker() { | 24 ResourceTracker::~ResourceTracker() {} |
26 } | |
27 | 25 |
28 void ResourceTracker::CheckThreadingPreconditions() const { | 26 void ResourceTracker::CheckThreadingPreconditions() const { |
29 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); | 27 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); |
30 #ifndef NDEBUG | 28 #ifndef NDEBUG |
31 ProxyLock::AssertAcquired(); | 29 ProxyLock::AssertAcquired(); |
32 #endif | 30 #endif |
33 } | 31 } |
34 | 32 |
35 Resource* ResourceTracker::GetResource(PP_Resource res) const { | 33 Resource* ResourceTracker::GetResource(PP_Resource res) const { |
36 CheckThreadingPreconditions(); | 34 CheckThreadingPreconditions(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // only true of the PPB_MessageLoop resource for the main thread. | 193 // only true of the PPB_MessageLoop resource for the main thread. |
196 if (object->pp_instance()) { | 194 if (object->pp_instance()) { |
197 InstanceMap::iterator found = instance_map_.find(object->pp_instance()); | 195 InstanceMap::iterator found = instance_map_.find(object->pp_instance()); |
198 if (found == instance_map_.end()) { | 196 if (found == instance_map_.end()) { |
199 // If you hit this, it's likely somebody forgot to call DidCreateInstance, | 197 // If you hit this, it's likely somebody forgot to call DidCreateInstance, |
200 // the resource was created with an invalid PP_Instance, or the renderer | 198 // the resource was created with an invalid PP_Instance, or the renderer |
201 // side tried to create a resource for a plugin that crashed/exited. This | 199 // side tried to create a resource for a plugin that crashed/exited. This |
202 // could happen for OOP plugins where due to reentrancies in context of | 200 // could happen for OOP plugins where due to reentrancies in context of |
203 // outgoing sync calls the renderer can send events after a plugin has | 201 // outgoing sync calls the renderer can send events after a plugin has |
204 // exited. | 202 // exited. |
205 DLOG(INFO) << "Failed to find plugin instance in instance map"; | 203 VLOG(1) << "Failed to find plugin instance in instance map"; |
206 return 0; | 204 return 0; |
207 } | 205 } |
208 found->second->resources.insert(new_id); | 206 found->second->resources.insert(new_id); |
209 } | 207 } |
210 | 208 |
211 live_resources_[new_id] = ResourceAndRefCount(object, 0); | 209 live_resources_[new_id] = ResourceAndRefCount(object, 0); |
212 return new_id; | 210 return new_id; |
213 } | 211 } |
214 | 212 |
215 void ResourceTracker::RemoveResource(Resource* object) { | 213 void ResourceTracker::RemoveResource(Resource* object) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 return true; | 258 return true; |
261 #else | 259 #else |
262 // The invalid PP_Resource value could appear at both sides. | 260 // The invalid PP_Resource value could appear at both sides. |
263 if (res == 0) | 261 if (res == 0) |
264 return true; | 262 return true; |
265 | 263 |
266 // Skipping the type bits, the least significant bit of |res| should be the | 264 // Skipping the type bits, the least significant bit of |res| should be the |
267 // same as that of |last_resource_value_|. | 265 // same as that of |last_resource_value_|. |
268 return ((res >> kPPIdTypeBits) & 1) == (last_resource_value_ & 1); | 266 return ((res >> kPPIdTypeBits) & 1) == (last_resource_value_ & 1); |
269 #endif | 267 #endif |
270 | |
271 } | 268 } |
272 | 269 |
273 } // namespace ppapi | 270 } // namespace ppapi |
OLD | NEW |