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

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

Issue 12277004: Make SimpleEntryImpl::Close asynchronous. (Closed) Base URL: http://git.chromium.org/git/chromium.git@3-doomdoom
Patch Set: remediation 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
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // underlying files. On POSIX, this is fine; the files are still open on the 79 // underlying files. On POSIX, this is fine; the files are still open on the
80 // SimpleSynchronousEntry, and operations can even happen on them. The files 80 // SimpleSynchronousEntry, and operations can even happen on them. The files
81 // will be removed from the filesystem when they are closed. 81 // will be removed from the filesystem when they are closed.
82 DoomEntry(path_, key_, CompletionCallback()); 82 DoomEntry(path_, key_, CompletionCallback());
83 #else 83 #else
84 NOTIMPLEMENTED(); 84 NOTIMPLEMENTED();
85 #endif 85 #endif
86 } 86 }
87 87
88 void SimpleEntryImpl::Close() { 88 void SimpleEntryImpl::Close() {
89 if (synchronous_entry_in_use_by_worker_) { 89 if (!synchronous_entry_in_use_by_worker_) {
90 NOTIMPLEMENTED(); 90 WorkerPool::PostTask(FROM_HERE,
91 delete this; 91 base::Bind(&SimpleSynchronousEntry::Close,
92 return; 92 base::Unretained(synchronous_entry_)),
93 true);
93 } 94 }
94 DCHECK(synchronous_entry_);
Randy Smith (Not in Mondays) 2013/02/26 18:47:58 I don't see how this change might result in synchr
gavinp 2013/02/26 21:00:34 You're right. This was cruft that got mismerged wh
Randy Smith (Not in Mondays) 2013/02/26 21:13:11 Still a little confused--the last patch set still
gavinp 2013/02/27 21:50:01 Aha, I was also confused. In response to this comm
95 WorkerPool::PostTask(FROM_HERE,
96 base::Bind(&SimpleSynchronousEntry::Close,
97 base::Unretained(synchronous_entry_)),
98 true);
99 synchronous_entry_ = NULL;
100 // Entry::Close() is expected to release this entry. See disk_cache.h for 95 // Entry::Close() is expected to release this entry. See disk_cache.h for
101 // details. 96 // details.
102 delete this; 97 delete this;
103 } 98 }
104 99
105 std::string SimpleEntryImpl::GetKey() const { 100 std::string SimpleEntryImpl::GetKey() const {
106 return key_; 101 return key_;
107 } 102 }
108 103
109 Time SimpleEntryImpl::GetLastUsed() const { 104 Time SimpleEntryImpl::GetLastUsed() const {
110 return last_used_; 105 return last_used_;
111 } 106 }
112 107
113 Time SimpleEntryImpl::GetLastModified() const { 108 Time SimpleEntryImpl::GetLastModified() const {
114 return last_modified_; 109 return last_modified_;
115 } 110 }
116 111
117 int32 SimpleEntryImpl::GetDataSize(int index) const { 112 int32 SimpleEntryImpl::GetDataSize(int index) const {
118 return data_size_[index]; 113 return data_size_[index];
119 } 114 }
120 115
121 int SimpleEntryImpl::ReadData(int index, 116 int SimpleEntryImpl::ReadData(int index,
122 int offset, 117 int offset,
123 net::IOBuffer* buf, 118 net::IOBuffer* buf,
124 int buf_len, 119 int buf_len,
125 const CompletionCallback& callback) { 120 const CompletionCallback& callback) {
126 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does 121 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does
127 // make overlapping read requests when multiple transactions access the same 122 // make overlapping read requests when multiple transactions access the same
128 // entry as read only. 123 // entry as read only. This might make calling SimpleSynchronousEntry::Close()
124 // correctly more tricky (see SimpleEntryImpl::EntryOperationComplete).
129 if (synchronous_entry_in_use_by_worker_) { 125 if (synchronous_entry_in_use_by_worker_) {
130 NOTIMPLEMENTED(); 126 NOTIMPLEMENTED();
131 CHECK(false); 127 CHECK(false);
132 } 128 }
133 synchronous_entry_in_use_by_worker_ = true; 129 synchronous_entry_in_use_by_worker_ = true;
134 SynchronousOperationCallback sync_operation_callback = 130 SynchronousOperationCallback sync_operation_callback =
135 base::Bind(&SimpleEntryImpl::EntryOperationComplete, 131 base::Bind(&SimpleEntryImpl::EntryOperationComplete,
136 callback, weak_ptr_factory_.GetWeakPtr()); 132 callback, weak_ptr_factory_.GetWeakPtr(), synchronous_entry_);
137 WorkerPool::PostTask(FROM_HERE, 133 WorkerPool::PostTask(FROM_HERE,
138 base::Bind(&SimpleSynchronousEntry::ReadData, 134 base::Bind(&SimpleSynchronousEntry::ReadData,
139 base::Unretained(synchronous_entry_), 135 base::Unretained(synchronous_entry_),
140 index, offset, make_scoped_refptr(buf), 136 index, offset, make_scoped_refptr(buf),
141 buf_len, sync_operation_callback), 137 buf_len, sync_operation_callback),
142 true); 138 true);
143 return net::ERR_IO_PENDING; 139 return net::ERR_IO_PENDING;
144 } 140 }
145 141
146 int SimpleEntryImpl::WriteData(int index, 142 int SimpleEntryImpl::WriteData(int index,
147 int offset, 143 int offset,
148 net::IOBuffer* buf, 144 net::IOBuffer* buf,
149 int buf_len, 145 int buf_len,
150 const CompletionCallback& callback, 146 const CompletionCallback& callback,
151 bool truncate) { 147 bool truncate) {
152 if (synchronous_entry_in_use_by_worker_) { 148 if (synchronous_entry_in_use_by_worker_) {
153 NOTIMPLEMENTED(); 149 NOTIMPLEMENTED();
154 CHECK(false); 150 CHECK(false);
155 } 151 }
156 synchronous_entry_in_use_by_worker_ = true; 152 synchronous_entry_in_use_by_worker_ = true;
157 SynchronousOperationCallback sync_operation_callback = 153 SynchronousOperationCallback sync_operation_callback =
158 base::Bind(&SimpleEntryImpl::EntryOperationComplete, 154 base::Bind(&SimpleEntryImpl::EntryOperationComplete,
159 callback, weak_ptr_factory_.GetWeakPtr()); 155 callback, weak_ptr_factory_.GetWeakPtr(), synchronous_entry_);
160 WorkerPool::PostTask(FROM_HERE, 156 WorkerPool::PostTask(FROM_HERE,
161 base::Bind(&SimpleSynchronousEntry::WriteData, 157 base::Bind(&SimpleSynchronousEntry::WriteData,
162 base::Unretained(synchronous_entry_), 158 base::Unretained(synchronous_entry_),
163 index, offset, make_scoped_refptr(buf), 159 index, offset, make_scoped_refptr(buf),
164 buf_len, sync_operation_callback, truncate), 160 buf_len, sync_operation_callback, truncate),
165 true); 161 true);
166 return net::ERR_IO_PENDING; 162 return net::ERR_IO_PENDING;
167 } 163 }
168 164
169 int SimpleEntryImpl::ReadSparseData(int64 offset, 165 int SimpleEntryImpl::ReadSparseData(int64 offset,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return; 230 return;
235 } 231 }
236 *out_entry = new SimpleEntryImpl(sync_entry); 232 *out_entry = new SimpleEntryImpl(sync_entry);
237 completion_callback.Run(net::OK); 233 completion_callback.Run(net::OK);
238 } 234 }
239 235
240 // static 236 // static
241 void SimpleEntryImpl::EntryOperationComplete( 237 void SimpleEntryImpl::EntryOperationComplete(
242 const CompletionCallback& completion_callback, 238 const CompletionCallback& completion_callback,
243 base::WeakPtr<SimpleEntryImpl> entry, 239 base::WeakPtr<SimpleEntryImpl> entry,
240 SimpleSynchronousEntry* sync_entry,
244 int result) { 241 int result) {
245 if (entry) { 242 if (entry) {
246 DCHECK(entry->synchronous_entry_in_use_by_worker_); 243 DCHECK(entry->synchronous_entry_in_use_by_worker_);
247 entry->synchronous_entry_in_use_by_worker_ = false; 244 entry->synchronous_entry_in_use_by_worker_ = false;
248 entry->SetSynchronousData(); 245 entry->SetSynchronousData();
246 } else {
247 // |entry| must have had Close() called while this operation was in flight.
248 // Since the simple cache now only supports one pending entry operation in
249 // flight at a time, it's safe to now call Close() on |sync_entry|.
250 WorkerPool::PostTask(FROM_HERE,
251 base::Bind(&SimpleSynchronousEntry::Close,
252 base::Unretained(sync_entry)),
Randy Smith (Not in Mondays) 2013/02/26 18:47:58 I would feel better about this change if the owner
gavinp 2013/02/26 21:00:34 Done.
253 true);
249 } 254 }
250 completion_callback.Run(result); 255 completion_callback.Run(result);
251 } 256 }
252 257
253 void SimpleEntryImpl::SetSynchronousData() { 258 void SimpleEntryImpl::SetSynchronousData() {
254 DCHECK(!synchronous_entry_in_use_by_worker_); 259 DCHECK(!synchronous_entry_in_use_by_worker_);
255 260
256 // TODO(felipeg): These copies to avoid data races are not optimal. While 261 // TODO(felipeg): These copies to avoid data races are not optimal. While
257 // adding an IO thread index (for fast misses etc...), we can store this data 262 // adding an IO thread index (for fast misses etc...), we can store this data
258 // in that structure. This also solves problems with last_used() on ext4 263 // in that structure. This also solves problems with last_used() on ext4
259 // filesystems not being accurate. 264 // filesystems not being accurate.
260 265
261 last_used_ = synchronous_entry_->last_used(); 266 last_used_ = synchronous_entry_->last_used();
262 last_modified_ = synchronous_entry_->last_modified(); 267 last_modified_ = synchronous_entry_->last_modified();
263 for (int i = 0; i < kSimpleEntryFileCount; ++i) 268 for (int i = 0; i < kSimpleEntryFileCount; ++i)
264 data_size_[i] = synchronous_entry_->data_size(i); 269 data_size_[i] = synchronous_entry_->data_size(i);
265 } 270 }
266 271
267 } // namespace disk_cache 272 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698