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

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.cc

Issue 13913010: Add Cache size to the Simple Index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/simple/simple_entry_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_entry_impl.h" 5 #include "net/disk_cache/simple/simple_entry_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/callback.h" 9 #include "base/callback.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // entry as read only. This might make calling SimpleSynchronousEntry::Close() 136 // entry as read only. This might make calling SimpleSynchronousEntry::Close()
137 // correctly more tricky (see SimpleEntryImpl::EntryOperationComplete). 137 // correctly more tricky (see SimpleEntryImpl::EntryOperationComplete).
138 if (synchronous_entry_in_use_by_worker_) { 138 if (synchronous_entry_in_use_by_worker_) {
139 NOTIMPLEMENTED(); 139 NOTIMPLEMENTED();
140 CHECK(false); 140 CHECK(false);
141 } 141 }
142 synchronous_entry_in_use_by_worker_ = true; 142 synchronous_entry_in_use_by_worker_ = true;
143 index_->UseIfExists(key_); 143 index_->UseIfExists(key_);
144 SynchronousOperationCallback sync_operation_callback = 144 SynchronousOperationCallback sync_operation_callback =
145 base::Bind(&SimpleEntryImpl::EntryOperationComplete, 145 base::Bind(&SimpleEntryImpl::EntryOperationComplete,
146 callback, weak_ptr_factory_.GetWeakPtr(), synchronous_entry_); 146 index_, callback, weak_ptr_factory_.GetWeakPtr(),
147 synchronous_entry_);
147 WorkerPool::PostTask(FROM_HERE, 148 WorkerPool::PostTask(FROM_HERE,
148 base::Bind(&SimpleSynchronousEntry::ReadData, 149 base::Bind(&SimpleSynchronousEntry::ReadData,
149 base::Unretained(synchronous_entry_), 150 base::Unretained(synchronous_entry_),
150 index, offset, make_scoped_refptr(buf), 151 index, offset, make_scoped_refptr(buf),
151 buf_len, sync_operation_callback), 152 buf_len, sync_operation_callback),
152 true); 153 true);
153 return net::ERR_IO_PENDING; 154 return net::ERR_IO_PENDING;
154 } 155 }
155 156
156 int SimpleEntryImpl::WriteData(int index, 157 int SimpleEntryImpl::WriteData(int index,
157 int offset, 158 int offset,
158 net::IOBuffer* buf, 159 net::IOBuffer* buf,
159 int buf_len, 160 int buf_len,
160 const CompletionCallback& callback, 161 const CompletionCallback& callback,
161 bool truncate) { 162 bool truncate) {
162 if (synchronous_entry_in_use_by_worker_) { 163 if (synchronous_entry_in_use_by_worker_) {
163 NOTIMPLEMENTED(); 164 NOTIMPLEMENTED();
164 CHECK(false); 165 CHECK(false);
165 } 166 }
166 synchronous_entry_in_use_by_worker_ = true; 167 synchronous_entry_in_use_by_worker_ = true;
167 index_->UseIfExists(key_); 168 index_->UseIfExists(key_);
168 SynchronousOperationCallback sync_operation_callback = 169 SynchronousOperationCallback sync_operation_callback =
169 base::Bind(&SimpleEntryImpl::EntryOperationComplete, 170 base::Bind(&SimpleEntryImpl::EntryOperationComplete,
170 callback, weak_ptr_factory_.GetWeakPtr(), synchronous_entry_); 171 index_, callback, weak_ptr_factory_.GetWeakPtr(),
172 synchronous_entry_);
171 WorkerPool::PostTask(FROM_HERE, 173 WorkerPool::PostTask(FROM_HERE,
172 base::Bind(&SimpleSynchronousEntry::WriteData, 174 base::Bind(&SimpleSynchronousEntry::WriteData,
173 base::Unretained(synchronous_entry_), 175 base::Unretained(synchronous_entry_),
174 index, offset, make_scoped_refptr(buf), 176 index, offset, make_scoped_refptr(buf),
175 buf_len, sync_operation_callback, truncate), 177 buf_len, sync_operation_callback, truncate),
176 true); 178 true);
177 return net::ERR_IO_PENDING; 179 return net::ERR_IO_PENDING;
178 } 180 }
179 181
180 int SimpleEntryImpl::ReadSparseData(int64 offset, 182 int SimpleEntryImpl::ReadSparseData(int64 offset,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 return; 253 return;
252 } 254 }
253 if (index) 255 if (index)
254 index->Insert(sync_entry->key()); 256 index->Insert(sync_entry->key());
255 *out_entry = new SimpleEntryImpl(sync_entry, index); 257 *out_entry = new SimpleEntryImpl(sync_entry, index);
256 completion_callback.Run(net::OK); 258 completion_callback.Run(net::OK);
257 } 259 }
258 260
259 // static 261 // static
260 void SimpleEntryImpl::EntryOperationComplete( 262 void SimpleEntryImpl::EntryOperationComplete(
263 base::WeakPtr<SimpleIndex> index,
261 const CompletionCallback& completion_callback, 264 const CompletionCallback& completion_callback,
262 base::WeakPtr<SimpleEntryImpl> entry, 265 base::WeakPtr<SimpleEntryImpl> entry,
263 SimpleSynchronousEntry* sync_entry, 266 SimpleSynchronousEntry* sync_entry,
264 int result) { 267 int result) {
268 if (sync_entry && index)
gavinp 2013/04/09 16:42:57 sync_entry should always be non NULL, I think. So
felipeg 2013/04/09 16:46:58 Done.
269 index->UpdateEntrySize(sync_entry->key(), sync_entry->GetFileSize());
270
265 if (entry) { 271 if (entry) {
266 DCHECK(entry->synchronous_entry_in_use_by_worker_); 272 DCHECK(entry->synchronous_entry_in_use_by_worker_);
267 entry->synchronous_entry_in_use_by_worker_ = false; 273 entry->synchronous_entry_in_use_by_worker_ = false;
268 entry->SetSynchronousData(); 274 entry->SetSynchronousData();
269 } else { 275 } else {
270 // |entry| must have had Close() called while this operation was in flight. 276 // |entry| must have had Close() called while this operation was in flight.
271 // Since the simple cache now only supports one pending entry operation in 277 // Since the simple cache now only supports one pending entry operation in
272 // flight at a time, it's safe to now call Close() on |sync_entry|. 278 // flight at a time, it's safe to now call Close() on |sync_entry|.
273 WorkerPool::PostTask(FROM_HERE, 279 WorkerPool::PostTask(FROM_HERE,
274 base::Bind(&SimpleSynchronousEntry::Close, 280 base::Bind(&SimpleSynchronousEntry::Close,
275 base::Unretained(sync_entry)), 281 base::Unretained(sync_entry)),
276 true); 282 true);
277 } 283 }
278 completion_callback.Run(result); 284 completion_callback.Run(result);
279 } 285 }
280 286
281 void SimpleEntryImpl::SetSynchronousData() { 287 void SimpleEntryImpl::SetSynchronousData() {
282 DCHECK(!synchronous_entry_in_use_by_worker_); 288 DCHECK(!synchronous_entry_in_use_by_worker_);
283 // TODO(felipeg): These copies to avoid data races are not optimal. While 289 // TODO(felipeg): These copies to avoid data races are not optimal. While
284 // adding an IO thread index (for fast misses etc...), we can store this data 290 // adding an IO thread index (for fast misses etc...), we can store this data
285 // in that structure. This also solves problems with last_used() on ext4 291 // in that structure. This also solves problems with last_used() on ext4
286 // filesystems not being accurate. 292 // filesystems not being accurate.
287 last_used_ = synchronous_entry_->last_used(); 293 last_used_ = synchronous_entry_->last_used();
288 last_modified_ = synchronous_entry_->last_modified(); 294 last_modified_ = synchronous_entry_->last_modified();
289 for (int i = 0; i < kSimpleEntryFileCount; ++i) 295 for (int i = 0; i < kSimpleEntryFileCount; ++i)
290 data_size_[i] = synchronous_entry_->data_size(i); 296 data_size_[i] = synchronous_entry_->data_size(i);
291 } 297 }
292 298
293 } // namespace disk_cache 299 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_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