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

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

Issue 10912086: Add CHECKs to ensure that PPAPI resources are created on the right thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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
« no previous file with comments | « chrome/test/ppapi/ppapi_browsertest.cc ('k') | ppapi/shared_impl/resource_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_
6 #define PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ 6 #define PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "base/threading/thread_checker_impl.h"
14 #include "ppapi/c/pp_instance.h" 16 #include "ppapi/c/pp_instance.h"
15 #include "ppapi/c/pp_resource.h" 17 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/shared_impl/ppapi_shared_export.h" 18 #include "ppapi/shared_impl/ppapi_shared_export.h"
17 19
18 namespace ppapi { 20 namespace ppapi {
19 21
20 class Resource; 22 class Resource;
21 23
22 class PPAPI_SHARED_EXPORT ResourceTracker { 24 class PPAPI_SHARED_EXPORT ResourceTracker {
23 public: 25 public:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // resource will have 0 plugin refcount. This is called by the resource 58 // resource will have 0 plugin refcount. This is called by the resource
57 // constructor. 59 // constructor.
58 // 60 //
59 // Returns 0 if the resource could not be added. 61 // Returns 0 if the resource could not be added.
60 virtual PP_Resource AddResource(Resource* object); 62 virtual PP_Resource AddResource(Resource* object);
61 63
62 // The opposite of AddResource, this removes the tracking information for 64 // The opposite of AddResource, this removes the tracking information for
63 // the given resource. It's called from the resource destructor. 65 // the given resource. It's called from the resource destructor.
64 virtual void RemoveResource(Resource* object); 66 virtual void RemoveResource(Resource* object);
65 67
68 private:
66 // Calls LastPluginRefWasDeleted on the given resource object and cancels 69 // Calls LastPluginRefWasDeleted on the given resource object and cancels
67 // pending callbacks for the resource. 70 // pending callbacks for the resource.
68 void LastPluginRefWasDeleted(Resource* object); 71 void LastPluginRefWasDeleted(Resource* object);
69 72
70 private:
71 typedef std::set<PP_Resource> ResourceSet; 73 typedef std::set<PP_Resource> ResourceSet;
72 74
73 struct InstanceData { 75 struct InstanceData {
74 // Lists all resources associated with the given instance as non-owning 76 // Lists all resources associated with the given instance as non-owning
75 // pointers. This allows us to notify those resources that the instance is 77 // pointers. This allows us to notify those resources that the instance is
76 // going away (otherwise, they may crash if they outlive the instance). 78 // going away (otherwise, they may crash if they outlive the instance).
77 ResourceSet resources; 79 ResourceSet resources;
78 }; 80 };
79 typedef base::hash_map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; 81 typedef base::hash_map<PP_Instance, linked_ptr<InstanceData> > InstanceMap;
80 82
81 InstanceMap instance_map_; 83 InstanceMap instance_map_;
82 84
83 // For each PP_Resource, keep the object pointer and a plugin use count. 85 // For each PP_Resource, keep the object pointer and a plugin use count.
84 // This use count is different then Resource object's RefCount, and is 86 // This use count is different then Resource object's RefCount, and is
85 // manipulated using this AddRefResource/UnrefResource. When the plugin use 87 // manipulated using this AddRefResource/UnrefResource. When the plugin use
86 // count is positive, we keep an extra ref on the Resource on 88 // count is positive, we keep an extra ref on the Resource on
87 // behalf of the plugin. When it drops to 0, we free that ref, keeping 89 // behalf of the plugin. When it drops to 0, we free that ref, keeping
88 // the resource in the list. 90 // the resource in the list.
89 // 91 //
90 // A resource will be in this list as long as the object is alive. 92 // A resource will be in this list as long as the object is alive.
91 typedef std::pair<Resource*, int> ResourceAndRefCount; 93 typedef std::pair<Resource*, int> ResourceAndRefCount;
92 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap; 94 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap;
93 ResourceMap live_resources_; 95 ResourceMap live_resources_;
94 96
95 int32 last_resource_value_; 97 int32 last_resource_value_;
96 98
97 base::WeakPtrFactory<ResourceTracker> weak_ptr_factory_; 99 base::WeakPtrFactory<ResourceTracker> weak_ptr_factory_;
98 100
101 // TODO(raymes): We won't need to do thread checks once pepper calls are
102 // allowed off of the main thread.
103 // See http://code.google.com/p/chromium/issues/detail?id=92909.
104 #ifdef ENABLE_PEPPER_THREADING
105 base::ThreadCheckerDoNothing thread_checker_;
106 #else
107 // TODO(raymes): We've seen plugins (Flash) creating resources from random
108 // threads. Let's always crash for now in this case. Once we have a handle
109 // over how common this is, we can change ThreadCheckerImpl->ThreadChecker
110 // so that we only crash in debug mode. See
111 // https://code.google.com/p/chromium/issues/detail?id=146415.
112 base::ThreadCheckerImpl thread_checker_;
113 #endif
114
99 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); 115 DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
100 }; 116 };
101 117
102 } // namespace ppapi 118 } // namespace ppapi
103 119
104 #endif // PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ 120 #endif // PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_
OLDNEW
« no previous file with comments | « chrome/test/ppapi/ppapi_browsertest.cc ('k') | ppapi/shared_impl/resource_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698