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

Side by Side Diff: jni/JniLogSystem.cpp

Issue 4761138508070912: Issue 1848 - Clean up local reference handling (Closed)
Patch Set: Created Jan. 22, 2015, 6:53 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/JniJsValue.cpp ('k') | jni/JniUpdateAvailableCallback.cpp » ('j') | 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 22 matching lines...) Expand all
33 33
34 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) 34 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject)
35 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem(), logLevelClas s(new JniGlobalReference<jclass>(env, env->FindClass(PKG("LogSystem$LogLevel"))) ) 35 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem(), logLevelClas s(new JniGlobalReference<jclass>(env, env->FindClass(PKG("LogSystem$LogLevel"))) )
36 { 36 {
37 } 37 }
38 38
39 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source) 39 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source)
40 { 40 {
41 JNIEnvAcquire env(GetJavaVM()); 41 JNIEnvAcquire env(GetJavaVM());
42 42
43 jclass clazz = env->GetObjectClass(GetCallbackObject()); 43 jmethodID method = env->GetMethodID(
44 jmethodID method = env->GetMethodID(clazz, "logCallback", "(" TYP("LogSystem$L ogLevel") "Ljava/lang/String;Ljava/lang/String;)V"); 44 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())) ,
45 "logCallback", "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang /String;)V");
45 46
46 // TODO: Set log level from Java and handle it here (to reduce C++->Java calls ) 47 // TODO: Set log level from Java and handle it here (to reduce C++->Java calls )
47 48
48 if (method) 49 if (method)
49 { 50 {
50 const char* enumName = 0; 51 const char* enumName = 0;
51 52
52 switch (logLevel) 53 switch (logLevel)
53 { 54 {
54 default: 55 default:
(...skipping 11 matching lines...) Expand all
66 break; 67 break;
67 case AdblockPlus::LogSystem::LOG_LEVEL_ERROR: 68 case AdblockPlus::LogSystem::LOG_LEVEL_ERROR:
68 enumName = "ERROR"; 69 enumName = "ERROR";
69 break; 70 break;
70 } 71 }
71 72
72 jclass enumClass = logLevelClass->Get(); 73 jclass enumClass = logLevelClass->Get();
73 if (enumClass) 74 if (enumClass)
74 { 75 {
75 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("LogSy stem$LogLevel")); 76 jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("LogSy stem$LogLevel"));
76 jobject jLogLevel = env->GetStaticObjectField(enumClass, enumField); 77 JniLocalReference<jobject> jLogLevel(*env, env->GetStaticObjectField(enumC lass, enumField));
77 78
78 jstring jMessage = env->NewStringUTF(message.c_str()); 79 JniLocalReference<jstring> jMessage(*env, env->NewStringUTF(message.c_str( )));
79 jstring jSource = env->NewStringUTF(source.c_str()); 80 JniLocalReference<jstring> jSource(*env, env->NewStringUTF(source.c_str()) );
80 81
81 env->CallVoidMethod(GetCallbackObject(), method, jLogLevel, jMessage, jSou rce); 82 env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage, *j Source);
82 } 83 }
83 84
84 CheckAndLogJavaException(*env); 85 CheckAndLogJavaException(*env);
85 } 86 }
86 } 87 }
87 88
88 static JNINativeMethod methods[] = 89 static JNINativeMethod methods[] =
89 { 90 {
90 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 91 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
91 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 92 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
92 }; 93 };
93 94
94 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_ registerNatives(JNIEnv *env, jclass clazz) 95 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_ registerNatives(JNIEnv *env, jclass clazz)
95 { 96 {
96 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 97 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
97 } 98 }
OLDNEW
« no previous file with comments | « jni/JniJsValue.cpp ('k') | jni/JniUpdateAvailableCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld