OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 DCHECK(sync_entry); | |
269 if (sync_entry && index) | |
gavinp
2013/04/10 10:33:23
if (index)
felipeg
2013/04/10 11:45:35
Done.
| |
270 index->UpdateEntrySize(sync_entry->key(), sync_entry->GetFileSize()); | |
271 | |
265 if (entry) { | 272 if (entry) { |
266 DCHECK(entry->synchronous_entry_in_use_by_worker_); | 273 DCHECK(entry->synchronous_entry_in_use_by_worker_); |
267 entry->synchronous_entry_in_use_by_worker_ = false; | 274 entry->synchronous_entry_in_use_by_worker_ = false; |
268 entry->SetSynchronousData(); | 275 entry->SetSynchronousData(); |
269 } else { | 276 } else { |
270 // |entry| must have had Close() called while this operation was in flight. | 277 // |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 | 278 // 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|. | 279 // flight at a time, it's safe to now call Close() on |sync_entry|. |
273 WorkerPool::PostTask(FROM_HERE, | 280 WorkerPool::PostTask(FROM_HERE, |
274 base::Bind(&SimpleSynchronousEntry::Close, | 281 base::Bind(&SimpleSynchronousEntry::Close, |
275 base::Unretained(sync_entry)), | 282 base::Unretained(sync_entry)), |
276 true); | 283 true); |
277 } | 284 } |
278 completion_callback.Run(result); | 285 completion_callback.Run(result); |
279 } | 286 } |
280 | 287 |
281 void SimpleEntryImpl::SetSynchronousData() { | 288 void SimpleEntryImpl::SetSynchronousData() { |
282 DCHECK(!synchronous_entry_in_use_by_worker_); | 289 DCHECK(!synchronous_entry_in_use_by_worker_); |
283 // TODO(felipeg): These copies to avoid data races are not optimal. While | 290 // 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 | 291 // 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 | 292 // in that structure. This also solves problems with last_used() on ext4 |
286 // filesystems not being accurate. | 293 // filesystems not being accurate. |
287 last_used_ = synchronous_entry_->last_used(); | 294 last_used_ = synchronous_entry_->last_used(); |
288 last_modified_ = synchronous_entry_->last_modified(); | 295 last_modified_ = synchronous_entry_->last_modified(); |
289 for (int i = 0; i < kSimpleEntryFileCount; ++i) | 296 for (int i = 0; i < kSimpleEntryFileCount; ++i) |
290 data_size_[i] = synchronous_entry_->data_size(i); | 297 data_size_[i] = synchronous_entry_->data_size(i); |
291 } | 298 } |
292 | 299 |
293 } // namespace disk_cache | 300 } // namespace disk_cache |
OLD | NEW |