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: net/disk_cache/simple/simple_backend_impl.cc

Issue 1884453002: Revert of Convert //net and //chromecast to std::unordered_* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_index.h » ('j') | 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_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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 282 }
283 283
284 void SimpleBackendImpl::OnDoomStart(uint64_t entry_hash) { 284 void SimpleBackendImpl::OnDoomStart(uint64_t entry_hash) {
285 DCHECK_EQ(0u, entries_pending_doom_.count(entry_hash)); 285 DCHECK_EQ(0u, entries_pending_doom_.count(entry_hash));
286 entries_pending_doom_.insert( 286 entries_pending_doom_.insert(
287 std::make_pair(entry_hash, std::vector<Closure>())); 287 std::make_pair(entry_hash, std::vector<Closure>()));
288 } 288 }
289 289
290 void SimpleBackendImpl::OnDoomComplete(uint64_t entry_hash) { 290 void SimpleBackendImpl::OnDoomComplete(uint64_t entry_hash) {
291 DCHECK_EQ(1u, entries_pending_doom_.count(entry_hash)); 291 DCHECK_EQ(1u, entries_pending_doom_.count(entry_hash));
292 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 292 base::hash_map<uint64_t, std::vector<Closure>>::iterator it =
293 entries_pending_doom_.find(entry_hash); 293 entries_pending_doom_.find(entry_hash);
294 std::vector<Closure> to_run_closures; 294 std::vector<Closure> to_run_closures;
295 to_run_closures.swap(it->second); 295 to_run_closures.swap(it->second);
296 entries_pending_doom_.erase(it); 296 entries_pending_doom_.erase(it);
297 297
298 for (auto& closure : to_run_closures) 298 for (auto& closure : to_run_closures)
299 closure.Run(); 299 closure.Run();
300 } 300 }
301 301
302 void SimpleBackendImpl::DoomEntries(std::vector<uint64_t>* entry_hashes, 302 void SimpleBackendImpl::DoomEntries(std::vector<uint64_t>* entry_hashes,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return index_->GetEntryCount(); 371 return index_->GetEntryCount();
372 } 372 }
373 373
374 int SimpleBackendImpl::OpenEntry(const std::string& key, 374 int SimpleBackendImpl::OpenEntry(const std::string& key,
375 Entry** entry, 375 Entry** entry,
376 const CompletionCallback& callback) { 376 const CompletionCallback& callback) {
377 const uint64_t entry_hash = simple_util::GetEntryHashKey(key); 377 const uint64_t entry_hash = simple_util::GetEntryHashKey(key);
378 378
379 // TODO(gavinp): Factor out this (not quite completely) repetitive code 379 // TODO(gavinp): Factor out this (not quite completely) repetitive code
380 // block from OpenEntry/CreateEntry/DoomEntry. 380 // block from OpenEntry/CreateEntry/DoomEntry.
381 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 381 base::hash_map<uint64_t, std::vector<Closure>>::iterator it =
382 entries_pending_doom_.find(entry_hash); 382 entries_pending_doom_.find(entry_hash);
383 if (it != entries_pending_doom_.end()) { 383 if (it != entries_pending_doom_.end()) {
384 Callback<int(const net::CompletionCallback&)> operation = 384 Callback<int(const net::CompletionCallback&)> operation =
385 base::Bind(&SimpleBackendImpl::OpenEntry, 385 base::Bind(&SimpleBackendImpl::OpenEntry,
386 base::Unretained(this), key, entry); 386 base::Unretained(this), key, entry);
387 it->second.push_back(base::Bind(&RunOperationAndCallback, 387 it->second.push_back(base::Bind(&RunOperationAndCallback,
388 operation, callback)); 388 operation, callback));
389 return net::ERR_IO_PENDING; 389 return net::ERR_IO_PENDING;
390 } 390 }
391 scoped_refptr<SimpleEntryImpl> simple_entry = 391 scoped_refptr<SimpleEntryImpl> simple_entry =
392 CreateOrFindActiveEntry(entry_hash, key); 392 CreateOrFindActiveEntry(entry_hash, key);
393 CompletionCallback backend_callback = 393 CompletionCallback backend_callback =
394 base::Bind(&SimpleBackendImpl::OnEntryOpenedFromKey, 394 base::Bind(&SimpleBackendImpl::OnEntryOpenedFromKey,
395 AsWeakPtr(), 395 AsWeakPtr(),
396 key, 396 key,
397 entry, 397 entry,
398 simple_entry, 398 simple_entry,
399 callback); 399 callback);
400 return simple_entry->OpenEntry(entry, backend_callback); 400 return simple_entry->OpenEntry(entry, backend_callback);
401 } 401 }
402 402
403 int SimpleBackendImpl::CreateEntry(const std::string& key, 403 int SimpleBackendImpl::CreateEntry(const std::string& key,
404 Entry** entry, 404 Entry** entry,
405 const CompletionCallback& callback) { 405 const CompletionCallback& callback) {
406 DCHECK_LT(0u, key.size()); 406 DCHECK_LT(0u, key.size());
407 const uint64_t entry_hash = simple_util::GetEntryHashKey(key); 407 const uint64_t entry_hash = simple_util::GetEntryHashKey(key);
408 408
409 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 409 base::hash_map<uint64_t, std::vector<Closure>>::iterator it =
410 entries_pending_doom_.find(entry_hash); 410 entries_pending_doom_.find(entry_hash);
411 if (it != entries_pending_doom_.end()) { 411 if (it != entries_pending_doom_.end()) {
412 Callback<int(const net::CompletionCallback&)> operation = 412 Callback<int(const net::CompletionCallback&)> operation =
413 base::Bind(&SimpleBackendImpl::CreateEntry, 413 base::Bind(&SimpleBackendImpl::CreateEntry,
414 base::Unretained(this), key, entry); 414 base::Unretained(this), key, entry);
415 it->second.push_back(base::Bind(&RunOperationAndCallback, 415 it->second.push_back(base::Bind(&RunOperationAndCallback,
416 operation, callback)); 416 operation, callback));
417 return net::ERR_IO_PENDING; 417 return net::ERR_IO_PENDING;
418 } 418 }
419 scoped_refptr<SimpleEntryImpl> simple_entry = 419 scoped_refptr<SimpleEntryImpl> simple_entry =
420 CreateOrFindActiveEntry(entry_hash, key); 420 CreateOrFindActiveEntry(entry_hash, key);
421 return simple_entry->CreateEntry(entry, callback); 421 return simple_entry->CreateEntry(entry, callback);
422 } 422 }
423 423
424 int SimpleBackendImpl::DoomEntry(const std::string& key, 424 int SimpleBackendImpl::DoomEntry(const std::string& key,
425 const net::CompletionCallback& callback) { 425 const net::CompletionCallback& callback) {
426 const uint64_t entry_hash = simple_util::GetEntryHashKey(key); 426 const uint64_t entry_hash = simple_util::GetEntryHashKey(key);
427 427
428 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 428 base::hash_map<uint64_t, std::vector<Closure>>::iterator it =
429 entries_pending_doom_.find(entry_hash); 429 entries_pending_doom_.find(entry_hash);
430 if (it != entries_pending_doom_.end()) { 430 if (it != entries_pending_doom_.end()) {
431 Callback<int(const net::CompletionCallback&)> operation = 431 Callback<int(const net::CompletionCallback&)> operation =
432 base::Bind(&SimpleBackendImpl::DoomEntry, base::Unretained(this), key); 432 base::Bind(&SimpleBackendImpl::DoomEntry, base::Unretained(this), key);
433 it->second.push_back(base::Bind(&RunOperationAndCallback, 433 it->second.push_back(base::Bind(&RunOperationAndCallback,
434 operation, callback)); 434 operation, callback));
435 return net::ERR_IO_PENDING; 435 return net::ERR_IO_PENDING;
436 } 436 }
437 scoped_refptr<SimpleEntryImpl> simple_entry = 437 scoped_refptr<SimpleEntryImpl> simple_entry =
438 CreateOrFindActiveEntry(entry_hash, key); 438 CreateOrFindActiveEntry(entry_hash, key);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 it->second->Doom(); 624 it->second->Doom();
625 DCHECK_EQ(0U, active_entries_.count(entry_hash)); 625 DCHECK_EQ(0U, active_entries_.count(entry_hash));
626 return CreateOrFindActiveEntry(entry_hash, key); 626 return CreateOrFindActiveEntry(entry_hash, key);
627 } 627 }
628 return make_scoped_refptr(it->second); 628 return make_scoped_refptr(it->second);
629 } 629 }
630 630
631 int SimpleBackendImpl::OpenEntryFromHash(uint64_t entry_hash, 631 int SimpleBackendImpl::OpenEntryFromHash(uint64_t entry_hash,
632 Entry** entry, 632 Entry** entry,
633 const CompletionCallback& callback) { 633 const CompletionCallback& callback) {
634 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 634 base::hash_map<uint64_t, std::vector<Closure>>::iterator it =
635 entries_pending_doom_.find(entry_hash); 635 entries_pending_doom_.find(entry_hash);
636 if (it != entries_pending_doom_.end()) { 636 if (it != entries_pending_doom_.end()) {
637 Callback<int(const net::CompletionCallback&)> operation = 637 Callback<int(const net::CompletionCallback&)> operation =
638 base::Bind(&SimpleBackendImpl::OpenEntryFromHash, 638 base::Bind(&SimpleBackendImpl::OpenEntryFromHash,
639 base::Unretained(this), entry_hash, entry); 639 base::Unretained(this), entry_hash, entry);
640 it->second.push_back(base::Bind(&RunOperationAndCallback, 640 it->second.push_back(base::Bind(&RunOperationAndCallback,
641 operation, callback)); 641 operation, callback));
642 return net::ERR_IO_PENDING; 642 return net::ERR_IO_PENDING;
643 } 643 }
644 644
645 EntryMap::iterator has_active = active_entries_.find(entry_hash); 645 EntryMap::iterator has_active = active_entries_.find(entry_hash);
646 if (has_active != active_entries_.end()) { 646 if (has_active != active_entries_.end()) {
647 return OpenEntry(has_active->second->key(), entry, callback); 647 return OpenEntry(has_active->second->key(), entry, callback);
648 } 648 }
649 649
650 scoped_refptr<SimpleEntryImpl> simple_entry = new SimpleEntryImpl( 650 scoped_refptr<SimpleEntryImpl> simple_entry = new SimpleEntryImpl(
651 cache_type_, path_, entry_hash, entry_operations_mode_, this, net_log_); 651 cache_type_, path_, entry_hash, entry_operations_mode_, this, net_log_);
652 CompletionCallback backend_callback = 652 CompletionCallback backend_callback =
653 base::Bind(&SimpleBackendImpl::OnEntryOpenedFromHash, 653 base::Bind(&SimpleBackendImpl::OnEntryOpenedFromHash,
654 AsWeakPtr(), entry_hash, entry, simple_entry, callback); 654 AsWeakPtr(), entry_hash, entry, simple_entry, callback);
655 return simple_entry->OpenEntry(entry, backend_callback); 655 return simple_entry->OpenEntry(entry, backend_callback);
656 } 656 }
657 657
658 int SimpleBackendImpl::DoomEntryFromHash(uint64_t entry_hash, 658 int SimpleBackendImpl::DoomEntryFromHash(uint64_t entry_hash,
659 const CompletionCallback& callback) { 659 const CompletionCallback& callback) {
660 Entry** entry = new Entry*(); 660 Entry** entry = new Entry*();
661 scoped_ptr<Entry*> scoped_entry(entry); 661 scoped_ptr<Entry*> scoped_entry(entry);
662 662
663 std::unordered_map<uint64_t, std::vector<Closure>>::iterator pending_it = 663 base::hash_map<uint64_t, std::vector<Closure>>::iterator pending_it =
664 entries_pending_doom_.find(entry_hash); 664 entries_pending_doom_.find(entry_hash);
665 if (pending_it != entries_pending_doom_.end()) { 665 if (pending_it != entries_pending_doom_.end()) {
666 Callback<int(const net::CompletionCallback&)> operation = 666 Callback<int(const net::CompletionCallback&)> operation =
667 base::Bind(&SimpleBackendImpl::DoomEntryFromHash, 667 base::Bind(&SimpleBackendImpl::DoomEntryFromHash,
668 base::Unretained(this), entry_hash); 668 base::Unretained(this), entry_hash);
669 pending_it->second.push_back(base::Bind(&RunOperationAndCallback, 669 pending_it->second.push_back(base::Bind(&RunOperationAndCallback,
670 operation, callback)); 670 operation, callback));
671 return net::ERR_IO_PENDING; 671 return net::ERR_IO_PENDING;
672 } 672 }
673 673
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } 746 }
747 747
748 // static 748 // static
749 void SimpleBackendImpl::FlushWorkerPoolForTesting() { 749 void SimpleBackendImpl::FlushWorkerPoolForTesting() {
750 // We only need to do this if we there is an active task runner. 750 // We only need to do this if we there is an active task runner.
751 if (base::ThreadTaskRunnerHandle::IsSet()) 751 if (base::ThreadTaskRunnerHandle::IsSet())
752 g_sequenced_worker_pool.Get().FlushForTesting(); 752 g_sequenced_worker_pool.Get().FlushForTesting();
753 } 753 }
754 754
755 } // namespace disk_cache 755 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_index.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698