OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/browser/net_disk_cache_remover.h" | |
6 | |
7 #include "base/bind_helpers.h" | |
8 #include "content/public/browser/browser_context.h" | |
9 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/render_process_host.h" | |
11 #include "content/public/browser/storage_partition.h" | |
12 #include "net/disk_cache/disk_cache.h" | |
13 #include "net/http/http_cache.h" | |
14 #include "net/http/http_transaction_factory.h" | |
15 #include "net/url_request/url_request_context_getter.h" | |
16 #include "net/url_request/url_request_context.h" | |
17 #include "net/base/completion_callback.h" | |
18 | |
19 using content::BrowserThread; | |
20 using disk_cache::Backend; | |
21 using net::CompletionCallback; | |
22 using net::URLRequestContextGetter; | |
23 | |
24 namespace { | |
25 // Everything is called and accessed on the IO thread. | |
26 | |
27 void Noop(int rv) { | |
28 DCHECK_EQ(net::OK, rv); | |
29 } | |
30 | |
31 void CallDoomAllEntries(Backend** backend, int rv) { | |
32 DCHECK_EQ(net::OK, rv); | |
33 (*backend)->DoomAllEntries(base::Bind(&Noop)); | |
34 } | |
35 | |
36 void ClearHttpDiskCacheOfContext(URLRequestContextGetter* context_getter) { | |
37 typedef Backend* BackendPtr; // Make line below easier to understand. | |
38 BackendPtr* backend_ptr = new BackendPtr(NULL); | |
39 CompletionCallback callback(base::Bind(&CallDoomAllEntries, | |
40 base::Owned(backend_ptr))); | |
41 | |
42 int rv = context_getter->GetURLRequestContext()-> | |
43 http_transaction_factory()->GetCache()->GetBackend(backend_ptr, callback); | |
44 | |
45 // If not net::ERR_IO_PENDING, then backend pointer is updated but callback | |
46 // is not called, so call it explicitly. | |
47 if (rv != net::ERR_IO_PENDING) | |
48 callback.Run(net::OK); | |
49 } | |
50 | |
51 void ClearHttpDiskCacheOnIoThread( | |
52 URLRequestContextGetter* main_context_getter, | |
53 URLRequestContextGetter* media_context_getter) { | |
54 ClearHttpDiskCacheOfContext(main_context_getter); | |
55 ClearHttpDiskCacheOfContext(media_context_getter); | |
56 } | |
57 | |
58 } // namespace | |
59 | |
60 namespace android_webview { | |
61 | |
62 void RemoveHttpDiskCache(content::RenderProcessHost* render_process_host) { | |
63 BrowserThread::PostTask( | |
64 BrowserThread::IO, FROM_HERE, | |
65 base::Bind(&ClearHttpDiskCacheOnIoThread, | |
66 base::Unretained(render_process_host->GetStoragePartition()-> | |
67 GetURLRequestContext()), | |
68 base::Unretained(render_process_host->GetStoragePartition()-> | |
69 GetMediaURLRequestContext()))); | |
70 } | |
71 | |
72 } // namespace android_webview | |
OLD | NEW |