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

Side by Side Diff: mojo/android/system/core_impl.cc

Issue 2047333003: Roll base to ec59756cc1ad02cc835bcca10056a621c9eb346c. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 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
« no previous file with comments | « mojo/android/javatests/validation_test_util.cc ('k') | shell/android/android_handler.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/android/system/core_impl.h" 5 #include "mojo/android/system/core_impl.h"
6 6
7 #include "base/android/base_jni_registrar.h" 7 #include "base/android/base_jni_registrar.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_registrar.h" 9 #include "base/android/jni_registrar.h"
10 #include "base/android/library_loader/library_loader_hooks.h" 10 #include "base/android/library_loader/library_loader_hooks.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 reinterpret_cast<const MojoHandleSignals*>(buffer_start + 4 * nb_handles); 87 reinterpret_cast<const MojoHandleSignals*>(buffer_start + 4 * nb_handles);
88 MojoHandleSignalsState* states_start = 88 MojoHandleSignalsState* states_start =
89 reinterpret_cast<MojoHandleSignalsState*>(buffer_start + 8 * nb_handles); 89 reinterpret_cast<MojoHandleSignalsState*>(buffer_start + 8 * nb_handles);
90 uint32_t* result_index = 90 uint32_t* result_index =
91 reinterpret_cast<uint32_t*>(buffer_start + 16 * nb_handles); 91 reinterpret_cast<uint32_t*>(buffer_start + 16 * nb_handles);
92 *result_index = static_cast<uint32_t>(-1); 92 *result_index = static_cast<uint32_t>(-1);
93 return MojoWaitMany(handle_start, signals_start, nb_handles, deadline, 93 return MojoWaitMany(handle_start, signals_start, nb_handles, deadline,
94 result_index, states_start); 94 result_index, states_start);
95 } 95 }
96 96
97 static jobject CreateMessagePipe(JNIEnv* env, 97 static ScopedJavaLocalRef<jobject> CreateMessagePipe(JNIEnv* env,
98 jobject jcaller, 98 jobject jcaller,
99 jobject options_buffer) { 99 jobject options_buffer) {
100 const MojoCreateMessagePipeOptions* options = NULL; 100 const MojoCreateMessagePipeOptions* options = NULL;
101 if (options_buffer) { 101 if (options_buffer) {
102 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); 102 const void* buffer_start = env->GetDirectBufferAddress(options_buffer);
103 DCHECK(buffer_start); 103 DCHECK(buffer_start);
104 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); 104 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u);
105 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); 105 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer);
106 DCHECK_EQ(buffer_size, sizeof(MojoCreateMessagePipeOptions)); 106 DCHECK_EQ(buffer_size, sizeof(MojoCreateMessagePipeOptions));
107 options = static_cast<const MojoCreateMessagePipeOptions*>(buffer_start); 107 options = static_cast<const MojoCreateMessagePipeOptions*>(buffer_start);
108 DCHECK_EQ(options->struct_size, buffer_size); 108 DCHECK_EQ(options->struct_size, buffer_size);
109 } 109 }
110 MojoHandle handle1; 110 MojoHandle handle1;
111 MojoHandle handle2; 111 MojoHandle handle2;
112 MojoResult result = MojoCreateMessagePipe(options, &handle1, &handle2); 112 MojoResult result = MojoCreateMessagePipe(options, &handle1, &handle2);
113 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) 113 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2);
114 .Release();
115 } 114 }
116 115
117 static jobject CreateDataPipe(JNIEnv* env, 116 static ScopedJavaLocalRef<jobject> CreateDataPipe(JNIEnv* env,
118 jobject jcaller, 117 jobject jcaller,
119 jobject options_buffer) { 118 jobject options_buffer) {
120 const MojoCreateDataPipeOptions* options = NULL; 119 const MojoCreateDataPipeOptions* options = NULL;
121 if (options_buffer) { 120 if (options_buffer) {
122 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); 121 const void* buffer_start = env->GetDirectBufferAddress(options_buffer);
123 DCHECK(buffer_start); 122 DCHECK(buffer_start);
124 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); 123 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u);
125 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); 124 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer);
126 DCHECK_EQ(buffer_size, sizeof(MojoCreateDataPipeOptions)); 125 DCHECK_EQ(buffer_size, sizeof(MojoCreateDataPipeOptions));
127 options = static_cast<const MojoCreateDataPipeOptions*>(buffer_start); 126 options = static_cast<const MojoCreateDataPipeOptions*>(buffer_start);
128 DCHECK_EQ(options->struct_size, buffer_size); 127 DCHECK_EQ(options->struct_size, buffer_size);
129 } 128 }
130 MojoHandle handle1; 129 MojoHandle handle1;
131 MojoHandle handle2; 130 MojoHandle handle2;
132 MojoResult result = MojoCreateDataPipe(options, &handle1, &handle2); 131 MojoResult result = MojoCreateDataPipe(options, &handle1, &handle2);
133 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) 132 return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2);
134 .Release();
135 } 133 }
136 134
137 static jobject CreateSharedBuffer(JNIEnv* env, 135 static ScopedJavaLocalRef<jobject> CreateSharedBuffer(JNIEnv* env,
138 jobject jcaller, 136 jobject jcaller,
139 jobject options_buffer, 137 jobject options_buffer,
140 jlong num_bytes) { 138 jlong num_bytes) {
141 const MojoCreateSharedBufferOptions* options = 0; 139 const MojoCreateSharedBufferOptions* options = 0;
142 if (options_buffer) { 140 if (options_buffer) {
143 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); 141 const void* buffer_start = env->GetDirectBufferAddress(options_buffer);
144 DCHECK(buffer_start); 142 DCHECK(buffer_start);
145 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); 143 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u);
146 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); 144 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer);
147 DCHECK_EQ(buffer_size, sizeof(MojoCreateSharedBufferOptions)); 145 DCHECK_EQ(buffer_size, sizeof(MojoCreateSharedBufferOptions));
148 options = static_cast<const MojoCreateSharedBufferOptions*>(buffer_start); 146 options = static_cast<const MojoCreateSharedBufferOptions*>(buffer_start);
149 DCHECK_EQ(options->struct_size, buffer_size); 147 DCHECK_EQ(options->struct_size, buffer_size);
150 } 148 }
151 MojoHandle handle; 149 MojoHandle handle;
152 MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle); 150 MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle);
153 return Java_CoreImpl_newResultAndInteger(env, result, handle).Release(); 151 return Java_CoreImpl_newResultAndInteger(env, result, handle);
154 } 152 }
155 153
156 static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) { 154 static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) {
157 return MojoClose(mojo_handle); 155 return MojoClose(mojo_handle);
158 } 156 }
159 157
160 static jint Wait(JNIEnv* env, 158 static jint Wait(JNIEnv* env,
161 jobject jcaller, 159 jobject jcaller,
162 jobject buffer, 160 jobject buffer,
163 jint mojo_handle, 161 jint mojo_handle,
(...skipping 30 matching lines...) Expand all
194 if (handles_buffer) { 192 if (handles_buffer) {
195 handles = 193 handles =
196 static_cast<MojoHandle*>(env->GetDirectBufferAddress(handles_buffer)); 194 static_cast<MojoHandle*>(env->GetDirectBufferAddress(handles_buffer));
197 num_handles = env->GetDirectBufferCapacity(handles_buffer) / 4; 195 num_handles = env->GetDirectBufferCapacity(handles_buffer) / 4;
198 } 196 }
199 // Java code will handle invalidating handles if the write succeeded. 197 // Java code will handle invalidating handles if the write succeeded.
200 return MojoWriteMessage( 198 return MojoWriteMessage(
201 mojo_handle, buffer_start, buffer_size, handles, num_handles, flags); 199 mojo_handle, buffer_start, buffer_size, handles, num_handles, flags);
202 } 200 }
203 201
204 static jobject ReadMessage(JNIEnv* env, 202 static ScopedJavaLocalRef<jobject> ReadMessage(JNIEnv* env,
205 jobject jcaller, 203 jobject jcaller,
206 jint mojo_handle, 204 jint mojo_handle,
207 jobject bytes, 205 jobject bytes,
208 jobject handles_buffer, 206 jobject handles_buffer,
209 jint flags) { 207 jint flags) {
210 void* buffer_start = 0; 208 void* buffer_start = 0;
211 uint32_t buffer_size = 0; 209 uint32_t buffer_size = 0;
212 if (bytes) { 210 if (bytes) {
213 buffer_start = env->GetDirectBufferAddress(bytes); 211 buffer_start = env->GetDirectBufferAddress(bytes);
214 DCHECK(buffer_start); 212 DCHECK(buffer_start);
215 buffer_size = env->GetDirectBufferCapacity(bytes); 213 buffer_size = env->GetDirectBufferCapacity(bytes);
216 } 214 }
217 MojoHandle* handles = 0; 215 MojoHandle* handles = 0;
218 uint32_t num_handles = 0; 216 uint32_t num_handles = 0;
219 if (handles_buffer) { 217 if (handles_buffer) {
220 handles = 218 handles =
221 static_cast<MojoHandle*>(env->GetDirectBufferAddress(handles_buffer)); 219 static_cast<MojoHandle*>(env->GetDirectBufferAddress(handles_buffer));
222 num_handles = env->GetDirectBufferCapacity(handles_buffer) / 4; 220 num_handles = env->GetDirectBufferCapacity(handles_buffer) / 4;
223 } 221 }
224 MojoResult result = MojoReadMessage( 222 MojoResult result = MojoReadMessage(
225 mojo_handle, buffer_start, &buffer_size, handles, &num_handles, flags); 223 mojo_handle, buffer_start, &buffer_size, handles, &num_handles, flags);
226 // Jave code will handle taking ownership of any received handle. 224 // Jave code will handle taking ownership of any received handle.
227 return Java_CoreImpl_newReadMessageResult( 225 return Java_CoreImpl_newReadMessageResult(env, result, buffer_size,
228 env, result, buffer_size, num_handles).Release(); 226 num_handles);
229 } 227 }
230 228
231 static jobject ReadData(JNIEnv* env, 229 static ScopedJavaLocalRef<jobject> ReadData(JNIEnv* env,
232 jobject jcaller, 230 jobject jcaller,
233 jint mojo_handle, 231 jint mojo_handle,
234 jobject elements, 232 jobject elements,
235 jint elements_capacity, 233 jint elements_capacity,
236 jint flags) { 234 jint flags) {
237 void* buffer_start = 0; 235 void* buffer_start = 0;
238 uint32_t buffer_size = elements_capacity; 236 uint32_t buffer_size = elements_capacity;
239 if (elements) { 237 if (elements) {
240 buffer_start = env->GetDirectBufferAddress(elements); 238 buffer_start = env->GetDirectBufferAddress(elements);
241 DCHECK(buffer_start); 239 DCHECK(buffer_start);
242 DCHECK(elements_capacity <= env->GetDirectBufferCapacity(elements)); 240 DCHECK(elements_capacity <= env->GetDirectBufferCapacity(elements));
243 } 241 }
244 MojoResult result = 242 MojoResult result =
245 MojoReadData(mojo_handle, buffer_start, &buffer_size, flags); 243 MojoReadData(mojo_handle, buffer_start, &buffer_size, flags);
246 return Java_CoreImpl_newResultAndInteger( 244 return Java_CoreImpl_newResultAndInteger(
247 env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0) 245 env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0);
248 .Release();
249 } 246 }
250 247
251 static jobject BeginReadData(JNIEnv* env, 248 static ScopedJavaLocalRef<jobject> BeginReadData(JNIEnv* env,
252 jobject jcaller, 249 jobject jcaller,
253 jint mojo_handle, 250 jint mojo_handle,
254 jint num_bytes, 251 jint num_bytes,
255 jint flags) { 252 jint flags) {
256 void const* buffer = 0; 253 void const* buffer = 0;
257 uint32_t buffer_size = num_bytes; 254 uint32_t buffer_size = num_bytes;
258 MojoResult result = 255 MojoResult result =
259 MojoBeginReadData(mojo_handle, &buffer, &buffer_size, flags); 256 MojoBeginReadData(mojo_handle, &buffer, &buffer_size, flags);
260 jobject byte_buffer = 0; 257 jobject byte_buffer = 0;
261 if (result == MOJO_RESULT_OK) { 258 if (result == MOJO_RESULT_OK) {
262 byte_buffer = 259 byte_buffer =
263 env->NewDirectByteBuffer(const_cast<void*>(buffer), buffer_size); 260 env->NewDirectByteBuffer(const_cast<void*>(buffer), buffer_size);
264 } 261 }
265 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer).Release(); 262 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer);
266 } 263 }
267 264
268 static jint EndReadData(JNIEnv* env, 265 static jint EndReadData(JNIEnv* env,
269 jobject jcaller, 266 jobject jcaller,
270 jint mojo_handle, 267 jint mojo_handle,
271 jint num_bytes_read) { 268 jint num_bytes_read) {
272 return MojoEndReadData(mojo_handle, num_bytes_read); 269 return MojoEndReadData(mojo_handle, num_bytes_read);
273 } 270 }
274 271
275 static jobject WriteData(JNIEnv* env, 272 static ScopedJavaLocalRef<jobject> WriteData(JNIEnv* env,
276 jobject jcaller, 273 jobject jcaller,
277 jint mojo_handle, 274 jint mojo_handle,
278 jobject elements, 275 jobject elements,
279 jint limit, 276 jint limit,
280 jint flags) { 277 jint flags) {
281 void* buffer_start = env->GetDirectBufferAddress(elements); 278 void* buffer_start = env->GetDirectBufferAddress(elements);
282 DCHECK(buffer_start); 279 DCHECK(buffer_start);
283 DCHECK(limit <= env->GetDirectBufferCapacity(elements)); 280 DCHECK(limit <= env->GetDirectBufferCapacity(elements));
284 uint32_t buffer_size = limit; 281 uint32_t buffer_size = limit;
285 MojoResult result = 282 MojoResult result =
286 MojoWriteData(mojo_handle, buffer_start, &buffer_size, flags); 283 MojoWriteData(mojo_handle, buffer_start, &buffer_size, flags);
287 return Java_CoreImpl_newResultAndInteger( 284 return Java_CoreImpl_newResultAndInteger(
288 env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0) 285 env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0);
289 .Release();
290 } 286 }
291 287
292 static jobject BeginWriteData(JNIEnv* env, 288 static ScopedJavaLocalRef<jobject> BeginWriteData(JNIEnv* env,
293 jobject jcaller, 289 jobject jcaller,
294 jint mojo_handle, 290 jint mojo_handle,
295 jint num_bytes, 291 jint num_bytes,
296 jint flags) { 292 jint flags) {
297 void* buffer = 0; 293 void* buffer = 0;
298 uint32_t buffer_size = num_bytes; 294 uint32_t buffer_size = num_bytes;
299 MojoResult result = 295 MojoResult result =
300 MojoBeginWriteData(mojo_handle, &buffer, &buffer_size, flags); 296 MojoBeginWriteData(mojo_handle, &buffer, &buffer_size, flags);
301 jobject byte_buffer = 0; 297 jobject byte_buffer = 0;
302 if (result == MOJO_RESULT_OK) { 298 if (result == MOJO_RESULT_OK) {
303 byte_buffer = env->NewDirectByteBuffer(buffer, buffer_size); 299 byte_buffer = env->NewDirectByteBuffer(buffer, buffer_size);
304 } 300 }
305 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer).Release(); 301 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer);
306 } 302 }
307 303
308 static jint EndWriteData(JNIEnv* env, 304 static jint EndWriteData(JNIEnv* env,
309 jobject jcaller, 305 jobject jcaller,
310 jint mojo_handle, 306 jint mojo_handle,
311 jint num_bytes_written) { 307 jint num_bytes_written) {
312 return MojoEndWriteData(mojo_handle, num_bytes_written); 308 return MojoEndWriteData(mojo_handle, num_bytes_written);
313 } 309 }
314 310
315 static jobject Duplicate(JNIEnv* env, 311 static ScopedJavaLocalRef<jobject> Duplicate(JNIEnv* env,
316 jobject jcaller, 312 jobject jcaller,
317 jint mojo_handle, 313 jint mojo_handle,
318 jobject options_buffer) { 314 jobject options_buffer) {
319 const MojoDuplicateBufferHandleOptions* options = 0; 315 const MojoDuplicateBufferHandleOptions* options = 0;
320 if (options_buffer) { 316 if (options_buffer) {
321 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); 317 const void* buffer_start = env->GetDirectBufferAddress(options_buffer);
322 DCHECK(buffer_start); 318 DCHECK(buffer_start);
323 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); 319 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer);
324 DCHECK_EQ(buffer_size, sizeof(MojoDuplicateBufferHandleOptions)); 320 DCHECK_EQ(buffer_size, sizeof(MojoDuplicateBufferHandleOptions));
325 options = 321 options =
326 static_cast<const MojoDuplicateBufferHandleOptions*>(buffer_start); 322 static_cast<const MojoDuplicateBufferHandleOptions*>(buffer_start);
327 DCHECK_EQ(options->struct_size, buffer_size); 323 DCHECK_EQ(options->struct_size, buffer_size);
328 } 324 }
329 MojoHandle handle; 325 MojoHandle handle;
330 MojoResult result = MojoDuplicateBufferHandle(mojo_handle, options, &handle); 326 MojoResult result = MojoDuplicateBufferHandle(mojo_handle, options, &handle);
331 return Java_CoreImpl_newResultAndInteger(env, result, handle).Release(); 327 return Java_CoreImpl_newResultAndInteger(env, result, handle);
332 } 328 }
333 329
334 static jobject Map(JNIEnv* env, 330 static ScopedJavaLocalRef<jobject> Map(JNIEnv* env,
335 jobject jcaller, 331 jobject jcaller,
336 jint mojo_handle, 332 jint mojo_handle,
337 jlong offset, 333 jlong offset,
338 jlong num_bytes, 334 jlong num_bytes,
339 jint flags) { 335 jint flags) {
340 void* buffer = 0; 336 void* buffer = 0;
341 MojoResult result = 337 MojoResult result =
342 MojoMapBuffer(mojo_handle, offset, num_bytes, &buffer, flags); 338 MojoMapBuffer(mojo_handle, offset, num_bytes, &buffer, flags);
343 jobject byte_buffer = 0; 339 jobject byte_buffer = 0;
344 if (result == MOJO_RESULT_OK) { 340 if (result == MOJO_RESULT_OK) {
345 byte_buffer = env->NewDirectByteBuffer(buffer, num_bytes); 341 byte_buffer = env->NewDirectByteBuffer(buffer, num_bytes);
346 } 342 }
347 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer).Release(); 343 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer);
348 } 344 }
349 345
350 static int Unmap(JNIEnv* env, jobject jcaller, jobject buffer) { 346 static int Unmap(JNIEnv* env, jobject jcaller, jobject buffer) {
351 void* buffer_start = env->GetDirectBufferAddress(buffer); 347 void* buffer_start = env->GetDirectBufferAddress(buffer);
352 DCHECK(buffer_start); 348 DCHECK(buffer_start);
353 return MojoUnmapBuffer(buffer_start); 349 return MojoUnmapBuffer(buffer_start);
354 } 350 }
355 351
356 static jobject AsyncWait(JNIEnv* env, 352 static ScopedJavaLocalRef<jobject> AsyncWait(JNIEnv* env,
357 jobject jcaller, 353 jobject jcaller,
358 jint mojo_handle, 354 jint mojo_handle,
359 jint signals, 355 jint signals,
360 jlong deadline, 356 jlong deadline,
361 jobject callback) { 357 jobject callback) {
362 AsyncWaitCallbackData* callback_data = 358 AsyncWaitCallbackData* callback_data =
363 new AsyncWaitCallbackData(env, jcaller, callback); 359 new AsyncWaitCallbackData(env, jcaller, callback);
364 MojoAsyncWaitID cancel_id; 360 MojoAsyncWaitID cancel_id;
365 if (static_cast<MojoHandle>(mojo_handle) != MOJO_HANDLE_INVALID) { 361 if (static_cast<MojoHandle>(mojo_handle) != MOJO_HANDLE_INVALID) {
366 cancel_id = Environment::GetDefaultAsyncWaiter()->AsyncWait( 362 cancel_id = Environment::GetDefaultAsyncWaiter()->AsyncWait(
367 mojo_handle, signals, deadline, AsyncWaitCallback, callback_data); 363 mojo_handle, signals, deadline, AsyncWaitCallback, callback_data);
368 } else { 364 } else {
369 cancel_id = kInvalidHandleCancelID; 365 cancel_id = kInvalidHandleCancelID;
370 base::MessageLoop::current()->PostTask( 366 base::MessageLoop::current()->PostTask(
371 FROM_HERE, 367 FROM_HERE,
372 base::Bind( 368 base::Bind(
373 &AsyncWaitCallback, callback_data, MOJO_RESULT_INVALID_ARGUMENT)); 369 &AsyncWaitCallback, callback_data, MOJO_RESULT_INVALID_ARGUMENT));
374 } 370 }
375 base::android::ScopedJavaLocalRef<jobject> cancellable = 371 base::android::ScopedJavaLocalRef<jobject> cancellable =
376 Java_CoreImpl_newAsyncWaiterCancellableImpl( 372 Java_CoreImpl_newAsyncWaiterCancellableImpl(
377 env, jcaller, cancel_id, reinterpret_cast<intptr_t>(callback_data)); 373 env, jcaller, cancel_id, reinterpret_cast<intptr_t>(callback_data));
378 callback_data->cancellable.Reset(env, cancellable.obj()); 374 callback_data->cancellable.Reset(env, cancellable.obj());
379 return cancellable.Release(); 375 return cancellable;
380 } 376 }
381 377
382 static void CancelAsyncWait(JNIEnv* env, 378 static void CancelAsyncWait(JNIEnv* env,
383 jobject jcaller, 379 jobject jcaller,
384 jlong id, 380 jlong id,
385 jlong data_ptr) { 381 jlong data_ptr) {
386 if (id == 0) { 382 if (id == 0) {
387 // If |id| is |kInvalidHandleCancelID|, the async wait was done on an 383 // If |id| is |kInvalidHandleCancelID|, the async wait was done on an
388 // invalid handle, so the AsyncWaitCallback will be called and will clear 384 // invalid handle, so the AsyncWaitCallback will be called and will clear
389 // the data_ptr. 385 // the data_ptr.
390 return; 386 return;
391 } 387 }
392 scoped_ptr<AsyncWaitCallbackData> deleter( 388 scoped_ptr<AsyncWaitCallbackData> deleter(
393 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); 389 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr));
394 Environment::GetDefaultAsyncWaiter()->CancelWait(id); 390 Environment::GetDefaultAsyncWaiter()->CancelWait(id);
395 } 391 }
396 392
397 static jint GetNativeBufferOffset(JNIEnv* env, 393 static jint GetNativeBufferOffset(JNIEnv* env,
398 jobject jcaller, 394 jobject jcaller,
399 jobject buffer, 395 jobject buffer,
400 jint alignment) { 396 jint alignment) {
401 jint offset = 397 jint offset =
402 reinterpret_cast<uintptr_t>(env->GetDirectBufferAddress(buffer)) % 398 reinterpret_cast<uintptr_t>(env->GetDirectBufferAddress(buffer)) %
403 alignment; 399 alignment;
404 if (offset == 0) 400 if (offset == 0)
405 return 0; 401 return 0;
406 return alignment - offset; 402 return alignment - offset;
407 } 403 }
408 404
409 static jobject GetBufferInformation(JNIEnv* env, 405 static ScopedJavaLocalRef<jobject> GetBufferInformation(JNIEnv* env,
410 jobject jcaller, 406 jobject jcaller,
411 jint mojo_handle) { 407 jint mojo_handle) {
412 MojoBufferInformation buffer_information; 408 MojoBufferInformation buffer_information;
413 MojoResult result = 409 MojoResult result =
414 MojoGetBufferInformation(static_cast<MojoHandle>(mojo_handle), 410 MojoGetBufferInformation(static_cast<MojoHandle>(mojo_handle),
415 &buffer_information, sizeof(buffer_information)); 411 &buffer_information, sizeof(buffer_information));
416 return Java_CoreImpl_newResultAndBufferInformation( 412 return Java_CoreImpl_newResultAndBufferInformation(
417 env, result, buffer_information.flags, 413 env, result, buffer_information.flags, buffer_information.num_bytes);
418 buffer_information.num_bytes)
419 .Release();
420 } 414 }
421 415
422 bool RegisterCoreImpl(JNIEnv* env) { 416 bool RegisterCoreImpl(JNIEnv* env) {
423 return RegisterNativesImpl(env); 417 return RegisterNativesImpl(env);
424 } 418 }
425 419
426 } // namespace android 420 } // namespace android
427 } // namespace mojo 421 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/android/javatests/validation_test_util.cc ('k') | shell/android/android_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698