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

Side by Side Diff: src/shared/ppapi_proxy/browser_callback.cc

Issue 6177007: ppapi_proxy: Support loading and reading urls. Proxy URLLoader.... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 11 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) 2010 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2010 The Native Client 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 "native_client/src/shared/ppapi_proxy/browser_callback.h" 5 #include "native_client/src/shared/ppapi_proxy/browser_callback.h"
6 6
7 #include <new> 7 #include <new>
8 8
9 #include "native_client/src/include/nacl_macros.h" 9 #include "native_client/src/include/nacl_macros.h"
10 #include "native_client/src/include/nacl_scoped_ptr.h" 10 #include "native_client/src/include/nacl_scoped_ptr.h"
11 #include "native_client/src/shared/platform/nacl_check.h" 11 #include "native_client/src/shared/platform/nacl_check.h"
12 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" 12 #include "native_client/src/shared/ppapi_proxy/browser_globals.h"
13 #include "native_client/src/shared/ppapi_proxy/utility.h" 13 #include "native_client/src/shared/ppapi_proxy/utility.h"
14 #include "native_client/src/shared/srpc/nacl_srpc.h" 14 #include "native_client/src/shared/srpc/nacl_srpc.h"
15 #include "ppapi/c/pp_completion_callback.h" 15 #include "ppapi/c/pp_completion_callback.h"
16 #include "srpcgen/ppp_rpc.h" 16 #include "srpcgen/ppp_rpc.h"
17 17
18 namespace ppapi_proxy { 18 namespace ppapi_proxy {
19 19
20 namespace { 20 namespace {
21 21
22 // Data structure used on the browser side to invoke a completion callback 22 // Data structure used on the browser side to invoke a completion callback
23 // on the plugin side. 23 // on the plugin side.
24 // 24 //
25 // A plugin-side callback is proxied over to the browser side using an id. 25 // A plugin-side callback is proxied over to the browser side using
26 // This id is then paired with a channel listened to by the nexe that supplied 26 // a |callback_id|. This id is then paired with an |srpc_channel| listened to
27 // the callback. 27 // by the nexe that supplied the callback.
28 //
29 // |read_buffer| is used with callbacks that are invoked on byte reads.
28 struct RemoteCallbackInfo { 30 struct RemoteCallbackInfo {
29 public:
30 NaClSrpcChannel* srpc_channel; 31 NaClSrpcChannel* srpc_channel;
31 int32_t callback_id; 32 int32_t callback_id;
33 char* read_buffer;
32 }; 34 };
33 35
34 // Calls the remote implementation of a callback on the plugin side. 36 // Calls the remote implementation of a callback on the plugin side.
35 // Implements a PP_CompletionCallback_Func type that can be used along with an 37 // Implements a PP_CompletionCallback_Func type that can be used along with an
36 // instance of a RemoteCallbackInfo as |user_data| to provide a 38 // instance of a RemoteCallbackInfo as |user_data| to provide a
37 // PP_CompletionCallback to browser functions. 39 // PP_CompletionCallback to browser functions.
38 // 40 //
39 // |remote_callback| is a pointer to a RemoteCallbackInfo, 41 // |remote_callback| is a pointer to a RemoteCallbackInfo,
40 // deleted after rpc via scoped_ptr. 42 // deleted after rpc via scoped_ptr. The associated |read_buffer| is also
43 // deleted.
41 // |result| is passed by the callback invoker to indicate success or error. 44 // |result| is passed by the callback invoker to indicate success or error.
42 // It is passed as-is to the plugin side callback. 45 // It is passed as-is to the plugin side callback.
43 void RunRemoteCallback(void* user_data, int32_t result) { 46 void RunRemoteCallback(void* user_data, int32_t result) {
44 CHECK(PPBCoreInterface()->IsMainThread()); 47 CHECK(PPBCoreInterface()->IsMainThread());
45 DebugPrintf("RunRemotecallback: result=%"NACL_PRId32"\n", result); 48 DebugPrintf("RunRemotecallback: result=%"NACL_PRId32"\n", result);
46 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback( 49 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback(
47 reinterpret_cast<RemoteCallbackInfo*>(user_data)); 50 reinterpret_cast<RemoteCallbackInfo*>(user_data));
51
52 nacl::scoped_ptr_malloc<char> read_buffer(remote_callback->read_buffer);
sehr (please use chromium) 2011/01/12 17:49:12 Just curious: is there a reason why you didn't use
polina 2011/01/12 23:44:27 No particular reason. Changed.
53 nacl_abi_size_t read_buffer_size = 0;
54 if (result > 0) { // Positive number indicates bytes read.
55 CHECK(remote_callback->read_buffer != NULL);
56 read_buffer_size = static_cast<nacl_abi_size_t>(result);
57 }
58
48 CompletionCallbackRpcClient::RunCompletionCallback( 59 CompletionCallbackRpcClient::RunCompletionCallback(
49 remote_callback->srpc_channel, 60 remote_callback->srpc_channel,
50 remote_callback->callback_id, 61 remote_callback->callback_id,
51 result); 62 result,
63 read_buffer_size,
64 read_buffer.get());
52 } 65 }
53 66
54 } // namespace 67 } // namespace
55 68
56 // Builds a RemoteCallbackInfo and returns PP_CompletionCallback corresponding 69 // Builds a RemoteCallbackInfo and returns PP_CompletionCallback corresponding
57 // to RunRemoteCallback or NULL on failure. 70 // to RunRemoteCallback or NULL on failure.
58 struct PP_CompletionCallback MakeRemoteCompletionCallback( 71 struct PP_CompletionCallback MakeRemoteCompletionCallback(
59 NaClSrpcChannel* srpc_channel, 72 NaClSrpcChannel* srpc_channel,
60 int32_t callback_id) { 73 int32_t callback_id,
74 int32_t bytes_to_read,
75 char** buffer) {
61 RemoteCallbackInfo* remote_callback = new(std::nothrow) RemoteCallbackInfo; 76 RemoteCallbackInfo* remote_callback = new(std::nothrow) RemoteCallbackInfo;
62 if (remote_callback == NULL) 77 if (remote_callback == NULL)
63 return PP_BlockUntilComplete(); 78 return PP_BlockUntilComplete();
64 remote_callback->srpc_channel = srpc_channel; 79 remote_callback->srpc_channel = srpc_channel;
65 remote_callback->callback_id = callback_id; 80 remote_callback->callback_id = callback_id;
81 remote_callback->read_buffer = NULL;
82
83 if (bytes_to_read > 0 && buffer != NULL) {
84 *buffer = reinterpret_cast<char*>(malloc(bytes_to_read));
85 remote_callback->read_buffer = *buffer;
86 }
87
66 return PP_MakeCompletionCallback(RunRemoteCallback, remote_callback); 88 return PP_MakeCompletionCallback(RunRemoteCallback, remote_callback);
67 } 89 }
68 90
91 struct PP_CompletionCallback MakeRemoteCompletionCallback(
92 NaClSrpcChannel* srpc_channel,
93 int32_t callback_id) {
94 return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL);
95 }
96
69 void DeleteRemoteCallbackInfo(struct PP_CompletionCallback callback) { 97 void DeleteRemoteCallbackInfo(struct PP_CompletionCallback callback) {
70 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback( 98 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback(
71 reinterpret_cast<RemoteCallbackInfo*>(callback.user_data)); 99 reinterpret_cast<RemoteCallbackInfo*>(callback.user_data));
100 nacl::scoped_ptr_malloc<char> read_buffer(remote_callback->read_buffer);
72 } 101 }
73 102
74 } // namespace ppapi_proxy 103 } // namespace ppapi_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698