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

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: Sans style 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) {
gavinp 2012/03/18 00:35:26 Do these long comments call the name kNoRandom int
rvargas (doing something else) 2012/03/20 02:54:23 I hear you, but I guess I'd have a comment here re
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();
gavinp 2012/03/18 00:35:26 ignore_result(trace_object_.release()); // Leak t
gavinp 2012/03/18 00:35:26 ignore_result(index_.release()); // Do we need th
gavinp 2012/03/18 00:35:26 What what about block_files_ ? I hacked up a patc
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_);
503 } 511 }
504 } 512 }
505 block_files_.CloseFiles(); 513 block_files_.CloseFiles();
506 index_ = NULL; 514 index_ = NULL;
507 ptr_factory_.InvalidateWeakPtrs(); 515 ptr_factory_.InvalidateWeakPtrs();
508 done_.Signal(); 516 done_.Signal();
509 } 517 }
510 518
511 // ------------------------------------------------------------------------ 519 // ------------------------------------------------------------------------
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 std::string tmp = base::StringPrintf("f_%06x", address.FileNumber()); 827 std::string tmp = base::StringPrintf("f_%06x", address.FileNumber());
820 return path_.AppendASCII(tmp); 828 return path_.AppendASCII(tmp);
821 } 829 }
822 830
823 MappedFile* BackendImpl::File(Addr address) { 831 MappedFile* BackendImpl::File(Addr address) {
824 if (disabled_) 832 if (disabled_)
825 return NULL; 833 return NULL;
826 return block_files_.GetFile(address); 834 return block_files_.GetFile(address);
827 } 835 }
828 836
837 base::WeakPtr<InFlightBackendIO> BackendImpl::GetBackgroundQueue() {
838 return background_queue_.GetWeakPtr();
839 }
840
829 bool BackendImpl::CreateExternalFile(Addr* address) { 841 bool BackendImpl::CreateExternalFile(Addr* address) {
830 int file_number = data_->header.last_file + 1; 842 int file_number = data_->header.last_file + 1;
831 Addr file_address(0); 843 Addr file_address(0);
832 bool success = false; 844 bool success = false;
833 for (int i = 0; i < 0x0fffffff; i++, file_number++) { 845 for (int i = 0; i < 0x0fffffff; i++, file_number++) {
834 if (!file_address.SetFileNumber(file_number)) { 846 if (!file_address.SetFileNumber(file_number)) {
835 file_number = 1; 847 file_number = 1;
836 continue; 848 continue;
837 } 849 }
838 FilePath name = GetFileName(file_address); 850 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) 2178 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2167 total_memory = kMaxBuffersSize; 2179 total_memory = kMaxBuffersSize;
2168 2180
2169 done = true; 2181 done = true;
2170 } 2182 }
2171 2183
2172 return static_cast<int>(total_memory); 2184 return static_cast<int>(total_memory);
2173 } 2185 }
2174 2186
2175 } // namespace disk_cache 2187 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698