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 <string.h> | 6 #include <string.h> |
7 #include <set> | |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "dart/runtime/include/dart_api.h" | 13 #include "dart/runtime/include/dart_api.h" |
13 #include "mojo/dart/embedder/builtin.h" | 14 #include "mojo/dart/embedder/builtin.h" |
15 #include "mojo/dart/embedder/isolate_data.h" | |
14 #include "mojo/public/c/system/core.h" | 16 #include "mojo/public/c/system/core.h" |
15 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
16 | 18 |
17 namespace mojo { | 19 namespace mojo { |
18 namespace dart { | 20 namespace dart { |
19 | 21 |
20 #define MOJO_NATIVE_LIST(V) \ | 22 #define MOJO_NATIVE_LIST(V) \ |
21 V(MojoSharedBuffer_Create, 2) \ | 23 V(MojoSharedBuffer_Create, 2) \ |
22 V(MojoSharedBuffer_Duplicate, 2) \ | 24 V(MojoSharedBuffer_Duplicate, 2) \ |
23 V(MojoSharedBuffer_Map, 5) \ | 25 V(MojoSharedBuffer_Map, 5) \ |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 struct CloserCallbackPeer { | 117 struct CloserCallbackPeer { |
116 MojoHandle handle; | 118 MojoHandle handle; |
117 }; | 119 }; |
118 | 120 |
119 static void MojoHandleCloserCallback(void* isolate_data, | 121 static void MojoHandleCloserCallback(void* isolate_data, |
120 Dart_WeakPersistentHandle handle, | 122 Dart_WeakPersistentHandle handle, |
121 void* peer) { | 123 void* peer) { |
122 CloserCallbackPeer* callback_peer = | 124 CloserCallbackPeer* callback_peer = |
123 reinterpret_cast<CloserCallbackPeer*>(peer); | 125 reinterpret_cast<CloserCallbackPeer*>(peer); |
124 if (callback_peer->handle != MOJO_HANDLE_INVALID) { | 126 if (callback_peer->handle != MOJO_HANDLE_INVALID) { |
125 MojoClose(callback_peer->handle); | 127 MojoResult res = MojoClose(callback_peer->handle); |
128 if (res == MOJO_RESULT_OK) { | |
129 LOG(ERROR) << "Handle Finalizer closing handle:\n\tisolate: " | |
sky
2015/03/11 17:17:57
Why the LOG(ERROR) here? Doesn't MOJO_RESULT_OK me
zra
2015/03/11 18:58:20
If the finalizer callback successfully closes a ha
| |
130 << "\n\thandle: " << callback_peer->handle; | |
131 } | |
126 } | 132 } |
127 delete callback_peer; | 133 delete callback_peer; |
128 } | 134 } |
129 | 135 |
130 // Setup a weak persistent handle for a Dart MojoHandle that calls MojoClose | 136 // Setup a weak persistent handle for a Dart MojoHandle that calls MojoClose |
131 // on the handle when the MojoHandle is GC'd or the VM is going down. | 137 // on the handle when the MojoHandle is GC'd or the VM is going down. |
132 void MojoHandle_Register(Dart_NativeArguments arguments) { | 138 void MojoHandle_Register(Dart_NativeArguments arguments) { |
133 // An instance of Dart class MojoHandle. | 139 // An instance of Dart class MojoHandle. |
134 Dart_Handle mojo_handle_instance = Dart_GetNativeArgument(arguments, 0); | 140 Dart_Handle mojo_handle_instance = Dart_GetNativeArgument(arguments, 0); |
135 if (!Dart_IsInstance(mojo_handle_instance)) { | 141 if (!Dart_IsInstance(mojo_handle_instance)) { |
(...skipping 24 matching lines...) Expand all Loading... | |
160 if (Dart_IsError(result)) { | 166 if (Dart_IsError(result)) { |
161 SetInvalidArgumentReturn(arguments); | 167 SetInvalidArgumentReturn(arguments); |
162 return; | 168 return; |
163 } | 169 } |
164 | 170 |
165 if (raw_handle == static_cast<int64_t>(MOJO_HANDLE_INVALID)) { | 171 if (raw_handle == static_cast<int64_t>(MOJO_HANDLE_INVALID)) { |
166 SetInvalidArgumentReturn(arguments); | 172 SetInvalidArgumentReturn(arguments); |
167 return; | 173 return; |
168 } | 174 } |
169 | 175 |
176 // Add the handle to this isolate's set. | |
177 Dart_Isolate isolate = Dart_CurrentIsolate(); | |
178 void* data = Dart_IsolateData(isolate); | |
179 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); | |
180 isolate_data->unclosed_handles.insert(raw_handle); | |
181 | |
182 // Set up a finalizer. | |
170 CloserCallbackPeer* callback_peer = new CloserCallbackPeer(); | 183 CloserCallbackPeer* callback_peer = new CloserCallbackPeer(); |
171 callback_peer->handle = static_cast<MojoHandle>(raw_handle); | 184 callback_peer->handle = static_cast<MojoHandle>(raw_handle); |
172 Dart_NewWeakPersistentHandle(mojo_handle_instance, | 185 Dart_NewWeakPersistentHandle(mojo_handle_instance, |
173 reinterpret_cast<void*>(callback_peer), | 186 reinterpret_cast<void*>(callback_peer), |
174 sizeof(CloserCallbackPeer), | 187 sizeof(CloserCallbackPeer), |
175 MojoHandleCloserCallback); | 188 MojoHandleCloserCallback); |
176 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); | 189 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); |
177 } | 190 } |
178 | 191 |
179 void MojoHandle_Close(Dart_NativeArguments arguments) { | 192 void MojoHandle_Close(Dart_NativeArguments arguments) { |
180 int64_t handle; | 193 int64_t handle; |
181 CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument); | 194 CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument); |
182 | 195 |
196 // Remove the handle from this isolate's set. | |
197 Dart_Isolate isolate = Dart_CurrentIsolate(); | |
198 void* data = Dart_IsolateData(isolate); | |
199 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); | |
200 isolate_data->unclosed_handles.erase(handle); | |
201 | |
183 MojoResult res = MojoClose(static_cast<MojoHandle>(handle)); | 202 MojoResult res = MojoClose(static_cast<MojoHandle>(handle)); |
184 | 203 |
185 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res)); | 204 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res)); |
186 } | 205 } |
187 | 206 |
188 void MojoHandle_Wait(Dart_NativeArguments arguments) { | 207 void MojoHandle_Wait(Dart_NativeArguments arguments) { |
189 int64_t handle = 0; | 208 int64_t handle = 0; |
190 int64_t signals = 0; | 209 int64_t signals = 0; |
191 int64_t deadline = 0; | 210 int64_t deadline = 0; |
192 CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument); | 211 CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument); |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 mojo_control_handle = control_handle; | 812 mojo_control_handle = control_handle; |
794 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); | 813 Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(MOJO_RESULT_OK)); |
795 } | 814 } |
796 | 815 |
797 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { | 816 void MojoHandleWatcher_GetControlHandle(Dart_NativeArguments arguments) { |
798 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); | 817 Dart_SetIntegerReturnValue(arguments, mojo_control_handle); |
799 } | 818 } |
800 | 819 |
801 } // namespace dart | 820 } // namespace dart |
802 } // namespace mojo | 821 } // namespace mojo |
OLD | NEW |