Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: jni/Utils.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Stupid auto-formatter^^ Created Feb. 4, 2015, 12:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « jni/Utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 17 matching lines...) Expand all
28 28
29 const char* cStr = env->GetStringUTFChars(str, 0); 29 const char* cStr = env->GetStringUTFChars(str, 0);
30 std::string ret(cStr); 30 std::string ret(cStr);
31 env->ReleaseStringUTFChars(str, cStr); 31 env->ReleaseStringUTFChars(str, cStr);
32 32
33 return ret; 33 return ret;
34 } 34 }
35 35
36 jobject NewJniArrayList(JNIEnv* env) 36 jobject NewJniArrayList(JNIEnv* env)
37 { 37 {
38 jclass clazz = env->FindClass("java/util/ArrayList"); 38 JniLocalReference<jclass> clazz(env, env->FindClass("java/util/ArrayList"));
39 jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V"); 39 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "()V");
40 return env->NewObject(clazz, ctor); 40 return env->NewObject(*clazz, ctor);
41 } 41 }
42 42
43 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value) 43 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value)
44 { 44 {
45 jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lan g/Object;)Z"); 45 JniLocalReference<jclass> clazz(env, env->GetObjectClass(list));
46 jmethodID add = env->GetMethodID(*clazz, "add", "(Ljava/lang/Object;)Z");
46 env->CallBooleanMethod(list, add, value); 47 env->CallBooleanMethod(list, add, value);
47 } 48 }
48 49
49 void JniThrowException(JNIEnv* env, const std::string& message) 50 void JniThrowException(JNIEnv* env, const std::string& message)
50 { 51 {
51 jclass clazz = env->FindClass(PKG("AdblockPlusException")); 52 JniLocalReference<jclass> clazz(env,
52 env->ThrowNew(clazz, message.c_str()); 53 env->FindClass(PKG("AdblockPlusException")));
54 env->ThrowNew(*clazz, message.c_str());
53 } 55 }
54 56
55 void JniThrowException(JNIEnv* env, const std::exception& e) 57 void JniThrowException(JNIEnv* env, const std::exception& e)
56 { 58 {
57 JniThrowException(env, e.what()); 59 JniThrowException(env, e.what());
58 } 60 }
59 61
60 void JniThrowException(JNIEnv* env) 62 void JniThrowException(JNIEnv* env)
61 { 63 {
62 JniThrowException(env, "Unknown exception from libadblockplus"); 64 JniThrowException(env, "Unknown exception from libadblockplus");
(...skipping 14 matching lines...) Expand all
77 } 79 }
78 } 80 }
79 81
80 JNIEnvAcquire::~JNIEnvAcquire() 82 JNIEnvAcquire::~JNIEnvAcquire()
81 { 83 {
82 if (attachmentStatus == JNI_EDETACHED) 84 if (attachmentStatus == JNI_EDETACHED)
83 { 85 {
84 javaVM->DetachCurrentThread(); 86 javaVM->DetachCurrentThread();
85 } 87 }
86 } 88 }
OLDNEW
« no previous file with comments | « jni/Utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld