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

Delta Between Two Patch Sets: src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29355392: Issue 4485 - Clear cache directory (Closed)
Left Patch Set: Created Sept. 30, 2016, 2:48 a.m.
Right Patch Set: Adding null check for listFiles Created Sept. 30, 2016, 3:02 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
« no previous file with change/comment | « no previous file | src/org/adblockplus/sbrowser/contentblocker/engine/Subscriptions.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 import android.net.Uri; 48 import android.net.Uri;
49 import android.os.Handler; 49 import android.os.Handler;
50 import android.os.Looper; 50 import android.os.Looper;
51 import android.preference.PreferenceManager; 51 import android.preference.PreferenceManager;
52 import android.util.Log; 52 import android.util.Log;
53 53
54 public final class Engine 54 public final class Engine
55 { 55 {
56 private static final String TAG = Engine.class.getSimpleName(); 56 private static final String TAG = Engine.class.getSimpleName();
57 57
58 public static final String ABP_VERSION = "2.0";
59
60 // TODO make use of this regex's 58 // TODO make use of this regex's
61 public static final Pattern RE_SUBSCRIPTION_HEADER = Pattern.compile( 59 public static final Pattern RE_SUBSCRIPTION_HEADER = Pattern.compile(
62 "\\[Adblock(?:\\s*Plus\\s*([\\d\\.]+)?)?\\]", Pattern.CASE_INSENSITIVE); 60 "\\[Adblock(?:\\s*Plus\\s*([\\d\\.]+)?)?\\]", Pattern.CASE_INSENSITIVE);
63 public static final Pattern RE_FILTER_META = Pattern.compile("^\\s*!\\s*(\\w+) \\s*:\\s*(.*)"); 61 public static final Pattern RE_FILTER_META = Pattern.compile("^\\s*!\\s*(\\w+) \\s*:\\s*(.*)");
64 public static final Pattern RE_FILTER_ELEMHIDE = Pattern 62 public static final Pattern RE_FILTER_ELEMHIDE = Pattern
65 .compile("^([^\\/\\*\\|\\@\"!]*?)#(\\@)?(?:([\\w\\-]+|\\*)((?:\\([\\w\\-]+ (?:[$^*]?=[^\\(\\)\"]*)?\\))*)|#([^{}]+))$"); 63 .compile("^([^\\/\\*\\|\\@\"!]*?)#(\\@)?(?:([\\w\\-]+|\\*)((?:\\([\\w\\-]+ (?:[$^*]?=[^\\(\\)\"]*)?\\))*)|#([^{}]+))$");
66 public static final Pattern RE_FILTER_REGEXP = Pattern 64 public static final Pattern RE_FILTER_REGEXP = Pattern
67 .compile("^(@@)?\\/.*\\/(?:\\$~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:= [^,\\s]+)?)*)?$"); 65 .compile("^(@@)?\\/.*\\/(?:\\$~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:= [^,\\s]+)?)*)?$");
68 public static final Pattern RE_FILTER_OPTIONS = Pattern 66 public static final Pattern RE_FILTER_OPTIONS = Pattern
69 .compile("\\$(~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:=[^,\\s]+)?)*)$") ; 67 .compile("\\$(~?[\\w\\-]+(?:=[^,\\s]+)?(?:,~?[\\w\\-]+(?:=[^,\\s]+)?)*)$") ;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 { 249 {
252 Log.d(TAG, "Writing filters..."); 250 Log.d(TAG, "Writing filters...");
253 final File filterFile = this.subscriptions.createAndWriteFile(); 251 final File filterFile = this.subscriptions.createAndWriteFile();
254 252
255 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferen ces(this.serviceContext); 253 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferen ces(this.serviceContext);
256 final String key = this.serviceContext.getString(R.string.key_cached_filte r_path); 254 final String key = this.serviceContext.getString(R.string.key_cached_filte r_path);
257 prefs.edit().putString(key, filterFile.getAbsolutePath()).commit(); 255 prefs.edit().putString(key, filterFile.getAbsolutePath()).commit();
258 256
259 Log.d(TAG, "Cleaning up cache..."); 257 Log.d(TAG, "Cleaning up cache...");
260 final File dummyFile = getDummyFilterFile(this.serviceContext); 258 final File dummyFile = getDummyFilterFile(this.serviceContext);
261 for (final File file : getFilterCacheDir(this.serviceContext).listFiles()) 259 final File[] cacheDirFiles = getFilterCacheDir(this.serviceContext).listFi les();
anton 2016/09/30 06:17:15 listFiles() can return `null` is getFilterCacheDir
diegocarloslima 2016/09/30 14:35:47 The directory should exists in order for the previ
262 { 260 if (cacheDirFiles != null)
263 if (!file.equals(dummyFile) && !file.equals(filterFile)) 261 {
262 for (final File file : cacheDirFiles)
264 { 263 {
265 Log.d(TAG, "Deleting file:" + file); 264 if (!file.equals(dummyFile) && !file.equals(filterFile))
266 file.delete(); 265 {
266 Log.d(TAG, "Deleting file:" + file);
267 file.delete();
268 }
267 } 269 }
268 } 270 }
269 } 271 }
270 catch (IOException e) 272 catch (IOException e)
271 { 273 {
272 Log.e(TAG, "Failed to write filters", e); 274 Log.e(TAG, "Failed to write filters", e);
273 } 275 }
274 finally 276 finally
275 { 277 {
276 this.unlock(); 278 this.unlock();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 finally 483 finally
482 { 484 {
483 writer.close(); 485 writer.close();
484 } 486 }
485 } 487 }
486 return dummyFilterFile; 488 return dummyFilterFile;
487 } 489 }
488 490
489 public static void writeFilterHeaders(Writer writer) throws IOException 491 public static void writeFilterHeaders(Writer writer) throws IOException
490 { 492 {
491 writer.write("[Adblock Plus" + ABP_VERSION + "]\n"); 493 writer.write("[Adblock Plus 2.0]\n");
492 writer.write("! This file was automatically created.\n"); 494 writer.write("! This file was automatically created.\n");
493 } 495 }
494 496
495 private static File getCachedFilterFile(Context context) 497 private static File getCachedFilterFile(Context context)
496 { 498 {
497 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(context); 499 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference s(context);
498 final String cachedFilterPath = prefs.getString(context.getString(R.string.k ey_cached_filter_path), null); 500 final String cachedFilterPath = prefs.getString(context.getString(R.string.k ey_cached_filter_path), null);
499 if (cachedFilterPath != null) 501 if (cachedFilterPath != null)
500 { 502 {
501 return new File(cachedFilterPath); 503 return new File(cachedFilterPath);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 Log.d(TAG, headers.toString()); 724 Log.d(TAG, headers.toString());
723 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers); 725 this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers);
724 } 726 }
725 } 727 }
726 728
727 public void connectivityChanged() 729 public void connectivityChanged()
728 { 730 {
729 this.downloader.connectivityChanged(); 731 this.downloader.connectivityChanged();
730 } 732 }
731 } 733 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld