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

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

Issue 11414147: Add ability to create pending resource hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | « ppapi/host/ppapi_host.h ('k') | ppapi/host/resource_host.h » ('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 #include "ppapi/host/ppapi_host.h" 5 #include "ppapi/host/ppapi_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/host/host_factory.h" 9 #include "ppapi/host/host_factory.h"
10 #include "ppapi/host/host_message_context.h" 10 #include "ppapi/host/host_message_context.h"
(...skipping 10 matching lines...) Expand all
21 21
22 // Put a cap on the maximum number of resources so we don't explode if the 22 // Put a cap on the maximum number of resources so we don't explode if the
23 // renderer starts spamming us. 23 // renderer starts spamming us.
24 const size_t kMaxResourcesPerPlugin = 1 << 14; 24 const size_t kMaxResourcesPerPlugin = 1 << 14;
25 25
26 } // namespace 26 } // namespace
27 27
28 PpapiHost::PpapiHost(IPC::Sender* sender, 28 PpapiHost::PpapiHost(IPC::Sender* sender,
29 const PpapiPermissions& perms) 29 const PpapiPermissions& perms)
30 : sender_(sender), 30 : sender_(sender),
31 permissions_(perms) { 31 permissions_(perms),
32 next_pending_resource_host_id_(1) {
32 } 33 }
33 34
34 PpapiHost::~PpapiHost() { 35 PpapiHost::~PpapiHost() {
35 // Delete these explicitly before destruction since then the host is still 36 // Delete these explicitly before destruction since then the host is still
36 // technically alive in case one of the filters accesses us from the 37 // technically alive in case one of the filters accesses us from the
37 // destructor. 38 // destructor.
38 instance_message_filters_.clear(); 39 instance_message_filters_.clear();
39 } 40 }
40 41
41 bool PpapiHost::Send(IPC::Message* msg) { 42 bool PpapiHost::Send(IPC::Message* msg) {
42 return sender_->Send(msg); 43 return sender_->Send(msg);
43 } 44 }
44 45
45 bool PpapiHost::OnMessageReceived(const IPC::Message& msg) { 46 bool PpapiHost::OnMessageReceived(const IPC::Message& msg) {
46 bool handled = true; 47 bool handled = true;
47 IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg) 48 IPC_BEGIN_MESSAGE_MAP(PpapiHost, msg)
48 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall, 49 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCall,
49 OnHostMsgResourceCall) 50 OnHostMsgResourceCall)
50 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_ResourceSyncCall, 51 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_ResourceSyncCall,
51 OnHostMsgResourceSyncCall) 52 OnHostMsgResourceSyncCall)
52 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated, 53 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreated,
53 OnHostMsgResourceCreated) 54 OnHostMsgResourceCreated)
55 IPC_MESSAGE_HANDLER(PpapiHostMsg_AttachToPendingHost,
56 OnHostMsgAttachToPendingHost)
54 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed, 57 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceDestroyed,
55 OnHostMsgResourceDestroyed) 58 OnHostMsgResourceDestroyed)
56 IPC_MESSAGE_UNHANDLED(handled = false) 59 IPC_MESSAGE_UNHANDLED(handled = false)
57 IPC_END_MESSAGE_MAP() 60 IPC_END_MESSAGE_MAP()
58 61
59 if (!handled) { 62 if (!handled) {
60 for (size_t i = 0; i < instance_message_filters_.size(); i++) { 63 for (size_t i = 0; i < instance_message_filters_.size(); i++) {
61 if (instance_message_filters_[i]->OnInstanceMessageReceived(msg)) { 64 if (instance_message_filters_[i]->OnInstanceMessageReceived(msg)) {
62 handled = true; 65 handled = true;
63 break; 66 break;
(...skipping 10 matching lines...) Expand all
74 PpapiHostMsg_ResourceSyncCall::WriteReplyParams(context.sync_reply_msg, 77 PpapiHostMsg_ResourceSyncCall::WriteReplyParams(context.sync_reply_msg,
75 context.params, msg); 78 context.params, msg);
76 Send(context.sync_reply_msg); 79 Send(context.sync_reply_msg);
77 } else { 80 } else {
78 Send(new PpapiPluginMsg_ResourceReply(context.params, msg)); 81 Send(new PpapiPluginMsg_ResourceReply(context.params, msg));
79 } 82 }
80 } 83 }
81 84
82 void PpapiHost::SendUnsolicitedReply(PP_Resource resource, 85 void PpapiHost::SendUnsolicitedReply(PP_Resource resource,
83 const IPC::Message& msg) { 86 const IPC::Message& msg) {
87 DCHECK(resource); // If this fails, host is probably pending.
84 proxy::ResourceMessageReplyParams params(resource, 0); 88 proxy::ResourceMessageReplyParams params(resource, 0);
85 Send(new PpapiPluginMsg_ResourceReply(params, msg)); 89 Send(new PpapiPluginMsg_ResourceReply(params, msg));
86 } 90 }
87 91
92 int PpapiHost::AddPendingResourceHost(scoped_ptr<ResourceHost> resource_host) {
93 // The resource ID should not be assigned.
94 DCHECK(resource_host->pp_resource() == 0);
95
96 int pending_id = next_pending_resource_host_id_++;
97 pending_resource_hosts_[pending_id] =
98 linked_ptr<ResourceHost>(resource_host.release());
99 return pending_id;
100 }
101
88 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) { 102 void PpapiHost::AddHostFactoryFilter(scoped_ptr<HostFactory> filter) {
89 host_factory_filters_.push_back(filter.release()); 103 host_factory_filters_.push_back(filter.release());
90 } 104 }
91 105
92 void PpapiHost::AddInstanceMessageFilter( 106 void PpapiHost::AddInstanceMessageFilter(
93 scoped_ptr<InstanceMessageFilter> filter) { 107 scoped_ptr<InstanceMessageFilter> filter) {
94 instance_message_filters_.push_back(filter.release()); 108 instance_message_filters_.push_back(filter.release());
95 } 109 }
96 110
97 void PpapiHost::OnHostMsgResourceCall( 111 void PpapiHost::OnHostMsgResourceCall(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 resource_host = host_factory_filters_[i]->CreateResourceHost( 158 resource_host = host_factory_filters_[i]->CreateResourceHost(
145 this, params, instance, nested_msg).Pass(); 159 this, params, instance, nested_msg).Pass();
146 if (resource_host.get()) 160 if (resource_host.get())
147 break; 161 break;
148 } 162 }
149 if (!resource_host.get()) { 163 if (!resource_host.get()) {
150 NOTREACHED(); 164 NOTREACHED();
151 return; 165 return;
152 } 166 }
153 167
168 // Resource should have been assigned a nonzero PP_Resource.
169 DCHECK(resource_host->pp_resource());
170
154 resources_[params.pp_resource()] = 171 resources_[params.pp_resource()] =
155 linked_ptr<ResourceHost>(resource_host.release()); 172 linked_ptr<ResourceHost>(resource_host.release());
156 } 173 }
157 174
175 void PpapiHost::OnHostMsgAttachToPendingHost(PP_Resource pp_resource,
176 int pending_host_id) {
177 PendingHostResourceMap::iterator found =
178 pending_resource_hosts_.find(pending_host_id);
179 if (found == pending_resource_hosts_.end()) {
180 // Plugin sent a bad ID.
181 NOTREACHED();
182 return;
183 }
184 found->second->SetPPResourceForPendingHost(pp_resource);
185 resources_[pp_resource] = found->second;
186 pending_resource_hosts_.erase(found);
187 }
188
158 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) { 189 void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) {
159 ResourceMap::iterator found = resources_.find(resource); 190 ResourceMap::iterator found = resources_.find(resource);
160 if (found == resources_.end()) { 191 if (found == resources_.end()) {
161 NOTREACHED(); 192 NOTREACHED();
162 return; 193 return;
163 } 194 }
164 resources_.erase(found); 195 resources_.erase(found);
165 } 196 }
166 197
167 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const { 198 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const {
168 ResourceMap::const_iterator found = resources_.find(resource); 199 ResourceMap::const_iterator found = resources_.find(resource);
169 return found == resources_.end() ? NULL : found->second.get(); 200 return found == resources_.end() ? NULL : found->second.get();
170 } 201 }
171 202
172 } // namespace host 203 } // namespace host
173 } // namespace ppapi 204 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/host/ppapi_host.h ('k') | ppapi/host/resource_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698