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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 delete this; | 106 delete this; |
107 } | 107 } |
108 | 108 |
109 std::string SimpleEntryImpl::GetKey() const { | 109 std::string SimpleEntryImpl::GetKey() const { |
110 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
111 return key_; | 111 return key_; |
112 } | 112 } |
113 | 113 |
114 Time SimpleEntryImpl::GetLastUsed() const { | 114 Time SimpleEntryImpl::GetLastUsed() const { |
115 DCHECK(thread_checker_.CalledOnValidThread()); | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
116 if (synchronous_entry_in_use_by_worker_) { | 116 return last_used_; |
117 NOTIMPLEMENTED() << ": Synchronous operations overlapping an asynchronous " | |
118 << "operation."; | |
119 NOTREACHED(); | |
120 } | |
121 return synchronous_entry_->last_used(); | |
122 } | 117 } |
123 | 118 |
124 Time SimpleEntryImpl::GetLastModified() const { | 119 Time SimpleEntryImpl::GetLastModified() const { |
125 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
126 if (synchronous_entry_in_use_by_worker_) { | 121 return last_modified_; |
127 NOTIMPLEMENTED() << ": Synchronous operations overlapping an asynchronous " | |
128 << "operation."; | |
129 NOTREACHED(); | |
130 } | |
131 return synchronous_entry_->last_modified(); | |
132 } | 122 } |
133 | 123 |
134 int32 SimpleEntryImpl::GetDataSize(int index) const { | 124 int32 SimpleEntryImpl::GetDataSize(int index) const { |
135 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
136 if (synchronous_entry_in_use_by_worker_) { | 126 return data_size_[index]; |
137 NOTIMPLEMENTED() << ": Synchronous operations overlapping an asynchronous " | |
138 << "operation."; | |
139 NOTREACHED(); | |
140 } | |
141 return synchronous_entry_->data_size(index); | |
142 } | 127 } |
143 | 128 |
144 int SimpleEntryImpl::ReadData(int index, | 129 int SimpleEntryImpl::ReadData(int index, |
145 int offset, | 130 int offset, |
146 net::IOBuffer* buf, | 131 net::IOBuffer* buf, |
147 int buf_len, | 132 int buf_len, |
148 const CompletionCallback& callback) { | 133 const CompletionCallback& callback) { |
149 DCHECK(thread_checker_.CalledOnValidThread()); | 134 DCHECK(thread_checker_.CalledOnValidThread()); |
150 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does | 135 // TODO(gavinp): Add support for overlapping reads. The net::HttpCache does |
151 // make overlapping read requests when multiple transactions access the same | 136 // make overlapping read requests when multiple transactions access the same |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { | 221 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { |
237 // TODO(gavinp): Determine if the simple backend should support sparse data. | 222 // TODO(gavinp): Determine if the simple backend should support sparse data. |
238 DCHECK(thread_checker_.CalledOnValidThread()); | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
239 NOTIMPLEMENTED(); | 224 NOTIMPLEMENTED(); |
240 return net::ERR_FAILED; | 225 return net::ERR_FAILED; |
241 } | 226 } |
242 | 227 |
243 SimpleEntryImpl::SimpleEntryImpl( | 228 SimpleEntryImpl::SimpleEntryImpl( |
244 SimpleSynchronousEntry* synchronous_entry) | 229 SimpleSynchronousEntry* synchronous_entry) |
245 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 230 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
231 path_(synchronous_entry->path()), | |
246 key_(synchronous_entry->key()), | 232 key_(synchronous_entry->key()), |
247 synchronous_entry_(synchronous_entry), | 233 synchronous_entry_(NULL), |
248 synchronous_entry_in_use_by_worker_(false), | 234 synchronous_entry_in_use_by_worker_(false), |
249 has_been_doomed_(false) { | 235 has_been_doomed_(false) { |
250 DCHECK(synchronous_entry); | 236 SetSynchronousData(); |
251 } | 237 } |
252 | 238 |
253 SimpleEntryImpl::~SimpleEntryImpl() { | 239 SimpleEntryImpl::~SimpleEntryImpl() { |
254 DCHECK(thread_checker_.CalledOnValidThread()); | 240 DCHECK(thread_checker_.CalledOnValidThread()); |
255 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; | 241 DCHECK(!synchronous_entry_) << "synchronous_entry_ = " << synchronous_entry_; |
256 } | 242 } |
257 | 243 |
258 // static | 244 // static |
259 void SimpleEntryImpl::CreationOperationComplete( | 245 void SimpleEntryImpl::CreationOperationComplete( |
260 const CompletionCallback& completion_callback, | 246 const CompletionCallback& completion_callback, |
(...skipping 17 matching lines...) Expand all Loading... | |
278 void SimpleEntryImpl::EntryOperationComplete( | 264 void SimpleEntryImpl::EntryOperationComplete( |
279 const CompletionCallback& completion_callback, | 265 const CompletionCallback& completion_callback, |
280 base::WeakPtr<SimpleEntryImpl> entry, | 266 base::WeakPtr<SimpleEntryImpl> entry, |
281 SimpleSynchronousEntry* sync_entry, | 267 SimpleSynchronousEntry* sync_entry, |
282 int result) { | 268 int result) { |
283 DCHECK(sync_entry); | 269 DCHECK(sync_entry); |
284 if (entry) { | 270 if (entry) { |
285 DCHECK(entry->synchronous_entry_in_use_by_worker_); | 271 DCHECK(entry->synchronous_entry_in_use_by_worker_); |
286 DCHECK_EQ(entry->synchronous_entry_, sync_entry); | 272 DCHECK_EQ(entry->synchronous_entry_, sync_entry); |
287 entry->synchronous_entry_in_use_by_worker_ = false; | 273 entry->synchronous_entry_in_use_by_worker_ = false; |
274 entry->SetSynchronousData(); | |
275 | |
288 } | 276 } |
289 completion_callback.Run(result); | 277 completion_callback.Run(result); |
290 } | 278 } |
291 | 279 |
280 void SimpleEntryImpl::SetSynchronousData() { | |
281 DCHECK(thread_checker_.CalledOnValidThread()); | |
282 DCHECK(!synchronous_entry_in_use_by_worker_); | |
283 | |
284 // TODO(felipeg): These copies to avoid data races are not optimal. While | |
285 // adding an IO thread index (for fast misses etc...), we can store this data | |
286 // in that structure. This also solves problems with last_used() on ext4 | |
287 // filesystems not being accurate. | |
gavinp
2013/02/12 16:17:49
I am, like pasko, afraid of data races, and that's
felipeg
2013/02/12 16:23:08
You are right.
We will need to store this on the i
| |
288 | |
289 last_used_ = synchronous_entry_->last_used(); | |
290 last_modified_ = synchronous_entry_->last_modified(); | |
291 for (int i = 0; i < kSimpleEntryFileCount; ++i) | |
292 data_size_[i] = synchronous_entry_->data_size(i); | |
293 } | |
294 | |
292 } // namespace disk_cache | 295 } // namespace disk_cache |
OLD | NEW |