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

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

Issue 7585025: Reland 95309. Add a template to handle properly issuing completion callbacks. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « ppapi/proxy/ppb_surface_3d_proxy.cc ('k') | ppapi/thunk/ppb_audio_api.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) 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
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // This heap object will get deleted by the callback handler. 510 // This heap object will get deleted by the callback handler.
511 // TODO(brettw) this will be leaked if the plugin closes the resource! 511 // TODO(brettw) this will be leaked if the plugin closes the resource!
512 // (Also including the plugin unloading and having the resource implicitly 512 // (Also including the plugin unloading and having the resource implicitly
513 // destroyed. Depending on the cleanup ordering, we may not need the weak 513 // destroyed. Depending on the cleanup ordering, we may not need the weak
514 // pointer here.) 514 // pointer here.)
515 ReadCallbackInfo* info = new ReadCallbackInfo; 515 ReadCallbackInfo* info = new ReadCallbackInfo;
516 info->resource = loader; 516 info->resource = loader;
517 // TODO(brettw) have a way to check for out-of-memory. 517 // TODO(brettw) have a way to check for out-of-memory.
518 info->read_buffer.resize(bytes_to_read); 518 info->read_buffer.resize(bytes_to_read);
519 519
520 CompletionCallback callback = callback_factory_.NewOptionalCallback( 520 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter(
521 &PPB_URLLoader_Proxy::OnReadCallback, info); 521 loader, callback_factory_, &PPB_URLLoader_Proxy::OnReadCallback, info);
522
523 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader);
524 int32_t result = PP_ERROR_BADRESOURCE;
525 if (enter.succeeded()) { 522 if (enter.succeeded()) {
526 result = enter.object()->ReadResponseBody( 523 enter.SetResult(enter.object()->ReadResponseBody(
527 const_cast<char*>(info->read_buffer.c_str()), 524 const_cast<char*>(info->read_buffer.c_str()),
528 bytes_to_read, callback.pp_completion_callback()); 525 bytes_to_read, enter.callback()));
529 }
530 if (result != PP_OK_COMPLETIONPENDING) {
531 // Send error (or perhaps success for synchronous reads) back to plugin.
532 // The callback function is already set up to do this and also delete the
533 // callback info.
534 callback.Run(result);
535 } 526 }
536 } 527 }
537 528
538 void PPB_URLLoader_Proxy::OnMsgFinishStreamingToFile( 529 void PPB_URLLoader_Proxy::OnMsgFinishStreamingToFile(
539 const HostResource& loader, 530 const HostResource& loader,
540 uint32_t serialized_callback) { 531 uint32_t serialized_callback) {
541 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); 532 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader);
542 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); 533 PP_CompletionCallback callback = ReceiveCallback(serialized_callback);
543 int32_t result = PP_ERROR_BADRESOURCE; 534 int32_t result = PP_ERROR_BADRESOURCE;
544 if (enter.succeeded()) 535 if (enter.succeeded())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 info->read_buffer.resize(bytes_read); 577 info->read_buffer.resize(bytes_read);
587 578
588 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( 579 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack(
589 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); 580 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer));
590 581
591 delete info; 582 delete info;
592 } 583 }
593 584
594 } // namespace proxy 585 } // namespace proxy
595 } // namespace pp 586 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_surface_3d_proxy.cc ('k') | ppapi/thunk/ppb_audio_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698