This source file includes following definitions.
- Noop
- CallDoomAllEntries
- ClearHttpDiskCacheOfContext
- ClearHttpDiskCacheOnIoThread
- RemoveHttpDiskCache
#include "android_webview/browser/net_disk_cache_remover.h"
#include "base/bind_helpers.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "net/disk_cache/disk_cache.h"
#include "net/http/http_cache.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_context.h"
#include "net/base/completion_callback.h"
using content::BrowserThread;
using disk_cache::Backend;
using net::CompletionCallback;
using net::URLRequestContextGetter;
namespace {
void Noop(int rv) {
DCHECK(rv == net::OK);
}
void CallDoomAllEntries(Backend** backend, int rv) {
DCHECK(rv == net::OK);
(*backend)->DoomAllEntries(base::Bind(&Noop));
}
void ClearHttpDiskCacheOfContext(URLRequestContextGetter* context_getter) {
typedef Backend* BackendPtr;
BackendPtr* backend_ptr = new BackendPtr(NULL);
CompletionCallback callback(base::Bind(&CallDoomAllEntries,
base::Owned(backend_ptr)));
int rv = context_getter->GetURLRequestContext()->
http_transaction_factory()->GetCache()->GetBackend(backend_ptr, callback);
if (rv != net::ERR_IO_PENDING)
callback.Run(net::OK);
}
void ClearHttpDiskCacheOnIoThread(
URLRequestContextGetter* main_context_getter,
URLRequestContextGetter* media_context_getter) {
ClearHttpDiskCacheOfContext(main_context_getter);
ClearHttpDiskCacheOfContext(media_context_getter);
}
}
namespace android_webview {
void RemoveHttpDiskCache(content::BrowserContext* browser_context,
int renderer_child_id) {
URLRequestContextGetter* main_context_getter =
browser_context->GetRequestContextForRenderProcess(renderer_child_id);
URLRequestContextGetter* media_context_getter =
browser_context->GetMediaRequestContextForRenderProcess(
renderer_child_id);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearHttpDiskCacheOnIoThread,
base::Unretained(main_context_getter),
base::Unretained(media_context_getter)));
}
}