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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 const CompletionCallback& callback) { | 167 const CompletionCallback& callback) { |
168 WorkerPool::PostTask(FROM_HERE, | 168 WorkerPool::PostTask(FROM_HERE, |
169 base::Bind(&SimpleSynchronousEntry::DoomEntry, path, key, | 169 base::Bind(&SimpleSynchronousEntry::DoomEntry, path, key, |
170 MessageLoopProxy::current(), callback), | 170 MessageLoopProxy::current(), callback), |
171 true); | 171 true); |
172 return net::ERR_IO_PENDING; | 172 return net::ERR_IO_PENDING; |
173 } | 173 } |
174 | 174 |
175 void SimpleEntryImpl::Doom() { | 175 void SimpleEntryImpl::Doom() { |
176 DCHECK(thread_checker_.CalledOnValidThread()); | 176 DCHECK(thread_checker_.CalledOnValidThread()); |
177 if (!synchronous_entry_) { | 177 #if defined(OS_WIN) |
felipeg
2013/02/12 13:36:56
For windows we could fallback to the previous impl
gavinp
2013/02/12 16:36:31
Hmmm. But I've removed SimpleSynchronousEntry::Doo
| |
178 NOTIMPLEMENTED() << ": Overlapping an asynchronous operation."; | 178 NOTIMPLEMENTED(); |
179 return; | 179 #else |
180 } | 180 // This implementation depends on POSIX file erasure semantics working. |
felipeg
2013/02/12 13:36:56
Maybe adding a little bit more info here would be
gavinp
2013/02/12 16:36:31
Done.
| |
181 WorkerPool::PostTask(FROM_HERE, | 181 DoomEntry(path_, key_, CompletionCallback()); |
182 base::Bind(&SimpleSynchronousEntry::DoomAndClose, | 182 #endif |
183 base::Unretained(ReleaseSynchronousEntry())), | |
184 true); | |
185 has_been_doomed_ = true; | |
186 } | 183 } |
187 | 184 |
188 void SimpleEntryImpl::Close() { | 185 void SimpleEntryImpl::Close() { |
189 DCHECK(thread_checker_.CalledOnValidThread()); | 186 DCHECK(thread_checker_.CalledOnValidThread()); |
190 if (!synchronous_entry_) { | 187 if (!synchronous_entry_) { |
191 NOTIMPLEMENTED() << ": Overlapping an asynchronous operation."; | 188 NOTIMPLEMENTED() << ": Overlapping an asynchronous operation."; |
192 delete this; | 189 delete this; |
193 return; | 190 return; |
194 } | 191 } |
195 if (!has_been_doomed_) { | 192 |
196 WorkerPool::PostTask(FROM_HERE, | 193 WorkerPool::PostTask(FROM_HERE, |
197 base::Bind(&SimpleSynchronousEntry::Close, | 194 base::Bind(&SimpleSynchronousEntry::Close, |
198 base::Unretained( | 195 base::Unretained( |
199 ReleaseSynchronousEntry())), | 196 ReleaseSynchronousEntry())), |
200 true); | 197 true); |
201 } | |
202 // Entry::Close() is expected to release this entry. See disk_cache.h for | 198 // Entry::Close() is expected to release this entry. See disk_cache.h for |
203 // details. | 199 // details. |
204 delete this; | 200 delete this; |
205 } | 201 } |
206 | 202 |
207 std::string SimpleEntryImpl::GetKey() const { | 203 std::string SimpleEntryImpl::GetKey() const { |
208 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
209 return key_; | 205 return key_; |
210 } | 206 } |
211 | 207 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 DCHECK(thread_checker_.CalledOnValidThread()); | 313 DCHECK(thread_checker_.CalledOnValidThread()); |
318 NOTIMPLEMENTED(); | 314 NOTIMPLEMENTED(); |
319 return net::ERR_FAILED; | 315 return net::ERR_FAILED; |
320 } | 316 } |
321 | 317 |
322 SimpleEntryImpl::SimpleEntryImpl( | 318 SimpleEntryImpl::SimpleEntryImpl( |
323 SimpleSynchronousEntry* synchronous_entry) | 319 SimpleSynchronousEntry* synchronous_entry) |
324 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 320 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
325 path_(synchronous_entry->path()), | 321 path_(synchronous_entry->path()), |
326 key_(synchronous_entry->key()), | 322 key_(synchronous_entry->key()), |
327 synchronous_entry_(NULL), | 323 synchronous_entry_(NULL) { |
328 has_been_doomed_(false) { | |
329 SetSynchronousEntry(synchronous_entry); | 324 SetSynchronousEntry(synchronous_entry); |
330 } | 325 } |
331 | 326 |
332 SimpleEntryImpl::~SimpleEntryImpl() { | 327 SimpleEntryImpl::~SimpleEntryImpl() { |
333 DCHECK(thread_checker_.CalledOnValidThread()); | 328 DCHECK(thread_checker_.CalledOnValidThread()); |
334 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; | 329 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; |
335 } | 330 } |
336 | 331 |
337 SimpleSynchronousEntry* SimpleEntryImpl::ReleaseSynchronousEntry() { | 332 SimpleSynchronousEntry* SimpleEntryImpl::ReleaseSynchronousEntry() { |
338 DCHECK(synchronous_entry_); | 333 DCHECK(synchronous_entry_); |
339 SimpleSynchronousEntry* retval = synchronous_entry_; | 334 SimpleSynchronousEntry* retval = synchronous_entry_; |
340 synchronous_entry_ = NULL; | 335 synchronous_entry_ = NULL; |
341 return retval; | 336 return retval; |
342 } | 337 } |
343 | 338 |
344 void SimpleEntryImpl::SetSynchronousEntry( | 339 void SimpleEntryImpl::SetSynchronousEntry( |
345 SimpleSynchronousEntry* synchronous_entry) { | 340 SimpleSynchronousEntry* synchronous_entry) { |
346 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; | 341 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; |
347 synchronous_entry_ = synchronous_entry; | 342 synchronous_entry_ = synchronous_entry; |
348 last_used_ = synchronous_entry_->last_used(); | 343 last_used_ = synchronous_entry_->last_used(); |
349 last_modified_ = synchronous_entry_->last_modified(); | 344 last_modified_ = synchronous_entry_->last_modified(); |
350 for (int i = 0; i < kSimpleEntryFileCount; ++i) | 345 for (int i = 0; i < kSimpleEntryFileCount; ++i) |
351 data_size_[i] = synchronous_entry_->data_size(i); | 346 data_size_[i] = synchronous_entry_->data_size(i); |
352 } | 347 } |
353 | 348 |
354 } // namespace disk_cache | 349 } // namespace disk_cache |
OLD | NEW |