()
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | @SuppressWarnings("unchecked") |
| 183 | protected ResultType doBackground() throws Throwable { |
| 184 | |
| 185 | if (this.isCancelled()) { |
| 186 | throw new Callback.CancelledException("cancelled before request"); |
| 187 | } |
| 188 | |
| 189 | // 初始化请求参数 |
| 190 | ResultType result = null; |
| 191 | resolveLoadType(); |
| 192 | request = createNewRequest(); |
| 193 | checkDownloadTask(); |
| 194 | // retry 初始化 |
| 195 | boolean retry = true; |
| 196 | int retryCount = 0; |
| 197 | Throwable exception = null; |
| 198 | HttpRetryHandler retryHandler = this.params.getHttpRetryHandler(); |
| 199 | if (retryHandler == null) { |
| 200 | retryHandler = new HttpRetryHandler(); |
| 201 | } |
| 202 | retryHandler.setMaxRetryCount(this.params.getMaxRetryCount()); |
| 203 | |
| 204 | if (this.isCancelled()) { |
| 205 | throw new Callback.CancelledException("cancelled before request"); |
| 206 | } |
| 207 | |
| 208 | // 检查缓存 |
| 209 | Object cacheResult = null; |
| 210 | if (cacheCallback != null && HttpMethod.permitsCache(params.getMethod())) { |
| 211 | // 尝试从缓存获取结果, 并为请求头加入缓存控制参数. |
| 212 | try { |
| 213 | clearRawResult(); |
| 214 | LogUtil.d("load cache: " + this.request.getRequestUri()); |
| 215 | rawResult = this.request.loadResultFromCache(); |
| 216 | } catch (Throwable ex) { |
| 217 | LogUtil.w("load disk cache error", ex); |
| 218 | } |
| 219 | |
| 220 | if (this.isCancelled()) { |
| 221 | clearRawResult(); |
| 222 | throw new Callback.CancelledException("cancelled before request"); |
| 223 | } |
| 224 | |
| 225 | if (rawResult != null) { |
| 226 | if (prepareCallback != null) { |
| 227 | try { |
| 228 | cacheResult = prepareCallback.prepare(rawResult); |
| 229 | } catch (Throwable ex) { |
| 230 | cacheResult = null; |
| 231 | LogUtil.w("prepare disk cache error", ex); |
| 232 | } finally { |
| 233 | clearRawResult(); |
| 234 | } |
| 235 | } else { |
| 236 | cacheResult = rawResult; |
| 237 | } |
| 238 |
nothing calls this directly
no test coverage detected