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 #ifndef WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "ppapi/shared_impl/callback_tracker.h" | 9 #include "ppapi/shared_impl/callback_tracker.h" |
10 #include "ppapi/shared_impl/ppapi_globals.h" | 10 #include "ppapi/shared_impl/ppapi_globals.h" |
11 #include "ppapi/shared_impl/resource_tracker.h" | 11 #include "ppapi/shared_impl/resource_tracker.h" |
12 #include "ppapi/shared_impl/var_tracker.h" | 12 #include "ppapi/shared_impl/var_tracker.h" |
13 #include "webkit/plugins/ppapi/host_var_tracker.h" | 13 #include "webkit/plugins/ppapi/host_var_tracker.h" |
14 #include "webkit/plugins/webkit_plugins_export.h" | 14 #include "webkit/plugins/webkit_plugins_export.h" |
15 | 15 |
16 namespace webkit { | 16 namespace webkit { |
17 namespace ppapi { | 17 namespace ppapi { |
18 | 18 |
19 class PluginInstance; | 19 class PluginInstance; |
20 class PluginModule; | 20 class PluginModule; |
21 | 21 |
22 class HostGlobals : public ::ppapi::PpapiGlobals { | 22 class HostGlobals : public ::ppapi::PpapiGlobals { |
23 public: | 23 public: |
24 HostGlobals(); | 24 HostGlobals(); |
| 25 HostGlobals(::ppapi::PpapiGlobals::ForTest); |
25 virtual ~HostGlobals(); | 26 virtual ~HostGlobals(); |
26 | 27 |
27 // Getter for the global singleton. Generally, you should use | 28 // Getter for the global singleton. Generally, you should use |
28 // PpapiGlobals::Get() when possible. Use this only when you need some | 29 // PpapiGlobals::Get() when possible. Use this only when you need some |
29 // host-specific functionality. | 30 // host-specific functionality. |
30 inline static HostGlobals* Get() { return host_globals_; } | 31 inline static HostGlobals* Get() { |
| 32 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); |
| 33 return static_cast<HostGlobals*>(PpapiGlobals::Get()); |
| 34 } |
31 | 35 |
32 // PpapiGlobals implementation. | 36 // PpapiGlobals implementation. |
33 virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; | 37 virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; |
34 virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; | 38 virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; |
35 virtual ::ppapi::CallbackTracker* GetCallbackTrackerForInstance( | 39 virtual ::ppapi::CallbackTracker* GetCallbackTrackerForInstance( |
36 PP_Instance instance) OVERRIDE; | 40 PP_Instance instance) OVERRIDE; |
37 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( | 41 virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( |
38 PP_Instance inst, | 42 PP_Instance inst, |
39 ::ppapi::ApiID id) OVERRIDE; | 43 ::ppapi::ApiID id) OVERRIDE; |
40 virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; | 44 virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; |
| 45 virtual base::Lock* GetProxyLock() OVERRIDE; |
41 | 46 |
42 HostVarTracker* host_var_tracker() { | 47 HostVarTracker* host_var_tracker() { |
43 return &host_var_tracker_; | 48 return &host_var_tracker_; |
44 } | 49 } |
45 | 50 |
46 // PP_Modules ---------------------------------------------------------------- | 51 // PP_Modules ---------------------------------------------------------------- |
47 | 52 |
48 // Adds a new plugin module to the list of tracked module, and returns a new | 53 // Adds a new plugin module to the list of tracked module, and returns a new |
49 // module handle to identify it. | 54 // module handle to identify it. |
50 PP_Module AddModule(PluginModule* module); | 55 PP_Module AddModule(PluginModule* module); |
(...skipping 17 matching lines...) Expand all Loading... |
68 void InstanceDeleted(PP_Instance instance); | 73 void InstanceDeleted(PP_Instance instance); |
69 | 74 |
70 void InstanceCrashed(PP_Instance instance); | 75 void InstanceCrashed(PP_Instance instance); |
71 | 76 |
72 // Returns a pointer to the plugin instance object associated with the given | 77 // Returns a pointer to the plugin instance object associated with the given |
73 // instance handle. The return value will be NULL if the handle is invalid or | 78 // instance handle. The return value will be NULL if the handle is invalid or |
74 // if the instance has crashed. | 79 // if the instance has crashed. |
75 WEBKIT_PLUGINS_EXPORT PluginInstance* GetInstance(PP_Instance instance); | 80 WEBKIT_PLUGINS_EXPORT PluginInstance* GetInstance(PP_Instance instance); |
76 | 81 |
77 private: | 82 private: |
| 83 // PpapiGlobals overrides. |
| 84 virtual bool IsHostGlobals() const OVERRIDE; |
| 85 |
78 // Per-instance data we track. | 86 // Per-instance data we track. |
79 struct InstanceData; | 87 struct InstanceData; |
80 | 88 |
81 WEBKIT_PLUGINS_EXPORT static HostGlobals* host_globals_; | 89 WEBKIT_PLUGINS_EXPORT static HostGlobals* host_globals_; |
82 | 90 |
83 ::ppapi::ResourceTracker resource_tracker_; | 91 ::ppapi::ResourceTracker resource_tracker_; |
84 HostVarTracker host_var_tracker_; | 92 HostVarTracker host_var_tracker_; |
85 | 93 |
86 // Tracks all live instances and their associated data. | 94 // Tracks all live instances and their associated data. |
87 typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; | 95 typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap; |
88 InstanceMap instance_map_; | 96 InstanceMap instance_map_; |
89 | 97 |
90 // Tracks all live modules. The pointers are non-owning, the PluginModule | 98 // Tracks all live modules. The pointers are non-owning, the PluginModule |
91 // destructor will notify us when the module is deleted. | 99 // destructor will notify us when the module is deleted. |
92 typedef std::map<PP_Module, PluginModule*> ModuleMap; | 100 typedef std::map<PP_Module, PluginModule*> ModuleMap; |
93 ModuleMap module_map_; | 101 ModuleMap module_map_; |
94 | 102 |
95 DISALLOW_COPY_AND_ASSIGN(HostGlobals); | 103 DISALLOW_COPY_AND_ASSIGN(HostGlobals); |
96 }; | 104 }; |
97 | 105 |
98 } // namespace ppapi | 106 } // namespace ppapi |
99 } // namespace webkit | 107 } // namespace webkit |
100 | 108 |
101 #endif // WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ | 109 #endif // WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_ |
OLD | NEW |