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

Side by Side Diff: ppapi/proxy/ppb_url_loader_proxy.cc

Issue 6899055: PPAPI: Force async callback invocation option. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/proxy/ppb_url_loader_proxy.h" 5 #include "ppapi/proxy/ppb_url_loader_proxy.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "ppapi/c/pp_completion_callback.h" 13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/ppb_url_loader.h" 16 #include "ppapi/c/ppb_url_loader.h"
17 #include "ppapi/c/private/ppb_proxy_private.h" 17 #include "ppapi/c/private/ppb_proxy_private.h"
18 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 18 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
19 #include "ppapi/proxy/host_dispatcher.h" 19 #include "ppapi/proxy/host_dispatcher.h"
20 #include "ppapi/proxy/plugin_dispatcher.h" 20 #include "ppapi/proxy/plugin_dispatcher.h"
21 #include "ppapi/proxy/plugin_resource.h" 21 #include "ppapi/proxy/plugin_resource.h"
22 #include "ppapi/proxy/plugin_resource_tracker.h" 22 #include "ppapi/proxy/plugin_resource_tracker.h"
23 #include "ppapi/proxy/ppapi_messages.h" 23 #include "ppapi/proxy/ppapi_messages.h"
24 #include "ppapi/proxy/ppb_url_response_info_proxy.h" 24 #include "ppapi/proxy/ppb_url_response_info_proxy.h"
25 #include "ppapi/thunk/common.h"
25 26
26 #if defined(OS_LINUX) 27 #if defined(OS_LINUX)
27 #include <sys/shm.h> 28 #include <sys/shm.h>
28 #endif 29 #endif
29 30
30 namespace pp { 31 namespace pp {
31 namespace proxy { 32 namespace proxy {
32 33
33 class URLLoader : public PluginResource { 34 class URLLoader : public PluginResource {
34 public: 35 public:
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 URLLoader* object = PluginResource::GetAs<URLLoader>(resource); 172 URLLoader* object = PluginResource::GetAs<URLLoader>(resource);
172 return BoolToPPBool(!!object); 173 return BoolToPPBool(!!object);
173 } 174 }
174 175
175 int32_t Open(PP_Resource loader_id, 176 int32_t Open(PP_Resource loader_id,
176 PP_Resource request_id, 177 PP_Resource request_id,
177 PP_CompletionCallback callback) { 178 PP_CompletionCallback callback) {
178 URLLoader* loader_object; 179 URLLoader* loader_object;
179 PluginDispatcher* dispatcher; 180 PluginDispatcher* dispatcher;
180 if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) 181 if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher))
181 return PP_ERROR_BADRESOURCE; 182 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADRESOURCE);
182 PluginResource* request_object = 183 PluginResource* request_object =
183 PluginResourceTracker::GetInstance()->GetResourceObject(request_id); 184 PluginResourceTracker::GetInstance()->GetResourceObject(request_id);
184 if (!request_object) 185 if (!request_object)
185 return PP_ERROR_BADRESOURCE; 186 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADRESOURCE);
186 187
187 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Open( 188 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Open(
188 INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(), 189 INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(),
189 request_object->host_resource(), 190 request_object->host_resource(),
190 dispatcher->callback_tracker().SendCallback(callback))); 191 dispatcher->callback_tracker().SendCallback(callback)));
191 return PP_OK_COMPLETIONPENDING; 192 return PP_OK_COMPLETIONPENDING;
192 } 193 }
193 194
194 int32_t FollowRedirect(PP_Resource loader_id, 195 int32_t FollowRedirect(PP_Resource loader_id,
195 PP_CompletionCallback callback) { 196 PP_CompletionCallback callback) {
196 URLLoader* loader_object; 197 URLLoader* loader_object;
197 PluginDispatcher* dispatcher; 198 PluginDispatcher* dispatcher;
198 if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) 199 if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher))
199 return PP_ERROR_BADRESOURCE; 200 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADRESOURCE);
200 201
201 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( 202 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect(
202 INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(), 203 INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(),
203 dispatcher->callback_tracker().SendCallback(callback))); 204 dispatcher->callback_tracker().SendCallback(callback)));
204 return PP_OK_COMPLETIONPENDING; 205 return PP_OK_COMPLETIONPENDING;
205 } 206 }
206 207
207 PP_Bool GetUploadProgress(PP_Resource loader_id, 208 PP_Bool GetUploadProgress(PP_Resource loader_id,
208 int64_t* bytes_sent, 209 int64_t* bytes_sent,
209 int64_t* total_bytes_to_be_sent) { 210 int64_t* total_bytes_to_be_sent) {
(...skipping 29 matching lines...) Expand all
239 return object->GetResponseInfo(); 240 return object->GetResponseInfo();
240 } 241 }
241 242
242 int32_t ReadResponseBody(PP_Resource loader_id, 243 int32_t ReadResponseBody(PP_Resource loader_id,
243 void* buffer, 244 void* buffer,
244 int32_t bytes_to_read, 245 int32_t bytes_to_read,
245 PP_CompletionCallback callback) { 246 PP_CompletionCallback callback) {
246 URLLoader* object; 247 URLLoader* object;
247 PluginDispatcher* dispatcher; 248 PluginDispatcher* dispatcher;
248 if (!RoutingDataFromURLLoader(loader_id, &object, &dispatcher)) 249 if (!RoutingDataFromURLLoader(loader_id, &object, &dispatcher))
249 return PP_ERROR_BADRESOURCE; 250 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADRESOURCE);
250 251
251 if (!buffer || bytes_to_read <= 0) 252 if (!buffer || bytes_to_read <= 0)
piman 2011/06/07 17:32:14 add braces around the next 2 lines
polina 2011/06/09 23:53:51 Done.
252 return PP_ERROR_BADARGUMENT; // Must specify an output buffer. 253 // Must specify an output buffer.
254 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADARGUMENT);
253 if (object->current_read_callback_.func) 255 if (object->current_read_callback_.func)
piman 2011/06/07 17:32:14 add braces around the next 2 lines
polina 2011/06/09 23:53:51 Done.
254 return PP_ERROR_INPROGRESS; // Can only have one request pending. 256 // Can only have one request pending.
257 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_INPROGRESS);
255 258
256 // Currently we don't support sync calls to read. We'll need to revisit 259 // Currently we don't support sync calls to read. We'll need to revisit
257 // how this works when we allow blocking calls (from background threads). 260 // how this works when we allow blocking calls (from background threads).
258 if (!callback.func) 261 if (!callback.func)
259 return PP_ERROR_BADARGUMENT; 262 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADARGUMENT);
260 263
261 if (static_cast<size_t>(bytes_to_read) <= object->buffer_.size()) { 264 if (static_cast<size_t>(bytes_to_read) <= object->buffer_.size()) {
262 // Special case: we've buffered enough data to be able to synchronously 265 // Special case: we've buffered enough data to be able to synchronously
263 // return data to the caller. Do so without making IPCs. 266 // return data to the caller. Do so without making IPCs.
264 object->PopBuffer(buffer, bytes_to_read); 267 object->PopBuffer(buffer, bytes_to_read);
265 return bytes_to_read; 268 return ppapi::thunk::MayForceCallback(callback, bytes_to_read);
266 } 269 }
267 270
268 object->current_read_callback_ = callback; 271 object->current_read_callback_ = callback;
269 object->current_read_buffer_ = buffer; 272 object->current_read_buffer_ = buffer;
270 object->current_read_buffer_size_ = bytes_to_read; 273 object->current_read_buffer_size_ = bytes_to_read;
271 274
272 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( 275 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody(
273 INTERFACE_ID_PPB_URL_LOADER, 276 INTERFACE_ID_PPB_URL_LOADER,
274 object->host_resource(), bytes_to_read)); 277 object->host_resource(), bytes_to_read));
275 return PP_OK_COMPLETIONPENDING; 278 return PP_OK_COMPLETIONPENDING;
276 } 279 }
277 280
278 int32_t FinishStreamingToFile(PP_Resource loader_id, 281 int32_t FinishStreamingToFile(PP_Resource loader_id,
279 PP_CompletionCallback callback) { 282 PP_CompletionCallback callback) {
280 URLLoader* loader_object; 283 URLLoader* loader_object;
281 PluginDispatcher* dispatcher; 284 PluginDispatcher* dispatcher;
282 if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) 285 if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher))
283 return PP_ERROR_BADRESOURCE; 286 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADRESOURCE);
284 287
285 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( 288 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile(
286 INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(), 289 INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(),
287 dispatcher->callback_tracker().SendCallback(callback))); 290 dispatcher->callback_tracker().SendCallback(callback)));
288 return PP_OK_COMPLETIONPENDING; 291 return PP_OK_COMPLETIONPENDING;
289 } 292 }
290 293
291 void Close(PP_Resource loader_id) { 294 void Close(PP_Resource loader_id) {
292 URLLoader* loader_object; 295 URLLoader* loader_object;
293 PluginDispatcher* dispatcher; 296 PluginDispatcher* dispatcher;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 return handled; 651 return handled;
649 } 652 }
650 653
651 void PPB_URLLoaderTrusted_Proxy::OnMsgGrantUniversalAccess( 654 void PPB_URLLoaderTrusted_Proxy::OnMsgGrantUniversalAccess(
652 const HostResource& loader) { 655 const HostResource& loader) {
653 ppb_url_loader_trusted_target()->GrantUniversalAccess(loader.host_resource()); 656 ppb_url_loader_trusted_target()->GrantUniversalAccess(loader.host_resource());
654 } 657 }
655 658
656 } // namespace proxy 659 } // namespace proxy
657 } // namespace pp 660 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698