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

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 9702059: Disk cache: Remove all non essential synchronization from the cache destructor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 disabled_(false), 345 disabled_(false),
346 new_eviction_(false), 346 new_eviction_(false),
347 first_timer_(true), 347 first_timer_(true),
348 user_load_(false), 348 user_load_(false),
349 net_log_(net_log), 349 net_log_(net_log),
350 done_(true, false), 350 done_(true, false),
351 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) { 351 ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
352 } 352 }
353 353
354 BackendImpl::~BackendImpl() { 354 BackendImpl::~BackendImpl() {
355 background_queue_.WaitForPendingIO(); 355 if (user_flags_ & kNoRandom) {
356 // This is a unit test, so we want to be strict about not leaking entries
357 // and completing all the work.
358 background_queue_.WaitForPendingIO();
359 } else {
360 // This is most likely not a test, so we want to do as little work as
361 // possible at this time, at the price of leaving dirty entries behind.
362 background_queue_.DropPendingIO();
363 }
356 364
357 if (background_queue_.BackgroundIsCurrentThread()) { 365 if (background_queue_.BackgroundIsCurrentThread()) {
358 // Unit tests may use the same thread for everything. 366 // Unit tests may use the same thread for everything.
359 CleanupCache(); 367 CleanupCache();
360 } else { 368 } else {
361 background_queue_.background_thread()->PostTask( 369 background_queue_.background_thread()->PostTask(
362 FROM_HERE, base::Bind(&FinalCleanupCallback, base::Unretained(this))); 370 FROM_HERE, base::Bind(&FinalCleanupCallback, base::Unretained(this)));
363 done_.Wait(); 371 done_.Wait();
364 } 372 }
365 } 373 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void BackendImpl::CleanupCache() { 497 void BackendImpl::CleanupCache() {
490 Trace("Backend Cleanup"); 498 Trace("Backend Cleanup");
491 eviction_.Stop(); 499 eviction_.Stop();
492 timer_.Stop(); 500 timer_.Stop();
493 501
494 if (init_) { 502 if (init_) {
495 stats_.Store(); 503 stats_.Store();
496 if (data_) 504 if (data_)
497 data_->header.crash = 0; 505 data_->header.crash = 0;
498 506
499 File::WaitForPendingIO(&num_pending_io_);
500 if (user_flags_ & kNoRandom) { 507 if (user_flags_ & kNoRandom) {
501 // This is a net_unittest, verify that we are not 'leaking' entries. 508 // This is a net_unittest, verify that we are not 'leaking' entries.
509 File::WaitForPendingIO(&num_pending_io_);
502 DCHECK(!num_refs_); 510 DCHECK(!num_refs_);
511 } else {
512 File::DropPendingIO();
gavinp 2012/03/20 15:40:08 This belt and suspenders approach looks good.
503 } 513 }
504 } 514 }
505 block_files_.CloseFiles(); 515 block_files_.CloseFiles();
506 index_ = NULL; 516 index_ = NULL;
507 ptr_factory_.InvalidateWeakPtrs(); 517 ptr_factory_.InvalidateWeakPtrs();
508 done_.Signal(); 518 done_.Signal();
509 } 519 }
510 520
511 // ------------------------------------------------------------------------ 521 // ------------------------------------------------------------------------
512 522
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 std::string tmp = base::StringPrintf("f_%06x", address.FileNumber()); 829 std::string tmp = base::StringPrintf("f_%06x", address.FileNumber());
820 return path_.AppendASCII(tmp); 830 return path_.AppendASCII(tmp);
821 } 831 }
822 832
823 MappedFile* BackendImpl::File(Addr address) { 833 MappedFile* BackendImpl::File(Addr address) {
824 if (disabled_) 834 if (disabled_)
825 return NULL; 835 return NULL;
826 return block_files_.GetFile(address); 836 return block_files_.GetFile(address);
827 } 837 }
828 838
839 base::WeakPtr<InFlightBackendIO> BackendImpl::GetBackgroundQueue() {
840 return background_queue_.GetWeakPtr();
841 }
842
829 bool BackendImpl::CreateExternalFile(Addr* address) { 843 bool BackendImpl::CreateExternalFile(Addr* address) {
830 int file_number = data_->header.last_file + 1; 844 int file_number = data_->header.last_file + 1;
831 Addr file_address(0); 845 Addr file_address(0);
832 bool success = false; 846 bool success = false;
833 for (int i = 0; i < 0x0fffffff; i++, file_number++) { 847 for (int i = 0; i < 0x0fffffff; i++, file_number++) {
834 if (!file_address.SetFileNumber(file_number)) { 848 if (!file_address.SetFileNumber(file_number)) {
835 file_number = 1; 849 file_number = 1;
836 continue; 850 continue;
837 } 851 }
838 FilePath name = GetFileName(file_address); 852 FilePath name = GetFileName(file_address);
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2180 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2167 total_memory = kMaxBuffersSize; 2181 total_memory = kMaxBuffersSize;
2168 2182
2169 done = true; 2183 done = true;
2170 } 2184 }
2171 2185
2172 return static_cast<int>(total_memory); 2186 return static_cast<int>(total_memory);
2173 } 2187 }
2174 2188
2175 } // namespace disk_cache 2189 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698