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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 } | 56 } |
57 return net::ERR_FAILED; | 57 return net::ERR_FAILED; |
58 } | 58 } |
59 | 59 |
60 // static | 60 // static |
61 int SimpleEntryImpl::CreateEntry(SimpleIndex* index, | 61 int SimpleEntryImpl::CreateEntry(SimpleIndex* index, |
62 const FilePath& path, | 62 const FilePath& path, |
63 const std::string& key, | 63 const std::string& key, |
64 Entry** entry, | 64 Entry** entry, |
65 const CompletionCallback& callback) { | 65 const CompletionCallback& callback) { |
66 // We insert the entry in the index before creating the entry files in the | |
67 // SimpleSynchronousEntry, because this way the worse scenario is when we | |
68 // have the entry in the index but we don't have the created files yet, this | |
69 // way we never leak files. CreationOperationComplete will remove the entry | |
gavinp
2013/04/19 11:30:17
nit: one space after .
felipeg
2013/04/19 12:20:29
Done.
| |
70 // from the index if the creation fails. | |
71 if (index) | |
72 index->Insert(key); | |
66 scoped_refptr<SimpleEntryImpl> new_entry = | 73 scoped_refptr<SimpleEntryImpl> new_entry = |
67 new SimpleEntryImpl(index, path, key); | 74 new SimpleEntryImpl(index, path, key); |
68 SynchronousCreationCallback sync_creation_callback = | 75 SynchronousCreationCallback sync_creation_callback = |
69 base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 76 base::Bind(&SimpleEntryImpl::CreationOperationComplete, |
70 new_entry, entry, callback); | 77 new_entry, entry, callback); |
71 WorkerPool::PostTask(FROM_HERE, | 78 WorkerPool::PostTask(FROM_HERE, |
72 base::Bind(&SimpleSynchronousEntry::CreateEntry, path, | 79 base::Bind(&SimpleSynchronousEntry::CreateEntry, path, |
73 key, MessageLoopProxy::current(), | 80 key, MessageLoopProxy::current(), |
74 sync_creation_callback), | 81 sync_creation_callback), |
75 true); | 82 true); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // The reference held by the Callback calling us will go out of scope and | 334 // The reference held by the Callback calling us will go out of scope and |
328 // delete |this| on leaving this scope. | 335 // delete |this| on leaving this scope. |
329 return; | 336 return; |
330 } | 337 } |
331 // The Backend interface requires us to return |this|, and keep the Entry | 338 // The Backend interface requires us to return |this|, and keep the Entry |
332 // alive until Entry::Close(). Adding a reference to self will keep |this| | 339 // alive until Entry::Close(). Adding a reference to self will keep |this| |
333 // alive after the scope of the Callback calling us is destroyed. | 340 // alive after the scope of the Callback calling us is destroyed. |
334 AddRef(); // Balanced in CloseInternal(). | 341 AddRef(); // Balanced in CloseInternal(). |
335 synchronous_entry_ = sync_entry; | 342 synchronous_entry_ = sync_entry; |
336 SetSynchronousData(); | 343 SetSynchronousData(); |
337 if (index_) | |
338 index_->Insert(key_); | |
339 *out_entry = this; | 344 *out_entry = this; |
340 completion_callback.Run(net::OK); | 345 completion_callback.Run(net::OK); |
341 } | 346 } |
342 | 347 |
343 void SimpleEntryImpl::EntryOperationComplete( | 348 void SimpleEntryImpl::EntryOperationComplete( |
344 const CompletionCallback& completion_callback, | 349 const CompletionCallback& completion_callback, |
345 int result) { | 350 int result) { |
346 DCHECK(io_thread_checker_.CalledOnValidThread()); | 351 DCHECK(io_thread_checker_.CalledOnValidThread()); |
347 DCHECK(synchronous_entry_); | 352 DCHECK(synchronous_entry_); |
348 DCHECK(operation_running_); | 353 DCHECK(operation_running_); |
(...skipping 19 matching lines...) Expand all Loading... | |
368 // adding an IO thread index (for fast misses etc...), we can store this data | 373 // adding an IO thread index (for fast misses etc...), we can store this data |
369 // in that structure. This also solves problems with last_used() on ext4 | 374 // in that structure. This also solves problems with last_used() on ext4 |
370 // filesystems not being accurate. | 375 // filesystems not being accurate. |
371 last_used_ = synchronous_entry_->last_used(); | 376 last_used_ = synchronous_entry_->last_used(); |
372 last_modified_ = synchronous_entry_->last_modified(); | 377 last_modified_ = synchronous_entry_->last_modified(); |
373 for (int i = 0; i < kSimpleEntryFileCount; ++i) | 378 for (int i = 0; i < kSimpleEntryFileCount; ++i) |
374 data_size_[i] = synchronous_entry_->data_size(i); | 379 data_size_[i] = synchronous_entry_->data_size(i); |
375 } | 380 } |
376 | 381 |
377 } // namespace disk_cache | 382 } // namespace disk_cache |
OLD | NEW |