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 29678590: Issue 6307 - Introduce external engine created callback (Closed)
Left Patch Set: Created Jan. 24, 2018, 12:46 p.m.
Right Patch Set: introduced custom listener interfaces Created Jan. 26, 2018, 12:46 p.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 final Runnable engineCreatedCallback = new Runnable() 51 private final SingleInstanceEngineProvider.EngineCreatedListener engineCreated Listener =
anton 2018/01/24 12:50:05 We could accept Runnable in some `AdblockHelper` m
52 new SingleInstanceEngineProvider.EngineCreatedListener()
52 { 53 {
53 @Override 54 @Override
54 public void run() 55 public void onAdblockEngineCreated(AdblockEngine engine)
55 { 56 {
56 AdblockSettings settings = storage.load(); 57 AdblockSettings settings = storage.load();
57 if (settings != null) 58 if (settings != null)
58 { 59 {
59 Log.d(TAG, "Applying saved adblock settings to adblock engine"); 60 Log.d(TAG, "Applying saved adblock settings to adblock engine");
60 // apply last saved settings to adblock engine. 61 // apply last saved settings to adblock engine.
61 // all the settings except `enabled` and whitelisted domains list 62 // all the settings except `enabled` and whitelisted domains list
62 // are saved by adblock engine itself 63 // are saved by adblock engine itself
63 provider.getEngine().setEnabled(settings.isAdblockEnabled()); 64 engine.setEnabled(settings.isAdblockEnabled());
64 provider.getEngine().setWhitelistedDomains(settings.getWhitelistedDomain s()); 65 engine.setWhitelistedDomains(settings.getWhitelistedDomains());
65 66
66 // allowed connection type is saved by filter engine but we need to over ride it 67 // allowed connection type is saved by filter engine but we need to over ride it
67 // as filter engine can be not created when changing 68 // as filter engine can be not created when changing
68 String connectionType = (settings.getAllowedConnectionType() != null 69 String connectionType = (settings.getAllowedConnectionType() != null
69 ? settings.getAllowedConnectionType().getValue() 70 ? settings.getAllowedConnectionType().getValue()
70 : null); 71 : null);
71 provider.getEngine().getFilterEngine().setAllowedConnectionType(connecti onType); 72 engine.getFilterEngine().setAllowedConnectionType(connectionType);
72 } 73 }
73 else 74 else
74 { 75 {
75 Log.w(TAG, "No saved adblock settings"); 76 Log.w(TAG, "No saved adblock settings");
76 } 77 }
77 } 78 }
78 }; 79 };
79 80
80 private final Runnable engineDisposedCallback = new Runnable() 81 private final SingleInstanceEngineProvider.EngineDisposedListener engineDispos edListener =
82 new SingleInstanceEngineProvider.EngineDisposedListener()
81 { 83 {
82 @Override 84 @Override
83 public void run() 85 public void onAdblockEngineDisposed()
84 { 86 {
85 Log.d(TAG, "Releasing adblock settings storage"); 87 Log.d(TAG, "Releasing adblock settings storage");
86 storage = null; 88 storage = null;
87 } 89 }
88 }; 90 };
89 91
90 // singleton 92 // singleton
91 protected AdblockHelper() 93 protected AdblockHelper()
92 { 94 {
93 // prevents instantiation 95 // prevents instantiation
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 boolean developmentBuild, String pref erenceName) 143 boolean developmentBuild, String pref erenceName)
142 { 144 {
143 initProvider(context, basePath, developmentBuild); 145 initProvider(context, basePath, developmentBuild);
144 initStorage(context, preferenceName); 146 initStorage(context, preferenceName);
145 return provider; 147 return provider;
146 } 148 }
147 149
148 private void initProvider(Context context, String basePath, boolean developmen tBuild) 150 private void initProvider(Context context, String basePath, boolean developmen tBuild)
149 { 151 {
150 provider = new SingleInstanceEngineProvider(context, basePath, developmentBu ild); 152 provider = new SingleInstanceEngineProvider(context, basePath, developmentBu ild);
151 provider.addEngineCreatedCallback(engineCreatedCallback); 153 provider.addEngineCreatedListener(engineCreatedListener);
152 provider.addEngineDisposedCallback(engineDisposedCallback); 154 provider.addEngineDisposedListener(engineDisposedListener);
153 } 155 }
154 156
155 private void initStorage(Context context, String settingsPreferenceName) 157 private void initStorage(Context context, String settingsPreferenceName)
156 { 158 {
157 // read and apply current settings 159 // read and apply current settings
158 SharedPreferences settingsPrefs = context.getSharedPreferences( 160 SharedPreferences settingsPrefs = context.getSharedPreferences(
159 settingsPreferenceName, 161 settingsPreferenceName,
160 Context.MODE_PRIVATE); 162 Context.MODE_PRIVATE);
161 163
162 storage = new SharedPrefsStorage(settingsPrefs); 164 storage = new SharedPrefsStorage(settingsPrefs);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 202
201 /** 203 /**
202 * @deprecated The method is deprecated: use .getProvider().getCounter() inste ad 204 * @deprecated The method is deprecated: use .getProvider().getCounter() inste ad
203 */ 205 */
204 @Deprecated 206 @Deprecated
205 public int getCounter() 207 public int getCounter()
206 { 208 {
207 return provider.getCounter(); 209 return provider.getCounter();
208 } 210 }
209 } 211 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld