Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: ios/net/http_cache_helper.cc

Issue 2270063005: Add support for time based deletion of browsing data on iOS (Closed)
Patch Set: Updated comment in AccountConsistencyService Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/net/http_cache_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/net/http_cache_helper.h" 5 #include "ios/net/http_cache_helper.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 15 matching lines...) Expand all
26 // Posts |callback| on |task_runner|. 26 // Posts |callback| on |task_runner|.
27 void PostCallback(const scoped_refptr<base::TaskRunner>& task_runner, 27 void PostCallback(const scoped_refptr<base::TaskRunner>& task_runner,
28 const net::CompletionCallback& callback, 28 const net::CompletionCallback& callback,
29 int error) { 29 int error) {
30 task_runner->PostTask(FROM_HERE, base::Bind(callback, error)); 30 task_runner->PostTask(FROM_HERE, base::Bind(callback, error));
31 } 31 }
32 32
33 // Clears the disk_cache::Backend on the IO thread and deletes |backend|. 33 // Clears the disk_cache::Backend on the IO thread and deletes |backend|.
34 void DoomHttpCache(std::unique_ptr<disk_cache::Backend*> backend, 34 void DoomHttpCache(std::unique_ptr<disk_cache::Backend*> backend,
35 const scoped_refptr<base::TaskRunner>& client_task_runner, 35 const scoped_refptr<base::TaskRunner>& client_task_runner,
36 const base::Time& delete_begin,
37 const base::Time& delete_end,
36 const net::CompletionCallback& callback, 38 const net::CompletionCallback& callback,
37 int error) { 39 int error) {
38 // |*backend| may be null in case of error. 40 // |*backend| may be null in case of error.
39 if (*backend) { 41 if (*backend) {
40 (*backend)->DoomAllEntries( 42 (*backend)->DoomEntriesBetween(
43 delete_begin, delete_end,
41 base::Bind(&PostCallback, client_task_runner, callback)); 44 base::Bind(&PostCallback, client_task_runner, callback));
42 } else { 45 } else {
43 client_task_runner->PostTask(FROM_HERE, base::Bind(callback, error)); 46 client_task_runner->PostTask(FROM_HERE, base::Bind(callback, error));
44 } 47 }
45 } 48 }
46 49
47 // Clears various caches synchronously and the disk_cache::Backend 50 // Clears various caches synchronously and the disk_cache::Backend
48 // asynchronously. 51 // asynchronously.
49 void ClearHttpCacheOnIOThread( 52 void ClearHttpCacheOnIOThread(
50 const scoped_refptr<net::URLRequestContextGetter>& getter, 53 const scoped_refptr<net::URLRequestContextGetter>& getter,
51 const scoped_refptr<base::TaskRunner>& client_task_runner, 54 const scoped_refptr<base::TaskRunner>& client_task_runner,
55 const base::Time& delete_begin,
56 const base::Time& delete_end,
52 const net::CompletionCallback& callback) { 57 const net::CompletionCallback& callback) {
53 net::HttpCache* http_cache = 58 net::HttpCache* http_cache =
54 getter->GetURLRequestContext()->http_transaction_factory()->GetCache(); 59 getter->GetURLRequestContext()->http_transaction_factory()->GetCache();
55 60
56 // Clear QUIC server information from memory and the disk cache. 61 // Clear QUIC server information from memory and the disk cache.
57 http_cache->GetSession() 62 http_cache->GetSession()
58 ->quic_stream_factory() 63 ->quic_stream_factory()
59 ->ClearCachedStatesInCryptoConfig(base::Callback<bool(const GURL&)>()); 64 ->ClearCachedStatesInCryptoConfig(base::Callback<bool(const GURL&)>());
60 65
61 // Clear SDCH dictionary state. 66 // Clear SDCH dictionary state.
62 net::SdchManager* sdch_manager = 67 net::SdchManager* sdch_manager =
63 getter->GetURLRequestContext()->sdch_manager(); 68 getter->GetURLRequestContext()->sdch_manager();
64 // The test is probably overkill, since chrome should always have an 69 // The test is probably overkill, since chrome should always have an
65 // SdchManager. But in general the URLRequestContext is *not* 70 // SdchManager. But in general the URLRequestContext is *not*
66 // guaranteed to have an SdchManager, so checking is wise. 71 // guaranteed to have an SdchManager, so checking is wise.
67 if (sdch_manager) 72 if (sdch_manager)
68 sdch_manager->ClearData(); 73 sdch_manager->ClearData();
69 74
70 std::unique_ptr<disk_cache::Backend*> backend( 75 std::unique_ptr<disk_cache::Backend*> backend(
71 new disk_cache::Backend*(nullptr)); 76 new disk_cache::Backend*(nullptr));
72 disk_cache::Backend** backend_ptr = backend.get(); 77 disk_cache::Backend** backend_ptr = backend.get();
73 net::CompletionCallback doom_callback = 78 net::CompletionCallback doom_callback =
74 base::Bind(&DoomHttpCache, base::Passed(std::move(backend)), 79 base::Bind(&DoomHttpCache, base::Passed(std::move(backend)),
75 client_task_runner, callback); 80 client_task_runner, delete_begin, delete_end, callback);
76 81
77 int rv = http_cache->GetBackend(backend_ptr, doom_callback); 82 int rv = http_cache->GetBackend(backend_ptr, doom_callback);
78 83
79 if (rv != net::ERR_IO_PENDING) { 84 if (rv != net::ERR_IO_PENDING) {
80 // GetBackend doesn't call the callback if it completes synchronously, so 85 // GetBackend doesn't call the callback if it completes synchronously, so
81 // call it directly here. 86 // call it directly here.
82 doom_callback.Run(rv); 87 doom_callback.Run(rv);
83 } 88 }
84 } 89 }
85 90
86 } // namespace 91 } // namespace
87 92
88 namespace net { 93 namespace net {
89 94
90 void ClearHttpCache(const scoped_refptr<net::URLRequestContextGetter>& getter, 95 void ClearHttpCache(const scoped_refptr<net::URLRequestContextGetter>& getter,
91 const scoped_refptr<base::TaskRunner>& network_task_runner, 96 const scoped_refptr<base::TaskRunner>& network_task_runner,
97 const base::Time& delete_begin,
98 const base::Time& delete_end,
92 const net::CompletionCallback& callback) { 99 const net::CompletionCallback& callback) {
100 DCHECK(delete_end != base::Time());
93 network_task_runner->PostTask( 101 network_task_runner->PostTask(
94 FROM_HERE, base::Bind(&ClearHttpCacheOnIOThread, getter, 102 FROM_HERE, base::Bind(&ClearHttpCacheOnIOThread, getter,
95 base::ThreadTaskRunnerHandle::Get(), callback)); 103 base::ThreadTaskRunnerHandle::Get(), delete_begin,
104 delete_end, callback));
96 } 105 }
97 106
98 } // namespace net 107 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/http_cache_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698