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

Unified Diff: src/org/adblockplus/android/AdblockPlus.java

Issue 5641446598115328: Move referrer mapping to a dedicated class (Closed)
Patch Set: Created July 15, 2014, 12:58 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/org/adblockplus/android/ReferrerMapping.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/android/AdblockPlus.java
===================================================================
--- a/src/org/adblockplus/android/AdblockPlus.java
+++ b/src/org/adblockplus/android/AdblockPlus.java
@@ -93,24 +93,7 @@
private static AdblockPlus instance;
- private static class ReferrerMappingCache extends LinkedHashMap<String, String>
- {
- private static final long serialVersionUID = 1L;
- private static final int MAX_SIZE = 5000;
-
- public ReferrerMappingCache()
- {
- super(MAX_SIZE + 1, 0.75f, true);
- }
-
- @Override
- protected boolean removeEldestEntry(final Map.Entry<String, String> eldest)
- {
- return size() > MAX_SIZE;
- }
- };
-
- private final ReferrerMappingCache referrerMapping = new ReferrerMappingCache();
+ private final ReferrerMapping referrerMapping = new ReferrerMapping();
/**
* Returns pointer to itself (singleton pattern).
@@ -359,7 +342,7 @@
{
final String fullUrl = !"".equals(query) ? url + "?" + query : url;
if (referrer != null)
- referrerMapping.put(fullUrl, referrer);
+ referrerMapping.add(fullUrl, referrer);
if (!filteringEnabled)
return false;
@@ -392,26 +375,12 @@
if (contentType == null)
contentType = "OTHER";
- final List<String> referrerChain = buildReferrerChain(referrer);
+ final List<String> referrerChain = referrerMapping.buildReferrerChain(referrer);
Log.d("Referrer chain", fullUrl + ": " + referrerChain.toString());
final String[] referrerChainArray = referrerChain.toArray(new String[referrerChain.size()]);
return abpEngine.matches(fullUrl, contentType, referrerChainArray);
}
- private List<String> buildReferrerChain(String url)
- {
- final List<String> referrerChain = new ArrayList<String>();
- // We need to limit the chain length to ensure we don't block indefinitely if there's
- // a referrer loop.
- final int maxChainLength = 10;
- for (int i = 0; i < maxChainLength && url != null; i++)
- {
- referrerChain.add(0, url);
- url = referrerMapping.get(url);
- }
- return referrerChain;
- }
-
/**
* Checks if filtering is enabled.
*/
« no previous file with comments | « no previous file | src/org/adblockplus/android/ReferrerMapping.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld