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

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

Issue 12378050: PPAPI: Remove threading options; it's always on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PDFResource unit test Created 7 years, 8 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 | « ppapi/shared_impl/test_globals.cc ('k') | ppapi/shared_impl/var_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_VAR_TRACKER_H_ 5 #ifndef PPAPI_SHARED_IMPL_VAR_TRACKER_H_
6 #define PPAPI_SHARED_IMPL_VAR_TRACKER_H_ 6 #define PPAPI_SHARED_IMPL_VAR_TRACKER_H_
7 7
8 #include <vector> 8 #include <vector>
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/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
13 #include "base/shared_memory.h" 14 #include "base/shared_memory.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/thread_checker.h"
15 #include "ppapi/c/pp_instance.h" 16 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/c/pp_module.h" 17 #include "ppapi/c/pp_module.h"
17 #include "ppapi/c/pp_resource.h" 18 #include "ppapi/c/pp_resource.h"
18 #include "ppapi/c/pp_var.h" 19 #include "ppapi/c/pp_var.h"
19 #include "ppapi/shared_impl/host_resource.h" 20 #include "ppapi/shared_impl/host_resource.h"
20 #include "ppapi/shared_impl/ppapi_shared_export.h" 21 #include "ppapi/shared_impl/ppapi_shared_export.h"
21 22
22 namespace ppapi { 23 namespace ppapi {
23 24
24 class ArrayBufferVar; 25 class ArrayBufferVar;
25 class Var; 26 class Var;
26 27
27 // Tracks non-POD (refcounted) var objects held by a plugin. 28 // Tracks non-POD (refcounted) var objects held by a plugin.
28 // 29 //
29 // The tricky part is the concept of a "tracked object". These are only 30 // The tricky part is the concept of a "tracked object". These are only
30 // necessary in the plugin side of the proxy when running out of process. A 31 // necessary in the plugin side of the proxy when running out of process. A
31 // tracked object is one that the plugin is aware of, but doesn't hold a 32 // tracked object is one that the plugin is aware of, but doesn't hold a
32 // reference to. This will happen when the plugin is passed an object as an 33 // reference to. This will happen when the plugin is passed an object as an
33 // argument from the host (renderer) as an input argument to a sync function, 34 // argument from the host (renderer) as an input argument to a sync function,
34 // but where ownership is not passed. 35 // but where ownership is not passed.
35 // 36 //
36 // This class maintains the "track_with_no_reference_count" but doesn't do 37 // This class maintains the "track_with_no_reference_count" but doesn't do
37 // anything with it other than call virtual functions. The interesting parts 38 // anything with it other than call virtual functions. The interesting parts
38 // are added by the PluginObjectVar derived from this class. 39 // are added by the PluginObjectVar derived from this class.
39 class PPAPI_SHARED_EXPORT VarTracker 40 class PPAPI_SHARED_EXPORT VarTracker {
40 #ifdef ENABLE_PEPPER_THREADING
41 : NON_EXPORTED_BASE(public base::NonThreadSafeDoNothing) {
42 #else
43 // TODO(dmichael): Remove the thread checking when calls are allowed off the
44 // main thread (crbug.com/92909).
45 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
46 #endif
47 public: 41 public:
48 VarTracker(); 42 // A SINGLE_THREADED VarTracker will use a thread-checker to make sure it's
43 // always invoked on the same thread on which it was constructed. A
44 // THREAD_SAFE VarTracker will check that the ProxyLock is held. See
45 // CheckThreadingPreconditions() for more details.
46 enum ThreadMode { SINGLE_THREADED, THREAD_SAFE };
47 explicit VarTracker(ThreadMode thread_mode);
49 virtual ~VarTracker(); 48 virtual ~VarTracker();
50 49
51 // Called by the Var object to add a new var to the tracker. 50 // Called by the Var object to add a new var to the tracker.
52 int32 AddVar(Var* var); 51 int32 AddVar(Var* var);
53 52
54 // Looks up a given var and returns a reference to the Var if it exists. 53 // Looks up a given var and returns a reference to the Var if it exists.
55 // Returns NULL if the var type is not an object we track (POD) or is 54 // Returns NULL if the var type is not an object we track (POD) or is
56 // invalid. 55 // invalid.
57 Var* GetVar(int32 var_id) const; 56 Var* GetVar(int32 var_id) const;
58 Var* GetVar(const PP_Var& var) const; 57 Var* GetVar(const PP_Var& var) const;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 int track_with_no_reference_count; 140 int track_with_no_reference_count;
142 }; 141 };
143 typedef base::hash_map<int32, VarInfo> VarMap; 142 typedef base::hash_map<int32, VarInfo> VarMap;
144 143
145 // Specifies what should happen with the refcount when calling AddVarInternal. 144 // Specifies what should happen with the refcount when calling AddVarInternal.
146 enum AddVarRefMode { 145 enum AddVarRefMode {
147 ADD_VAR_TAKE_ONE_REFERENCE, 146 ADD_VAR_TAKE_ONE_REFERENCE,
148 ADD_VAR_CREATE_WITH_NO_REFERENCE 147 ADD_VAR_CREATE_WITH_NO_REFERENCE
149 }; 148 };
150 149
150 // On the host-side, make sure we are called on the right thread. On the
151 // plugin side, make sure we have the proxy lock.
152 void CheckThreadingPreconditions() const;
153
151 // Implementation of AddVar that allows the caller to specify whether the 154 // Implementation of AddVar that allows the caller to specify whether the
152 // initial refcount of the added object will be 0 or 1. 155 // initial refcount of the added object will be 0 or 1.
153 // 156 //
154 // Overridden in the plugin proxy to do additional object tracking. 157 // Overridden in the plugin proxy to do additional object tracking.
155 virtual int32 AddVarInternal(Var* var, AddVarRefMode mode); 158 virtual int32 AddVarInternal(Var* var, AddVarRefMode mode);
156 159
157 // Convenience functions for doing lookups into the live_vars_ map. 160 // Convenience functions for doing lookups into the live_vars_ map.
158 VarMap::iterator GetLiveVar(int32 id); 161 VarMap::iterator GetLiveVar(int32 id);
159 VarMap::iterator GetLiveVar(const PP_Var& var); 162 VarMap::iterator GetLiveVar(const PP_Var& var);
160 VarMap::const_iterator GetLiveVar(const PP_Var& var) const; 163 VarMap::const_iterator GetLiveVar(const PP_Var& var) const;
(...skipping 30 matching lines...) Expand all
191 194
192 private: 195 private:
193 // Create and return a new ArrayBufferVar size_in_bytes bytes long. This is 196 // Create and return a new ArrayBufferVar size_in_bytes bytes long. This is
194 // implemented by the Host and Plugin tracker separately, so that it can be 197 // implemented by the Host and Plugin tracker separately, so that it can be
195 // a real WebKit ArrayBuffer on the host side. 198 // a real WebKit ArrayBuffer on the host side.
196 virtual ArrayBufferVar* CreateArrayBuffer(uint32 size_in_bytes) = 0; 199 virtual ArrayBufferVar* CreateArrayBuffer(uint32 size_in_bytes) = 0;
197 virtual ArrayBufferVar* CreateShmArrayBuffer( 200 virtual ArrayBufferVar* CreateShmArrayBuffer(
198 uint32 size_in_bytes, 201 uint32 size_in_bytes,
199 base::SharedMemoryHandle handle) = 0; 202 base::SharedMemoryHandle handle) = 0;
200 203
204 // On the host side, we want to check that we are only called on the main
205 // thread. This is to protect us from accidentally using the tracker from
206 // other threads (especially the IO thread). On the plugin side, the tracker
207 // is protected by the proxy lock and is thread-safe, so this will be NULL.
208 scoped_ptr<base::ThreadChecker> thread_checker_;
209
201 DISALLOW_COPY_AND_ASSIGN(VarTracker); 210 DISALLOW_COPY_AND_ASSIGN(VarTracker);
202 }; 211 };
203 212
204 } // namespace ppapi 213 } // namespace ppapi
205 214
206 #endif // PPAPI_SHARED_IMPL_VAR_TRACKER_H_ 215 #endif // PPAPI_SHARED_IMPL_VAR_TRACKER_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/test_globals.cc ('k') | ppapi/shared_impl/var_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698