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

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

Issue 5172657418928128: Determine the frame structure (Closed)
Patch Set: Map referrers 1:1, use a more reasonable initial cache size Created Nov. 27, 2013, 1:37 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 | « src/org/adblockplus/android/ABPEngine.java ('k') | no next file » | 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
@@ -23,7 +23,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Pattern;
@@ -84,6 +88,25 @@
private ABPEngine abpEngine;
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(Map.Entry<String, String> eldest)
+ {
+ return size() > MAX_SIZE;
+ }
+ };
+
+ private ReferrerMappingCache referrerMapping = new ReferrerMappingCache();
/**
* Returns pointer to itself (singleton pattern).
@@ -338,6 +361,9 @@
*/
public boolean matches(String url, String query, String referrer, String accept)
{
+ if (referrer != null)
+ referrerMapping.put(url, referrer);
+
if (!filteringEnabled)
return false;
@@ -368,7 +394,24 @@
if (!"".equals(query))
url = url + "?" + query;
- return abpEngine.matches(url, contentType, referrer);
+ final List<String> referrerChain = buildReferrerChain(referrer);
+ Log.d("Referrer chain", url + ": " + referrerChain.toString());
+ String[] referrerChainArray = referrerChain.toArray(new String[referrerChain.size()]);
+ return abpEngine.matches(url, contentType, referrerChainArray);
+ }
+
+ private List<String> buildReferrerChain(String url)
+ {
+ final List<String> referrerChain = new ArrayList<String>();
+ if (url != null)
+ {
+ referrerChain.add(url);
+
+ final String referrer = referrerMapping.get(url);
+ if (referrer != null)
+ referrerChain.addAll(buildReferrerChain(referrer));
+ }
Wladimir Palant 2013/11/27 14:00:30 Please don't use recursive algorithms where they d
Felix Dahlke 2013/11/27 14:47:32 Valid points, fixed.
+ return referrerChain;
}
/**
« no previous file with comments | « src/org/adblockplus/android/ABPEngine.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld