| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 int pos = 0; | 138 int pos = 0; |
| 139 for (const std::string& key : keys) { | 139 for (const std::string& key : keys) { |
| 140 WaitForCompletion(backend_->CreateEntry( | 140 WaitForCompletion(backend_->CreateEntry( |
| 141 key, &entries_[pos++], done_callback_)); | 141 key, &entries_[pos++], done_callback_)); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 void DeleteEntries( | 145 void DeleteEntries( |
| 146 const base::Callback<bool(const disk_cache::Entry*)>& condition) { | 146 const base::Callback<bool(const disk_cache::Entry*)>& condition) { |
| 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 147 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 148 ConditionalCacheDeletionHelper* helper = new ConditionalCacheDeletionHelper( | 148 auto* helper = new ConditionalCacheDeletionHelper(backend_, condition); |
| 149 backend_, | |
| 150 condition); | |
| 151 | 149 |
| 152 WaitForCompletion(helper->DeleteAndDestroySelfWhenFinished(done_callback_)); | 150 WaitForCompletion(helper->DeleteAndDestroySelfWhenFinished(done_callback_)); |
| 153 } | 151 } |
| 154 | 152 |
| 155 void GetRemainingKeys() { | 153 void GetRemainingKeys() { |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 154 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 157 current_entry_ = nullptr; | 155 current_entry_ = nullptr; |
| 158 iterator_ = backend_->CreateIterator(); | 156 iterator_ = backend_->CreateIterator(); |
| 159 GetNextKey(net::OK); | 157 GetNextKey(net::OK); |
| 160 } | 158 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 std::unique_ptr<base::WaitableEvent> waitable_event_; | 196 std::unique_ptr<base::WaitableEvent> waitable_event_; |
| 199 int remaining_tasks_; | 197 int remaining_tasks_; |
| 200 | 198 |
| 201 std::vector<std::string> remaining_keys_; | 199 std::vector<std::string> remaining_keys_; |
| 202 }; | 200 }; |
| 203 | 201 |
| 204 // Tests that ConditionalCacheDeletionHelper only deletes those cache entries | 202 // Tests that ConditionalCacheDeletionHelper only deletes those cache entries |
| 205 // that match the condition. | 203 // that match the condition. |
| 206 IN_PROC_BROWSER_TEST_F(ConditionalCacheDeletionHelperBrowserTest, Condition) { | 204 IN_PROC_BROWSER_TEST_F(ConditionalCacheDeletionHelperBrowserTest, Condition) { |
| 207 // Create 5 entries. | 205 // Create 5 entries. |
| 208 std::set<std::string> keys; | 206 std::set<std::string> keys = {"123", "47", "56", "81", "42"}; |
| 209 keys.insert("123"); | |
| 210 keys.insert("47"); | |
| 211 keys.insert("56"); | |
| 212 keys.insert("81"); | |
| 213 keys.insert("42"); | |
| 214 | 207 |
| 215 BrowserThread::PostTask( | 208 BrowserThread::PostTask( |
| 216 BrowserThread::IO, FROM_HERE, | 209 BrowserThread::IO, FROM_HERE, |
| 217 base::Bind(&ConditionalCacheDeletionHelperBrowserTest::CreateCacheEntries, | 210 base::Bind(&ConditionalCacheDeletionHelperBrowserTest::CreateCacheEntries, |
| 218 base::Unretained(this), | 211 base::Unretained(this), |
| 219 base::ConstRef(keys))); | 212 base::ConstRef(keys))); |
| 220 WaitForTasksOnIOThread(); | 213 WaitForTasksOnIOThread(); |
| 221 | 214 |
| 222 // Delete the entries whose keys are even numbers. | 215 // Delete the entries whose keys are even numbers. |
| 223 BrowserThread::PostTask( | 216 BrowserThread::PostTask( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 BrowserThread::IO, FROM_HERE, | 302 BrowserThread::IO, FROM_HERE, |
| 310 base::Bind(&ConditionalCacheDeletionHelperBrowserTest::GetRemainingKeys, | 303 base::Bind(&ConditionalCacheDeletionHelperBrowserTest::GetRemainingKeys, |
| 311 base::Unretained(this))); | 304 base::Unretained(this))); |
| 312 WaitForTasksOnIOThread(); | 305 WaitForTasksOnIOThread(); |
| 313 | 306 |
| 314 keys.insert(newer_keys.begin(), newer_keys.end()); | 307 keys.insert(newer_keys.begin(), newer_keys.end()); |
| 315 keys.erase("https://example.com/foo/bar/icon2.png"); | 308 keys.erase("https://example.com/foo/bar/icon2.png"); |
| 316 keys.erase("https://example.com/foo/bar/icon3.png"); | 309 keys.erase("https://example.com/foo/bar/icon3.png"); |
| 317 CompareRemainingKeys(keys); | 310 CompareRemainingKeys(keys); |
| 318 } | 311 } |
| OLD | NEW |