OLD | NEW |
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 #include "ppapi/host/ppapi_host.h" | 5 #include "ppapi/host/ppapi_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <utility> |
| 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/host/host_factory.h" | 13 #include "ppapi/host/host_factory.h" |
12 #include "ppapi/host/host_message_context.h" | 14 #include "ppapi/host/host_message_context.h" |
13 #include "ppapi/host/instance_message_filter.h" | 15 #include "ppapi/host/instance_message_filter.h" |
14 #include "ppapi/host/resource_host.h" | 16 #include "ppapi/host/resource_host.h" |
15 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/proxy/resource_message_params.h" | 18 #include "ppapi/proxy/resource_message_params.h" |
17 #include "ppapi/proxy/serialized_handle.h" | 19 #include "ppapi/proxy/serialized_handle.h" |
18 #include "ppapi/shared_impl/host_resource.h" | 20 #include "ppapi/shared_impl/host_resource.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 NOTREACHED(); | 147 NOTREACHED(); |
146 return 0; | 148 return 0; |
147 } | 149 } |
148 | 150 |
149 if (pending_resource_hosts_.size() + resources_.size() | 151 if (pending_resource_hosts_.size() + resources_.size() |
150 >= kMaxResourcesPerPlugin) { | 152 >= kMaxResourcesPerPlugin) { |
151 return 0; | 153 return 0; |
152 } | 154 } |
153 | 155 |
154 int pending_id = next_pending_resource_host_id_++; | 156 int pending_id = next_pending_resource_host_id_++; |
155 pending_resource_hosts_[pending_id] = | 157 pending_resource_hosts_[pending_id] = std::move(resource_host); |
156 linked_ptr<ResourceHost>(resource_host.release()); | |
157 return pending_id; | 158 return pending_id; |
158 } | 159 } |
159 | 160 |
160 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { | 161 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { |
161 host_factory_filters_.push_back(filter.release()); | 162 host_factory_filters_.push_back(std::move(filter)); |
162 } | 163 } |
163 | 164 |
164 void PpapiHost::AddInstanceMessageFilter( | 165 void PpapiHost::AddInstanceMessageFilter( |
165 scoped_ptr<InstanceMessageFilter> filter) { | 166 scoped_ptr<InstanceMessageFilter> filter) { |
166 instance_message_filters_.push_back(filter.release()); | 167 instance_message_filters_.push_back(std::move(filter)); |
167 } | 168 } |
168 | 169 |
169 void PpapiHost::OnHostMsgResourceCall( | 170 void PpapiHost::OnHostMsgResourceCall( |
170 const proxy::ResourceMessageCallParams& params, | 171 const proxy::ResourceMessageCallParams& params, |
171 const IPC::Message& nested_msg) { | 172 const IPC::Message& nested_msg) { |
172 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCall", | 173 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCall", |
173 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), | 174 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), |
174 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); | 175 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); |
175 HostMessageContext context(params); | 176 HostMessageContext context(params); |
176 HandleResourceCall(params, nested_msg, &context); | 177 HandleResourceCall(params, nested_msg, &context); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 CreateResourceHost(params.pp_resource(), instance, nested_msg); | 239 CreateResourceHost(params.pp_resource(), instance, nested_msg); |
239 | 240 |
240 if (!resource_host.get()) { | 241 if (!resource_host.get()) { |
241 NOTREACHED(); | 242 NOTREACHED(); |
242 return; | 243 return; |
243 } | 244 } |
244 | 245 |
245 // Resource should have been assigned a nonzero PP_Resource. | 246 // Resource should have been assigned a nonzero PP_Resource. |
246 DCHECK(resource_host->pp_resource()); | 247 DCHECK(resource_host->pp_resource()); |
247 | 248 |
248 resources_[params.pp_resource()] = | 249 resources_[params.pp_resource()] = std::move(resource_host); |
249 linked_ptr<ResourceHost>(resource_host.release()); | |
250 } | 250 } |
251 | 251 |
252 void PpapiHost::OnHostMsgAttachToPendingHost(PP_Resource pp_resource, | 252 void PpapiHost::OnHostMsgAttachToPendingHost(PP_Resource pp_resource, |
253 int pending_host_id) { | 253 int pending_host_id) { |
254 PendingHostResourceMap::iterator found = | 254 PendingHostResourceMap::iterator found = |
255 pending_resource_hosts_.find(pending_host_id); | 255 pending_resource_hosts_.find(pending_host_id); |
256 if (found == pending_resource_hosts_.end()) { | 256 if (found == pending_resource_hosts_.end()) { |
257 // Plugin sent a bad ID. | 257 // Plugin sent a bad ID. |
258 NOTREACHED(); | 258 NOTREACHED(); |
259 return; | 259 return; |
260 } | 260 } |
261 found->second->SetPPResourceForPendingHost(pp_resource); | 261 found->second->SetPPResourceForPendingHost(pp_resource); |
262 resources_[pp_resource] = found->second; | 262 resources_[pp_resource] = std::move(found->second); |
263 pending_resource_hosts_.erase(found); | 263 pending_resource_hosts_.erase(found); |
264 } | 264 } |
265 | 265 |
266 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { | 266 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { |
267 ResourceMap::iterator found = resources_.find(resource); | 267 ResourceMap::iterator found = resources_.find(resource); |
268 if (found == resources_.end()) { | 268 if (found == resources_.end()) { |
269 NOTREACHED(); | 269 NOTREACHED(); |
270 return; | 270 return; |
271 } | 271 } |
272 // Invoking the HostResource destructor might result in looking up the | 272 // Invoking the HostResource destructor might result in looking up the |
273 // PP_Resource in resources_. std::map is not well specified as to whether the | 273 // PP_Resource in resources_. std::map is not well specified as to whether the |
274 // element will be there or not. Therefore, we delay destruction of the | 274 // element will be there or not. Therefore, we delay destruction of the |
275 // HostResource until after we've made sure the map no longer contains | 275 // HostResource until after we've made sure the map no longer contains |
276 // |resource|. | 276 // |resource|. |
277 linked_ptr<ResourceHost> delete_at_end_of_scope(found->second); | 277 scoped_ptr<ResourceHost> delete_at_end_of_scope(std::move(found->second)); |
278 resources_.erase(found); | 278 resources_.erase(found); |
279 } | 279 } |
280 | 280 |
281 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { | 281 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { |
282 ResourceMap::const_iterator found = resources_.find(resource); | 282 ResourceMap::const_iterator found = resources_.find(resource); |
283 return found == resources_.end() ? NULL : found->second.get(); | 283 return found == resources_.end() ? NULL : found->second.get(); |
284 } | 284 } |
285 | 285 |
286 } // namespace host | 286 } // namespace host |
287 } // namespace ppapi | 287 } // namespace ppapi |
OLD | NEW |