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

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: syncing 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // entry as read only. This might make calling SimpleSynchronousEntry::Close() 143 // entry as read only. This might make calling SimpleSynchronousEntry::Close()
144 // correctly more tricky (see SimpleEntryImpl::EntryOperationComplete). 144 // correctly more tricky (see SimpleEntryImpl::EntryOperationComplete).
145 if (synchronous_entry_in_use_by_worker_) { 145 if (synchronous_entry_in_use_by_worker_) {
146 NOTIMPLEMENTED(); 146 NOTIMPLEMENTED();
147 CHECK(false); 147 CHECK(false);
148 } 148 }
149 synchronous_entry_in_use_by_worker_ = true; 149 synchronous_entry_in_use_by_worker_ = true;
150 index_->UseIfExists(key_); 150 index_->UseIfExists(key_);
151 SynchronousOperationCallback sync_operation_callback = 151 SynchronousOperationCallback sync_operation_callback =
152 base::Bind(&SimpleEntryImpl::EntryOperationComplete, 152 base::Bind(&SimpleEntryImpl::EntryOperationComplete,
153 callback, weak_ptr_factory_.GetWeakPtr(), synchronous_entry_); 153 index_, callback, weak_ptr_factory_.GetWeakPtr(),
154 synchronous_entry_);
154 WorkerPool::PostTask(FROM_HERE, 155 WorkerPool::PostTask(FROM_HERE,
155 base::Bind(&SimpleSynchronousEntry::ReadData, 156 base::Bind(&SimpleSynchronousEntry::ReadData,
156 base::Unretained(synchronous_entry_), 157 base::Unretained(synchronous_entry_),
157 index, offset, make_scoped_refptr(buf), 158 index, offset, make_scoped_refptr(buf),
158 buf_len, sync_operation_callback), 159 buf_len, sync_operation_callback),
159 true); 160 true);
160 return net::ERR_IO_PENDING; 161 return net::ERR_IO_PENDING;
161 } 162 }
162 163
163 int SimpleEntryImpl::WriteData(int index, 164 int SimpleEntryImpl::WriteData(int index,
164 int offset, 165 int offset,
165 net::IOBuffer* buf, 166 net::IOBuffer* buf,
166 int buf_len, 167 int buf_len,
167 const CompletionCallback& callback, 168 const CompletionCallback& callback,
168 bool truncate) { 169 bool truncate) {
169 DCHECK(io_thread_checker_.CalledOnValidThread()); 170 DCHECK(io_thread_checker_.CalledOnValidThread());
170 if (synchronous_entry_in_use_by_worker_) { 171 if (synchronous_entry_in_use_by_worker_) {
171 NOTIMPLEMENTED(); 172 NOTIMPLEMENTED();
172 CHECK(false); 173 CHECK(false);
173 } 174 }
174 synchronous_entry_in_use_by_worker_ = true; 175 synchronous_entry_in_use_by_worker_ = true;
175 index_->UseIfExists(key_); 176 index_->UseIfExists(key_);
176 SynchronousOperationCallback sync_operation_callback = 177 SynchronousOperationCallback sync_operation_callback =
177 base::Bind(&SimpleEntryImpl::EntryOperationComplete, 178 base::Bind(&SimpleEntryImpl::EntryOperationComplete,
178 callback, weak_ptr_factory_.GetWeakPtr(), synchronous_entry_); 179 index_, callback, weak_ptr_factory_.GetWeakPtr(),
180 synchronous_entry_);
179 WorkerPool::PostTask(FROM_HERE, 181 WorkerPool::PostTask(FROM_HERE,
180 base::Bind(&SimpleSynchronousEntry::WriteData, 182 base::Bind(&SimpleSynchronousEntry::WriteData,
181 base::Unretained(synchronous_entry_), 183 base::Unretained(synchronous_entry_),
182 index, offset, make_scoped_refptr(buf), 184 index, offset, make_scoped_refptr(buf),
183 buf_len, sync_operation_callback, truncate), 185 buf_len, sync_operation_callback, truncate),
184 true); 186 true);
185 return net::ERR_IO_PENDING; 187 return net::ERR_IO_PENDING;
186 } 188 }
187 189
188 int SimpleEntryImpl::ReadSparseData(int64 offset, 190 int SimpleEntryImpl::ReadSparseData(int64 offset,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 return; 268 return;
267 } 269 }
268 if (index) 270 if (index)
269 index->Insert(sync_entry->key()); 271 index->Insert(sync_entry->key());
270 *out_entry = new SimpleEntryImpl(sync_entry, index); 272 *out_entry = new SimpleEntryImpl(sync_entry, index);
271 completion_callback.Run(net::OK); 273 completion_callback.Run(net::OK);
272 } 274 }
273 275
274 // static 276 // static
275 void SimpleEntryImpl::EntryOperationComplete( 277 void SimpleEntryImpl::EntryOperationComplete(
278 base::WeakPtr<SimpleIndex> index,
276 const CompletionCallback& completion_callback, 279 const CompletionCallback& completion_callback,
277 base::WeakPtr<SimpleEntryImpl> entry, 280 base::WeakPtr<SimpleEntryImpl> entry,
278 SimpleSynchronousEntry* sync_entry, 281 SimpleSynchronousEntry* sync_entry,
279 int result) { 282 int result) {
283 DCHECK(sync_entry);
284 if (index)
285 index->UpdateEntrySize(sync_entry->key(), sync_entry->GetFileSize());
286
280 if (entry) { 287 if (entry) {
281 DCHECK(entry->synchronous_entry_in_use_by_worker_); 288 DCHECK(entry->synchronous_entry_in_use_by_worker_);
282 entry->synchronous_entry_in_use_by_worker_ = false; 289 entry->synchronous_entry_in_use_by_worker_ = false;
283 entry->SetSynchronousData(); 290 entry->SetSynchronousData();
284 } else { 291 } else {
285 // |entry| must have had Close() called while this operation was in flight. 292 // |entry| must have had Close() called while this operation was in flight.
286 // Since the simple cache now only supports one pending entry operation in 293 // Since the simple cache now only supports one pending entry operation in
287 // flight at a time, it's safe to now call Close() on |sync_entry|. 294 // flight at a time, it's safe to now call Close() on |sync_entry|.
288 WorkerPool::PostTask(FROM_HERE, 295 WorkerPool::PostTask(FROM_HERE,
289 base::Bind(&SimpleSynchronousEntry::Close, 296 base::Bind(&SimpleSynchronousEntry::Close,
(...skipping 10 matching lines...) Expand all
300 // adding an IO thread index (for fast misses etc...), we can store this data 307 // adding an IO thread index (for fast misses etc...), we can store this data
301 // in that structure. This also solves problems with last_used() on ext4 308 // in that structure. This also solves problems with last_used() on ext4
302 // filesystems not being accurate. 309 // filesystems not being accurate.
303 last_used_ = synchronous_entry_->last_used(); 310 last_used_ = synchronous_entry_->last_used();
304 last_modified_ = synchronous_entry_->last_modified(); 311 last_modified_ = synchronous_entry_->last_modified();
305 for (int i = 0; i < kSimpleEntryFileCount; ++i) 312 for (int i = 0; i < kSimpleEntryFileCount; ++i)
306 data_size_[i] = synchronous_entry_->data_size(i); 313 data_size_[i] = synchronous_entry_->data_size(i);
307 } 314 }
308 315
309 } // namespace disk_cache 316 } // 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