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

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: fix merge 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 CompletionCallback& callback) { 67 const CompletionCallback& callback) {
68 WorkerPool::PostTask(FROM_HERE, 68 WorkerPool::PostTask(FROM_HERE,
69 base::Bind(&SimpleSynchronousEntry::DoomEntry, path, key, 69 base::Bind(&SimpleSynchronousEntry::DoomEntry, path, key,
70 MessageLoopProxy::current(), callback), 70 MessageLoopProxy::current(), callback),
71 true); 71 true);
72 return net::ERR_IO_PENDING; 72 return net::ERR_IO_PENDING;
73 } 73 }
74 74
75 void SimpleEntryImpl::Doom() { 75 void SimpleEntryImpl::Doom() {
76 DCHECK(thread_checker_.CalledOnValidThread()); 76 DCHECK(thread_checker_.CalledOnValidThread());
77 if (synchronous_entry_in_use_by_worker_) { 77 #if defined(OS_POSIX)
78 NOTIMPLEMENTED() << ": Overlapping an asynchronous operation."; 78 // This call to static SimpleEntryImpl::DoomEntry() will just erase the
rvargas (doing something else) 2013/02/13 03:23:46 I think this is wrong, but it is also wrong on the
felipeg 2013/02/13 13:47:36 Hi Ricardo, Sorry, why ReaData(old_content) will
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 DCHECK(thread_checker_.CalledOnValidThread()); 89 DCHECK(thread_checker_.CalledOnValidThread());
91 if (synchronous_entry_in_use_by_worker_) { 90 if (synchronous_entry_in_use_by_worker_) {
92 NOTIMPLEMENTED() << ": Overlapping an asynchronous operation."; 91 NOTIMPLEMENTED() << ": Overlapping an asynchronous operation.";
93 delete this; 92 delete this;
94 return; 93 return;
95 } 94 }
96 DCHECK(synchronous_entry_ || has_been_doomed_); 95 DCHECK(synchronous_entry_);
97 if (!has_been_doomed_) { 96 WorkerPool::PostTask(FROM_HERE,
98 WorkerPool::PostTask(FROM_HERE, 97 base::Bind(&SimpleSynchronousEntry::Close,
99 base::Bind(&SimpleSynchronousEntry::Close, 98 base::Unretained(synchronous_entry_)),
100 base::Unretained(synchronous_entry_)), 99 true);
101 true); 100 synchronous_entry_ = NULL;
102 synchronous_entry_ = NULL;
103 }
104 // Entry::Close() is expected to release this entry. See disk_cache.h for 101 // Entry::Close() is expected to release this entry. See disk_cache.h for
105 // details. 102 // details.
106 delete this; 103 delete this;
107 } 104 }
108 105
109 std::string SimpleEntryImpl::GetKey() const { 106 std::string SimpleEntryImpl::GetKey() const {
110 DCHECK(thread_checker_.CalledOnValidThread()); 107 DCHECK(thread_checker_.CalledOnValidThread());
111 return key_; 108 return key_;
112 } 109 }
113 110
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 NOTIMPLEMENTED(); 221 NOTIMPLEMENTED();
225 return net::ERR_FAILED; 222 return net::ERR_FAILED;
226 } 223 }
227 224
228 SimpleEntryImpl::SimpleEntryImpl( 225 SimpleEntryImpl::SimpleEntryImpl(
229 SimpleSynchronousEntry* synchronous_entry) 226 SimpleSynchronousEntry* synchronous_entry)
230 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 227 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
231 path_(synchronous_entry->path()), 228 path_(synchronous_entry->path()),
232 key_(synchronous_entry->key()), 229 key_(synchronous_entry->key()),
233 synchronous_entry_(NULL), 230 synchronous_entry_(NULL),
234 synchronous_entry_in_use_by_worker_(false), 231 synchronous_entry_in_use_by_worker_(false) {
235 has_been_doomed_(false) {
236 SetSynchronousData(); 232 SetSynchronousData();
237 } 233 }
238 234
239 SimpleEntryImpl::~SimpleEntryImpl() { 235 SimpleEntryImpl::~SimpleEntryImpl() {
240 DCHECK(thread_checker_.CalledOnValidThread()); 236 DCHECK(thread_checker_.CalledOnValidThread());
241 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; 237 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_;
242 } 238 }
243 239
244 // static 240 // static
245 void SimpleEntryImpl::CreationOperationComplete( 241 void SimpleEntryImpl::CreationOperationComplete(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // in that structure. This also solves problems with last_used() on ext4 281 // in that structure. This also solves problems with last_used() on ext4
286 // filesystems not being accurate. 282 // filesystems not being accurate.
287 283
288 last_used_ = synchronous_entry_->last_used(); 284 last_used_ = synchronous_entry_->last_used();
289 last_modified_ = synchronous_entry_->last_modified(); 285 last_modified_ = synchronous_entry_->last_modified();
290 for (int i = 0; i < kSimpleEntryFileCount; ++i) 286 for (int i = 0; i < kSimpleEntryFileCount; ++i)
291 data_size_[i] = synchronous_entry_->data_size(i); 287 data_size_[i] = synchronous_entry_->data_size(i);
292 } 288 }
293 289
294 } // namespace disk_cache 290 } // 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