| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 connection.getInputStream(), StandardCharsets.UTF_8))) | 102 connection.getInputStream(), StandardCharsets.UTF_8))) |
| 103 { | 103 { |
| 104 for (int ch = r.read(); ch != -1; ch = r.read()) | 104 for (int ch = r.read(); ch != -1; ch = r.read()) |
| 105 { | 105 { |
| 106 sb.append((char) ch); | 106 sb.append((char) ch); |
| 107 } | 107 } |
| 108 job.responseText = sb.toString(); | 108 job.responseText = sb.toString(); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 public void enqueueDownload(final URL url, final String id, final Map<String, String> headers) | 112 public void enqueueDownload(final URL url, final String id, final Map<String, String> headers, final boolean allowMetered) |
|
anton
2018/01/19 10:53:02
the line seems to be too long
jens
2018/01/19 11:00:47
Acknowledged.
| |
| 113 { | 113 { |
| 114 this.lock(); | 114 this.lock(); |
| 115 try | 115 try |
| 116 { | 116 { |
| 117 if (!this.enqueuedIds.contains(id)) | 117 if (!this.enqueuedIds.contains(id)) |
| 118 { | 118 { |
| 119 this.enqueuedIds.add(id); | 119 this.enqueuedIds.add(id); |
| 120 this.downloadJobs.add(new DownloadJob(url, id, headers)); | 120 this.downloadJobs.add(new DownloadJob(url, id, headers, allowMetered)); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 finally | 123 finally |
| 124 { | 124 { |
| 125 this.unlock(); | 125 this.unlock(); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 public static Downloader create(final Engine engine) | 129 public static Downloader create(final Engine engine) |
| 130 { | 130 { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 160 try | 160 try |
| 161 { | 161 { |
| 162 if (!this.downloader.downloaderEnabled) | 162 if (!this.downloader.downloaderEnabled) |
| 163 { | 163 { |
| 164 Thread.sleep(30000); | 164 Thread.sleep(30000); |
| 165 continue; | 165 continue; |
| 166 } | 166 } |
| 167 job = this.downloader.downloadJobs.poll(5 * 60, TimeUnit.SECONDS); | 167 job = this.downloader.downloadJobs.poll(5 * 60, TimeUnit.SECONDS); |
| 168 if (job != null) | 168 if (job != null) |
| 169 { | 169 { |
| 170 if (this.downloader.engine.canUseInternet()) | 170 if (this.downloader.engine.canUseInternet() || job.allowMetered) |
| 171 { | 171 { |
| 172 Log.d(TAG, "Downloading '" + job.id + "' using " + job.url); | 172 Log.d(TAG, "Downloading '" + job.id + "' using " + job.url); |
| 173 download(job); | 173 download(job); |
| 174 Log.d(TAG, "Downloading '" + job.id + "' finished with response co de " | 174 Log.d(TAG, "Downloading '" + job.id + "' finished with response co de " |
| 175 + job.responseCode); | 175 + job.responseCode); |
| 176 this.downloader.lock(); | 176 this.downloader.lock(); |
| 177 try | 177 try |
| 178 { | 178 { |
| 179 this.downloader.enqueuedIds.remove(job.id); | 179 this.downloader.enqueuedIds.remove(job.id); |
| 180 } | 180 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 Log.d(TAG, "Handler thread finished"); | 236 Log.d(TAG, "Handler thread finished"); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 private static class DownloadJob | 240 private static class DownloadJob |
| 241 { | 241 { |
| 242 private final URL url; | 242 private final URL url; |
| 243 private final String id; | 243 private final String id; |
| 244 private final boolean allowMetered; | |
| 244 private final HashMap<String, String> headers = new HashMap<>(); | 245 private final HashMap<String, String> headers = new HashMap<>(); |
| 245 private int retryCount = 0; | 246 private int retryCount = 0; |
| 246 | 247 |
| 247 private int responseCode = 0; | 248 private int responseCode = 0; |
| 248 private final HashMap<String, String> responseHeaders = new HashMap<>(); | 249 private final HashMap<String, String> responseHeaders = new HashMap<>(); |
| 249 private String responseText = null; | 250 private String responseText = null; |
| 250 | 251 |
| 251 public DownloadJob(final URL url, final String id, final Map<String, String> headers) | 252 public DownloadJob(final URL url, final String id, final Map<String, String> headers, boolean allowMetered) |
| 252 { | 253 { |
| 253 this.url = url; | 254 this.url = url; |
| 254 this.id = id; | 255 this.id = id; |
| 256 this.allowMetered = allowMetered; | |
| 255 if (headers != null) | 257 if (headers != null) |
| 256 { | 258 { |
| 257 this.headers.putAll(headers); | 259 this.headers.putAll(headers); |
| 258 } | 260 } |
| 259 } | 261 } |
| 260 } | 262 } |
| 261 } | 263 } |
| OLD | NEW |