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

Delta Between Two Patch Sets: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java

Issue 29671734: Issue 6265 - Create shared AdblockEngine instance in AdblockWebView in background (Closed)
Left Patch Set: Created Jan. 17, 2018, 11:48 a.m.
Right Patch Set: Sergey's comments Created Jan. 22, 2018, 6:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 30 matching lines...) Expand all
41 41
42 /** 42 /**
43 * Suggested preference name to store intercepted subscription requests 43 * Suggested preference name to store intercepted subscription requests
44 */ 44 */
45 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD"; 45 public static final String PRELOAD_PREFERENCE_NAME = "ADBLOCK_PRELOAD";
46 private static AdblockHelper _instance; 46 private static AdblockHelper _instance;
47 47
48 private SingleInstanceEngineProvider provider; 48 private SingleInstanceEngineProvider provider;
49 private AdblockSettingsStorage storage; 49 private AdblockSettingsStorage storage;
50 50
51 private Runnable engineCreatedCallback = new Runnable() 51 private final Runnable engineCreatedCallback = new Runnable()
diegocarloslima 2018/01/19 12:17:45 maybe declare it final?
anton 2018/01/19 12:27:01 Acknowledged.
52 { 52 {
53 @Override 53 @Override
54 public void run() 54 public void run()
55 { 55 {
56 AdblockSettings settings = storage.load(); 56 AdblockSettings settings = storage.load();
57 if (settings != null) 57 if (settings != null)
58 { 58 {
59 Log.d(TAG, "Applying saved adblock settings to adblock engine"); 59 Log.d(TAG, "Applying saved adblock settings to adblock engine");
60 // apply last saved settings to adblock engine 60 // apply last saved settings to adblock engine.
61
jens 2018/01/19 09:54:44 Do wen need that empty line?
anton 2018/01/19 10:15:10 it's just [optional] separation between comments (
jens 2018/01/19 10:22:43 I would say that's up to you. I was just not sure
diegocarloslima 2018/01/19 12:17:46 for me it looks a bit weird this new line between
anton 2018/01/19 12:27:01 Acknowledged.
62 // all the settings except `enabled` and whitelisted domains list 61 // all the settings except `enabled` and whitelisted domains list
63 // are saved by adblock engine itself 62 // are saved by adblock engine itself
64 provider.getEngine().setEnabled(settings.isAdblockEnabled()); 63 provider.getEngine().setEnabled(settings.isAdblockEnabled());
65 provider.getEngine().setWhitelistedDomains(settings.getWhitelistedDomain s()); 64 provider.getEngine().setWhitelistedDomains(settings.getWhitelistedDomain s());
66 65
67 // allowed connection type is saved by filter engine but we need to over ride it 66 // allowed connection type is saved by filter engine but we need to over ride it
68 // as filter engine can be not created when changing 67 // as filter engine can be not created when changing
69 String connectionType = (settings.getAllowedConnectionType() != null 68 String connectionType = (settings.getAllowedConnectionType() != null
70 ? settings.getAllowedConnectionType().getValue() 69 ? settings.getAllowedConnectionType().getValue()
71 : null); 70 : null);
72 provider.getEngine().getFilterEngine().setAllowedConnectionType(connecti onType); 71 provider.getEngine().getFilterEngine().setAllowedConnectionType(connecti onType);
73 } 72 }
74 else 73 else
75 { 74 {
76 Log.w(TAG, "No saved adblock settings"); 75 Log.w(TAG, "No saved adblock settings");
77 } 76 }
78 } 77 }
79 }; 78 };
80 79
81 private Runnable engineDisposedCallback = new Runnable() 80 private final Runnable engineDisposedCallback = new Runnable()
diegocarloslima 2018/01/19 12:17:46 maybe declare it final?
anton 2018/01/19 12:27:01 Acknowledged.
82 { 81 {
83 @Override 82 @Override
84 public void run() 83 public void run()
85 { 84 {
86 Log.d(TAG, "Releasing adblock settings storage"); 85 Log.d(TAG, "Releasing adblock settings storage");
87 storage = null; 86 storage = null;
88 } 87 }
89 }; 88 };
90 89
91 // singleton 90 // singleton
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 private void initStorage(Context context, String settingsPreferenceName) 155 private void initStorage(Context context, String settingsPreferenceName)
157 { 156 {
158 // read and apply current settings 157 // read and apply current settings
159 SharedPreferences settingsPrefs = context.getSharedPreferences( 158 SharedPreferences settingsPrefs = context.getSharedPreferences(
160 settingsPreferenceName, 159 settingsPreferenceName,
161 Context.MODE_PRIVATE); 160 Context.MODE_PRIVATE);
162 161
163 storage = new SharedPrefsStorage(settingsPrefs); 162 storage = new SharedPrefsStorage(settingsPrefs);
164 } 163 }
165 164
166 // The methods below are deprecated: use .getProvider().method() instead 165 /**
diegocarloslima 2018/01/19 12:17:45 This comment would be better inside the javadoc pa
anton 2018/01/19 12:27:01 Acknowledged.
167 166 * @deprecated The method is deprecated: use .getProvider().retain() instead
167 */
168 @Deprecated 168 @Deprecated
169 public boolean retain(boolean asynchronous) 169 public boolean retain(boolean asynchronous)
170 { 170 {
171 return provider.retain(asynchronous); 171 return provider.retain(asynchronous);
172 } 172 }
173 173
174 /**
175 * @deprecated The method is deprecated: use .getProvider().waitForReady() ins tead
176 */
174 @Deprecated 177 @Deprecated
175 public void waitForReady() 178 public void waitForReady()
176 { 179 {
177 provider.waitForReady(); 180 provider.waitForReady();
178 } 181 }
179 182
183 /**
184 * @deprecated The method is deprecated: use .getProvider().getEngine() instea d
185 */
180 @Deprecated 186 @Deprecated
181 public AdblockEngine getEngine() 187 public AdblockEngine getEngine()
182 { 188 {
183 return provider.getEngine(); 189 return provider.getEngine();
184 } 190 }
185 191
192 /**
193 * @deprecated The method is deprecated: use .getProvider().release() instead
194 */
186 @Deprecated 195 @Deprecated
187 public boolean release() 196 public boolean release()
188 { 197 {
189 return provider.release(); 198 return provider.release();
190 } 199 }
191 200
201 /**
202 * @deprecated The method is deprecated: use .getProvider().getCounter() inste ad
203 */
192 @Deprecated 204 @Deprecated
193 public int getCounter() 205 public int getCounter()
194 { 206 {
195 return provider.getCounter(); 207 return provider.getCounter();
196 } 208 }
197 } 209 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld