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

Delta Between Two Patch Sets: libadblockplus-android/jni/JniFileSystem.cpp

Issue 29347315: Issue 4231 - Fix unstable FilterEngineTest.testSetRemoveFilterChangeCallback (Closed)
Left Patch Set: Introduced file system abstraction to java and using LazyFileSystem for filter tests Created July 10, 2016, 10:47 a.m.
Right Patch Set: made helper methods static, fixed 'remove' for fs callback Created Dec. 13, 2016, 9:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 "read", 50 "read",
51 "(Ljava/lang/String;)Ljava/lang/String;"); 51 "(Ljava/lang/String;)Ljava/lang/String;");
52 52
53 JniLocalReference<jstring> jPath(*env, env->NewStringUTF(path.c_str())); 53 JniLocalReference<jstring> jPath(*env, env->NewStringUTF(path.c_str()));
54 jstring jData = (jstring)env->CallObjectMethod(GetCallbackObject(), method, *j Path); 54 jstring jData = (jstring)env->CallObjectMethod(GetCallbackObject(), method, *j Path);
55 CheckAndLogJavaException(*env); 55 CheckAndLogJavaException(*env);
56 56
57 if (!jData) 57 if (!jData)
58 return NULL; 58 return NULL;
59 59
60 std::string cData = JniJavaToStdString(*env, jData); 60 std::string cData = JniJavaToStdString(*env, jData);
anton 2016/07/10 10:53:11 some concern here - since it's extremely difficult
61 std::shared_ptr<std::istream> cSharedStream(new std::istringstream(cData)); 61 std::shared_ptr<std::istream> cSharedStream(new std::istringstream(cData));
62 return cSharedStream; 62 return cSharedStream;
63 } 63 }
64 64
65 void JniFileSystemCallback::Write(const std::string& path, std::shared_ptr<std:: istream> data) 65 void JniFileSystemCallback::Write(const std::string& path, std::shared_ptr<std:: istream> data)
66 { 66 {
67 JNIEnvAcquire env(GetJavaVM()); 67 JNIEnvAcquire env(GetJavaVM());
68 68
69 jmethodID method = env->GetMethodID( 69 jmethodID method = env->GetMethodID(
70 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())), 70 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())),
71 "write", 71 "write",
72 "(Ljava/lang/String;Ljava/lang/String;)V"); 72 "(Ljava/lang/String;Ljava/lang/String;)V");
73 73
74 JniLocalReference<jstring> jPath(*env, env->NewStringUTF(path.c_str())); 74 JniLocalReference<jstring> jPath(*env, env->NewStringUTF(path.c_str()));
75 75
76 // read all the data from the stream into buffer (no appropriate way to pass s treams over JNI) 76 // read all the data from the stream into buffer (no appropriate way to pass s treams over JNI)
77 std::string cData = JniStdStreamToStdString(data.get()); 77 std::string cData = JniStdStreamToStdString(data.get());
anton 2016/07/10 10:53:11 some concern here too - since it's extremely diffi
78 JniLocalReference<jstring> jData(*env, env->NewStringUTF(cData.c_str())); 78 JniLocalReference<jstring> jData(*env, env->NewStringUTF(cData.c_str()));
79 79
80 env->CallVoidMethod(GetCallbackObject(), method, *jPath, *jData); 80 env->CallVoidMethod(GetCallbackObject(), method, *jPath, *jData);
81 CheckAndLogJavaException(*env); 81 CheckAndLogJavaException(*env);
82 } 82 }
83 83
84 void JniFileSystemCallback::Move(const std::string& fromPath, const std::string& toPath) 84 void JniFileSystemCallback::Move(const std::string& fromPath, const std::string& toPath)
85 { 85 {
86 JNIEnvAcquire env(GetJavaVM()); 86 JNIEnvAcquire env(GetJavaVM());
87 87
88 jmethodID method = env->GetMethodID( 88 jmethodID method = env->GetMethodID(
89 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())), 89 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())),
90 "move", 90 "move",
91 "(Ljava/lang/String;Ljava/lang/String;)V"); 91 "(Ljava/lang/String;Ljava/lang/String;)V");
92 92
93 JniLocalReference<jstring> jFromPath(*env, env->NewStringUTF(fromPath.c_str()) ); 93 JniLocalReference<jstring> jFromPath(*env, env->NewStringUTF(fromPath.c_str()) );
94 JniLocalReference<jstring> jToPath(*env, env->NewStringUTF(toPath.c_str())); 94 JniLocalReference<jstring> jToPath(*env, env->NewStringUTF(toPath.c_str()));
95 95
96 env->CallVoidMethod(GetCallbackObject(), method, *jFromPath, *jToPath); 96 env->CallVoidMethod(GetCallbackObject(), method, *jFromPath, *jToPath);
97 CheckAndLogJavaException(*env); 97 CheckAndLogJavaException(*env);
98 } 98 }
99 99
100 void JniFileSystemCallback::Remove(const std::string& path) 100 void JniFileSystemCallback::Remove(const std::string& path)
101 { 101 {
102 JNIEnvAcquire env(GetJavaVM()); 102 JNIEnvAcquire env(GetJavaVM());
103 103
104 jmethodID method = env->GetMethodID( 104 jmethodID method = env->GetMethodID(
105 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())), 105 *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())),
106 "move", 106 "remove",
107 "(Ljava/lang/String;Ljava/lang/String;)V"); 107 "(Ljava/lang/String;)V");
108 108
109 JniLocalReference<jstring> jPath(*env, env->NewStringUTF(path.c_str())); 109 JniLocalReference<jstring> jPath(*env, env->NewStringUTF(path.c_str()));
110 110
111 env->CallVoidMethod(GetCallbackObject(), method, *jPath); 111 env->CallVoidMethod(GetCallbackObject(), method, *jPath);
112 CheckAndLogJavaException(*env); 112 CheckAndLogJavaException(*env);
113 } 113 }
114 114
115 AdblockPlus::FileSystem::StatResult JniFileSystemCallback::Stat(const std::strin g& path) const 115 AdblockPlus::FileSystem::StatResult JniFileSystemCallback::Stat(const std::strin g& path) const
116 { 116 {
117 JNIEnvAcquire env(GetJavaVM()); 117 JNIEnvAcquire env(GetJavaVM());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 static JNINativeMethod methods[] = 174 static JNINativeMethod methods[] =
175 { 175 {
176 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 176 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
177 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 177 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
178 }; 178 };
179 179
180 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FileSystem _registerNatives(JNIEnv *env, jclass clazz) 180 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_FileSystem _registerNatives(JNIEnv *env, jclass clazz)
181 { 181 {
182 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 182 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
183 } 183 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld