Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 20 matching lines...) Expand all Loading... | |
31 import java.util.concurrent.atomic.AtomicInteger; | 31 import java.util.concurrent.atomic.AtomicInteger; |
32 | 32 |
33 /** | 33 /** |
34 * AdblockHelper shared resources | 34 * AdblockHelper shared resources |
35 * (singleton) | 35 * (singleton) |
36 */ | 36 */ |
37 public class AdblockHelper | 37 public class AdblockHelper |
38 { | 38 { |
39 private static final String TAG = Utils.getTag(AdblockHelper.class); | 39 private static final String TAG = Utils.getTag(AdblockHelper.class); |
40 | 40 |
41 // basePath to store subscription files | |
42 public static final String BASE_PATH_DIRECTORY = "adblock"; | |
diegocarloslima
2017/03/28 13:47:15
I would suggest to move this constant to AdblockEn
anton
2017/03/28 13:59:06
Acknowledged.
| |
43 | |
44 /** | 41 /** |
45 * Suggested preference name to store settings | 42 * Suggested preference name to store settings |
46 */ | 43 */ |
47 public static final String PREFERENCE_NAME = "ADBLOCK"; | 44 public static final String PREFERENCE_NAME = "ADBLOCK"; |
48 | 45 |
49 /** | 46 /** |
50 * Suggested preference name to store intercepted subscription requests | 47 * Suggested preference name to store intercepted subscription requests |
51 */ | 48 */ |
52 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; | 49 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; |
53 private static AdblockHelper _instance; | 50 private static AdblockHelper _instance; |
54 | 51 |
55 private Context context; | 52 private Context context; |
56 private boolean developmentBuild; | 53 private boolean developmentBuild; |
57 private String settingsPreferenceName; | 54 private String settingsPreferenceName; |
58 private String preloadedPreferenceName; | 55 private String preloadedPreferenceName; |
59 private Map<String, Integer> URLtoResourceIdMap; | 56 private Map<String, Integer> urlToResourceIdMap; |
diegocarloslima
2017/03/28 13:47:15
'toResource' should be 'ToResource'. Also, it's re
anton
2017/03/28 13:59:06
Acknowledged.
| |
60 private AdblockEngine engine; | 57 private AdblockEngine engine; |
61 private AdblockSettingsStorage storage; | 58 private AdblockSettingsStorage storage; |
62 private CountDownLatch engineCreated; | 59 private CountDownLatch engineCreated; |
63 | 60 |
64 /* | 61 /* |
65 Simple ARC management for AdblockEngine | 62 Simple ARC management for AdblockEngine |
66 Use `retain` and `release` | 63 Use `retain` and `release` |
67 */ | 64 */ |
68 | 65 |
69 private AtomicInteger referenceCounter = new AtomicInteger(0); | 66 private AtomicInteger referenceCounter = new AtomicInteger(0); |
(...skipping 25 matching lines...) Expand all Loading... | |
95 | 92 |
96 public AdblockSettingsStorage getStorage() | 93 public AdblockSettingsStorage getStorage() |
97 { | 94 { |
98 return storage; | 95 return storage; |
99 } | 96 } |
100 | 97 |
101 /** | 98 /** |
102 * Init with context | 99 * Init with context |
103 * @param context application context | 100 * @param context application context |
104 * @param developmentBuild debug or release? | 101 * @param developmentBuild debug or release? |
105 * @param preferenceName Shared Preferences name to store adlock settings | 102 * @param preferenceName Shared Preferences name to store adblock settings |
106 */ | 103 */ |
107 public AdblockHelper init(Context context, boolean developmentBuild, String pr eferenceName) | 104 public AdblockHelper init(Context context, boolean developmentBuild, String pr eferenceName) |
108 { | 105 { |
109 this.context = context.getApplicationContext(); | 106 this.context = context.getApplicationContext(); |
110 this.developmentBuild = developmentBuild; | 107 this.developmentBuild = developmentBuild; |
111 this.settingsPreferenceName = preferenceName; | 108 this.settingsPreferenceName = preferenceName; |
112 return this; | 109 return this; |
113 } | 110 } |
114 | 111 |
115 /** | 112 /** |
116 * Use preloaded subscriptions | 113 * Use preloaded subscriptions |
117 * @param preferenceName Shared Preferences name to store intercepted requests stats | 114 * @param preferenceName Shared Preferences name to store intercepted requests stats |
118 * @param URLtoResourceIdMap | 115 * @param urlToResourceIdMap |
119 */ | 116 */ |
120 public void preloadSubscriptions(String preferenceName, Map<String, Integer> U RLtoResourceIdMap) | 117 public void preloadSubscriptions(String preferenceName, Map<String, Integer> u rlToResourceIdMap) |
diegocarloslima
2017/03/28 13:47:15
same suggestion here, change 'URLtoResourceIdMap'
anton
2017/03/28 13:59:06
Acknowledged.
| |
121 { | 118 { |
122 this.preloadedPreferenceName = preferenceName; | 119 this.preloadedPreferenceName = preferenceName; |
123 this.URLtoResourceIdMap = URLtoResourceIdMap; | 120 this.urlToResourceIdMap = urlToResourceIdMap; |
124 } | 121 } |
125 | 122 |
126 private void createAdblock() | 123 private void createAdblock() |
127 { | 124 { |
128 Log.d(TAG, "Creating adblock engine ..."); | 125 Log.d(TAG, "Creating adblock engine ..."); |
129 | 126 |
130 // read and apply current settings | 127 // read and apply current settings |
131 SharedPreferences settingsPrefs = context.getSharedPreferences( | 128 SharedPreferences settingsPrefs = context.getSharedPreferences( |
132 settingsPreferenceName, | 129 settingsPreferenceName, |
133 Context.MODE_PRIVATE); | 130 Context.MODE_PRIVATE); |
134 storage = new SharedPrefsStorage(settingsPrefs); | 131 storage = new SharedPrefsStorage(settingsPrefs); |
135 | 132 |
136 File basePath = context.getDir(BASE_PATH_DIRECTORY, Context.MODE_PRIVATE); | 133 File basePath = context.getDir(AdblockEngine.BASE_PATH_DIRECTORY, Context.MO DE_PRIVATE); |
137 AdblockEngine.Builder builder = AdblockEngine | 134 AdblockEngine.Builder builder = AdblockEngine |
138 .builder( | 135 .builder( |
139 AdblockEngine.generateAppInfo(context, developmentBuild), | 136 AdblockEngine.generateAppInfo(context, developmentBuild), |
140 basePath.getAbsolutePath()) | 137 basePath.getAbsolutePath()) |
141 .enableElementHiding(true); | 138 .enableElementHiding(true); |
142 | 139 |
143 // if preloaded subscriptions provided | 140 // if preloaded subscriptions provided |
144 if (preloadedPreferenceName != null) | 141 if (preloadedPreferenceName != null) |
145 { | 142 { |
146 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es( | 143 SharedPreferences preloadedSubscriptionsPrefs = context.getSharedPreferenc es( |
147 preloadedPreferenceName, | 144 preloadedPreferenceName, |
148 Context.MODE_PRIVATE); | 145 Context.MODE_PRIVATE); |
149 builder.preloadSubscriptions( | 146 builder.preloadSubscriptions( |
150 context, | 147 context, |
151 URLtoResourceIdMap, | 148 urlToResourceIdMap, |
152 new AndroidWebRequestResourceWrapper.SharedPrefsStorage(preloadedSubscri ptionsPrefs)); | 149 new AndroidWebRequestResourceWrapper.SharedPrefsStorage(preloadedSubscri ptionsPrefs)); |
153 } | 150 } |
154 | 151 |
155 engine = builder.build(); | 152 engine = builder.build(); |
156 | 153 |
157 Log.d(TAG, "AdblockHelper engine created"); | 154 Log.d(TAG, "AdblockHelper engine created"); |
158 | 155 |
159 AdblockSettings settings = storage.load(); | 156 AdblockSettings settings = storage.load(); |
160 if (settings != null) | 157 if (settings != null) |
161 { | 158 { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 engineCreated.countDown(); | 262 engineCreated.countDown(); |
266 engineCreated = null; | 263 engineCreated = null; |
267 } | 264 } |
268 else | 265 else |
269 { | 266 { |
270 disposeAdblock(); | 267 disposeAdblock(); |
271 } | 268 } |
272 } | 269 } |
273 } | 270 } |
274 } | 271 } |
LEFT | RIGHT |