OLD | NEW |
1 // Copyright (c) 2012 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 "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 namespace android { | 74 namespace android { |
75 | 75 |
76 JNIEnv* AttachCurrentThread() { | 76 JNIEnv* AttachCurrentThread() { |
77 DCHECK(g_jvm); | 77 DCHECK(g_jvm); |
78 JNIEnv* env = NULL; | 78 JNIEnv* env = NULL; |
79 jint ret = g_jvm->AttachCurrentThread(&env, NULL); | 79 jint ret = g_jvm->AttachCurrentThread(&env, NULL); |
80 DCHECK_EQ(JNI_OK, ret); | 80 DCHECK_EQ(JNI_OK, ret); |
81 return env; | 81 return env; |
82 } | 82 } |
83 | 83 |
| 84 JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) { |
| 85 DCHECK(g_jvm); |
| 86 JavaVMAttachArgs args; |
| 87 args.version = JNI_VERSION_1_2; |
| 88 args.name = thread_name.c_str(); |
| 89 args.group = NULL; |
| 90 JNIEnv* env = NULL; |
| 91 jint ret = g_jvm->AttachCurrentThread(&env, &args); |
| 92 DCHECK_EQ(JNI_OK, ret); |
| 93 return env; |
| 94 } |
| 95 |
84 void DetachFromVM() { | 96 void DetachFromVM() { |
85 // Ignore the return value, if the thread is not attached, DetachCurrentThread | 97 // Ignore the return value, if the thread is not attached, DetachCurrentThread |
86 // will fail. But it is ok as the native thread may never be attached. | 98 // will fail. But it is ok as the native thread may never be attached. |
87 if (g_jvm) | 99 if (g_jvm) |
88 g_jvm->DetachCurrentThread(); | 100 g_jvm->DetachCurrentThread(); |
89 } | 101 } |
90 | 102 |
91 void InitVM(JavaVM* vm) { | 103 void InitVM(JavaVM* vm) { |
92 DCHECK(!g_jvm); | 104 DCHECK(!g_jvm); |
93 g_jvm = vm; | 105 g_jvm = vm; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // RVO should avoid any extra copies of the exception string. | 211 // RVO should avoid any extra copies of the exception string. |
200 base::android::BuildInfo::GetInstance()->set_java_exception_info( | 212 base::android::BuildInfo::GetInstance()->set_java_exception_info( |
201 GetJavaExceptionInfo(env, java_throwable)); | 213 GetJavaExceptionInfo(env, java_throwable)); |
202 | 214 |
203 // Now, feel good about it and die. | 215 // Now, feel good about it and die. |
204 CHECK(false); | 216 CHECK(false); |
205 } | 217 } |
206 | 218 |
207 } // namespace android | 219 } // namespace android |
208 } // namespace base | 220 } // namespace base |
OLD | NEW |