| 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> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 "Line", IPC_MESSAGE_ID_LINE(msg.type())); | 119 "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
| 120 DCHECK(resource); // If this fails, host is probably pending. | 120 DCHECK(resource); // If this fails, host is probably pending. |
| 121 proxy::ResourceMessageReplyParams params(resource, 0); | 121 proxy::ResourceMessageReplyParams params(resource, 0); |
| 122 for (std::vector<SerializedHandle>::const_iterator it = handles.begin(); | 122 for (std::vector<SerializedHandle>::const_iterator it = handles.begin(); |
| 123 it != handles.end(); ++it) { | 123 it != handles.end(); ++it) { |
| 124 params.AppendHandle(*it); | 124 params.AppendHandle(*it); |
| 125 } | 125 } |
| 126 Send(new PpapiPluginMsg_ResourceReply(params, msg)); | 126 Send(new PpapiPluginMsg_ResourceReply(params, msg)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 scoped_ptr<ResourceHost> PpapiHost::CreateResourceHost( | 129 std::unique_ptr<ResourceHost> PpapiHost::CreateResourceHost( |
| 130 PP_Resource resource, | 130 PP_Resource resource, |
| 131 PP_Instance instance, | 131 PP_Instance instance, |
| 132 const IPC::Message& nested_msg) { | 132 const IPC::Message& nested_msg) { |
| 133 scoped_ptr<ResourceHost> resource_host; | 133 std::unique_ptr<ResourceHost> resource_host; |
| 134 DCHECK(!host_factory_filters_.empty()); // Caller forgot to add a factory. | 134 DCHECK(!host_factory_filters_.empty()); // Caller forgot to add a factory. |
| 135 for (size_t i = 0; i < host_factory_filters_.size(); i++) { | 135 for (size_t i = 0; i < host_factory_filters_.size(); i++) { |
| 136 resource_host = host_factory_filters_[i]->CreateResourceHost( | 136 resource_host = host_factory_filters_[i]->CreateResourceHost( |
| 137 this, resource, instance, nested_msg); | 137 this, resource, instance, nested_msg); |
| 138 if (resource_host.get()) | 138 if (resource_host.get()) |
| 139 break; | 139 break; |
| 140 } | 140 } |
| 141 return resource_host; | 141 return resource_host; |
| 142 } | 142 } |
| 143 | 143 |
| 144 int PpapiHost::AddPendingResourceHost(scoped_ptr<ResourceHost> resource_host) { | 144 int PpapiHost::AddPendingResourceHost( |
| 145 std::unique_ptr<ResourceHost> resource_host) { |
| 145 // The resource ID should not be assigned. | 146 // The resource ID should not be assigned. |
| 146 if (!resource_host.get() || resource_host->pp_resource() != 0) { | 147 if (!resource_host.get() || resource_host->pp_resource() != 0) { |
| 147 NOTREACHED(); | 148 NOTREACHED(); |
| 148 return 0; | 149 return 0; |
| 149 } | 150 } |
| 150 | 151 |
| 151 if (pending_resource_hosts_.size() + resources_.size() | 152 if (pending_resource_hosts_.size() + resources_.size() |
| 152 >= kMaxResourcesPerPlugin) { | 153 >= kMaxResourcesPerPlugin) { |
| 153 return 0; | 154 return 0; |
| 154 } | 155 } |
| 155 | 156 |
| 156 int pending_id = next_pending_resource_host_id_++; | 157 int pending_id = next_pending_resource_host_id_++; |
| 157 pending_resource_hosts_[pending_id] = std::move(resource_host); | 158 pending_resource_hosts_[pending_id] = std::move(resource_host); |
| 158 return pending_id; | 159 return pending_id; |
| 159 } | 160 } |
| 160 | 161 |
| 161 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { | 162 void PpapiHost::AddHostFactoryFilter(std::unique_ptr<HostFactory> filter) { |
| 162 host_factory_filters_.push_back(std::move(filter)); | 163 host_factory_filters_.push_back(std::move(filter)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void PpapiHost::AddInstanceMessageFilter( | 166 void PpapiHost::AddInstanceMessageFilter( |
| 166 scoped_ptr<InstanceMessageFilter> filter) { | 167 std::unique_ptr<InstanceMessageFilter> filter) { |
| 167 instance_message_filters_.push_back(std::move(filter)); | 168 instance_message_filters_.push_back(std::move(filter)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void PpapiHost::OnHostMsgResourceCall( | 171 void PpapiHost::OnHostMsgResourceCall( |
| 171 const proxy::ResourceMessageCallParams& params, | 172 const proxy::ResourceMessageCallParams& params, |
| 172 const IPC::Message& nested_msg) { | 173 const IPC::Message& nested_msg) { |
| 173 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCall", | 174 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCall", |
| 174 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), | 175 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), |
| 175 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); | 176 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); |
| 176 HostMessageContext context(params); | 177 HostMessageContext context(params); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCreated", | 229 TRACE_EVENT2("ppapi proxy", "PpapiHost::OnHostMsgResourceCreated", |
| 229 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), | 230 "Class", IPC_MESSAGE_ID_CLASS(nested_msg.type()), |
| 230 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); | 231 "Line", IPC_MESSAGE_ID_LINE(nested_msg.type())); |
| 231 | 232 |
| 232 if (pending_resource_hosts_.size() + resources_.size() | 233 if (pending_resource_hosts_.size() + resources_.size() |
| 233 >= kMaxResourcesPerPlugin) { | 234 >= kMaxResourcesPerPlugin) { |
| 234 return; | 235 return; |
| 235 } | 236 } |
| 236 | 237 |
| 237 // Run through all filters until one grabs this message. | 238 // Run through all filters until one grabs this message. |
| 238 scoped_ptr<ResourceHost> resource_host = | 239 std::unique_ptr<ResourceHost> resource_host = |
| 239 CreateResourceHost(params.pp_resource(), instance, nested_msg); | 240 CreateResourceHost(params.pp_resource(), instance, nested_msg); |
| 240 | 241 |
| 241 if (!resource_host.get()) { | 242 if (!resource_host.get()) { |
| 242 NOTREACHED(); | 243 NOTREACHED(); |
| 243 return; | 244 return; |
| 244 } | 245 } |
| 245 | 246 |
| 246 // Resource should have been assigned a nonzero PP_Resource. | 247 // Resource should have been assigned a nonzero PP_Resource. |
| 247 DCHECK(resource_host->pp_resource()); | 248 DCHECK(resource_host->pp_resource()); |
| 248 | 249 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 267 ResourceMap::iterator found = resources_.find(resource); | 268 ResourceMap::iterator found = resources_.find(resource); |
| 268 if (found == resources_.end()) { | 269 if (found == resources_.end()) { |
| 269 NOTREACHED(); | 270 NOTREACHED(); |
| 270 return; | 271 return; |
| 271 } | 272 } |
| 272 // Invoking the HostResource destructor might result in looking up the | 273 // 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 | 274 // 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 | 275 // 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 | 276 // HostResource until after we've made sure the map no longer contains |
| 276 // |resource|. | 277 // |resource|. |
| 277 scoped_ptr<ResourceHost> delete_at_end_of_scope(std::move(found->second)); | 278 std::unique_ptr<ResourceHost> delete_at_end_of_scope( |
| 279 std::move(found->second)); |
| 278 resources_.erase(found); | 280 resources_.erase(found); |
| 279 } | 281 } |
| 280 | 282 |
| 281 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { | 283 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { |
| 282 ResourceMap::const_iterator found = resources_.find(resource); | 284 ResourceMap::const_iterator found = resources_.find(resource); |
| 283 return found == resources_.end() ? NULL : found->second.get(); | 285 return found == resources_.end() ? NULL : found->second.get(); |
| 284 } | 286 } |
| 285 | 287 |
| 286 } // namespace host | 288 } // namespace host |
| 287 } // namespace ppapi | 289 } // namespace ppapi |
| OLD | NEW |