| 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 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 16 #include "dart/runtime/include/dart_api.h" | 17 #include "dart/runtime/include/dart_api.h" |
| 17 #include "mojo/dart/embedder/builtin.h" | 18 #include "mojo/dart/embedder/builtin.h" |
| 18 | 19 |
| 19 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 20 #include <android/log.h> | 21 #include <android/log.h> |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 namespace mojo { | 24 namespace mojo { |
| 24 namespace dart { | 25 namespace dart { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 const int64_t kMaxRandomBytes = 4096; | 115 const int64_t kMaxRandomBytes = 4096; |
| 115 int64_t count64 = 0; | 116 int64_t count64 = 0; |
| 116 if (!GetInt64Value(count_obj, &count64) || (count64 < 0) || | 117 if (!GetInt64Value(count_obj, &count64) || (count64 < 0) || |
| 117 (count64 > kMaxRandomBytes)) { | 118 (count64 > kMaxRandomBytes)) { |
| 118 Dart_Handle error = Dart_NewStringFromCString( | 119 Dart_Handle error = Dart_NewStringFromCString( |
| 119 "Invalid argument: count must be a positive int " | 120 "Invalid argument: count must be a positive int " |
| 120 "less than or equal to 4096."); | 121 "less than or equal to 4096."); |
| 121 Dart_ThrowException(error); | 122 Dart_ThrowException(error); |
| 122 } | 123 } |
| 123 intptr_t count = static_cast<intptr_t>(count64); | 124 intptr_t count = static_cast<intptr_t>(count64); |
| 124 scoped_ptr<uint8_t[]> buffer(new uint8_t[count]); | 125 std::unique_ptr<uint8_t[]> buffer(new uint8_t[count]); |
| 125 | 126 |
| 126 base::RandBytes(reinterpret_cast<void*>(buffer.get()), count); | 127 base::RandBytes(reinterpret_cast<void*>(buffer.get()), count); |
| 127 | 128 |
| 128 Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, count); | 129 Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, count); |
| 129 if (Dart_IsError(result)) { | 130 if (Dart_IsError(result)) { |
| 130 Dart_Handle error = Dart_NewStringFromCString( | 131 Dart_Handle error = Dart_NewStringFromCString( |
| 131 "Failed to allocate storage."); | 132 "Failed to allocate storage."); |
| 132 Dart_ThrowException(error); | 133 Dart_ThrowException(error); |
| 133 } | 134 } |
| 134 Dart_ListSetAsBytes(result, 0, buffer.get(), count); | 135 Dart_ListSetAsBytes(result, 0, buffer.get(), count); |
| 135 Dart_SetReturnValue(args, result); | 136 Dart_SetReturnValue(args, result); |
| 136 } | 137 } |
| 137 | 138 |
| 138 } // namespace bin | 139 } // namespace bin |
| 139 } // namespace dart | 140 } // namespace dart |
| OLD | NEW |