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

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

Issue 9227008: WebSocket Pepper API: SRPC proxy implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win32 build Created 8 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) 2011 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 "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/browser_ppp.h" 13 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
14 #include "native_client/src/shared/ppapi_proxy/object_serialize.h"
14 #include "native_client/src/shared/ppapi_proxy/utility.h" 15 #include "native_client/src/shared/ppapi_proxy/utility.h"
15 #include "native_client/src/shared/srpc/nacl_srpc.h" 16 #include "native_client/src/shared/srpc/nacl_srpc.h"
16 #include "ppapi/c/pp_completion_callback.h" 17 #include "ppapi/c/pp_completion_callback.h"
17 #include "native_client/src/trusted/plugin/plugin.h" 18 #include "native_client/src/trusted/plugin/plugin.h"
18 #include "srpcgen/ppp_rpc.h" 19 #include "srpcgen/ppp_rpc.h"
19 20
21 using pp::Var;
dmichael (off chromium) 2012/01/17 23:32:45 Do you need this? I don't see where you're using i
Takashi Toyoshima 2012/01/18 11:07:16 Sorry. It was needed, but is not used now. I delet
22
20 namespace ppapi_proxy { 23 namespace ppapi_proxy {
21 24
22 namespace { 25 namespace {
23 26
24 bool BytesWereRead(int32_t num_bytes) { 27 bool BytesWereRead(int32_t num_bytes) {
25 return (num_bytes > 0); 28 return (num_bytes > 0);
26 } 29 }
27 30
28 nacl_abi_size_t CastToNaClAbiSize(int32_t result) { 31 nacl_abi_size_t CastToNaClAbiSize(int32_t result) {
29 return static_cast<nacl_abi_size_t>(result); 32 return static_cast<nacl_abi_size_t>(result);
(...skipping 12 matching lines...) Expand all
42 // depending on how the callback operation was initiated, and 45 // depending on how the callback operation was initiated, and
43 // |check_result_func| provides an abstraction to the semantics. 46 // |check_result_func| provides an abstraction to the semantics.
44 // |get_size_read_func| is a pointer to a function used to get the 47 // |get_size_read_func| is a pointer to a function used to get the
45 // number of bytes read. The way the number of bytes read 48 // number of bytes read. The way the number of bytes read
46 // retrieved/calculated may be different depending on how the callback was 49 // retrieved/calculated may be different depending on how the callback was
47 // initiated, and |get_size_read_func| provides the indirection. 50 // initiated, and |get_size_read_func| provides the indirection.
48 struct RemoteCallbackInfo { 51 struct RemoteCallbackInfo {
49 NaClSrpcChannel* srpc_channel; 52 NaClSrpcChannel* srpc_channel;
50 int32_t callback_id; 53 int32_t callback_id;
51 char* read_buffer; 54 char* read_buffer;
55 PP_Var read_var;
52 CheckResultFunc check_result_func; 56 CheckResultFunc check_result_func;
53 GetReadSizeFunc get_size_read_func; 57 GetReadSizeFunc get_size_read_func;
54 }; 58 };
55 59
56 // Calls the remote implementation of a callback on the plugin side. 60 // Calls the remote implementation of a callback on the plugin side.
57 // Implements a PP_CompletionCallback_Func type that can be used along with an 61 // Implements a PP_CompletionCallback_Func type that can be used along with an
58 // instance of a RemoteCallbackInfo as |user_data| to provide a 62 // instance of a RemoteCallbackInfo as |user_data| to provide a
59 // PP_CompletionCallback to browser functions. 63 // PP_CompletionCallback to browser functions.
60 // 64 //
61 // |remote_callback| is a pointer to a RemoteCallbackInfo, 65 // |remote_callback| is a pointer to a RemoteCallbackInfo,
(...skipping 14 matching lines...) Expand all
76 if (LookupBrowserPppForInstance(instance) == NULL) { 80 if (LookupBrowserPppForInstance(instance) == NULL) {
77 DebugPrintf("RunRemoteCallback: proxy=NULL\n", result); 81 DebugPrintf("RunRemoteCallback: proxy=NULL\n", result);
78 return; 82 return;
79 } 83 }
80 84
81 nacl_abi_size_t read_buffer_size = 0; 85 nacl_abi_size_t read_buffer_size = 0;
82 CheckResultFunc check_result_func = remote_callback->check_result_func; 86 CheckResultFunc check_result_func = remote_callback->check_result_func;
83 GetReadSizeFunc get_size_read_func = remote_callback->get_size_read_func; 87 GetReadSizeFunc get_size_read_func = remote_callback->get_size_read_func;
84 if ((*check_result_func)(result) && remote_callback->read_buffer != NULL) 88 if ((*check_result_func)(result) && remote_callback->read_buffer != NULL)
85 read_buffer_size = (*get_size_read_func)(result); 89 read_buffer_size = (*get_size_read_func)(result);
90 if (remote_callback->read_var.type != PP_VARTYPE_NULL) {
91 read_buffer_size = kMaxReturnVarSize;
92 read_buffer.reset(
93 Serialize(&remote_callback->read_var, 1, &read_buffer_size));
94 }
86 95
87 NaClSrpcError srpc_result = 96 NaClSrpcError srpc_result =
88 CompletionCallbackRpcClient::RunCompletionCallback( 97 CompletionCallbackRpcClient::RunCompletionCallback(
89 remote_callback->srpc_channel, 98 remote_callback->srpc_channel,
90 remote_callback->callback_id, 99 remote_callback->callback_id,
91 result, 100 result,
92 read_buffer_size, 101 read_buffer_size,
93 read_buffer.get()); 102 read_buffer.get());
94 DebugPrintf("RunRemoteCallback: %s\n", 103 DebugPrintf("RunRemoteCallback: %s\n",
95 NaClSrpcErrorString(srpc_result)); 104 NaClSrpcErrorString(srpc_result));
96 if (srpc_result == NACL_SRPC_RESULT_INTERNAL) 105 if (srpc_result == NACL_SRPC_RESULT_INTERNAL)
97 CleanUpAfterDeadNexe(instance); 106 CleanUpAfterDeadNexe(instance);
98 } 107 }
99 108
100 } // namespace 109 } // namespace
101 110
102 // Builds a RemoteCallbackInfo and returns PP_CompletionCallback corresponding 111 // Builds a RemoteCallbackInfo and returns PP_CompletionCallback corresponding
103 // to RunRemoteCallback or NULL on failure. 112 // to RunRemoteCallback or NULL on failure.
104 struct PP_CompletionCallback MakeRemoteCompletionCallback( 113 struct PP_CompletionCallback MakeRemoteCompletionCallback(
105 NaClSrpcChannel* srpc_channel, 114 NaClSrpcChannel* srpc_channel,
106 int32_t callback_id, 115 int32_t callback_id,
107 int32_t bytes_to_read, 116 int32_t bytes_to_read,
108 char** buffer, 117 char** buffer,
118 PP_Var** var,
109 CheckResultFunc check_result_func, 119 CheckResultFunc check_result_func,
110 GetReadSizeFunc get_size_read_func) { 120 GetReadSizeFunc get_size_read_func) {
111 RemoteCallbackInfo* remote_callback = new(std::nothrow) RemoteCallbackInfo; 121 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback(
112 if (remote_callback == NULL) // new failed. 122 new(std::nothrow) RemoteCallbackInfo);
123 if (remote_callback.get() == NULL) // new failed.
113 return PP_BlockUntilComplete(); 124 return PP_BlockUntilComplete();
114 remote_callback->srpc_channel = srpc_channel; 125 remote_callback->srpc_channel = srpc_channel;
115 remote_callback->callback_id = callback_id; 126 remote_callback->callback_id = callback_id;
116 remote_callback->read_buffer = NULL; 127 remote_callback->read_buffer = NULL;
128 remote_callback->read_var = PP_MakeNull();
117 remote_callback->check_result_func = check_result_func; 129 remote_callback->check_result_func = check_result_func;
118 remote_callback->get_size_read_func = get_size_read_func; 130 remote_callback->get_size_read_func = get_size_read_func;
119 131
120 if (bytes_to_read > 0 && buffer != NULL) { 132 if (bytes_to_read > 0 && buffer != NULL) {
121 *buffer = new(std::nothrow) char[bytes_to_read]; 133 *buffer = new(std::nothrow) char[bytes_to_read];
122 if (*buffer == NULL) // new failed. 134 if (*buffer == NULL) // new failed.
123 return PP_BlockUntilComplete(); 135 return PP_BlockUntilComplete();
124 remote_callback->read_buffer = *buffer; 136 remote_callback->read_buffer = *buffer;
125 } 137 }
138 if (var)
139 *var = &remote_callback->read_var;
126 140
127 return PP_MakeOptionalCompletionCallback( 141 return PP_MakeOptionalCompletionCallback(
128 RunRemoteCallback, remote_callback); 142 RunRemoteCallback, remote_callback.release());
129 } 143 }
130 144
131 struct PP_CompletionCallback MakeRemoteCompletionCallback( 145 struct PP_CompletionCallback MakeRemoteCompletionCallback(
146 NaClSrpcChannel* srpc_channel,
147 int32_t callback_id,
148 int32_t bytes_to_read,
149 char** buffer,
150 CheckResultFunc check_result_func,
151 GetReadSizeFunc get_size_read_func) {
152 return MakeRemoteCompletionCallback(srpc_channel, callback_id, bytes_to_read,
153 buffer, NULL, BytesWereRead,
154 CastToNaClAbiSize);
155 }
156
157 struct PP_CompletionCallback MakeRemoteCompletionCallback(
132 NaClSrpcChannel* srpc_channel, 158 NaClSrpcChannel* srpc_channel,
133 int32_t callback_id, 159 int32_t callback_id,
134 int32_t bytes_to_read, 160 int32_t bytes_to_read,
135 char** buffer) { 161 char** buffer) {
136 return MakeRemoteCompletionCallback(srpc_channel, callback_id, bytes_to_read, 162 return MakeRemoteCompletionCallback(srpc_channel, callback_id, bytes_to_read,
137 buffer, BytesWereRead, CastToNaClAbiSize); 163 buffer, BytesWereRead, CastToNaClAbiSize);
138 } 164 }
139 165
140 struct PP_CompletionCallback MakeRemoteCompletionCallback( 166 struct PP_CompletionCallback MakeRemoteCompletionCallback(
141 NaClSrpcChannel* srpc_channel, 167 NaClSrpcChannel* srpc_channel,
168 int32_t callback_id,
169 PP_Var** var) {
170 return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL, var,
171 BytesWereRead, CastToNaClAbiSize);
172 }
173
174 struct PP_CompletionCallback MakeRemoteCompletionCallback(
175 NaClSrpcChannel* srpc_channel,
142 int32_t callback_id) { 176 int32_t callback_id) {
143 return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL); 177 return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL);
144 } 178 }
145 179
146 void DeleteRemoteCallbackInfo(struct PP_CompletionCallback callback) { 180 void DeleteRemoteCallbackInfo(struct PP_CompletionCallback callback) {
147 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback( 181 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback(
148 reinterpret_cast<RemoteCallbackInfo*>(callback.user_data)); 182 reinterpret_cast<RemoteCallbackInfo*>(callback.user_data));
149 nacl::scoped_array<char> read_buffer(remote_callback->read_buffer); 183 nacl::scoped_array<char> read_buffer(remote_callback->read_buffer);
150 } 184 }
151 185
152 } // namespace ppapi_proxy 186 } // namespace ppapi_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698