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

Side by Side Diff: ppapi/host/ppapi_host.h

Issue 454433002: PPAPI: Introduce concept of ResourceHosts "pinning" each other (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | « base/memory/linked_ptr.h ('k') | ppapi/host/ppapi_host.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_HOST_PPAPI_HOST_H_ 5 #ifndef PPAPI_HOST_PPAPI_HOST_H_
6 #define PPAPI_HOST_PPAPI_HOST_H_ 6 #define PPAPI_HOST_PPAPI_HOST_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // ownership of the pointer. 84 // ownership of the pointer.
85 void AddHostFactoryFilter(scoped_ptr<HostFactory> filter); 85 void AddHostFactoryFilter(scoped_ptr<HostFactory> filter);
86 86
87 // Adds the given message filter to the host. The PpapiHost will take 87 // Adds the given message filter to the host. The PpapiHost will take
88 // ownership of the pointer. 88 // ownership of the pointer.
89 void AddInstanceMessageFilter(scoped_ptr<InstanceMessageFilter> filter); 89 void AddInstanceMessageFilter(scoped_ptr<InstanceMessageFilter> filter);
90 90
91 // Returns null if the resource doesn't exist. 91 // Returns null if the resource doesn't exist.
92 host::ResourceHost* GetResourceHost(PP_Resource resource) const; 92 host::ResourceHost* GetResourceHost(PP_Resource resource) const;
93 93
94 // Pin |owned_host| in memory so long as |owner_host| still needs it. Even
95 // if the plugin is done using |owned_host|, it will be kept alive until
96 // |owner_host| calls UnpinHost.
97 void PinHost(ResourceHost* owner_host, ResourceHost* owned_host);
98 // Called to indicate that the |owner_host| no longer requires |owned_host|.
99 // This may result in |owned_host| being deleted, if:
100 // (a) The plugin has finished with it, and
101 // (b) No other ResourceHosts have it pinned.
102 void UnpinHost(ResourceHost* owner_host, ResourceHost* owned_host);
103
94 private: 104 private:
95 friend class InstanceMessageFilter; 105 friend class InstanceMessageFilter;
96 106
97 void HandleResourceCall( 107 void HandleResourceCall(
98 const proxy::ResourceMessageCallParams& params, 108 const proxy::ResourceMessageCallParams& params,
99 const IPC::Message& nested_msg, 109 const IPC::Message& nested_msg,
100 HostMessageContext* context); 110 HostMessageContext* context);
101 111
102 // Message handlers. 112 // Message handlers.
103 void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params, 113 void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params,
104 const IPC::Message& nested_msg); 114 const IPC::Message& nested_msg);
105 void OnHostMsgInProcessResourceCall( 115 void OnHostMsgInProcessResourceCall(
106 int routing_id, 116 int routing_id,
107 const proxy::ResourceMessageCallParams& params, 117 const proxy::ResourceMessageCallParams& params,
108 const IPC::Message& nested_msg); 118 const IPC::Message& nested_msg);
109 void OnHostMsgResourceSyncCall( 119 void OnHostMsgResourceSyncCall(
110 const proxy::ResourceMessageCallParams& params, 120 const proxy::ResourceMessageCallParams& params,
111 const IPC::Message& nested_msg, 121 const IPC::Message& nested_msg,
112 IPC::Message* reply_msg); 122 IPC::Message* reply_msg);
113 void OnHostMsgResourceCreated(const proxy::ResourceMessageCallParams& param, 123 void OnHostMsgResourceCreated(const proxy::ResourceMessageCallParams& param,
114 PP_Instance instance, 124 PP_Instance instance,
115 const IPC::Message& nested_msg); 125 const IPC::Message& nested_msg);
116 void OnHostMsgAttachToPendingHost(PP_Resource resource, int pending_host_id); 126 void OnHostMsgAttachToPendingHost(PP_Resource resource, int pending_host_id);
117 void OnHostMsgResourceDestroyed(PP_Resource resource); 127 void OnHostMsgResourceDestroyed(PP_Resource resource);
118 128
129 // Get a linked_ptr to the given ResourceHost. It's important to get at the
130 // right one; if we just do:
131 // linked_ptr<ResourceHost> ptr(raw_host_ptr);
132 // ...we get a linked_ptr with its own separate reference tracking, and we'll
133 // eventually double-delete |*raw_host_ptr|.
134 linked_ptr<ResourceHost> RawToLinkedPtr(ResourceHost* host);
135
119 // Non-owning pointer. 136 // Non-owning pointer.
120 IPC::Sender* sender_; 137 IPC::Sender* sender_;
121 138
122 PpapiPermissions permissions_; 139 PpapiPermissions permissions_;
123 140
124 // Filters for resource creation messages. Note that since we don't support 141 // Filters for resource creation messages. Note that since we don't support
125 // deleting these dynamically we don't need to worry about modifications 142 // deleting these dynamically we don't need to worry about modifications
126 // during iteration. If we add that capability, this should be replaced with 143 // during iteration. If we add that capability, this should be replaced with
127 // an ObserverList. 144 // an ObserverList.
128 ScopedVector<HostFactory> host_factory_filters_; 145 ScopedVector<HostFactory> host_factory_filters_;
129 146
130 // Filters for instance messages. Note that since we don't support deleting 147 // Filters for instance messages. Note that since we don't support deleting
131 // these dynamically we don't need to worry about modifications during 148 // these dynamically we don't need to worry about modifications during
132 // iteration. If we add that capability, this should be replaced with an 149 // iteration. If we add that capability, this should be replaced with an
133 // ObserverList. 150 // ObserverList.
134 ScopedVector<InstanceMessageFilter> instance_message_filters_; 151 ScopedVector<InstanceMessageFilter> instance_message_filters_;
135 152
136 typedef std::map<PP_Resource, linked_ptr<ResourceHost> > ResourceMap; 153 typedef std::map<PP_Resource, linked_ptr<ResourceHost> > ResourceMap;
137 ResourceMap resources_; 154 ResourceMap resources_;
138 155
139 // Resources that have been created in the host and have not yet had the 156 // Resources that have been created in the host and have not yet had the
140 // corresponding PluginResource associated with them. 157 // corresponding PluginResource associated with them.
141 // See PpapiHostMsg_AttachToPendingHost. 158 // See PpapiHostMsg_AttachToPendingHost.
142 typedef std::map<int, linked_ptr<ResourceHost> > PendingHostResourceMap; 159 typedef std::map<int, linked_ptr<ResourceHost> > PendingHostResourceMap;
143 PendingHostResourceMap pending_resource_hosts_; 160 PendingHostResourceMap pending_resource_hosts_;
144 int next_pending_resource_host_id_; 161 int next_pending_resource_host_id_;
145 162
163 // Some hosts may need to Pin another host in memory for some amount of time.
164 // The main example at the time of writing is PepperGraphics2DHost, which may
165 // have a queue of ImageDataHosts that it requires for doing paints. This
166 // needs to work even if the plugin deletes the ImageDataResource. So
167 // owner_to_owned_map_ keeps a linked_ptr to any "pinned" hosts to make sure
168 // that they live long enough, even when the plugin is done with the resource
169 // and the host gets removed from resource_hosts_ or pending_resource_hosts_.
170 typedef std::map<linked_ptr<ResourceHost>, int > PinCountMap;
171 typedef std::map<ResourceHost*, PinCountMap> OwnerToOwnedHostMap;
172 OwnerToOwnedHostMap owner_to_owned_map_;
173
146 DISALLOW_COPY_AND_ASSIGN(PpapiHost); 174 DISALLOW_COPY_AND_ASSIGN(PpapiHost);
147 }; 175 };
148 176
149 } // namespace host 177 } // namespace host
150 } // namespace ppapi 178 } // namespace ppapi
151 179
152 #endif // PPAPI_HOST_PPAPIE_HOST_H_ 180 #endif // PPAPI_HOST_PPAPIE_HOST_H_
OLDNEW
« no previous file with comments | « base/memory/linked_ptr.h ('k') | ppapi/host/ppapi_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698