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

Issue 29671734: Issue 6265 - Create shared AdblockEngine instance in AdblockWebView in background (Closed)

Created:
Jan. 17, 2018, 11:48 a.m. by anton
Modified:
Jan. 22, 2018, 11:58 a.m.
CC:
sergei
Visibility:
Public.

Description

Issue 6265 - Create shared AdblockEngine instance in AdblockWebView in background

Patch Set 1 #

Total comments: 26

Patch Set 2 : addressed Diego's comments #

Total comments: 2

Patch Set 3 : @deprecated in javadoc, order #

Patch Set 4 : Sergey's comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+316 lines, -623 lines) Patch
M libadblockplus-android-settings/AndroidManifest.xml View 1 chunk +7 lines, -7 lines 0 comments Download
M libadblockplus-android-settings/build.gradle View 1 chunk +2 lines, -2 lines 0 comments Download
M libadblockplus-android-settings/pom.xml View 2 chunks +2 lines, -2 lines 0 comments Download
M libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java View 1 2 3 4 chunks +83 lines, -192 lines 0 comments Download
M libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockSettings.java View 2 3 1 chunk +1 line, -0 lines 0 comments Download
M libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockSettingsStorage.java View 2 3 1 chunk +1 line, -0 lines 0 comments Download
D libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/ConnectionType.java View 2 3 1 chunk +0 lines, -89 lines 0 comments Download
M libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/GeneralSettingsFragment.java View 2 3 1 chunk +1 line, -0 lines 0 comments Download
D libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/IsAllowedConnectionCallbackImpl.java View 2 3 1 chunk +0 lines, -72 lines 0 comments Download
M libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/SharedPrefsStorage.java View 2 3 1 chunk +1 line, -0 lines 0 comments Download
M libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/IsAllowedConnectionCallbackImplTest.java View 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M libadblockplus-android-webview/AndroidManifest.xml View 1 chunk +5 lines, -5 lines 0 comments Download
M libadblockplus-android-webview/build.gradle View 1 chunk +2 lines, -2 lines 0 comments Download
M libadblockplus-android-webview/pom.xml View 2 chunks +2 lines, -2 lines 0 comments Download
M libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java View 1 2 3 18 chunks +47 lines, -55 lines 0 comments Download
M libadblockplus-android-webviewapp/AndroidManifest.xml View 1 chunk +3 lines, -3 lines 0 comments Download
M libadblockplus-android-webviewapp/build.gradle View 1 chunk +2 lines, -2 lines 0 comments Download
M libadblockplus-android-webviewapp/pom.xml View 3 chunks +3 lines, -3 lines 0 comments Download
M libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/MainActivity.java View 2 3 3 chunks +3 lines, -28 lines 0 comments Download
M libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/SettingsActivity.java View 2 3 3 chunks +6 lines, -4 lines 0 comments Download
M libadblockplus-android/AndroidManifest.xml View 1 chunk +5 lines, -5 lines 0 comments Download
M libadblockplus-android/build.gradle View 1 chunk +3 lines, -3 lines 0 comments Download
M libadblockplus-android/pom.xml View 1 chunk +1 line, -1 line 0 comments Download
A libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngineProvider.java View 1 2 3 1 chunk +54 lines, -0 lines 0 comments Download
A + libadblockplus-android/src/org/adblockplus/libadblockplus/android/ConnectionType.java View 2 3 2 chunks +2 lines, -2 lines 0 comments Download
A + libadblockplus-android/src/org/adblockplus/libadblockplus/android/IsAllowedConnectionCallbackImpl.java View 2 3 1 chunk +1 line, -2 lines 0 comments Download
A + libadblockplus-android/src/org/adblockplus/libadblockplus/android/SingleInstanceEngineProvider.java View 2 3 7 chunks +77 lines, -140 lines 0 comments Download

Messages

