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

Unified Diff: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java

Issue 29371750: Issue 4794 - adblock engine creating/releasing concurrency (Closed)
Patch Set: updated versions (from minor to patches), made gradle/maven versions consistent Created Jan. 25, 2017, 11:55 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libadblockplus-android-settings/pom.xml ('k') | libadblockplus-android-webview/pom.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java
diff --git a/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java b/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java
index 0840fa3e182bd8896eae3fb937c1415504657cdb..bd2a25719538651340710c400e0180401770b476 100644
--- a/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java
+++ b/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java
@@ -106,9 +106,6 @@ public class AdblockHelper
SharedPreferences prefs = context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
storage = new SharedPrefsStorage(prefs);
- // latch is required for async (see `waitForReady()`)
- engineCreated = new CountDownLatch(1);
-
engine = AdblockEngine.create(
AdblockEngine.generateAppInfo(context, developmentBuild),
context.getCacheDir().getAbsolutePath(),
@@ -129,9 +126,6 @@ public class AdblockHelper
{
Log.w(TAG, "No saved adblock settings");
}
-
- // unlock waiting client thread
- engineCreated.countDown();
}
/**
@@ -142,7 +136,7 @@ public class AdblockHelper
{
if (engineCreated == null)
{
- throw new RuntimeException("AdblockHelper Plus usage exception: call retain(...) first");
+ throw new RuntimeException("AdblockHelper Plus usage exception: call retain(true) first");
}
try
@@ -164,10 +158,6 @@ public class AdblockHelper
engine.dispose();
engine = null;
- // to unlock waiting client in WaitForReady()
- engineCreated.countDown();
- engineCreated = null;
-
storage = null;
}
@@ -196,12 +186,18 @@ public class AdblockHelper
}
else
{
+ // latch is required for async (see `waitForReady()`)
+ engineCreated = new CountDownLatch(1);
+
new Thread(new Runnable()
{
@Override
public void run()
{
createAdblock();
+
+ // unlock waiting client thread
+ engineCreated.countDown();
}
}).start();
}
@@ -215,8 +211,20 @@ public class AdblockHelper
{
if (referenceCounter.decrementAndGet() == 0)
{
- waitForReady();
- disposeAdblock();
+ if (engineCreated != null)
+ {
+ // retained asynchronously
+ waitForReady();
+ disposeAdblock();
+
+ // to unlock waiting client in waitForReady()
+ engineCreated.countDown();
+ engineCreated = null;
+ }
+ else
+ {
+ disposeAdblock();
+ }
}
}
}
« no previous file with comments | « libadblockplus-android-settings/pom.xml ('k') | libadblockplus-android-webview/pom.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld