| 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 41592ace84661ace8e97c007e5a9caec66dc8e37..e97ef2fa7ed53470105469be8613fb3e57538851 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 |
| @@ -59,6 +59,7 @@ public class AdblockHelper |
| private AdblockEngine engine; |
| private AdblockSettingsStorage storage; |
| private CountDownLatch engineCreated; |
| + private Long v8IsolatePtr; |
| /* |
| Simple ARC management for AdblockEngine |
| @@ -131,6 +132,11 @@ public class AdblockHelper |
| return this; |
| } |
| + public void useV8Isolate(long ptr) |
| + { |
| + this.v8IsolatePtr = ptr; |
| + } |
| + |
| private void createAdblock() |
| { |
| ConnectivityManager connectivityManager = |
| @@ -152,6 +158,11 @@ public class AdblockHelper |
| .setIsAllowedConnectionCallback(isAllowedConnectionCallback) |
| .enableElementHiding(true); |
| + if (v8IsolatePtr != null) |
| + { |
| + builder.useV8Isolate(v8IsolatePtr); |
| + } |
| + |
| // if preloaded subscriptions provided |
| if (preloadedPreferenceName != null) |
| { |
| @@ -239,11 +250,16 @@ public class AdblockHelper |
| * @param asynchronous If `true` engines will be created in background thread without locking of |
| * current thread. Use waitForReady() before getEngine() later. |
| * If `false` locks current thread. |
| + * @return if a new instance is allocated |
| */ |
| - public synchronized void retain(boolean asynchronous) |
| + public synchronized boolean retain(boolean asynchronous) |
|
sergei
2017/09/26 09:44:13
It seems this code and `lastInstance` are not used
anton
2017/09/26 10:55:06
They are related but i will split it into separate
|
| { |
| + boolean firstInstance = false; |
| + |
| if (referenceCounter.getAndIncrement() == 0) |
| { |
| + firstInstance = true; |
| + |
| if (!asynchronous) |
| { |
| createAdblock(); |
| @@ -266,15 +282,21 @@ public class AdblockHelper |
| }).start(); |
| } |
| } |
| + return firstInstance; |
| } |
| /** |
| * Unregister AdblockHelper engine client |
| + * @return if the last instance is destroyed |
| */ |
| - public synchronized void release() |
| + public synchronized boolean release() |
| { |
| + boolean lastInstance = false; |
| + |
| if (referenceCounter.decrementAndGet() == 0) |
| { |
| + lastInstance = true; |
| + |
| if (engineCreated != null) |
| { |
| // retained asynchronously |
| @@ -290,5 +312,6 @@ public class AdblockHelper |
| disposeAdblock(); |
| } |
| } |
| + return lastInstance; |
| } |
| } |