Total messages: 16
anton
Previously AdblockWebView accepted AdblockEngine as argument but creating AdblockEngine is long-running operation. Now it has ...
Jan. 17, 2018, 11:57 a.m. (2018-01-17 11:57:13 UTC) #1
jens
On 2018/01/17 11:57:13, anton wrote: > Previously AdblockWebView accepted AdblockEngine as argument but creating > ...
Jan. 19, 2018, 9:54 a.m. (2018-01-19 09:54:37 UTC) #2
jens
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java File libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java#newcode61 libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java:61: Do wen need that empty line?
Jan. 19, 2018, 9:54 a.m. (2018-01-19 09:54:44 UTC) #3
anton
On 2018/01/19 09:54:37, jens wrote: > On 2018/01/17 11:57:13, anton wrote: > > Previously AdblockWebView ...
Jan. 19, 2018, 10:15 a.m. (2018-01-19 10:15:03 UTC) #4
anton
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java File libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java#newcode61 libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java:61: On 2018/01/19 09:54:44, jens wrote: > Do wen need ...
Jan. 19, 2018, 10:15 a.m. (2018-01-19 10:15:10 UTC) #5
jens
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java File libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java#newcode61 libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java:61: On 2018/01/19 10:15:10, anton wrote: > On 2018/01/19 09:54:44, ...
Jan. 19, 2018, 10:22 a.m. (2018-01-19 10:22:44 UTC) #6
diegocarloslima
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java File libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java#newcode51 libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java:51: private Runnable engineCreatedCallback = new Runnable() maybe declare it ...
Jan. 19, 2018, 12:17 p.m. (2018-01-19 12:17:46 UTC) #7
anton
uploaded new patch set https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java File libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java#newcode51 libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java:51: private Runnable engineCreatedCallback = new ...
Jan. 19, 2018, 12:27 p.m. (2018-01-19 12:27:01 UTC) #8
anton
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/AndroidManifest.xml File libadblockplus-android-webview/AndroidManifest.xml (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/AndroidManifest.xml#newcode4 libadblockplus-android-webview/AndroidManifest.xml:4: android:versionCode="3" On 2018/01/19 12:17:46, diegocarloslima wrote: > Is this ...
Jan. 19, 2018, 12:36 p.m. (2018-01-19 12:36:47 UTC) #9
diegocarloslima
https://codereview.adblockplus.org/29671734/diff/29674608/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java File libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java (right): https://codereview.adblockplus.org/29671734/diff/29674608/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java#newcode166 libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java:166: * The method is deprecated: use .getProvider().retain() instead It ...
Jan. 19, 2018, 12:59 p.m. (2018-01-19 12:59:19 UTC) #10
anton
On 2018/01/19 12:59:19, diegocarloslima wrote: > https://codereview.adblockplus.org/29671734/diff/29674608/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java > File > libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java > (right): > > ...
Jan. 19, 2018, 1:05 p.m. (2018-01-19 13:05:35 UTC) #11
sergei
Few thoughts and BTW the changes in last patches are missing previous changes. I have ...
Jan. 19, 2018, 1:56 p.m. (2018-01-19 13:56:42 UTC) #12
diegocarloslima
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java File libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java#newcode239 libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java:239: if (this.provider != null && provider != null && ...
Jan. 19, 2018, 3:56 p.m. (2018-01-19 15:56:12 UTC) #13
anton
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java File libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java (right): https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java#newcode239 libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java:239: if (this.provider != null && provider != null && ...
Jan. 22, 2018, 6:17 a.m. (2018-01-22 06:17:38 UTC) #14
anton
On 2018/01/22 06:17:38, anton wrote: > https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java > File > libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java > (right): > > ...
Jan. 22, 2018, 7 a.m. (2018-01-22 07:00:20 UTC) #15
diegocarloslima
Jan. 22, 2018, 11:35 a.m. (2018-01-22 11:35:52 UTC) #16
On 2018/01/22 07:00:20, anton wrote:
> On 2018/01/22 06:17:38, anton wrote:
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> > File
> >
>
libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java
> > (right):
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> >
>
libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java:239:
> > if (this.provider != null && provider != null && this.provider == provider)
> > On 2018/01/19 13:56:41, sergei wrote:
> > > So, if both this.provider and provider are null then there will NPE later.
> > What
> > > about just checking whether `this.provider == provider` and checking that
> it's
> > > not null when it's accessed. It might be better to do it in another
> > codereview.
> > > 
> > > Alternatively it could make sense to even prohibit to pass null here.
> > 
> > I'd prefer to fix it by adding `null` check.
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> >
>
libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java:968:
> > if (provider.getCounter() == 0)
> > On 2018/01/19 13:56:41, sergei wrote:
> > > Can it actually happen and if so, why it cannot happen few lines below?
> > > 
> > > I have not check the whole threading here but IMO it would be better to
> > > implement it differently, of course in another issue.
> > > As I understood ElemHideThread can be created several times for the same
> > > instance of AdblockWebView (WebView) class, so instead of just overriding
a
> > > member (elemHideThread) what can be a cause of race conditions there
should
> be
> > > something a bit more advanced and the code of the ElemHide thread should
not
> > > care about existence of all requirements. How to do it?
> > > When the thread is being started it should be counted somehow, depending
> what
> > > you want later. Let's say it's added to a linked list, but perhaps in Java
> > world
> > > it can be just an incrementing of a counter. When the thread finishes its
> > useful
> > > work it should somehow (either by obtaining a lock or sending an
> asynchronous
> > > task to the the "main" thread) remove itself from that linked list (linked
> > list
> > > is useful for performance because a thread can hold an iterator and use it
> as
> > ID
> > > to remove itself while other iterators are not invalided). In the dispose
> > method
> > > of our WebView instead of assigning a "post run" task to some thread we
> > should:
> > > switch to the state when no more ElemHide threads can be created, cancel
> > running
> > > threads (by setting of a WebView AtomicBoolean member to true, see below),
> > then
> > > wait for the finishing of a useful work of all currently running threads
> > > (basically, wait until that linked list is empty or the counter value is
> zero)
> > > and then dispose AdblockEngine, since there are no any users of it in some
> > > thread anymore.
> > > When the list of selectors is ready then we should schedule a task to the
> > "main
> > > thread" and perform the injection there if the ElemHideThread (or some
other
> > ID)
> > > corresponds to the currently being viewed web site.
> > > Canceling could be implemented as a callback function which is
synchronously
> > > checking whether the currently being viewed web site is still the same and
> > that
> > > a global cancelling is not triggered (the value of WebView AtomicBoolean
> > > member).
> > 
> > I've just reviewed the code and it seems that it can happen in *very* rare
> case:
> > 1) elemhide thread #1 is created, but not started
> > 2) URL #2 set, started loading. Elemhide thread #2 is created, but not
started
> > 3) dispose called
> > 4) thread #2 started, finishRunnable set, filter engine actually disposed,
ref
> > counter = 0
> > 5) thread #1 started (check is required)
> > 
> > Note thread starting takes time and the order is not guaranteed.
> > We can refactor multithreading here is separate thread (please create
separate
> > ticket)
> > but i'm absolutely sure existing check does not hurt.
> > 
> > In fact it happened few times when website forwards to "mobile" or
> > "per-language" version of webpage
> > so changing of URL happens quickly and elemhiding for URL #1 is not
finished.
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> >
>
libadblockplus-android-webview/src/org/adblockplus/libadblockplus/android/webview/AdblockWebView.java:1087:
> > private void initProvider()
> > On 2018/01/19 13:56:41, sergei wrote:
> > > Would it be better to call it ensureAbpProvider()?
> > > 
> > > SingleInstanceEngineProvider has member `private AdblockEngine engine;`,
so
> > when
> > > there are several instances of the WebView then each is using its own
> instance
> > > of AdblockEngine with its own FilterEngine, I thought that the idea is
that
> > they
> > > shared the same instance of AdblockEngine.
> > 
> > Acknowledged.
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> > File
> >
>
libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/SettingsActivity.java
> > (left):
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> >
>
libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/android/webviewapp/SettingsActivity.java:46:
> > AdblockHelper.get().retain(MainActivity.ADBLOCKENGINE_RETAIN_ASYNC);
> > On 2018/01/19 13:56:41, sergei wrote:
> > > I'm not sure that changing from ADBLOCKENGINE_RETAIN_ASYNC to Boolean true
> is
> > > better.
> > 
> > What do you mean "better"?
> > Previously we had this flag to adjust is it should be done async or synch.
> Since
> > now it's up to  AdblockWebView and it does it in async way (no choice) we
> don't
> > have this setting.
> > 
> > We could invoke it sync here or async + waitForReady - does not make sense
(it
> > just affects the code line when it's locked).
> > In practice since we create AdblockEngine in MainActivity we don't create
new
> > instance of FilterEngine but just inc/dec the counter.
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> > File
> >
>
libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngineProvider.java
> > (right):
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> >
>
libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngineProvider.java:27:
> > * @return if a new instance is allocated
> > On 2018/01/19 13:56:41, sergei wrote:
> > > Is it actually required to know that a new instance is allocated?
> > 
> > Yes, in AdblockChromium we need to know it to send new raw instance address.
> > 
> >
>
https://codereview.adblockplus.org/29671734/diff/29671735/libadblockplus-andr...
> >
>
libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngineProvider.java:39:
> > * @return AdblockEngine instance. Can be `null` is not yet retained or
already
> > released
> > On 2018/01/19 13:56:41, sergei wrote:
> > > Typo in "Can be `null` is not yet retained"
> > 
> > Acknowledged.
> 
> Uploaded new patch set

LGTM

Powered by Google App Engine
This is Rietveld