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

Side by Side Diff: src/org/adblockplus/android/ReferrerMapping.java

Issue 5641446598115328: Move referrer mapping to a dedicated class (Closed)
Patch Set: Created July 15, 2014, 12:58 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/org/adblockplus/android/AdblockPlus.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/AdblockPlus.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld