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

Side by Side Diff: net/disk_cache/simple/simple_index.cc

Issue 22430014: Clean up Simple Index handling of removed entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove one redundant specification Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 (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_index.h" 5 #include "net/disk_cache/simple/simple_index.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 cache_size_ -= (*it)->second.GetEntrySize(); 376 cache_size_ -= (*it)->second.GetEntrySize();
377 cache_size_ += entry_size; 377 cache_size_ += entry_size;
378 (*it)->second.SetEntrySize(entry_size); 378 (*it)->second.SetEntrySize(entry_size);
379 } 379 }
380 380
381 void SimpleIndex::MergeInitializingSet( 381 void SimpleIndex::MergeInitializingSet(
382 scoped_ptr<SimpleIndexLoadResult> load_result) { 382 scoped_ptr<SimpleIndexLoadResult> load_result) {
383 DCHECK(io_thread_checker_.CalledOnValidThread()); 383 DCHECK(io_thread_checker_.CalledOnValidThread());
384 DCHECK(load_result->did_load); 384 DCHECK(load_result->did_load);
385 385
386 SimpleIndex::EntrySet* index_file_entries = &load_result->entries; 386 EntrySet* index_file_entries = &load_result->entries;
387 // First, remove the entries that are in the |removed_entries_| from both 387
388 // sets. 388 for (base::hash_set<uint64>::const_iterator it = removed_entries_.begin();
389 for (base::hash_set<uint64>::const_iterator it = 389 it != removed_entries_.end(); ++it) {
390 removed_entries_.begin(); it != removed_entries_.end(); ++it) {
391 entries_set_.erase(*it);
392 index_file_entries->erase(*it); 390 index_file_entries->erase(*it);
393 } 391 }
392 removed_entries_.clear();
394 393
395 for (EntrySet::const_iterator it = entries_set_.begin(); 394 for (EntrySet::const_iterator it = entries_set_.begin();
396 it != entries_set_.end(); ++it) { 395 it != entries_set_.end(); ++it) {
397 const uint64 entry_hash = it->first; 396 const uint64 entry_hash = it->first;
398 std::pair<EntrySet::iterator, bool> insert_result = 397 std::pair<EntrySet::iterator, bool> insert_result =
399 index_file_entries->insert(EntrySet::value_type(entry_hash, 398 index_file_entries->insert(EntrySet::value_type(entry_hash,
400 EntryMetadata())); 399 EntryMetadata()));
401 EntrySet::iterator& possibly_inserted_entry = insert_result.first; 400 EntrySet::iterator& possibly_inserted_entry = insert_result.first;
402 possibly_inserted_entry->second = it->second; 401 possibly_inserted_entry->second = it->second;
403 } 402 }
404 403
405 uint64 merged_cache_size = 0; 404 uint64 merged_cache_size = 0;
406 for (EntrySet::iterator it = index_file_entries->begin(); 405 for (EntrySet::iterator it = index_file_entries->begin();
407 it != index_file_entries->end(); ++it) { 406 it != index_file_entries->end(); ++it) {
408 merged_cache_size += it->second.GetEntrySize(); 407 merged_cache_size += it->second.GetEntrySize();
409 } 408 }
410 409
411 entries_set_.swap(*index_file_entries); 410 entries_set_.swap(*index_file_entries);
412 cache_size_ = merged_cache_size; 411 cache_size_ = merged_cache_size;
413 initialized_ = true; 412 initialized_ = true;
414 removed_entries_.clear();
415 413
416 // The actual IO is asynchronous, so calling WriteToDisk() shouldn't slow the 414 // The actual IO is asynchronous, so calling WriteToDisk() shouldn't slow the
417 // merge down much. 415 // merge down much.
418 if (load_result->flush_required) 416 if (load_result->flush_required)
419 WriteToDisk(); 417 WriteToDisk();
420 418
421 UMA_HISTOGRAM_CUSTOM_COUNTS("SimpleCache.IndexInitializationWaiters", 419 UMA_HISTOGRAM_CUSTOM_COUNTS("SimpleCache.IndexInitializationWaiters",
422 to_run_when_initialized_.size(), 0, 100, 20); 420 to_run_when_initialized_.size(), 0, 100, 20);
423 // Run all callbacks waiting for the index to come up. 421 // Run all callbacks waiting for the index to come up.
424 for (CallbackList::iterator it = to_run_when_initialized_.begin(), 422 for (CallbackList::iterator it = to_run_when_initialized_.begin(),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 entries_set_.erase(it++); 491 entries_set_.erase(it++);
494 continue; 492 continue;
495 } 493 }
496 } 494 }
497 ++it; 495 ++it;
498 } 496 }
499 return ret_hashes.Pass(); 497 return ret_hashes.Pass();
500 } 498 }
501 499
502 } // namespace disk_cache 500 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698