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 comment Created Sept. 8, 2017, 12:20 p.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 /**
32 * If an interface parameter value is null then a default implementation is
33 * chosen.
34 * If basePath is null then paths are not resolved to a full path, thus
35 * current working directory is used.
36 */
37 public Platform(final LogSystem logSystem, final WebRequest webRequest, final String basePath)
38 {
39 this(ctor(logSystem, webRequest, basePath));
40 }
41
42 protected Platform(final long ptr)
43 {
44 this.ptr = ptr;
45 this.disposer = new Disposer(this, new DisposeWrapper(ptr));
46 }
47
48 public void setUpJsEngine(final AppInfo appInfo)
49 {
50 setUpJsEngine(this.ptr, appInfo);
51 }
52
53 public JsEngine getJsEngine()
54 {
55 return new JsEngine(getJsEnginePtr(this.ptr));
56 }
57
58 public void setUpFilterEngine(final IsAllowedConnectionCallback isSubscription DownloadAllowedCallback)
59 {
60 setUpFilterEngine(this.ptr, isSubscriptionDownloadAllowedCallback);
61 }
62
63 public FilterEngine getFilterEngine()
64 {
65 // Initially FilterEngine is not constructed when Platform is instantiated
66 // and in addition FilterEngine is being created asynchronously, the call
67 // of `ensureFilterEngine` causes a construction of FilterEngine if it's
68 // not created yet and waits for it.
69 ensureFilterEngine(this.ptr);
70 return new FilterEngine(this.ptr);
71 }
72
73 @Override
74 public void dispose()
75 {
76 this.disposer.dispose();
77 }
78
79 private final static class DisposeWrapper implements Disposable
80 {
81 private final long ptr;
82
83 public DisposeWrapper(final long ptr)
84 {
85 this.ptr = ptr;
86 }
87
88 @Override
89 public void dispose()
90 {
91 dtor(this.ptr);
92 }
93 }
94
95 private final static native void registerNatives();
96
97 private final static native long ctor(LogSystem logSystem, WebRequest webReque st, String basePath);
98
99 private final static native void setUpJsEngine(long ptr, AppInfo appInfo);
100
101 private final static native long getJsEnginePtr(long ptr);
102
103 private final static native void setUpFilterEngine(long ptr, IsAllowedConnecti onCallback isSubscriptionDownloadAllowedCallback);
104
105 private final static native void ensureFilterEngine(long ptr);
106
107 private final static native void dtor(long ptr);
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld