Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 24 matching lines...) Expand all Loading... | |
35 { | 35 { |
36 private static final String TAG = Utils.getTag(AdblockHelper.class); | 36 private static final String TAG = Utils.getTag(AdblockHelper.class); |
37 | 37 |
38 /** | 38 /** |
39 * Suggested preference name | 39 * Suggested preference name |
40 */ | 40 */ |
41 public static final String PREFERENCE_NAME = "ADBLOCK"; | 41 public static final String PREFERENCE_NAME = "ADBLOCK"; |
42 private static AdblockHelper _instance; | 42 private static AdblockHelper _instance; |
43 | 43 |
44 private Context context; | 44 private Context context; |
45 private String basePath; | |
45 private boolean developmentBuild; | 46 private boolean developmentBuild; |
46 private String preferenceName; | 47 private String preferenceName; |
47 private AdblockEngine engine; | 48 private AdblockEngine engine; |
48 private AdblockSettingsStorage storage; | 49 private AdblockSettingsStorage storage; |
49 private CountDownLatch engineCreated; | 50 private CountDownLatch engineCreated; |
50 | 51 |
51 /* | 52 /* |
52 Simple ARC management for AdblockEngine | 53 Simple ARC management for AdblockEngine |
53 Use `retain` and `release` | 54 Use `retain` and `release` |
54 */ | 55 */ |
(...skipping 26 matching lines...) Expand all Loading... | |
81 } | 82 } |
82 | 83 |
83 public AdblockSettingsStorage getStorage() | 84 public AdblockSettingsStorage getStorage() |
84 { | 85 { |
85 return storage; | 86 return storage; |
86 } | 87 } |
87 | 88 |
88 /** | 89 /** |
89 * Init with context | 90 * Init with context |
90 * @param context application context | 91 * @param context application context |
92 * @param basePath file system root to store files | |
93 * @param developmentBuild debug or release? | |
94 * @param preferenceName Shared Preferences name | |
95 */ | |
96 public void init(Context context, String basePath, boolean developmentBuild, S tring preferenceName) | |
97 { | |
98 this.context = context.getApplicationContext(); | |
99 this.basePath = basePath; | |
100 this.developmentBuild = developmentBuild; | |
101 this.preferenceName = preferenceName; | |
102 } | |
103 | |
104 /** | |
105 * Init with context | |
106 * @param context application context | |
91 * @param developmentBuild debug or release? | 107 * @param developmentBuild debug or release? |
92 * @param preferenceName Shared Preferences name | 108 * @param preferenceName Shared Preferences name |
93 */ | 109 */ |
94 public void init(Context context, boolean developmentBuild, String preferenceN ame) | 110 public void init(Context context, boolean developmentBuild, String preferenceN ame) |
95 { | 111 { |
96 this.context = context.getApplicationContext(); | 112 init(context, context.getCacheDir().getAbsolutePath(), developmentBuild, pre ferenceName); |
diegocarloslima
2017/03/13 13:58:11
As you already pointed, it would be better to use
anton
2017/03/14 04:15:26
Well, i'd prefer to remove it at all or leave as-i
diegocarloslima
2017/03/16 19:55:23
I'm not against removing it, but if we decide to k
| |
97 this.developmentBuild = developmentBuild; | |
98 this.preferenceName = preferenceName; | |
99 } | 113 } |
100 | 114 |
101 private void createAdblock() | 115 private void createAdblock() |
102 { | 116 { |
103 Log.d(TAG, "Creating adblock engine ..."); | 117 Log.d(TAG, "Creating adblock engine ..."); |
104 | 118 |
105 // read and apply current settings | 119 // read and apply current settings |
106 SharedPreferences prefs = context.getSharedPreferences(preferenceName, Conte xt.MODE_PRIVATE); | 120 SharedPreferences prefs = context.getSharedPreferences(preferenceName, Conte xt.MODE_PRIVATE); |
107 storage = new SharedPrefsStorage(prefs); | 121 storage = new SharedPrefsStorage(prefs); |
108 | 122 |
109 // latch is required for async (see `waitForReady()`) | 123 // latch is required for async (see `waitForReady()`) |
110 engineCreated = new CountDownLatch(1); | 124 engineCreated = new CountDownLatch(1); |
111 | 125 |
112 engine = AdblockEngine.create( | 126 engine = AdblockEngine.create( |
113 AdblockEngine.generateAppInfo(context, developmentBuild), | 127 AdblockEngine.generateAppInfo(context, developmentBuild), |
114 context.getCacheDir().getAbsolutePath(), | 128 basePath, true); // `true` as we need element hiding |
115 true); // `true` as we need element hiding | |
116 Log.d(TAG, "AdblockHelper engine created"); | 129 Log.d(TAG, "AdblockHelper engine created"); |
117 | 130 |
118 AdblockSettings settings = storage.load(); | 131 AdblockSettings settings = storage.load(); |
119 if (settings != null) | 132 if (settings != null) |
120 { | 133 { |
121 Log.d(TAG, "Applying saved adblock settings to adblock engine"); | 134 Log.d(TAG, "Applying saved adblock settings to adblock engine"); |
122 // apply last saved settings to adblock engine | 135 // apply last saved settings to adblock engine |
123 | 136 |
124 // all the settings except `enabled` and whitelisted domains are saved by adblock engine itself | 137 // all the settings except `enabled` and whitelisted domains are saved by adblock engine itself |
125 engine.setEnabled(settings.isAdblockEnabled()); | 138 engine.setEnabled(settings.isAdblockEnabled()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 */ | 226 */ |
214 public synchronized void release() | 227 public synchronized void release() |
215 { | 228 { |
216 if (referenceCounter.decrementAndGet() == 0) | 229 if (referenceCounter.decrementAndGet() == 0) |
217 { | 230 { |
218 waitForReady(); | 231 waitForReady(); |
219 disposeAdblock(); | 232 disposeAdblock(); |
220 } | 233 } |
221 } | 234 } |
222 } | 235 } |
OLD | NEW |