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

Delta Between Two Patch Sets: src/org/adblockplus/android/ABPEngine.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Created April 11, 2014, 1:31 p.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 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
« no previous file with change/comment | « src/org/adblockplus/ChunkedOutputStream.java ('k') | src/org/adblockplus/android/AboutDialog.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 20 matching lines...) Expand all
31 import org.adblockplus.libadblockplus.WebRequest; 31 import org.adblockplus.libadblockplus.WebRequest;
32 32
33 import android.content.Context; 33 import android.content.Context;
34 import android.content.pm.PackageInfo; 34 import android.content.pm.PackageInfo;
35 import android.content.pm.PackageManager.NameNotFoundException; 35 import android.content.pm.PackageManager.NameNotFoundException;
36 import android.os.Build.VERSION; 36 import android.os.Build.VERSION;
37 import android.util.Log; 37 import android.util.Log;
38 38
39 public final class ABPEngine 39 public final class ABPEngine
40 { 40 {
41 private final static String TAG = Utils.getTag(ABPEngine.class); 41 private static final String TAG = Utils.getTag(ABPEngine.class);
42 42
43 private final Context context; 43 private final Context context;
44 44
45 /*
46 * The fields below are volatile because:
47 *
48 * I encountered JNI related bugs/crashes caused by JNI backed Java objects. I t seemed that under
49 * certain conditions the objects were optimized away which resulted in crashe s when trying to
50 * release the object, sometimes even on access.
51 *
52 * The only solution that really worked was to declare the variables holding t he references
53 * volatile, this seems to prevent the JNI from 'optimizing away' those object s (as a volatile
54 * variable might be changed at any time from any thread).
55 */
45 private volatile JsEngine jsEngine; 56 private volatile JsEngine jsEngine;
Felix Dahlke 2014/04/16 15:24:25 Why do these have to be volatile? How I understand
René Jeschke 2014/04/16 17:51:47 I have encountered problems with JNI backed Java o
46 private volatile FilterEngine filterEngine; 57 private volatile FilterEngine filterEngine;
47 private volatile LogSystem logSystem; 58 private volatile LogSystem logSystem;
48 private volatile WebRequest webRequest; 59 private volatile WebRequest webRequest;
49 private volatile EventCallback updateCallback; 60 private volatile EventCallback updateCallback;
50 private volatile UpdaterCallback updaterCallback; 61 private volatile UpdaterCallback updaterCallback;
51 private volatile FilterChangeCallback filterChangeCallback; 62 private volatile FilterChangeCallback filterChangeCallback;
52 63
53 private ABPEngine(final Context context) 64 private ABPEngine(final Context context)
54 { 65 {
55 this.context = context; 66 this.context = context;
(...skipping 12 matching lines...) Expand all
68 Log.e(TAG, "Failed to get the application version number", e); 79 Log.e(TAG, "Failed to get the application version number", e);
69 } 80 }
70 final String sdkVersion = String.valueOf(VERSION.SDK_INT); 81 final String sdkVersion = String.valueOf(VERSION.SDK_INT);
71 final String locale = context.getResources().getConfiguration().locale.toStr ing(); 82 final String locale = context.getResources().getConfiguration().locale.toStr ing();
72 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release); 83 final boolean developmentBuild = !context.getResources().getBoolean(R.bool.d ef_release);
73 84
74 return AppInfo.builder() 85 return AppInfo.builder()
75 .setVersion(version) 86 .setVersion(version)
76 .setApplicationVersion(sdkVersion) 87 .setApplicationVersion(sdkVersion)
77 .setLocale(locale) 88 .setLocale(locale)
78 .setDevelopmentBuild(developmentBuild) 89 .setDevelopmentBuild(developmentBuild)
Felix Dahlke 2014/04/16 15:24:25 Looks like trailing whitespace, can you make sure
René Jeschke 2014/04/16 17:51:47 Don't have any trailing whitespaces in my editor f
79 .build(); 90 .build();
80 } 91 }
81 92
82 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath) 93 public static ABPEngine create(final Context context, final AppInfo appInfo, f inal String basePath)
83 { 94 {
84 final ABPEngine engine = new ABPEngine(context); 95 final ABPEngine engine = new ABPEngine(context);
85 96
86 engine.jsEngine = new JsEngine(appInfo); 97 engine.jsEngine = new JsEngine(appInfo);
87 engine.jsEngine.setDefaultFileSystem(basePath); 98 engine.jsEngine.setDefaultFileSystem(basePath);
88 99
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 this.filterChangeCallback.dispose(); 159 this.filterChangeCallback.dispose();
149 this.filterChangeCallback = null; 160 this.filterChangeCallback = null;
150 } 161 }
151 } 162 }
152 163
153 public boolean isFirstRun() 164 public boolean isFirstRun()
154 { 165 {
155 return this.filterEngine.isFirstRun(); 166 return this.filterEngine.isFirstRun();
156 } 167 }
157 168
158 private static org.adblockplus.android.Subscription convertJsSubscription(fina l Subscription sub) 169 private static org.adblockplus.android.Subscription convertJsSubscription(fina l Subscription jsSubscription)
159 { 170 {
160 final org.adblockplus.android.Subscription ret = new org.adblockplus.android .Subscription(); 171 final org.adblockplus.android.Subscription subscription = new org.adblockplu s.android.Subscription();
Felix Dahlke 2014/04/16 15:24:25 How about calling this "subscription" (or "sub") a
René Jeschke 2014/04/16 17:51:47 Done.
161 172
162 ret.title = sub.getProperty("title").toString(); 173 subscription.title = jsSubscription.getProperty("title").toString();
163 ret.url = sub.getProperty("url").toString(); 174 subscription.url = jsSubscription.getProperty("url").toString();
164 175
165 return ret; 176 return subscription;
166 } 177 }
167 178
168 private static org.adblockplus.android.Subscription[] convertJsSubscriptions(f inal List<Subscription> subs) 179 private static org.adblockplus.android.Subscription[] convertJsSubscriptions(f inal List<Subscription> jsSubscriptions)
169 { 180 {
170 final org.adblockplus.android.Subscription[] ret = new org.adblockplus.andro id.Subscription[subs.size()]; 181 final org.adblockplus.android.Subscription[] subscriptions = new org.adblock plus.android.Subscription[jsSubscriptions.size()];
171 182
172 for (int i = 0; i < ret.length; i++) 183 for (int i = 0; i < subscriptions.length; i++)
173 { 184 {
174 ret[i] = convertJsSubscription(subs.get(i)); 185 subscriptions[i] = convertJsSubscription(jsSubscriptions.get(i));
175 } 186 }
176 187
177 return ret; 188 return subscriptions;
178 } 189 }
179 190
180 public org.adblockplus.android.Subscription[] getRecommendedSubscriptions() 191 public org.adblockplus.android.Subscription[] getRecommendedSubscriptions()
181 { 192 {
182 return convertJsSubscriptions(this.filterEngine.fetchAvailableSubscriptions( )); 193 return convertJsSubscriptions(this.filterEngine.fetchAvailableSubscriptions( ));
183 } 194 }
184 195
185 public org.adblockplus.android.Subscription[] getListedSubscriptions() 196 public org.adblockplus.android.Subscription[] getListedSubscriptions()
186 { 197 {
187 return convertJsSubscriptions(this.filterEngine.getListedSubscriptions()); 198 return convertJsSubscriptions(this.filterEngine.getListedSubscriptions());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 272
262 public void updateSubscriptionStatus(final String url) 273 public void updateSubscriptionStatus(final String url)
263 { 274 {
264 final Subscription sub = this.filterEngine.getSubscription(url); 275 final Subscription sub = this.filterEngine.getSubscription(url);
265 if (sub != null) 276 if (sub != null)
266 { 277 {
267 Utils.updateSubscriptionStatus(this.context, sub); 278 Utils.updateSubscriptionStatus(this.context, sub);
268 } 279 }
269 } 280 }
270 } 281 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld