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

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

Issue 149218: Disk cache: Keep a map of all open entries.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/entry_impl.h" 5 #include "net/disk_cache/entry_impl.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // There was a failure writing the actual data. Mark the entry as dirty. 121 // There was a failure writing the actual data. Mark the entry as dirty.
122 int current_id = backend_->GetCurrentEntryId(); 122 int current_id = backend_->GetCurrentEntryId();
123 node_.Data()->dirty = current_id == 1 ? -1 : current_id - 1; 123 node_.Data()->dirty = current_id == 1 ? -1 : current_id - 1;
124 node_.Store(); 124 node_.Store();
125 } else if (node_.HasData() && node_.Data()->dirty) { 125 } else if (node_.HasData() && node_.Data()->dirty) {
126 node_.Data()->dirty = 0; 126 node_.Data()->dirty = 0;
127 node_.Store(); 127 node_.Store();
128 } 128 }
129 } 129 }
130 130
131 backend_->CacheEntryDestroyed(); 131 backend_->CacheEntryDestroyed(entry_.address());
132 } 132 }
133 133
134 void EntryImpl::Doom() { 134 void EntryImpl::Doom() {
135 if (doomed_) 135 if (doomed_)
136 return; 136 return;
137 137
138 SetPointerForInvalidEntry(backend_->GetCurrentEntryId()); 138 SetPointerForInvalidEntry(backend_->GetCurrentEntryId());
139 backend_->InternalDoomEntry(this); 139 backend_->InternalDoomEntry(this);
140 } 140 }
141 141
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 DCHECK(success); 499 DCHECK(success);
500 } 500 }
501 501
502 bool EntryImpl::LoadNodeAddress() { 502 bool EntryImpl::LoadNodeAddress() {
503 Addr address(entry_.Data()->rankings_node); 503 Addr address(entry_.Data()->rankings_node);
504 if (!node_.LazyInit(backend_->File(address), address)) 504 if (!node_.LazyInit(backend_->File(address), address))
505 return false; 505 return false;
506 return node_.Load(); 506 return node_.Load();
507 } 507 }
508 508
509 EntryImpl* EntryImpl::Update(EntryImpl* entry) { 509 bool EntryImpl::Update() {
510 DCHECK(entry->rankings()->HasData()); 510 DCHECK(node_.HasData());
511 511
512 RankingsNode* rankings = entry->rankings()->Data(); 512 RankingsNode* rankings = node_.Data();
513 if (rankings->pointer) { 513 if (rankings->pointer) {
514 // Already in memory. Prevent clearing the dirty flag on the destructor. 514 // Nothing to do here, the entry was in memory.
515 rankings->dirty = 0; 515 DCHECK(rankings->pointer == this);
516 EntryImpl* real_node = reinterpret_cast<EntryImpl*>(rankings->pointer);
517 real_node->AddRef();
518 entry->Release();
519 return real_node;
520 } else { 516 } else {
521 rankings->dirty = entry->backend_->GetCurrentEntryId(); 517 rankings->dirty = backend_->GetCurrentEntryId();
522 rankings->pointer = entry; 518 rankings->pointer = this;
523 if (!entry->rankings()->Store()) { 519 if (!node_.Store())
524 entry->Release(); 520 return false;
525 return NULL;
526 }
527 return entry;
528 } 521 }
522 return true;
529 } 523 }
530 524
531 bool EntryImpl::IsDirty(int32 current_id) { 525 bool EntryImpl::IsDirty(int32 current_id) {
532 DCHECK(node_.HasData()); 526 DCHECK(node_.HasData());
533 // We are checking if the entry is valid or not. If there is a pointer here, 527 // We are checking if the entry is valid or not. If there is a pointer here,
534 // |dirty| has to be the id of the cache that is using the entry (the one 528 // we should not be checking the entry.
535 // that created the pointer), 0 is not a valid id. 529 if (node_.Data()->pointer)
536 if (node_.Data()->pointer && !node_.Data()->dirty)
537 return true; 530 return true;
538 531
539 return node_.Data()->dirty && current_id != node_.Data()->dirty; 532 return node_.Data()->dirty && current_id != node_.Data()->dirty;
540 } 533 }
541 534
542 void EntryImpl::ClearDirtyFlag() { 535 void EntryImpl::ClearDirtyFlag() {
543 node_.Data()->dirty = 0; 536 node_.Data()->dirty = 0;
544 } 537 }
545 538
546 void EntryImpl::SetPointerForInvalidEntry(int32 new_id) { 539 void EntryImpl::SetPointerForInvalidEntry(int32 new_id) {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), 865 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this),
873 entry_.address().value(), node_.address().value()); 866 entry_.address().value(), node_.address().value());
874 867
875 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], 868 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0],
876 entry_.Data()->data_addr[1], entry_.Data()->long_key); 869 entry_.Data()->data_addr[1], entry_.Data()->long_key);
877 870
878 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty); 871 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty);
879 } 872 }
880 873
881 } // namespace disk_cache 874 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698