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

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

Issue 29453722: Noissue - Lint adjustments and optimizations (Closed)
Left Patch Set: Adjustments based on review comments Created June 13, 2017, 9:23 p.m.
Right Patch Set: Adjusting HashSet initialization in Subscription Created July 19, 2017, 4:40 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-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 14 matching lines...) Expand all
25 import java.io.File; 25 import java.io.File;
26 import java.io.FileInputStream; 26 import java.io.FileInputStream;
27 import java.io.FileOutputStream; 27 import java.io.FileOutputStream;
28 import java.io.IOException; 28 import java.io.IOException;
29 import java.io.StringReader; 29 import java.io.StringReader;
30 import java.net.URL; 30 import java.net.URL;
31 import java.nio.charset.StandardCharsets; 31 import java.nio.charset.StandardCharsets;
32 import java.security.MessageDigest; 32 import java.security.MessageDigest;
33 import java.security.NoSuchAlgorithmException; 33 import java.security.NoSuchAlgorithmException;
34 import java.util.ArrayList; 34 import java.util.ArrayList;
35 import java.util.Arrays;
35 import java.util.Collection; 36 import java.util.Collection;
36 import java.util.Collections; 37 import java.util.Collections;
37 import java.util.HashMap; 38 import java.util.HashMap;
38 import java.util.HashSet; 39 import java.util.HashSet;
39 import java.util.List; 40 import java.util.List;
40 import java.util.Locale; 41 import java.util.Locale;
41 import java.util.Map; 42 import java.util.Map;
42 import java.util.Map.Entry; 43 import java.util.Map.Entry;
43 import java.util.zip.GZIPInputStream; 44 import java.util.zip.GZIPInputStream;
44 import java.util.zip.GZIPOutputStream; 45 import java.util.zip.GZIPOutputStream;
45 46
46 import android.text.TextUtils; 47 import android.text.TextUtils;
47 import android.text.format.DateUtils; 48 import android.text.format.DateUtils;
48 import android.util.Log; 49 import android.util.Log;
49 50
50 /** 51 /**
51 * Simple subscription representation. 52 * Simple subscription representation.
52 */ 53 */
53 final class Subscription 54 final class Subscription
54 { 55 {
55 private static final String TAG = Subscription.class.getSimpleName(); 56 private static final String TAG = Subscription.class.getSimpleName();
56 public static final String KEY_TITLE = "title"; 57 public static final String KEY_TITLE = "title";
57 public static final String KEY_VERSION = "version"; 58 public static final String KEY_VERSION = "version";
58 public static final String KEY_FORCED_TITLE = "_title";
59 public static final String KEY_HTTP_ETAG = "_etag"; 59 public static final String KEY_HTTP_ETAG = "_etag";
60 public static final String KEY_HTTP_LAST_MODIFIED = "_last_modified"; 60 public static final String KEY_HTTP_LAST_MODIFIED = "_last_modified";
61 public static final String KEY_UPDATE_TIMESTAMP = "_update_timestamp"; 61 public static final String KEY_UPDATE_TIMESTAMP = "_update_timestamp";
62 public static final String KEY_TRIED_UPDATE_TIMESTAMP = "_tried_update_timesta mp"; 62 public static final String KEY_TRIED_UPDATE_TIMESTAMP = "_tried_update_timesta mp";
63 public static final String KEY_DOWNLOAD_COUNT = "_download_count"; 63 public static final String KEY_DOWNLOAD_COUNT = "_download_count";
64 public static final String KEY_ENABLED = "_enabled"; 64 public static final String KEY_ENABLED = "_enabled";
65 public static final String KEY_HAS_FILTERS = "_has_filters";
66 public static final String KEY_META_HASH = "_meta_hash"; 65 public static final String KEY_META_HASH = "_meta_hash";
67 66
68 private static final long MINIMAL_DOWNLOAD_INTERVAL = DateUtils.HOUR_IN_MILLIS / 4; 67 private static final long MINIMAL_DOWNLOAD_INTERVAL = DateUtils.HOUR_IN_MILLIS / 4;
69 private static final long DOWNLOAD_RETRY_INTERVAL = DateUtils.HOUR_IN_MILLIS; 68 private static final long DOWNLOAD_RETRY_INTERVAL = DateUtils.HOUR_IN_MILLIS;
70 69
71 private static final HashSet<String> ALLOWED_META_KEYS = new HashSet<>(); 70 /**
71 * List of meta keys that are allowed to import from a downloaded
72 * subscription.
73 */
74 private static final String[] ALLOWED_META_KEYS_ARRAY =
75 {
76 "checksum", KEY_VERSION, KEY_TITLE, "last modified", "expires", "homep age", "licence"
77 };
78 private static final HashSet<String> ALLOWED_META_KEYS =
79 new HashSet<>(Arrays.asList(ALLOWED_META_KEYS_ARRAY));
80
72 private static final Locale LOCALE_EN = Locale.ENGLISH; 81 private static final Locale LOCALE_EN = Locale.ENGLISH;
73 82
74 private final long updateInterval = DateUtils.DAY_IN_MILLIS 83 private final long updateInterval = DateUtils.DAY_IN_MILLIS
75 + (long) (DateUtils.HOUR_IN_MILLIS * 8. * Math.random()); 84 + (long) (DateUtils.HOUR_IN_MILLIS * 8. * Math.random());
76
77 /**
78 * List of meta keys that are allowed to import from a downloaded
79 * subscription.
80 */
81 private static final String[] ALLOWED_META_KEYS_ARRAY =
82 {
83 "checksum", KEY_VERSION, KEY_TITLE, "last modified", "expires", "homepage" , "licence"
84 };
85 85
86 private final URL url; 86 private final URL url;
87 private final Type type; 87 private final Type type;
88 private final HashMap<String, String> meta = new HashMap<>(); 88 private final HashMap<String, String> meta = new HashMap<>();
89 private final HashSet<String> filters = new HashSet<>(); 89 private final HashSet<String> filters = new HashSet<>();
90 90
91 private boolean metaDataValid = true; 91 private boolean metaDataValid = true;
92 private boolean filtersValid = true; 92 private boolean filtersValid = true;
93
94 static
95 {
96 Collections.addAll(ALLOWED_META_KEYS, ALLOWED_META_KEYS_ARRAY);
anton 2017/06/16 13:38:44 Can we replace: ``` private static final HashSet<S
diegocarloslima 2017/07/19 16:39:24 Yeah its possible to initialize the HashSet withou
97 }
98 93
99 /** 94 /**
100 * Subscription type. 95 * Subscription type.
101 * 96 *
102 * @author René Jeschke &lt;rene@adblockplus.org&gt; 97 * @author René Jeschke &lt;rene@adblockplus.org&gt;
103 */ 98 */
104 public enum Type 99 public enum Type
105 { 100 {
106 /** 101 /**
107 * Initiated from an URL, can be automatically downloaded. 102 * Initiated from an URL, can be automatically downloaded.
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 this.serializeMetaData(metaFile); 600 this.serializeMetaData(metaFile);
606 if (filtersChanged) 601 if (filtersChanged)
607 { 602 {
608 this.serializeFilters(filtersFile); 603 this.serializeFilters(filtersFile);
609 this.clearFilters(); 604 this.clearFilters();
610 } 605 }
611 606
612 return filtersChanged; 607 return filtersChanged;
613 } 608 }
614 } 609 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld