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

Delta Between Two Patch Sets: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequestResourceWrapper.java

Issue 29389555: Issue 5010 - Allow to preload subscription files (Closed)
Left Patch Set: diego's comments Created March 28, 2017, 2:04 p.m.
Right Patch Set: force downloading actually Created March 30, 2017, 10:12 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 "https://easylist-downloads.adblockplus.org/liste_fr+easylist.txt"; 69 "https://easylist-downloads.adblockplus.org/liste_fr+easylist.txt";
70 public static final String EASYLIST_ROMANIAN = 70 public static final String EASYLIST_ROMANIAN =
71 "https://easylist-downloads.adblockplus.org/rolist+easylist.txt"; 71 "https://easylist-downloads.adblockplus.org/rolist+easylist.txt";
72 public static final String EASYLIST_RUSSIAN = 72 public static final String EASYLIST_RUSSIAN =
73 "https://easylist-downloads.adblockplus.org/ruadlist+easylist.txt"; 73 "https://easylist-downloads.adblockplus.org/ruadlist+easylist.txt";
74 public static final String ACCEPTABLE_ADS = 74 public static final String ACCEPTABLE_ADS =
75 "https://easylist-downloads.adblockplus.org/exceptionrules.txt"; 75 "https://easylist-downloads.adblockplus.org/exceptionrules.txt";
76 76
77 private Context context; 77 private Context context;
78 private WebRequest request; 78 private WebRequest request;
79 private Map<String, Integer> URLtoResouceIdMap; 79 private Map<String, Integer> urlToResourceIdMap;
80 private Storage storage; 80 private Storage storage;
81 private Listener listener; 81 private Listener listener;
82 82
83 /** 83 /**
84 * Constructor 84 * Constructor
85 * @param context android context 85 * @param context android context
86 * @param request wrapped request to perform the request if it's not preloaded subscription requested 86 * @param request wrapped request to perform the request if it's not preloaded subscription requested
87 * @param URLtoResourceIdMap map URL -> android resource id for preloaded subs criptions 87 * @param urlToResourceIdMap map URL -> android resource id for preloaded subs criptions
88 * See AndroidWebRequestResourceWrapper.EASYLIST_... constants 88 * See AndroidWebRequestResourceWrapper.EASYLIST_... constants
89 * @param storage Storage impl to remember served interceptions 89 * @param storage Storage impl to remember served interceptions
90 */ 90 */
91 public AndroidWebRequestResourceWrapper(Context context, WebRequest request, 91 public AndroidWebRequestResourceWrapper(Context context, WebRequest request,
92 Map<String, Integer> URLtoResourceIdMa p, 92 Map<String, Integer> urlToResourceIdMa p,
93 Storage storage) 93 Storage storage)
94 { 94 {
95 this.context = context; 95 this.context = context;
96 this.request = request; 96 this.request = request;
97 this.URLtoResouceIdMap = Collections.synchronizedMap(URLtoResourceIdMap); 97 this.urlToResourceIdMap = Collections.synchronizedMap(urlToResourceIdMap);
98 this.storage = storage; 98 this.storage = storage;
99 } 99 }
100 100
101 public Listener getListener() 101 public Listener getListener()
102 { 102 {
103 return listener; 103 return listener;
104 } 104 }
105 105
106 public void setListener(Listener listener) 106 public void setListener(Listener listener)
107 { 107 {
108 this.listener = listener; 108 this.listener = listener;
109 } 109 }
110 110
111 @Override 111 @Override
112 public ServerResponse httpGET(String url, List<HeaderEntry> headers) 112 public ServerResponse httpGET(String url, List<HeaderEntry> headers)
113 { 113 {
114 // since parameters may vary we need to ignore them 114 // since parameters may vary we need to ignore them
115 String urlWithoutParams = url.substring(0, url.indexOf("?")); 115 String urlWithoutParams = url.substring(0, url.indexOf("?"));
116 Integer resourceId = URLtoResouceIdMap.get(urlWithoutParams); 116 Integer resourceId = urlToResourceIdMap.get(urlWithoutParams);
117 117
118 if (resourceId != null) 118 if (resourceId != null)
119 { 119 {
120 if (!storage.contains(urlWithoutParams)) 120 if (!storage.contains(urlWithoutParams))
121 { 121 {
122 Log.w(TAG, "Intercepting request for " + url + " with resource #" + reso urceId.intValue()); 122 Log.w(TAG, "Intercepting request for " + url + " with resource #" + reso urceId.intValue());
123 ServerResponse response = buildResourceContentResponse(resourceId); 123 ServerResponse response = buildResourceContentResponse(resourceId);
124 storage.put(urlWithoutParams); 124 storage.put(urlWithoutParams);
125 125
126 if (listener != null) 126 if (listener != null)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 .commit(); 247 .commit();
248 } 248 }
249 249
250 @Override 250 @Override
251 public synchronized boolean contains(String url) 251 public synchronized boolean contains(String url)
252 { 252 {
253 return urls.contains(url); 253 return urls.contains(url);
254 } 254 }
255 } 255 }
256 } 256 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld