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

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

Issue 14183: Disk cache: move eviction code to a separate file.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | « net/disk_cache/eviction.h ('k') | net/disk_cache/rankings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/eviction.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop.h"
9 #include "base/string_util.h"
10 #include "base/time.h"
11 #include "net/disk_cache/backend_impl.h"
12 #include "net/disk_cache/entry_impl.h"
13 #include "net/disk_cache/trace.h"
14
15 using base::Time;
16
17 namespace {
18
19 const int kCleanUpMargin = 1024 * 1024;
20
21 int LowWaterAdjust(int high_water) {
22 if (high_water < kCleanUpMargin)
23 return 0;
24
25 return high_water - kCleanUpMargin;
26 }
27
28 } // namespace
29
30 namespace disk_cache {
31
32 void Eviction::Init(BackendImpl* backend) {
33 // We grab a bunch of info from the backend to make the code a little cleaner
34 // when we're actually doing work.
35 backend_ = backend;
36 rankings_ = &backend->rankings_;
37 header_ = &backend_->data_->header;
38 max_size_ = LowWaterAdjust(backend_->max_size_);
39 }
40
41 void Eviction::TrimCache(bool empty) {
42 Trace("*** Trim Cache ***");
43 if (backend_->disabled_)
44 return;
45
46 Time start = Time::Now();
47 Rankings::ScopedRankingsBlock node(rankings_);
48 Rankings::ScopedRankingsBlock next(rankings_,
49 rankings_->GetPrev(node.get(), Rankings::NO_USE));
50 DCHECK(next.get());
51 int target_size = empty ? 0 : max_size_;
52 int deleted = 0;
53 while (header_->num_bytes > target_size && next.get()) {
54 node.reset(next.release());
55 next.reset(rankings_->GetPrev(node.get(), Rankings::NO_USE));
56 if (!node->Data()->pointer || empty) {
57 // This entry is not being used by anybody.
58 EntryImpl* entry;
59 bool dirty;
60 if (backend_->NewEntry(Addr(node->Data()->contents), &entry, &dirty)) {
61 Trace("NewEntry failed on Trim 0x%x", node->address().value());
62 continue;
63 }
64
65 if (node->Data()->pointer) {
66 entry = EntryImpl::Update(entry);
67 }
68 ReportTrimTimes(entry);
69 entry->Doom();
70 entry->Release();
71 if (!empty)
72 backend_->OnEvent(Stats::TRIM_ENTRY);
73 if (++deleted == 4 && !empty) {
74 #if defined(OS_WIN)
75 MessageLoop::current()->PostTask(FROM_HERE,
76 factory_.NewRunnableMethod(&Eviction::TrimCache, false));
77 break;
78 #endif
79 }
80 }
81 }
82
83 UMA_HISTOGRAM_TIMES(L"DiskCache.TotalTrimTime", Time::Now() - start);
84 Trace("*** Trim Cache end ***");
85 return;
86 }
87
88 void Eviction::UpdateRank(EntryImpl* entry, bool modified) {
89 rankings_->UpdateRank(entry->rankings(), modified, GetListForEntry(entry));
90 }
91
92 void Eviction::OnOpenEntry(EntryImpl* entry) {
93 }
94
95 void Eviction::OnCreateEntry(EntryImpl* entry) {
96 rankings_->Insert(entry->rankings(), true, GetListForEntry(entry));
97 }
98
99 void Eviction::OnDoomEntry(EntryImpl* entry) {
100 rankings_->Remove(entry->rankings(), GetListForEntry(entry));
101 }
102
103 void Eviction::OnDestroyEntry(EntryImpl* entry) {
104 }
105
106 void Eviction::ReportTrimTimes(EntryImpl* entry) {
107 static bool first_time = true;
108 if (first_time) {
109 first_time = false;
110 std::wstring name(StringPrintf(L"DiskCache.TrimAge_%d",
111 header_->experiment));
112 static Histogram counter(name.c_str(), 1, 10000, 50);
113 counter.SetFlags(kUmaTargetedHistogramFlag);
114 counter.Add((Time::Now() - entry->GetLastUsed()).InHours());
115 }
116 }
117
118 Rankings::List Eviction::GetListForEntry(EntryImpl* entry) {
119 return Rankings::NO_USE;
120 }
121
122 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/eviction.h ('k') | net/disk_cache/rankings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698