| OLD | NEW |
| 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 part of core; | 5 part of core; |
| 6 | 6 |
| 7 class _MojoSharedBufferNatives { | 7 class _MojoSharedBufferNatives { |
| 8 static List Create(int num_bytes, int flags) | 8 static List Create(int num_bytes, int flags) |
| 9 native "MojoSharedBuffer_Create"; | 9 native "MojoSharedBuffer_Create"; |
| 10 | 10 |
| 11 static List Duplicate(int buffer_handle, int flags) | 11 static List Duplicate(int buffer_handle, int flags) |
| 12 native "MojoSharedBuffer_Duplicate"; | 12 native "MojoSharedBuffer_Duplicate"; |
| 13 | 13 |
| 14 static List Map(int buffer_handle, int offset, int num_bytes, int flags) | 14 static List Map(MojoSharedBuffer buffer, |
| 15 int buffer_handle, |
| 16 int offset, |
| 17 int num_bytes, |
| 18 int flags) |
| 15 native "MojoSharedBuffer_Map"; | 19 native "MojoSharedBuffer_Map"; |
| 16 | 20 |
| 17 static int Unmap(ByteData buffer) | 21 static int Unmap(ByteData buffer) |
| 18 native "MojoSharedBuffer_Unmap"; | 22 native "MojoSharedBuffer_Unmap"; |
| 19 } | 23 } |
| 20 | 24 |
| 21 | 25 |
| 22 class MojoSharedBuffer { | 26 class MojoSharedBuffer { |
| 23 static const int CREATE_FLAG_NONE = 0; | 27 static const int CREATE_FLAG_NONE = 0; |
| 24 static const int DUPLICATE_FLAG_NONE = 0; | 28 static const int DUPLICATE_FLAG_NONE = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 63 } |
| 60 assert((result is List) && (result.length == 2)); | 64 assert((result is List) && (result.length == 2)); |
| 61 var r = new MojoResult(result[0]); | 65 var r = new MojoResult(result[0]); |
| 62 if(!r.isOk) { | 66 if(!r.isOk) { |
| 63 return null; | 67 return null; |
| 64 } | 68 } |
| 65 | 69 |
| 66 MojoSharedBuffer dupe = new MojoSharedBuffer._(); | 70 MojoSharedBuffer dupe = new MojoSharedBuffer._(); |
| 67 dupe.status = r; | 71 dupe.status = r; |
| 68 dupe.handle = new RawMojoHandle(result[1]); | 72 dupe.handle = new RawMojoHandle(result[1]); |
| 69 dupe.mapping = msb.mapping; | 73 dupe.mapping = null; // The buffer is not mapped in the duplicate. |
| 70 return dupe; | 74 return dupe; |
| 71 } | 75 } |
| 72 | 76 |
| 73 MojoResult close() { | 77 MojoResult close() { |
| 74 if (handle == null) { | 78 if (handle == null) { |
| 75 status = MojoResult.INVALID_ARGUMENT; | 79 status = MojoResult.INVALID_ARGUMENT; |
| 76 return status; | 80 return status; |
| 77 } | 81 } |
| 78 MojoResult r = handle.close(); | 82 MojoResult r = handle.close(); |
| 79 status = r; | 83 status = r; |
| 80 mapping = null; | 84 mapping = null; |
| 81 return status; | 85 return status; |
| 82 } | 86 } |
| 83 | 87 |
| 84 MojoResult map(int offset, int num_bytes, [int flags = 0]) { | 88 MojoResult map(int offset, int num_bytes, [int flags = 0]) { |
| 85 if (handle == null) { | 89 if (handle == null) { |
| 86 status = MojoResult.INVALID_ARGUMENT; | 90 status = MojoResult.INVALID_ARGUMENT; |
| 87 return status; | 91 return status; |
| 88 } | 92 } |
| 89 List result = _MojoSharedBufferNatives.Map( | 93 List result = _MojoSharedBufferNatives.Map( |
| 90 handle.h, offset, num_bytes, flags); | 94 this, handle.h, offset, num_bytes, flags); |
| 91 if (result == null) { | 95 if (result == null) { |
| 92 status = MojoResult.INVALID_ARGUMENT; | 96 status = MojoResult.INVALID_ARGUMENT; |
| 93 return status; | 97 return status; |
| 94 } | 98 } |
| 95 assert((result is List) && (result.length == 2)); | 99 assert((result is List) && (result.length == 2)); |
| 96 status = new MojoResult(result[0]); | 100 status = new MojoResult(result[0]); |
| 97 mapping = result[1]; | 101 mapping = result[1]; |
| 98 return status; | 102 return status; |
| 99 } | 103 } |
| 100 | 104 |
| 101 MojoResult unmap() { | 105 MojoResult unmap() { |
| 102 int r = _MojoSharedBufferNatives.Unmap(mapping); | 106 int r = _MojoSharedBufferNatives.Unmap(mapping); |
| 103 status = new MojoResult(r); | 107 status = new MojoResult(r); |
| 104 mapping = null; | 108 mapping = null; |
| 105 return status; | 109 return status; |
| 106 } | 110 } |
| 107 } | 111 } |
| OLD | NEW |