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

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

Issue 12223075: Make SimpleEntryImpl::Doom() completely asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const std::string& key, 67 const std::string& key,
68 const CompletionCallback& callback) { 68 const CompletionCallback& callback) {
69 WorkerPool::PostTask(FROM_HERE, 69 WorkerPool::PostTask(FROM_HERE,
70 base::Bind(&SimpleSynchronousEntry::DoomEntry, path, key, 70 base::Bind(&SimpleSynchronousEntry::DoomEntry, path, key,
71 MessageLoopProxy::current(), callback), 71 MessageLoopProxy::current(), callback),
72 true); 72 true);
73 return net::ERR_IO_PENDING; 73 return net::ERR_IO_PENDING;
74 } 74 }
75 75
76 void SimpleEntryImpl::Doom() { 76 void SimpleEntryImpl::Doom() {
77 if (synchronous_entry_in_use_by_worker_) { 77 #if defined(OS_POSIX)
78 NOTIMPLEMENTED(); 78 // This call to static SimpleEntryImpl::DoomEntry() will just erase the
79 return; 79 // underlying files. On POSIX, this is fine; the files are still open on the
80 } 80 // SimpleSynchronousEntry, and operations can even happen on them. The files
81 WorkerPool::PostTask(FROM_HERE, 81 // will be removed from the filesystem when they are closed.
82 base::Bind(&SimpleSynchronousEntry::DoomAndClose, 82 DoomEntry(path_, key_, CompletionCallback());
83 base::Unretained(synchronous_entry_)), 83 #else
84 true); 84 NOTIMPLEMENTED();
85 synchronous_entry_ = NULL; 85 #endif
86 has_been_doomed_ = true;
87 } 86 }
88 87
89 void SimpleEntryImpl::Close() { 88 void SimpleEntryImpl::Close() {
90 if (synchronous_entry_in_use_by_worker_) { 89 if (synchronous_entry_in_use_by_worker_) {
91 NOTIMPLEMENTED(); 90 NOTIMPLEMENTED();
92 delete this; 91 delete this;
93 return; 92 return;
94 } 93 }
95 DCHECK(synchronous_entry_ || has_been_doomed_); 94 DCHECK(synchronous_entry_);
96 if (!has_been_doomed_) { 95 WorkerPool::PostTask(FROM_HERE,
97 WorkerPool::PostTask(FROM_HERE, 96 base::Bind(&SimpleSynchronousEntry::Close,
98 base::Bind(&SimpleSynchronousEntry::Close, 97 base::Unretained(synchronous_entry_)),
99 base::Unretained(synchronous_entry_)), 98 true);
100 true); 99 synchronous_entry_ = NULL;
101 synchronous_entry_ = NULL;
102 }
103 // Entry::Close() is expected to release this entry. See disk_cache.h for 100 // Entry::Close() is expected to release this entry. See disk_cache.h for
104 // details. 101 // details.
105 delete this; 102 delete this;
106 } 103 }
107 104
108 std::string SimpleEntryImpl::GetKey() const { 105 std::string SimpleEntryImpl::GetKey() const {
109 return key_; 106 return key_;
110 } 107 }
111 108
112 Time SimpleEntryImpl::GetLastUsed() const { 109 Time SimpleEntryImpl::GetLastUsed() const {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 NOTIMPLEMENTED(); 208 NOTIMPLEMENTED();
212 return net::ERR_FAILED; 209 return net::ERR_FAILED;
213 } 210 }
214 211
215 SimpleEntryImpl::SimpleEntryImpl( 212 SimpleEntryImpl::SimpleEntryImpl(
216 SimpleSynchronousEntry* synchronous_entry) 213 SimpleSynchronousEntry* synchronous_entry)
217 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 214 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
218 path_(synchronous_entry->path()), 215 path_(synchronous_entry->path()),
219 key_(synchronous_entry->key()), 216 key_(synchronous_entry->key()),
220 synchronous_entry_(synchronous_entry), 217 synchronous_entry_(synchronous_entry),
221 synchronous_entry_in_use_by_worker_(false), 218 synchronous_entry_in_use_by_worker_(false) {
222 has_been_doomed_(false) {
223 DCHECK(synchronous_entry); 219 DCHECK(synchronous_entry);
224 SetSynchronousData(); 220 SetSynchronousData();
225 } 221 }
226 222
227 SimpleEntryImpl::~SimpleEntryImpl() { 223 SimpleEntryImpl::~SimpleEntryImpl() {
228 DCHECK(!synchronous_entry_); 224 DCHECK(!synchronous_entry_);
229 } 225 }
230 226
231 // static 227 // static
232 void SimpleEntryImpl::CreationOperationComplete( 228 void SimpleEntryImpl::CreationOperationComplete(
(...skipping 29 matching lines...) Expand all
262 // in that structure. This also solves problems with last_used() on ext4 258 // in that structure. This also solves problems with last_used() on ext4
263 // filesystems not being accurate. 259 // filesystems not being accurate.
264 260
265 last_used_ = synchronous_entry_->last_used(); 261 last_used_ = synchronous_entry_->last_used();
266 last_modified_ = synchronous_entry_->last_modified(); 262 last_modified_ = synchronous_entry_->last_modified();
267 for (int i = 0; i < kSimpleEntryFileCount; ++i) 263 for (int i = 0; i < kSimpleEntryFileCount; ++i)
268 data_size_[i] = synchronous_entry_->data_size(i); 264 data_size_[i] = synchronous_entry_->data_size(i);
269 } 265 }
270 266
271 } // namespace disk_cache 267 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698