OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/disk_cache/simple/simple_backend_impl.h" | 5 #include "net/disk_cache/simple/simple_backend_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #include <functional> | 9 #include <functional> |
10 | 10 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 int SimpleBackendImpl::GetMaxFileSize() const { | 252 int SimpleBackendImpl::GetMaxFileSize() const { |
253 return index_->max_size() / kMaxFileRatio; | 253 return index_->max_size() / kMaxFileRatio; |
254 } | 254 } |
255 | 255 |
256 void SimpleBackendImpl::OnDeactivated(const SimpleEntryImpl* entry) { | 256 void SimpleBackendImpl::OnDeactivated(const SimpleEntryImpl* entry) { |
257 active_entries_.erase(entry->entry_hash()); | 257 active_entries_.erase(entry->entry_hash()); |
258 } | 258 } |
259 | 259 |
260 void SimpleBackendImpl::OnDoomStart(uint64 entry_hash) { | 260 void SimpleBackendImpl::OnDoomStart(uint64 entry_hash) { |
261 DCHECK_EQ(0u, entries_pending_doom_.count(entry_hash)); | 261 // TODO(ttuttle): Revert to DCHECK once http://crbug.com/317138 is fixed. |
| 262 CHECK_EQ(0u, entries_pending_doom_.count(entry_hash)); |
262 entries_pending_doom_.insert( | 263 entries_pending_doom_.insert( |
263 std::make_pair(entry_hash, std::vector<Closure>())); | 264 std::make_pair(entry_hash, std::vector<Closure>())); |
264 } | 265 } |
265 | 266 |
266 void SimpleBackendImpl::OnDoomComplete(uint64 entry_hash) { | 267 void SimpleBackendImpl::OnDoomComplete(uint64 entry_hash) { |
267 DCHECK_EQ(1u, entries_pending_doom_.count(entry_hash)); | 268 // TODO(ttuttle): Revert to DCHECK once http://crbug.com/317138 is fixed. |
| 269 CHECK_EQ(1u, entries_pending_doom_.count(entry_hash)); |
268 base::hash_map<uint64, std::vector<Closure> >::iterator it = | 270 base::hash_map<uint64, std::vector<Closure> >::iterator it = |
269 entries_pending_doom_.find(entry_hash); | 271 entries_pending_doom_.find(entry_hash); |
270 std::vector<Closure> to_run_closures; | 272 std::vector<Closure> to_run_closures; |
271 to_run_closures.swap(it->second); | 273 to_run_closures.swap(it->second); |
272 entries_pending_doom_.erase(it); | 274 entries_pending_doom_.erase(it); |
273 | 275 |
274 std::for_each(to_run_closures.begin(), to_run_closures.end(), | 276 std::for_each(to_run_closures.begin(), to_run_closures.end(), |
275 std::mem_fun_ref(&Closure::Run)); | 277 std::mem_fun_ref(&Closure::Run)); |
276 } | 278 } |
277 | 279 |
278 void SimpleBackendImpl::DoomEntries(std::vector<uint64>* entry_hashes, | 280 void SimpleBackendImpl::DoomEntries(std::vector<uint64>* entry_hashes, |
279 const net::CompletionCallback& callback) { | 281 const net::CompletionCallback& callback) { |
280 scoped_ptr<std::vector<uint64> > | 282 scoped_ptr<std::vector<uint64> > |
281 mass_doom_entry_hashes(new std::vector<uint64>()); | 283 mass_doom_entry_hashes(new std::vector<uint64>()); |
282 mass_doom_entry_hashes->swap(*entry_hashes); | 284 mass_doom_entry_hashes->swap(*entry_hashes); |
283 | 285 |
284 std::vector<uint64> to_doom_individually_hashes; | 286 std::vector<uint64> to_doom_individually_hashes; |
285 | 287 |
286 // For each of the entry hashes, there are two cases: | 288 // For each of the entry hashes, there are two cases: |
287 // 1. The entry is either open or pending doom, and so it should be doomed | 289 // 1. The entry is either open or pending doom, and so it should be doomed |
288 // individually to avoid flakes. | 290 // individually to avoid flakes. |
289 // 2. The entry is not in use at all, so we can call | 291 // 2. The entry is not in use at all, so we can call |
290 // SimpleSynchronousEntry::DoomEntrySet and delete the files en masse. | 292 // SimpleSynchronousEntry::DoomEntrySet and delete the files en masse. |
291 for (int i = mass_doom_entry_hashes->size() - 1; i >= 0; --i) { | 293 for (int i = mass_doom_entry_hashes->size() - 1; i >= 0; --i) { |
292 const uint64 entry_hash = (*mass_doom_entry_hashes)[i]; | 294 const uint64 entry_hash = (*mass_doom_entry_hashes)[i]; |
293 DCHECK(active_entries_.count(entry_hash) == 0 || | 295 // TODO(ttuttle): Revert to DCHECK once http://crbug.com/317138 is fixed. |
294 entries_pending_doom_.count(entry_hash) == 0) | 296 CHECK(active_entries_.count(entry_hash) == 0 || |
| 297 entries_pending_doom_.count(entry_hash) == 0) |
295 << "The entry 0x" << std::hex << entry_hash | 298 << "The entry 0x" << std::hex << entry_hash |
296 << " is both active and pending doom."; | 299 << " is both active and pending doom."; |
297 if (!active_entries_.count(entry_hash) && | 300 if (!active_entries_.count(entry_hash) && |
298 !entries_pending_doom_.count(entry_hash)) { | 301 !entries_pending_doom_.count(entry_hash)) { |
299 continue; | 302 continue; |
300 } | 303 } |
301 | 304 |
302 to_doom_individually_hashes.push_back(entry_hash); | 305 to_doom_individually_hashes.push_back(entry_hash); |
303 | 306 |
304 (*mass_doom_entry_hashes)[i] = mass_doom_entry_hashes->back(); | 307 (*mass_doom_entry_hashes)[i] = mass_doom_entry_hashes->back(); |
305 mass_doom_entry_hashes->resize(mass_doom_entry_hashes->size() - 1); | 308 mass_doom_entry_hashes->resize(mass_doom_entry_hashes->size() - 1); |
306 } | 309 } |
307 | 310 |
308 net::CompletionCallback barrier_callback = | 311 net::CompletionCallback barrier_callback = |
309 MakeBarrierCompletionCallback(to_doom_individually_hashes.size() + 1, | 312 MakeBarrierCompletionCallback(to_doom_individually_hashes.size() + 1, |
310 callback); | 313 callback); |
311 for (std::vector<uint64>::const_iterator | 314 for (std::vector<uint64>::const_iterator |
312 it = to_doom_individually_hashes.begin(), | 315 it = to_doom_individually_hashes.begin(), |
313 end = to_doom_individually_hashes.end(); it != end; ++it) { | 316 end = to_doom_individually_hashes.end(); it != end; ++it) { |
314 const int doom_result = DoomEntryFromHash(*it, barrier_callback); | 317 const int doom_result = DoomEntryFromHash(*it, barrier_callback); |
315 DCHECK_EQ(net::ERR_IO_PENDING, doom_result); | 318 // TODO(ttuttle): Revert to DCHECK once http://crbug.com/317138 is fixed. |
| 319 CHECK_EQ(net::ERR_IO_PENDING, doom_result); |
316 index_->Remove(*it); | 320 index_->Remove(*it); |
317 } | 321 } |
318 | 322 |
319 for (std::vector<uint64>::const_iterator it = mass_doom_entry_hashes->begin(), | 323 for (std::vector<uint64>::const_iterator it = mass_doom_entry_hashes->begin(), |
320 end = mass_doom_entry_hashes->end(); | 324 end = mass_doom_entry_hashes->end(); |
321 it != end; ++it) { | 325 it != end; ++it) { |
322 index_->Remove(*it); | 326 index_->Remove(*it); |
323 OnDoomStart(*it); | 327 OnDoomStart(*it); |
324 } | 328 } |
325 | 329 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 this)); | 710 this)); |
707 callback.Run(result); | 711 callback.Run(result); |
708 } | 712 } |
709 | 713 |
710 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 714 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
711 if (g_sequenced_worker_pool) | 715 if (g_sequenced_worker_pool) |
712 g_sequenced_worker_pool->FlushForTesting(); | 716 g_sequenced_worker_pool->FlushForTesting(); |
713 } | 717 } |
714 | 718 |
715 } // namespace disk_cache | 719 } // namespace disk_cache |
OLD | NEW |