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

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Subscriptions.java

Issue 29673565: Issue 6066 - Implement 'force update' functionality for subscriptions (Closed)
Patch Set: Fixes Created Jan. 23, 2018, 3:12 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
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 { 111 {
112 final Subscription sub = this.subscriptions.get(id); 112 final Subscription sub = this.subscriptions.get(id);
113 if (sub != null) 113 if (sub != null)
114 { 114 {
115 if (enabled != sub.isEnabled()) 115 if (enabled != sub.isEnabled())
116 { 116 {
117 sub.setEnabled(enabled); 117 sub.setEnabled(enabled);
118 sub.serializeMetaData(this.getMetaFile(sub)); 118 sub.serializeMetaData(this.getMetaFile(sub));
119 if (enabled) 119 if (enabled)
120 { 120 {
121 this.engine.enqueueDownload(sub, true); 121 this.engine.enqueueDownload(sub, true, false);
122 } 122 }
123 123
124 this.engine.subscriptionStateChanged(); 124 this.engine.subscriptionStateChanged();
125 this.engine.requestUpdateBroadcast(); 125 this.engine.requestUpdateBroadcast();
126 return true; 126 return true;
127 } 127 }
128 } 128 }
129 return false; 129 return false;
130 } 130 }
131 131
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 { 176 {
177 if (s.isEnabled()) 177 if (s.isEnabled())
178 { 178 {
179 Log.d(TAG, "Adding filters for '" + s.getId() + "'"); 179 Log.d(TAG, "Adding filters for '" + s.getId() + "'");
180 s.deserializeFilters(this.getFiltersFile(s)); 180 s.deserializeFilters(this.getFiltersFile(s));
181 s.copyFilters(filters); 181 s.copyFilters(filters);
182 s.clearFilters(); 182 s.clearFilters();
183 } 183 }
184 if ((!s.isMetaDataValid() || !s.isFiltersValid()) && s.getURL() != null) 184 if ((!s.isMetaDataValid() || !s.isFiltersValid()) && s.getURL() != null)
185 { 185 {
186 this.engine.enqueueDownload(s, true); 186 this.engine.enqueueDownload(s, true, false);
187 } 187 }
188 } 188 }
189 189
190 try (final BufferedWriter w = new BufferedWriter( 190 try (final BufferedWriter w = new BufferedWriter(
191 new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UT F_8))) 191 new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UT F_8)))
192 { 192 {
193 Log.d(TAG, "Writing " + filters.size() + " filters"); 193 Log.d(TAG, "Writing " + filters.size() + " filters");
194 Engine.writeFilterHeaders(w); 194 Engine.writeFilterHeaders(w);
195 for (final String filter : filters) 195 for (final String filter : filters)
196 { 196 {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 for (String title : USER_SUBSCRIPTIONS) 263 for (String title : USER_SUBSCRIPTIONS)
264 { 264 {
265 final Subscription userSub = Subscription.createUserSubscription(title); 265 final Subscription userSub = Subscription.createUserSubscription(title);
266 if (!this.subscriptions.containsKey(userSub.getId())) 266 if (!this.subscriptions.containsKey(userSub.getId()))
267 { 267 {
268 this.subscriptions.put(userSub.getId(), userSub); 268 this.subscriptions.put(userSub.getId(), userSub);
269 } 269 }
270 } 270 }
271 } 271 }
272 272
273 public void checkForUpdates() throws IOException 273 public void checkForUpdates(final boolean forced, final boolean allowMetered) throws IOException
274 { 274 {
275 for (Subscription sub : this.subscriptions.values()) 275 for (Subscription sub : this.subscriptions.values())
276 { 276 {
277 if (sub.isEnabled()) 277 if (sub.isEnabled())
278 { 278 {
279 this.engine.enqueueDownload(sub, false); 279 this.engine.enqueueDownload(sub, forced, allowMetered);
280 } 280 }
281 } 281 }
282 } 282 }
283 283
284 public void updateSubscription(final String id, final int responseCode, final String text, 284 public void updateSubscription(final String id, final int responseCode, final String text,
285 final Map<String, String> httpHeaders) 285 final Map<String, String> httpHeaders)
286 throws IOException 286 throws IOException
287 { 287 {
288 final Subscription sub = this.subscriptions.get(id); 288 final Subscription sub = this.subscriptions.get(id);
289 if (sub != null) 289 if (sub != null)
290 { 290 {
291 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub), 291 if (sub.updateSubscription(responseCode, text, httpHeaders, this.getMetaFi le(sub),
292 this.getFiltersFile(sub))) 292 this.getFiltersFile(sub)))
293 { 293 {
294 this.engine.requestUpdateBroadcast(); 294 this.engine.requestUpdateBroadcast();
295 } 295 }
296 } 296 }
297 } 297 }
298 } 298 }
OLDNEW

Powered by Google App Engine
This is Rietveld