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

Side by Side Diff: libadblockplus-android/src/org/adblockplus/libadblockplus/Platform.java

Issue 29536629: Issue 5556 - Update to use libadblockplus revision hg:566f64c8a2a8 (Closed) Base URL: github.com:abby-sergz/libadblockplus-android.git
Patch Set: address comments Created Sept. 8, 2017, 9:39 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package org.adblockplus.libadblockplus;
19
20 public class Platform implements Disposable
21 {
22 private final Disposer disposer;
23 protected final long ptr;
24
25 static
26 {
27 System.loadLibrary("adblockplus-jni");
28 registerNatives();
29 }
30
31 // If an interface parameter value is null then a default implementation is
32 // chosen.
33 // If basePath is null then paths are not resolved to a full path, thus
34 // current working directory is used.
35 public Platform(final LogSystem logSystem, final WebRequest webRequest, final String basePath)
36 {
37 this(ctor(logSystem, webRequest, basePath));
38 }
39
40 protected Platform(final long ptr)
41 {
42 this.ptr = ptr;
43 this.disposer = new Disposer(this, new DisposeWrapper(ptr));
44 }
45
46 public void setUpJsEngine(final AppInfo appInfo)
47 {
48 setUpJsEngine(this.ptr, appInfo);
49 }
50
51 public JsEngine getJsEngine()
52 {
53 return new JsEngine(getJsEnginePtr(this.ptr));
54 }
55
56 public void setUpFilterEngine(final IsAllowedConnectionCallback isSubscription DownloadAllowedCallback)
57 {
58 setUpFilterEngine(this.ptr, isSubscriptionDownloadAllowedCallback);
59 }
60
61 public FilterEngine getFilterEngine()
62 {
63 // Initially FilterEngine is not constructed when Platform is instantiated
64 // and in addition FilterEngine is being created asynchronously, the call
65 // of `ensureFilterEngine` causes a construction of FilterEngine if it's
66 // not created yet and waits for it.
67 ensureFilterEngine(this.ptr);
68 return new FilterEngine(this.ptr);
69 }
70
71 @Override
72 public void dispose()
73 {
74 this.disposer.dispose();
75 }
76
77 private final static class DisposeWrapper implements Disposable
78 {
79 private final long ptr;
80
81 public DisposeWrapper(final long ptr)
82 {
83 this.ptr = ptr;
84 }
85
86 @Override
87 public void dispose()
88 {
89 dtor(this.ptr);
90 }
91 }
92
93 private final static native void registerNatives();
94
95 private final static native long ctor(LogSystem logSystem, WebRequest webReque st, String basePath);
96
97 private final static native void setUpJsEngine(long ptr, AppInfo appInfo);
98
99 private final static native long getJsEnginePtr(long ptr);
100
101 private final static native void setUpFilterEngine(long ptr, IsAllowedConnecti onCallback isSubscriptionDownloadAllowedCallback);
102
103 private final static native void ensureFilterEngine(long ptr);
104
105 private final static native void dtor(long ptr);
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld