OLD | NEW |
(Empty) | |
| 1 package org.adblockplus.android; |
| 2 |
| 3 import java.util.ArrayList; |
| 4 import java.util.LinkedHashMap; |
| 5 import java.util.List; |
| 6 import java.util.Map; |
| 7 |
| 8 public class ReferrerMapping |
| 9 { |
| 10 private static class MappingCache extends LinkedHashMap<String, String> |
| 11 { |
| 12 private static final long serialVersionUID = 1L; |
| 13 private static final int MAX_SIZE = 5000; |
| 14 |
| 15 public MappingCache() |
| 16 { |
| 17 super(MAX_SIZE + 1, 0.75f, true); |
| 18 } |
| 19 |
| 20 @Override |
| 21 protected boolean removeEldestEntry(final Map.Entry<String, String> eldest) |
| 22 { |
| 23 return size() > MAX_SIZE; |
| 24 } |
| 25 }; |
| 26 |
| 27 private final MappingCache mappingCache = new MappingCache(); |
| 28 |
| 29 public void add(String fullUrl, String referrer) |
| 30 { |
| 31 mappingCache.put(fullUrl, referrer); |
| 32 } |
| 33 |
| 34 public List<String> buildReferrerChain(String url) |
| 35 { |
| 36 final List<String> referrerChain = new ArrayList<String>(); |
| 37 // We need to limit the chain length to ensure we don't block indefinitely |
| 38 // if there's a referrer loop. |
| 39 final int maxChainLength = 10; |
| 40 for (int i = 0; i < maxChainLength && url != null; i++) |
| 41 { |
| 42 referrerChain.add(0, url); |
| 43 url = mappingCache.get(url); |
| 44 } |
| 45 return referrerChain; |
| 46 } |
| 47 } |
OLD | NEW |