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