blob: a3478bf148e97e59acde8c2373906729ce7c507c [file] [log] [blame]
Jean-Baptiste Querud56b88a2012-11-07 07:48:57 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.volley.toolbox;
18
19import com.android.volley.Cache;
20import com.android.volley.NetworkResponse;
21import com.android.volley.Request;
22import com.android.volley.Response;
23
24import android.os.Handler;
25import android.os.Looper;
26
27/**
28 * A synthetic request used for clearing the cache.
29 */
30public class ClearCacheRequest extends Request<Object> {
31 private final Cache mCache;
32 private final Runnable mCallback;
33
34 /**
35 * Creates a synthetic request for clearing the cache.
36 * @param cache Cache to clear
37 * @param callback Callback to make on the main thread once the cache is clear,
38 * or null for none
39 */
40 public ClearCacheRequest(Cache cache, Runnable callback) {
Jean-Baptiste Querue48f4432012-11-07 07:54:36 -080041 super(Method.GET, null, null);
Jean-Baptiste Querud56b88a2012-11-07 07:48:57 -080042 mCache = cache;
43 mCallback = callback;
44 }
45
46 @Override
47 public boolean isCanceled() {
48 // This is a little bit of a hack, but hey, why not.
49 mCache.clear();
50 if (mCallback != null) {
51 Handler handler = new Handler(Looper.getMainLooper());
52 handler.postAtFrontOfQueue(mCallback);
53 }
54 return true;
55 }
56
57 @Override
58 public Priority getPriority() {
59 return Priority.IMMEDIATE;
60 }
61
62 @Override
63 protected Response<Object> parseNetworkResponse(NetworkResponse response) {
64 return null;
65 }
66
67 @Override
68 protected void deliverResponse(Object response) {
69 }
70}