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

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

Issue 11410029: Added a ResourceMessageFilter for handling resource messages on another thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Stash the |reply_msg| in the context so that it can be used to reply 111 // Stash the |reply_msg| in the context so that it can be used to reply
112 // to the sync message. 112 // to the sync message.
113 HostMessageContext context(params, reply_msg); 113 HostMessageContext context(params, reply_msg);
114 HandleResourceCall(params, nested_msg, &context); 114 HandleResourceCall(params, nested_msg, &context);
115 } 115 }
116 116
117 void PpapiHost::HandleResourceCall( 117 void PpapiHost::HandleResourceCall(
118 const proxy::ResourceMessageCallParams& params, 118 const proxy::ResourceMessageCallParams& params,
119 const IPC::Message& nested_msg, 119 const IPC::Message& nested_msg,
120 HostMessageContext* context) { 120 HostMessageContext* context) {
121 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
122
123 ResourceHost* resource_host = GetResourceHost(params.pp_resource()); 121 ResourceHost* resource_host = GetResourceHost(params.pp_resource());
124 if (resource_host) { 122 if (resource_host) {
125 reply_context.params.set_result( 123 resource_host->HandleMessage(nested_msg, context);
126 resource_host->OnResourceMessageReceived(nested_msg, context));
127
128 // Sanity check the resource handler. Note if the result was
129 // "completion pending" the resource host may have already sent the reply.
130 if (reply_context.params.result() == PP_OK_COMPLETIONPENDING) {
131 // Message handler should have only returned a pending result if a
132 // response will be sent to the plugin.
133 DCHECK(params.has_callback());
134
135 // Message handler should not have written a message to be returned if
136 // completion is pending.
137 DCHECK(context->reply_msg.type() == 0);
138 } else if (!params.has_callback()) {
139 // When no response is required, the message handler should not have
140 // written a message to be returned.
141 DCHECK(context->reply_msg.type() == 0);
142
143 // If there is no callback and the result of running the message handler
144 // was not PP_OK the client won't find out.
145 DLOG_IF(WARNING, reply_context.params.result() != PP_OK)
146 << "'Post' message handler failed to complete successfully.";
147 }
148 } else { 124 } else {
125 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
149 reply_context.params.set_result(PP_ERROR_BADRESOURCE); 126 reply_context.params.set_result(PP_ERROR_BADRESOURCE);
127 SendReply(reply_context, context->reply_msg);
yzshen1 2012/11/13 21:51:48 Maybe the message doesn't expect a reply.
raymes 2012/11/16 18:56:35 Done.
150 } 128 }
151
152 if (params.has_callback() &&
153 reply_context.params.result() != PP_OK_COMPLETIONPENDING)
154 SendReply(reply_context, context->reply_msg);
155 } 129 }
156 130
157 void PpapiHost::OnHostMsgResourceCreated( 131 void PpapiHost::OnHostMsgResourceCreated(
158 const proxy::ResourceMessageCallParams& params, 132 const proxy::ResourceMessageCallParams& params,
159 PP_Instance instance, 133 PP_Instance instance,
160 const IPC::Message& nested_msg) { 134 const IPC::Message& nested_msg) {
161 if (resources_.size() >= kMaxResourcesPerPlugin) 135 if (resources_.size() >= kMaxResourcesPerPlugin)
162 return; 136 return;
163 137
164 // Run through all filters until one grabs this message. 138 // Run through all filters until one grabs this message.
(...skipping 23 matching lines...) Expand all
188 resources_.erase(found); 162 resources_.erase(found);
189 } 163 }
190 164
191 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) { 165 ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) {
192 ResourceMap::iterator found = resources_.find(resource); 166 ResourceMap::iterator found = resources_.find(resource);
193 return found == resources_.end() ? NULL : found->second.get(); 167 return found == resources_.end() ? NULL : found->second.get();
194 } 168 }
195 169
196 } // namespace host 170 } // namespace host
197 } // namespace ppapi 171 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698