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

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

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Created 4 years, 3 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
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 <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 11 matching lines...) Expand all
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
25 #include "net/disk_cache/net_log_parameters.h" 25 #include "net/disk_cache/net_log_parameters.h"
26 #include "net/disk_cache/simple/simple_backend_impl.h" 26 #include "net/disk_cache/simple/simple_backend_impl.h"
27 #include "net/disk_cache/simple/simple_histogram_macros.h" 27 #include "net/disk_cache/simple/simple_histogram_macros.h"
28 #include "net/disk_cache/simple/simple_index.h" 28 #include "net/disk_cache/simple/simple_index.h"
29 #include "net/disk_cache/simple/simple_net_log_parameters.h" 29 #include "net/disk_cache/simple/simple_net_log_parameters.h"
30 #include "net/disk_cache/simple/simple_synchronous_entry.h" 30 #include "net/disk_cache/simple/simple_synchronous_entry.h"
31 #include "net/disk_cache/simple/simple_util.h" 31 #include "net/disk_cache/simple/simple_util.h"
32 #include "net/log/net_log_source_type.h"
32 #include "third_party/zlib/zlib.h" 33 #include "third_party/zlib/zlib.h"
33 34
34 namespace disk_cache { 35 namespace disk_cache {
35 namespace { 36 namespace {
36 37
37 // An entry can store sparse data taking up to 1 / kMaxSparseDataSizeDivisor of 38 // An entry can store sparse data taking up to 1 / kMaxSparseDataSizeDivisor of
38 // the cache. 39 // the cache.
39 const int64_t kMaxSparseDataSizeDivisor = 10; 40 const int64_t kMaxSparseDataSizeDivisor = 10;
40 41
41 // Used in histograms, please only add entries at the end. 42 // Used in histograms, please only add entries at the end.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 entry_hash_(entry_hash), 178 entry_hash_(entry_hash),
178 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS), 179 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS),
179 last_used_(Time::Now()), 180 last_used_(Time::Now()),
180 last_modified_(last_used_), 181 last_modified_(last_used_),
181 sparse_data_size_(0), 182 sparse_data_size_(0),
182 open_count_(0), 183 open_count_(0),
183 doomed_(false), 184 doomed_(false),
184 state_(STATE_UNINITIALIZED), 185 state_(STATE_UNINITIALIZED),
185 synchronous_entry_(NULL), 186 synchronous_entry_(NULL),
186 net_log_(net::BoundNetLog::Make(net_log, 187 net_log_(net::BoundNetLog::Make(net_log,
187 net::NetLog::SOURCE_DISK_CACHE_ENTRY)), 188 net::NetLogSourceType::DISK_CACHE_ENTRY)),
188 stream_0_data_(new net::GrowableIOBuffer()) { 189 stream_0_data_(new net::GrowableIOBuffer()) {
189 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_), 190 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_),
190 "arrays should be the same size"); 191 "arrays should be the same size");
191 static_assert(arraysize(data_size_) == arraysize(crc32s_), 192 static_assert(arraysize(data_size_) == arraysize(crc32s_),
192 "arrays should be the same size"); 193 "arrays should be the same size");
193 static_assert(arraysize(data_size_) == arraysize(have_written_), 194 static_assert(arraysize(data_size_) == arraysize(have_written_),
194 "arrays should be the same size"); 195 "arrays should be the same size");
195 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), 196 static_assert(arraysize(data_size_) == arraysize(crc_check_state_),
196 "arrays should be the same size"); 197 "arrays should be the same size");
197 MakeUninitialized(); 198 MakeUninitialized();
198 net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY, 199 net_log_.BeginEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY,
199 CreateNetLogSimpleEntryConstructionCallback(this)); 200 CreateNetLogSimpleEntryConstructionCallback(this));
200 } 201 }
201 202
202 void SimpleEntryImpl::SetActiveEntryProxy( 203 void SimpleEntryImpl::SetActiveEntryProxy(
203 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) { 204 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) {
204 DCHECK(!active_entry_proxy_); 205 DCHECK(!active_entry_proxy_);
205 active_entry_proxy_.reset(active_entry_proxy.release()); 206 active_entry_proxy_.reset(active_entry_proxy.release());
206 } 207 }
207 208
208 int SimpleEntryImpl::OpenEntry(Entry** out_entry, 209 int SimpleEntryImpl::OpenEntry(Entry** out_entry,
209 const CompletionCallback& callback) { 210 const CompletionCallback& callback) {
210 DCHECK(backend_.get()); 211 DCHECK(backend_.get());
211 212
212 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_CALL); 213 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_CALL);
213 214
214 bool have_index = backend_->index()->initialized(); 215 bool have_index = backend_->index()->initialized();
215 // This enumeration is used in histograms, add entries only at end. 216 // This enumeration is used in histograms, add entries only at end.
216 enum OpenEntryIndexEnum { 217 enum OpenEntryIndexEnum {
217 INDEX_NOEXIST = 0, 218 INDEX_NOEXIST = 0,
218 INDEX_MISS = 1, 219 INDEX_MISS = 1,
219 INDEX_HIT = 2, 220 INDEX_HIT = 2,
220 INDEX_MAX = 3, 221 INDEX_MAX = 3,
221 }; 222 };
222 OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST; 223 OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST;
223 if (have_index) { 224 if (have_index) {
224 if (backend_->index()->Has(entry_hash_)) 225 if (backend_->index()->Has(entry_hash_))
225 open_entry_index_enum = INDEX_HIT; 226 open_entry_index_enum = INDEX_HIT;
226 else 227 else
227 open_entry_index_enum = INDEX_MISS; 228 open_entry_index_enum = INDEX_MISS;
228 } 229 }
229 SIMPLE_CACHE_UMA(ENUMERATION, 230 SIMPLE_CACHE_UMA(ENUMERATION,
230 "OpenEntryIndexState", cache_type_, 231 "OpenEntryIndexState", cache_type_,
231 open_entry_index_enum, INDEX_MAX); 232 open_entry_index_enum, INDEX_MAX);
232 233
233 // If entry is not known to the index, initiate fast failover to the network. 234 // If entry is not known to the index, initiate fast failover to the network.
234 if (open_entry_index_enum == INDEX_MISS) { 235 if (open_entry_index_enum == INDEX_MISS) {
235 net_log_.AddEventWithNetErrorCode( 236 net_log_.AddEventWithNetErrorCode(
236 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, 237 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END,
237 net::ERR_FAILED); 238 net::ERR_FAILED);
238 return net::ERR_FAILED; 239 return net::ERR_FAILED;
239 } 240 }
240 241
241 pending_operations_.push(SimpleEntryOperation::OpenOperation( 242 pending_operations_.push(SimpleEntryOperation::OpenOperation(
242 this, have_index, callback, out_entry)); 243 this, have_index, callback, out_entry));
243 RunNextOperationIfNeeded(); 244 RunNextOperationIfNeeded();
244 return net::ERR_IO_PENDING; 245 return net::ERR_IO_PENDING;
245 } 246 }
246 247
247 int SimpleEntryImpl::CreateEntry(Entry** out_entry, 248 int SimpleEntryImpl::CreateEntry(Entry** out_entry,
248 const CompletionCallback& callback) { 249 const CompletionCallback& callback) {
249 DCHECK(backend_.get()); 250 DCHECK(backend_.get());
250 DCHECK_EQ(entry_hash_, simple_util::GetEntryHashKey(key_)); 251 DCHECK_EQ(entry_hash_, simple_util::GetEntryHashKey(key_));
251 252
252 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_CALL); 253 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_CALL);
253 254
254 bool have_index = backend_->index()->initialized(); 255 bool have_index = backend_->index()->initialized();
255 int ret_value = net::ERR_FAILED; 256 int ret_value = net::ERR_FAILED;
256 if (use_optimistic_operations_ && 257 if (use_optimistic_operations_ &&
257 state_ == STATE_UNINITIALIZED && pending_operations_.size() == 0) { 258 state_ == STATE_UNINITIALIZED && pending_operations_.size() == 0) {
258 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_OPTIMISTIC); 259 net_log_.AddEvent(
260 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_OPTIMISTIC);
259 261
260 ReturnEntryToCaller(out_entry); 262 ReturnEntryToCaller(out_entry);
261 pending_operations_.push(SimpleEntryOperation::CreateOperation( 263 pending_operations_.push(SimpleEntryOperation::CreateOperation(
262 this, have_index, CompletionCallback(), static_cast<Entry**>(NULL))); 264 this, have_index, CompletionCallback(), static_cast<Entry**>(NULL)));
263 ret_value = net::OK; 265 ret_value = net::OK;
264 } else { 266 } else {
265 pending_operations_.push(SimpleEntryOperation::CreateOperation( 267 pending_operations_.push(SimpleEntryOperation::CreateOperation(
266 this, have_index, callback, out_entry)); 268 this, have_index, callback, out_entry));
267 ret_value = net::ERR_IO_PENDING; 269 ret_value = net::ERR_IO_PENDING;
268 } 270 }
269 271
270 // We insert the entry in the index before creating the entry files in the 272 // We insert the entry in the index before creating the entry files in the
271 // SimpleSynchronousEntry, because this way the worst scenario is when we 273 // SimpleSynchronousEntry, because this way the worst scenario is when we
272 // have the entry in the index but we don't have the created files yet, this 274 // have the entry in the index but we don't have the created files yet, this
273 // way we never leak files. CreationOperationComplete will remove the entry 275 // way we never leak files. CreationOperationComplete will remove the entry
274 // from the index if the creation fails. 276 // from the index if the creation fails.
275 backend_->index()->Insert(entry_hash_); 277 backend_->index()->Insert(entry_hash_);
276 278
277 RunNextOperationIfNeeded(); 279 RunNextOperationIfNeeded();
278 return ret_value; 280 return ret_value;
279 } 281 }
280 282
281 int SimpleEntryImpl::DoomEntry(const CompletionCallback& callback) { 283 int SimpleEntryImpl::DoomEntry(const CompletionCallback& callback) {
282 if (doomed_) 284 if (doomed_)
283 return net::OK; 285 return net::OK;
284 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_CALL); 286 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_DOOM_CALL);
285 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_BEGIN); 287 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_DOOM_BEGIN);
286 288
287 MarkAsDoomed(); 289 MarkAsDoomed();
288 if (backend_.get()) 290 if (backend_.get())
289 backend_->OnDoomStart(entry_hash_); 291 backend_->OnDoomStart(entry_hash_);
290 pending_operations_.push(SimpleEntryOperation::DoomOperation(this, callback)); 292 pending_operations_.push(SimpleEntryOperation::DoomOperation(this, callback));
291 RunNextOperationIfNeeded(); 293 RunNextOperationIfNeeded();
292 return net::ERR_IO_PENDING; 294 return net::ERR_IO_PENDING;
293 } 295 }
294 296
295 void SimpleEntryImpl::SetKey(const std::string& key) { 297 void SimpleEntryImpl::SetKey(const std::string& key) {
296 key_ = key; 298 key_ = key;
297 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_SET_KEY, 299 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_SET_KEY,
298 net::NetLog::StringCallback("key", &key)); 300 net::NetLog::StringCallback("key", &key));
299 } 301 }
300 302
301 void SimpleEntryImpl::Doom() { 303 void SimpleEntryImpl::Doom() {
302 DoomEntry(CompletionCallback()); 304 DoomEntry(CompletionCallback());
303 } 305 }
304 306
305 void SimpleEntryImpl::Close() { 307 void SimpleEntryImpl::Close() {
306 DCHECK(io_thread_checker_.CalledOnValidThread()); 308 DCHECK(io_thread_checker_.CalledOnValidThread());
307 DCHECK_LT(0, open_count_); 309 DCHECK_LT(0, open_count_);
308 310
309 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_CALL); 311 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_CALL);
310 312
311 if (--open_count_ > 0) { 313 if (--open_count_ > 0) {
312 DCHECK(!HasOneRef()); 314 DCHECK(!HasOneRef());
313 Release(); // Balanced in ReturnEntryToCaller(). 315 Release(); // Balanced in ReturnEntryToCaller().
314 return; 316 return;
315 } 317 }
316 318
317 pending_operations_.push(SimpleEntryOperation::CloseOperation(this)); 319 pending_operations_.push(SimpleEntryOperation::CloseOperation(this));
318 DCHECK(!HasOneRef()); 320 DCHECK(!HasOneRef());
319 Release(); // Balanced in ReturnEntryToCaller(). 321 Release(); // Balanced in ReturnEntryToCaller().
(...skipping 22 matching lines...) Expand all
342 } 344 }
343 345
344 int SimpleEntryImpl::ReadData(int stream_index, 346 int SimpleEntryImpl::ReadData(int stream_index,
345 int offset, 347 int offset,
346 net::IOBuffer* buf, 348 net::IOBuffer* buf,
347 int buf_len, 349 int buf_len,
348 const CompletionCallback& callback) { 350 const CompletionCallback& callback) {
349 DCHECK(io_thread_checker_.CalledOnValidThread()); 351 DCHECK(io_thread_checker_.CalledOnValidThread());
350 352
351 if (net_log_.IsCapturing()) { 353 if (net_log_.IsCapturing()) {
352 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_CALL, 354 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_CALL,
353 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, 355 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len,
354 false)); 356 false));
355 } 357 }
356 358
357 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || 359 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount ||
358 buf_len < 0) { 360 buf_len < 0) {
359 if (net_log_.IsCapturing()) { 361 if (net_log_.IsCapturing()) {
360 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, 362 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END,
361 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); 363 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT));
362 } 364 }
363 365
364 RecordReadResult(cache_type_, READ_RESULT_INVALID_ARGUMENT); 366 RecordReadResult(cache_type_, READ_RESULT_INVALID_ARGUMENT);
365 return net::ERR_INVALID_ARGUMENT; 367 return net::ERR_INVALID_ARGUMENT;
366 } 368 }
367 if (pending_operations_.empty() && (offset >= GetDataSize(stream_index) || 369 if (pending_operations_.empty() && (offset >= GetDataSize(stream_index) ||
368 offset < 0 || !buf_len)) { 370 offset < 0 || !buf_len)) {
369 if (net_log_.IsCapturing()) { 371 if (net_log_.IsCapturing()) {
370 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, 372 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END,
371 CreateNetLogReadWriteCompleteCallback(0)); 373 CreateNetLogReadWriteCompleteCallback(0));
372 } 374 }
373 375
374 RecordReadResult(cache_type_, READ_RESULT_NONBLOCK_EMPTY_RETURN); 376 RecordReadResult(cache_type_, READ_RESULT_NONBLOCK_EMPTY_RETURN);
375 return 0; 377 return 0;
376 } 378 }
377 379
378 // TODO(clamy): return immediatly when reading from stream 0. 380 // TODO(clamy): return immediatly when reading from stream 0.
379 381
380 // TODO(felipeg): Optimization: Add support for truly parallel read 382 // TODO(felipeg): Optimization: Add support for truly parallel read
381 // operations. 383 // operations.
382 bool alone_in_queue = 384 bool alone_in_queue =
383 pending_operations_.size() == 0 && state_ == STATE_READY; 385 pending_operations_.size() == 0 && state_ == STATE_READY;
384 pending_operations_.push(SimpleEntryOperation::ReadOperation( 386 pending_operations_.push(SimpleEntryOperation::ReadOperation(
385 this, stream_index, offset, buf_len, buf, callback, alone_in_queue)); 387 this, stream_index, offset, buf_len, buf, callback, alone_in_queue));
386 RunNextOperationIfNeeded(); 388 RunNextOperationIfNeeded();
387 return net::ERR_IO_PENDING; 389 return net::ERR_IO_PENDING;
388 } 390 }
389 391
390 int SimpleEntryImpl::WriteData(int stream_index, 392 int SimpleEntryImpl::WriteData(int stream_index,
391 int offset, 393 int offset,
392 net::IOBuffer* buf, 394 net::IOBuffer* buf,
393 int buf_len, 395 int buf_len,
394 const CompletionCallback& callback, 396 const CompletionCallback& callback,
395 bool truncate) { 397 bool truncate) {
396 DCHECK(io_thread_checker_.CalledOnValidThread()); 398 DCHECK(io_thread_checker_.CalledOnValidThread());
397 399
398 if (net_log_.IsCapturing()) { 400 if (net_log_.IsCapturing()) {
399 net_log_.AddEvent( 401 net_log_.AddEvent(
400 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_CALL, 402 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_CALL,
401 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, 403 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len,
402 truncate)); 404 truncate));
403 } 405 }
404 406
405 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || 407 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount ||
406 offset < 0 || buf_len < 0) { 408 offset < 0 || buf_len < 0) {
407 if (net_log_.IsCapturing()) { 409 if (net_log_.IsCapturing()) {
408 net_log_.AddEvent( 410 net_log_.AddEvent(
409 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, 411 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END,
410 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); 412 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT));
411 } 413 }
412 RecordWriteResult(cache_type_, WRITE_RESULT_INVALID_ARGUMENT); 414 RecordWriteResult(cache_type_, WRITE_RESULT_INVALID_ARGUMENT);
413 return net::ERR_INVALID_ARGUMENT; 415 return net::ERR_INVALID_ARGUMENT;
414 } 416 }
415 if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) { 417 if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) {
416 if (net_log_.IsCapturing()) { 418 if (net_log_.IsCapturing()) {
417 net_log_.AddEvent( 419 net_log_.AddEvent(
418 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, 420 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END,
419 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); 421 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED));
420 } 422 }
421 RecordWriteResult(cache_type_, WRITE_RESULT_OVER_MAX_SIZE); 423 RecordWriteResult(cache_type_, WRITE_RESULT_OVER_MAX_SIZE);
422 return net::ERR_FAILED; 424 return net::ERR_FAILED;
423 } 425 }
424 ScopedOperationRunner operation_runner(this); 426 ScopedOperationRunner operation_runner(this);
425 427
426 // Stream 0 data is kept in memory, so can be written immediatly if there are 428 // Stream 0 data is kept in memory, so can be written immediatly if there are
427 // no IO operations pending. 429 // no IO operations pending.
428 if (stream_index == 0 && state_ == STATE_READY && 430 if (stream_index == 0 && state_ == STATE_READY &&
(...skipping 21 matching lines...) Expand all
450 // here to avoid paying the price of the RefCountedThreadSafe atomic 452 // here to avoid paying the price of the RefCountedThreadSafe atomic
451 // operations. 453 // operations.
452 if (buf) { 454 if (buf) {
453 op_buf = new IOBuffer(buf_len); 455 op_buf = new IOBuffer(buf_len);
454 memcpy(op_buf->data(), buf->data(), buf_len); 456 memcpy(op_buf->data(), buf->data(), buf_len);
455 } 457 }
456 op_callback = CompletionCallback(); 458 op_callback = CompletionCallback();
457 ret_value = buf_len; 459 ret_value = buf_len;
458 if (net_log_.IsCapturing()) { 460 if (net_log_.IsCapturing()) {
459 net_log_.AddEvent( 461 net_log_.AddEvent(
460 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_OPTIMISTIC, 462 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_OPTIMISTIC,
461 CreateNetLogReadWriteCompleteCallback(buf_len)); 463 CreateNetLogReadWriteCompleteCallback(buf_len));
462 } 464 }
463 } 465 }
464 466
465 pending_operations_.push(SimpleEntryOperation::WriteOperation(this, 467 pending_operations_.push(SimpleEntryOperation::WriteOperation(this,
466 stream_index, 468 stream_index,
467 offset, 469 offset,
468 buf_len, 470 buf_len,
469 op_buf.get(), 471 op_buf.get(),
470 truncate, 472 truncate,
471 optimistic, 473 optimistic,
472 op_callback)); 474 op_callback));
473 return ret_value; 475 return ret_value;
474 } 476 }
475 477
476 int SimpleEntryImpl::ReadSparseData(int64_t offset, 478 int SimpleEntryImpl::ReadSparseData(int64_t offset,
477 net::IOBuffer* buf, 479 net::IOBuffer* buf,
478 int buf_len, 480 int buf_len,
479 const CompletionCallback& callback) { 481 const CompletionCallback& callback) {
480 DCHECK(io_thread_checker_.CalledOnValidThread()); 482 DCHECK(io_thread_checker_.CalledOnValidThread());
481 483
482 if (net_log_.IsCapturing()) { 484 if (net_log_.IsCapturing()) {
483 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL, 485 net_log_.AddEvent(
484 CreateNetLogSparseOperationCallback(offset, buf_len)); 486 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL,
487 CreateNetLogSparseOperationCallback(offset, buf_len));
485 } 488 }
486 489
487 ScopedOperationRunner operation_runner(this); 490 ScopedOperationRunner operation_runner(this);
488 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation( 491 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation(
489 this, offset, buf_len, buf, callback)); 492 this, offset, buf_len, buf, callback));
490 return net::ERR_IO_PENDING; 493 return net::ERR_IO_PENDING;
491 } 494 }
492 495
493 int SimpleEntryImpl::WriteSparseData(int64_t offset, 496 int SimpleEntryImpl::WriteSparseData(int64_t offset,
494 net::IOBuffer* buf, 497 net::IOBuffer* buf,
495 int buf_len, 498 int buf_len,
496 const CompletionCallback& callback) { 499 const CompletionCallback& callback) {
497 DCHECK(io_thread_checker_.CalledOnValidThread()); 500 DCHECK(io_thread_checker_.CalledOnValidThread());
498 501
499 if (net_log_.IsCapturing()) { 502 if (net_log_.IsCapturing()) {
500 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_CALL, 503 net_log_.AddEvent(
501 CreateNetLogSparseOperationCallback(offset, buf_len)); 504 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_SPARSE_CALL,
505 CreateNetLogSparseOperationCallback(offset, buf_len));
502 } 506 }
503 507
504 ScopedOperationRunner operation_runner(this); 508 ScopedOperationRunner operation_runner(this);
505 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation( 509 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation(
506 this, offset, buf_len, buf, callback)); 510 this, offset, buf_len, buf, callback));
507 return net::ERR_IO_PENDING; 511 return net::ERR_IO_PENDING;
508 } 512 }
509 513
510 int SimpleEntryImpl::GetAvailableRange(int64_t offset, 514 int SimpleEntryImpl::GetAvailableRange(int64_t offset,
511 int len, 515 int len,
(...skipping 26 matching lines...) Expand all
538 // entry, so there's no need to coordinate which object is performing sparse 542 // entry, so there's no need to coordinate which object is performing sparse
539 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. 543 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly.
540 return net::OK; 544 return net::OK;
541 } 545 }
542 546
543 SimpleEntryImpl::~SimpleEntryImpl() { 547 SimpleEntryImpl::~SimpleEntryImpl() {
544 DCHECK(io_thread_checker_.CalledOnValidThread()); 548 DCHECK(io_thread_checker_.CalledOnValidThread());
545 DCHECK_EQ(0U, pending_operations_.size()); 549 DCHECK_EQ(0U, pending_operations_.size());
546 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); 550 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE);
547 DCHECK(!synchronous_entry_); 551 DCHECK(!synchronous_entry_);
548 net_log_.EndEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY); 552 net_log_.EndEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY);
549 } 553 }
550 554
551 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback, 555 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback,
552 int result) { 556 int result) {
553 if (callback.is_null()) 557 if (callback.is_null())
554 return; 558 return;
555 // Note that the callback is posted rather than directly invoked to avoid 559 // Note that the callback is posted rather than directly invoked to avoid
556 // reentrancy issues. 560 // reentrancy issues.
557 base::ThreadTaskRunnerHandle::Get()->PostTask( 561 base::ThreadTaskRunnerHandle::Get()->PostTask(
558 FROM_HERE, 562 FROM_HERE,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 executing_operation_->ReleaseReferences(); 668 executing_operation_->ReleaseReferences();
665 // |this| may have been deleted. 669 // |this| may have been deleted.
666 } 670 }
667 } 671 }
668 672
669 void SimpleEntryImpl::OpenEntryInternal(bool have_index, 673 void SimpleEntryImpl::OpenEntryInternal(bool have_index,
670 const CompletionCallback& callback, 674 const CompletionCallback& callback,
671 Entry** out_entry) { 675 Entry** out_entry) {
672 ScopedOperationRunner operation_runner(this); 676 ScopedOperationRunner operation_runner(this);
673 677
674 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_BEGIN); 678 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_BEGIN);
675 679
676 if (state_ == STATE_READY) { 680 if (state_ == STATE_READY) {
677 ReturnEntryToCaller(out_entry); 681 ReturnEntryToCaller(out_entry);
678 PostClientCallback(callback, net::OK); 682 PostClientCallback(callback, net::OK);
679 net_log_.AddEvent( 683 net_log_.AddEvent(
680 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, 684 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END,
681 CreateNetLogSimpleEntryCreationCallback(this, net::OK)); 685 CreateNetLogSimpleEntryCreationCallback(this, net::OK));
682 return; 686 return;
683 } 687 }
684 if (state_ == STATE_FAILURE) { 688 if (state_ == STATE_FAILURE) {
685 PostClientCallback(callback, net::ERR_FAILED); 689 PostClientCallback(callback, net::ERR_FAILED);
686 net_log_.AddEvent( 690 net_log_.AddEvent(
687 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, 691 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END,
688 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); 692 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED));
689 return; 693 return;
690 } 694 }
691 695
692 DCHECK_EQ(STATE_UNINITIALIZED, state_); 696 DCHECK_EQ(STATE_UNINITIALIZED, state_);
693 DCHECK(!synchronous_entry_); 697 DCHECK(!synchronous_entry_);
694 state_ = STATE_IO_PENDING; 698 state_ = STATE_IO_PENDING;
695 const base::TimeTicks start_time = base::TimeTicks::Now(); 699 const base::TimeTicks start_time = base::TimeTicks::Now();
696 std::unique_ptr<SimpleEntryCreationResults> results( 700 std::unique_ptr<SimpleEntryCreationResults> results(
697 new SimpleEntryCreationResults(SimpleEntryStat( 701 new SimpleEntryCreationResults(SimpleEntryStat(
698 last_used_, last_modified_, data_size_, sparse_data_size_))); 702 last_used_, last_modified_, data_size_, sparse_data_size_)));
699 Closure task = 703 Closure task =
700 base::Bind(&SimpleSynchronousEntry::OpenEntry, cache_type_, path_, key_, 704 base::Bind(&SimpleSynchronousEntry::OpenEntry, cache_type_, path_, key_,
701 entry_hash_, have_index, results.get()); 705 entry_hash_, have_index, results.get());
702 Closure reply = 706 Closure reply =
703 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback, 707 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback,
704 start_time, base::Passed(&results), out_entry, 708 start_time, base::Passed(&results), out_entry,
705 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END); 709 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END);
706 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 710 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
707 } 711 }
708 712
709 void SimpleEntryImpl::CreateEntryInternal(bool have_index, 713 void SimpleEntryImpl::CreateEntryInternal(bool have_index,
710 const CompletionCallback& callback, 714 const CompletionCallback& callback,
711 Entry** out_entry) { 715 Entry** out_entry) {
712 ScopedOperationRunner operation_runner(this); 716 ScopedOperationRunner operation_runner(this);
713 717
714 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_BEGIN); 718 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_BEGIN);
715 719
716 if (state_ != STATE_UNINITIALIZED) { 720 if (state_ != STATE_UNINITIALIZED) {
717 // There is already an active normal entry. 721 // There is already an active normal entry.
718 net_log_.AddEvent( 722 net_log_.AddEvent(
719 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_END, 723 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_END,
720 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); 724 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED));
721 PostClientCallback(callback, net::ERR_FAILED); 725 PostClientCallback(callback, net::ERR_FAILED);
722 return; 726 return;
723 } 727 }
724 DCHECK_EQ(STATE_UNINITIALIZED, state_); 728 DCHECK_EQ(STATE_UNINITIALIZED, state_);
725 DCHECK(!synchronous_entry_); 729 DCHECK(!synchronous_entry_);
726 730
727 state_ = STATE_IO_PENDING; 731 state_ = STATE_IO_PENDING;
728 732
729 // Since we don't know the correct values for |last_used_| and 733 // Since we don't know the correct values for |last_used_| and
(...skipping 14 matching lines...) Expand all
744 key_, 748 key_,
745 entry_hash_, 749 entry_hash_,
746 have_index, 750 have_index,
747 results.get()); 751 results.get());
748 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, 752 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete,
749 this, 753 this,
750 callback, 754 callback,
751 start_time, 755 start_time,
752 base::Passed(&results), 756 base::Passed(&results),
753 out_entry, 757 out_entry,
754 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_END); 758 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_END);
755 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 759 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
756 } 760 }
757 761
758 void SimpleEntryImpl::CloseInternal() { 762 void SimpleEntryImpl::CloseInternal() {
759 DCHECK(io_thread_checker_.CalledOnValidThread()); 763 DCHECK(io_thread_checker_.CalledOnValidThread());
760 typedef SimpleSynchronousEntry::CRCRecord CRCRecord; 764 typedef SimpleSynchronousEntry::CRCRecord CRCRecord;
761 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write( 765 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write(
762 new std::vector<CRCRecord>()); 766 new std::vector<CRCRecord>());
763 767
764 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); 768 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_BEGIN);
765 769
766 if (state_ == STATE_READY) { 770 if (state_ == STATE_READY) {
767 DCHECK(synchronous_entry_); 771 DCHECK(synchronous_entry_);
768 state_ = STATE_IO_PENDING; 772 state_ = STATE_IO_PENDING;
769 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 773 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
770 if (have_written_[i]) { 774 if (have_written_[i]) {
771 if (GetDataSize(i) == crc32s_end_offset_[i]) { 775 if (GetDataSize(i) == crc32s_end_offset_[i]) {
772 int32_t crc = GetDataSize(i) == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i]; 776 int32_t crc = GetDataSize(i) == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i];
773 crc32s_to_write->push_back(CRCRecord(i, true, crc)); 777 crc32s_to_write->push_back(CRCRecord(i, true, crc));
774 } else { 778 } else {
(...skipping 30 matching lines...) Expand all
805 void SimpleEntryImpl::ReadDataInternal(int stream_index, 809 void SimpleEntryImpl::ReadDataInternal(int stream_index,
806 int offset, 810 int offset,
807 net::IOBuffer* buf, 811 net::IOBuffer* buf,
808 int buf_len, 812 int buf_len,
809 const CompletionCallback& callback) { 813 const CompletionCallback& callback) {
810 DCHECK(io_thread_checker_.CalledOnValidThread()); 814 DCHECK(io_thread_checker_.CalledOnValidThread());
811 ScopedOperationRunner operation_runner(this); 815 ScopedOperationRunner operation_runner(this);
812 816
813 if (net_log_.IsCapturing()) { 817 if (net_log_.IsCapturing()) {
814 net_log_.AddEvent( 818 net_log_.AddEvent(
815 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_BEGIN, 819 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_BEGIN,
816 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, 820 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len,
817 false)); 821 false));
818 } 822 }
819 823
820 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { 824 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) {
821 if (!callback.is_null()) { 825 if (!callback.is_null()) {
822 RecordReadResult(cache_type_, READ_RESULT_BAD_STATE); 826 RecordReadResult(cache_type_, READ_RESULT_BAD_STATE);
823 // Note that the API states that client-provided callbacks for entry-level 827 // Note that the API states that client-provided callbacks for entry-level
824 // (i.e. non-backend) operations (e.g. read, write) are invoked even if 828 // (i.e. non-backend) operations (e.g. read, write) are invoked even if
825 // the backend was already destroyed. 829 // the backend was already destroyed.
826 base::ThreadTaskRunnerHandle::Get()->PostTask( 830 base::ThreadTaskRunnerHandle::Get()->PostTask(
827 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); 831 FROM_HERE, base::Bind(callback, net::ERR_FAILED));
828 } 832 }
829 if (net_log_.IsCapturing()) { 833 if (net_log_.IsCapturing()) {
830 net_log_.AddEvent( 834 net_log_.AddEvent(
831 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, 835 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END,
832 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); 836 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED));
833 } 837 }
834 return; 838 return;
835 } 839 }
836 DCHECK_EQ(STATE_READY, state_); 840 DCHECK_EQ(STATE_READY, state_);
837 if (offset >= GetDataSize(stream_index) || offset < 0 || !buf_len) { 841 if (offset >= GetDataSize(stream_index) || offset < 0 || !buf_len) {
838 RecordReadResult(cache_type_, READ_RESULT_FAST_EMPTY_RETURN); 842 RecordReadResult(cache_type_, READ_RESULT_FAST_EMPTY_RETURN);
839 // If there is nothing to read, we bail out before setting state_ to 843 // If there is nothing to read, we bail out before setting state_ to
840 // STATE_IO_PENDING. 844 // STATE_IO_PENDING.
841 if (!callback.is_null()) 845 if (!callback.is_null())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 int offset, 887 int offset,
884 net::IOBuffer* buf, 888 net::IOBuffer* buf,
885 int buf_len, 889 int buf_len,
886 const CompletionCallback& callback, 890 const CompletionCallback& callback,
887 bool truncate) { 891 bool truncate) {
888 DCHECK(io_thread_checker_.CalledOnValidThread()); 892 DCHECK(io_thread_checker_.CalledOnValidThread());
889 ScopedOperationRunner operation_runner(this); 893 ScopedOperationRunner operation_runner(this);
890 894
891 if (net_log_.IsCapturing()) { 895 if (net_log_.IsCapturing()) {
892 net_log_.AddEvent( 896 net_log_.AddEvent(
893 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_BEGIN, 897 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_BEGIN,
894 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, 898 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len,
895 truncate)); 899 truncate));
896 } 900 }
897 901
898 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { 902 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) {
899 RecordWriteResult(cache_type_, WRITE_RESULT_BAD_STATE); 903 RecordWriteResult(cache_type_, WRITE_RESULT_BAD_STATE);
900 if (net_log_.IsCapturing()) { 904 if (net_log_.IsCapturing()) {
901 net_log_.AddEvent( 905 net_log_.AddEvent(
902 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, 906 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END,
903 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); 907 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED));
904 } 908 }
905 if (!callback.is_null()) { 909 if (!callback.is_null()) {
906 base::ThreadTaskRunnerHandle::Get()->PostTask( 910 base::ThreadTaskRunnerHandle::Get()->PostTask(
907 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); 911 FROM_HERE, base::Bind(callback, net::ERR_FAILED));
908 } 912 }
909 // |this| may be destroyed after return here. 913 // |this| may be destroyed after return here.
910 return; 914 return;
911 } 915 }
912 916
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 void SimpleEntryImpl::ReadSparseDataInternal( 982 void SimpleEntryImpl::ReadSparseDataInternal(
979 int64_t sparse_offset, 983 int64_t sparse_offset,
980 net::IOBuffer* buf, 984 net::IOBuffer* buf,
981 int buf_len, 985 int buf_len,
982 const CompletionCallback& callback) { 986 const CompletionCallback& callback) {
983 DCHECK(io_thread_checker_.CalledOnValidThread()); 987 DCHECK(io_thread_checker_.CalledOnValidThread());
984 ScopedOperationRunner operation_runner(this); 988 ScopedOperationRunner operation_runner(this);
985 989
986 if (net_log_.IsCapturing()) { 990 if (net_log_.IsCapturing()) {
987 net_log_.AddEvent( 991 net_log_.AddEvent(
988 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, 992 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN,
989 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); 993 CreateNetLogSparseOperationCallback(sparse_offset, buf_len));
990 } 994 }
991 995
992 DCHECK_EQ(STATE_READY, state_); 996 DCHECK_EQ(STATE_READY, state_);
993 state_ = STATE_IO_PENDING; 997 state_ = STATE_IO_PENDING;
994 998
995 std::unique_ptr<int> result(new int()); 999 std::unique_ptr<int> result(new int());
996 std::unique_ptr<base::Time> last_used(new base::Time()); 1000 std::unique_ptr<base::Time> last_used(new base::Time());
997 Closure task = base::Bind( 1001 Closure task = base::Bind(
998 &SimpleSynchronousEntry::ReadSparseData, 1002 &SimpleSynchronousEntry::ReadSparseData,
(...skipping 11 matching lines...) Expand all
1010 void SimpleEntryImpl::WriteSparseDataInternal( 1014 void SimpleEntryImpl::WriteSparseDataInternal(
1011 int64_t sparse_offset, 1015 int64_t sparse_offset,
1012 net::IOBuffer* buf, 1016 net::IOBuffer* buf,
1013 int buf_len, 1017 int buf_len,
1014 const CompletionCallback& callback) { 1018 const CompletionCallback& callback) {
1015 DCHECK(io_thread_checker_.CalledOnValidThread()); 1019 DCHECK(io_thread_checker_.CalledOnValidThread());
1016 ScopedOperationRunner operation_runner(this); 1020 ScopedOperationRunner operation_runner(this);
1017 1021
1018 if (net_log_.IsCapturing()) { 1022 if (net_log_.IsCapturing()) {
1019 net_log_.AddEvent( 1023 net_log_.AddEvent(
1020 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_BEGIN, 1024 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_SPARSE_BEGIN,
1021 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); 1025 CreateNetLogSparseOperationCallback(sparse_offset, buf_len));
1022 } 1026 }
1023 1027
1024 DCHECK_EQ(STATE_READY, state_); 1028 DCHECK_EQ(STATE_READY, state_);
1025 state_ = STATE_IO_PENDING; 1029 state_ = STATE_IO_PENDING;
1026 1030
1027 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); 1031 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max();
1028 if (backend_.get()) { 1032 if (backend_.get()) {
1029 uint64_t max_cache_size = backend_->index()->max_size(); 1033 uint64_t max_cache_size = backend_->index()->max_size();
1030 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; 1034 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 base::Bind( 1107 base::Bind(
1104 &SimpleEntryImpl::DoomOperationComplete, this, callback, state_)); 1108 &SimpleEntryImpl::DoomOperationComplete, this, callback, state_));
1105 state_ = STATE_IO_PENDING; 1109 state_ = STATE_IO_PENDING;
1106 } 1110 }
1107 1111
1108 void SimpleEntryImpl::CreationOperationComplete( 1112 void SimpleEntryImpl::CreationOperationComplete(
1109 const CompletionCallback& completion_callback, 1113 const CompletionCallback& completion_callback,
1110 const base::TimeTicks& start_time, 1114 const base::TimeTicks& start_time,
1111 std::unique_ptr<SimpleEntryCreationResults> in_results, 1115 std::unique_ptr<SimpleEntryCreationResults> in_results,
1112 Entry** out_entry, 1116 Entry** out_entry,
1113 net::NetLog::EventType end_event_type) { 1117 net::NetLogEventType end_event_type) {
1114 DCHECK(io_thread_checker_.CalledOnValidThread()); 1118 DCHECK(io_thread_checker_.CalledOnValidThread());
1115 DCHECK_EQ(state_, STATE_IO_PENDING); 1119 DCHECK_EQ(state_, STATE_IO_PENDING);
1116 DCHECK(in_results); 1120 DCHECK(in_results);
1117 ScopedOperationRunner operation_runner(this); 1121 ScopedOperationRunner operation_runner(this);
1118 SIMPLE_CACHE_UMA(BOOLEAN, 1122 SIMPLE_CACHE_UMA(BOOLEAN,
1119 "EntryCreationResult", cache_type_, 1123 "EntryCreationResult", cache_type_,
1120 in_results->result == net::OK); 1124 in_results->result == net::OK);
1121 if (in_results->result != net::OK) { 1125 if (in_results->result != net::OK) {
1122 if (in_results->result != net::ERR_FILE_EXISTS) 1126 if (in_results->result != net::ERR_FILE_EXISTS)
1123 MarkAsDoomed(); 1127 MarkAsDoomed();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index]; 1211 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index];
1208 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result); 1212 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result);
1209 crc32s_end_offset_[stream_index] += *result; 1213 crc32s_end_offset_[stream_index] += *result;
1210 if (!have_written_[stream_index] && 1214 if (!have_written_[stream_index] &&
1211 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) { 1215 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) {
1212 // We have just read a file from start to finish, and so we have 1216 // We have just read a file from start to finish, and so we have
1213 // computed a crc of the entire file. We can check it now. If a cache 1217 // computed a crc of the entire file. We can check it now. If a cache
1214 // entry has a single reader, the normal pattern is to read from start 1218 // entry has a single reader, the normal pattern is to read from start
1215 // to finish. 1219 // to finish.
1216 1220
1217 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN); 1221 net_log_.AddEvent(
1222 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN);
1218 1223
1219 std::unique_ptr<int> new_result(new int()); 1224 std::unique_ptr<int> new_result(new int());
1220 Closure task = base::Bind(&SimpleSynchronousEntry::CheckEOFRecord, 1225 Closure task = base::Bind(&SimpleSynchronousEntry::CheckEOFRecord,
1221 base::Unretained(synchronous_entry_), 1226 base::Unretained(synchronous_entry_),
1222 stream_index, 1227 stream_index,
1223 *entry_stat, 1228 *entry_stat,
1224 crc32s_[stream_index], 1229 crc32s_[stream_index],
1225 new_result.get()); 1230 new_result.get());
1226 Closure reply = base::Bind(&SimpleEntryImpl::ChecksumOperationComplete, 1231 Closure reply = base::Bind(&SimpleEntryImpl::ChecksumOperationComplete,
1227 this, *result, stream_index, 1232 this, *result, stream_index,
(...skipping 13 matching lines...) Expand all
1241 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE); 1246 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE);
1242 } else { 1247 } else {
1243 RecordReadResult(cache_type_, READ_RESULT_SUCCESS); 1248 RecordReadResult(cache_type_, READ_RESULT_SUCCESS);
1244 if (crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_TO_END && 1249 if (crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_TO_END &&
1245 offset + *result == GetDataSize(stream_index)) { 1250 offset + *result == GetDataSize(stream_index)) {
1246 crc_check_state_[stream_index] = CRC_CHECK_NOT_DONE; 1251 crc_check_state_[stream_index] = CRC_CHECK_NOT_DONE;
1247 } 1252 }
1248 } 1253 }
1249 if (net_log_.IsCapturing()) { 1254 if (net_log_.IsCapturing()) {
1250 net_log_.AddEvent( 1255 net_log_.AddEvent(
1251 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, 1256 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END,
1252 CreateNetLogReadWriteCompleteCallback(*result)); 1257 CreateNetLogReadWriteCompleteCallback(*result));
1253 } 1258 }
1254 1259
1255 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); 1260 EntryOperationComplete(completion_callback, *entry_stat, std::move(result));
1256 } 1261 }
1257 1262
1258 void SimpleEntryImpl::WriteOperationComplete( 1263 void SimpleEntryImpl::WriteOperationComplete(
1259 int stream_index, 1264 int stream_index,
1260 const CompletionCallback& completion_callback, 1265 const CompletionCallback& completion_callback,
1261 std::unique_ptr<SimpleEntryStat> entry_stat, 1266 std::unique_ptr<SimpleEntryStat> entry_stat,
1262 std::unique_ptr<int> result) { 1267 std::unique_ptr<int> result) {
1263 if (*result >= 0) 1268 if (*result >= 0)
1264 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); 1269 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS);
1265 else 1270 else
1266 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); 1271 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE);
1267 if (net_log_.IsCapturing()) { 1272 if (net_log_.IsCapturing()) {
1268 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, 1273 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END,
1269 CreateNetLogReadWriteCompleteCallback(*result)); 1274 CreateNetLogReadWriteCompleteCallback(*result));
1270 } 1275 }
1271 1276
1272 if (*result < 0) { 1277 if (*result < 0) {
1273 crc32s_end_offset_[stream_index] = 0; 1278 crc32s_end_offset_[stream_index] = 0;
1274 } 1279 }
1275 1280
1276 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); 1281 EntryOperationComplete(completion_callback, *entry_stat, std::move(result));
1277 } 1282 }
1278 1283
1279 void SimpleEntryImpl::ReadSparseOperationComplete( 1284 void SimpleEntryImpl::ReadSparseOperationComplete(
1280 const CompletionCallback& completion_callback, 1285 const CompletionCallback& completion_callback,
1281 std::unique_ptr<base::Time> last_used, 1286 std::unique_ptr<base::Time> last_used,
1282 std::unique_ptr<int> result) { 1287 std::unique_ptr<int> result) {
1283 DCHECK(io_thread_checker_.CalledOnValidThread()); 1288 DCHECK(io_thread_checker_.CalledOnValidThread());
1284 DCHECK(synchronous_entry_); 1289 DCHECK(synchronous_entry_);
1285 DCHECK(result); 1290 DCHECK(result);
1286 1291
1287 if (net_log_.IsCapturing()) { 1292 if (net_log_.IsCapturing()) {
1288 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_END, 1293 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_END,
1289 CreateNetLogReadWriteCompleteCallback(*result)); 1294 CreateNetLogReadWriteCompleteCallback(*result));
1290 } 1295 }
1291 1296
1292 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, 1297 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_,
1293 sparse_data_size_); 1298 sparse_data_size_);
1294 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); 1299 EntryOperationComplete(completion_callback, entry_stat, std::move(result));
1295 } 1300 }
1296 1301
1297 void SimpleEntryImpl::WriteSparseOperationComplete( 1302 void SimpleEntryImpl::WriteSparseOperationComplete(
1298 const CompletionCallback& completion_callback, 1303 const CompletionCallback& completion_callback,
1299 std::unique_ptr<SimpleEntryStat> entry_stat, 1304 std::unique_ptr<SimpleEntryStat> entry_stat,
1300 std::unique_ptr<int> result) { 1305 std::unique_ptr<int> result) {
1301 DCHECK(io_thread_checker_.CalledOnValidThread()); 1306 DCHECK(io_thread_checker_.CalledOnValidThread());
1302 DCHECK(synchronous_entry_); 1307 DCHECK(synchronous_entry_);
1303 DCHECK(result); 1308 DCHECK(result);
1304 1309
1305 if (net_log_.IsCapturing()) { 1310 if (net_log_.IsCapturing()) {
1306 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END, 1311 net_log_.AddEvent(
1307 CreateNetLogReadWriteCompleteCallback(*result)); 1312 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END,
1313 CreateNetLogReadWriteCompleteCallback(*result));
1308 } 1314 }
1309 1315
1310 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); 1316 EntryOperationComplete(completion_callback, *entry_stat, std::move(result));
1311 } 1317 }
1312 1318
1313 void SimpleEntryImpl::GetAvailableRangeOperationComplete( 1319 void SimpleEntryImpl::GetAvailableRangeOperationComplete(
1314 const CompletionCallback& completion_callback, 1320 const CompletionCallback& completion_callback,
1315 std::unique_ptr<int> result) { 1321 std::unique_ptr<int> result) {
1316 DCHECK(io_thread_checker_.CalledOnValidThread()); 1322 DCHECK(io_thread_checker_.CalledOnValidThread());
1317 DCHECK(synchronous_entry_); 1323 DCHECK(synchronous_entry_);
1318 DCHECK(result); 1324 DCHECK(result);
1319 1325
1320 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, 1326 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_,
1321 sparse_data_size_); 1327 sparse_data_size_);
1322 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); 1328 EntryOperationComplete(completion_callback, entry_stat, std::move(result));
1323 } 1329 }
1324 1330
1325 void SimpleEntryImpl::DoomOperationComplete( 1331 void SimpleEntryImpl::DoomOperationComplete(
1326 const CompletionCallback& callback, 1332 const CompletionCallback& callback,
1327 State state_to_restore, 1333 State state_to_restore,
1328 int result) { 1334 int result) {
1329 state_ = state_to_restore; 1335 state_ = state_to_restore;
1330 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_END); 1336 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_DOOM_END);
1331 PostClientCallback(callback, result); 1337 PostClientCallback(callback, result);
1332 RunNextOperationIfNeeded(); 1338 RunNextOperationIfNeeded();
1333 if (backend_) 1339 if (backend_)
1334 backend_->OnDoomComplete(entry_hash_); 1340 backend_->OnDoomComplete(entry_hash_);
1335 } 1341 }
1336 1342
1337 void SimpleEntryImpl::ChecksumOperationComplete( 1343 void SimpleEntryImpl::ChecksumOperationComplete(
1338 int orig_result, 1344 int orig_result,
1339 int stream_index, 1345 int stream_index,
1340 const CompletionCallback& completion_callback, 1346 const CompletionCallback& completion_callback,
1341 std::unique_ptr<int> result) { 1347 std::unique_ptr<int> result) {
1342 DCHECK(io_thread_checker_.CalledOnValidThread()); 1348 DCHECK(io_thread_checker_.CalledOnValidThread());
1343 DCHECK(synchronous_entry_); 1349 DCHECK(synchronous_entry_);
1344 DCHECK_EQ(STATE_IO_PENDING, state_); 1350 DCHECK_EQ(STATE_IO_PENDING, state_);
1345 DCHECK(result); 1351 DCHECK(result);
1346 1352
1347 if (net_log_.IsCapturing()) { 1353 if (net_log_.IsCapturing()) {
1348 net_log_.AddEventWithNetErrorCode( 1354 net_log_.AddEventWithNetErrorCode(
1349 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_END, 1355 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CHECKSUM_END,
1350 *result); 1356 *result);
1351 } 1357 }
1352 1358
1353 if (*result == net::OK) { 1359 if (*result == net::OK) {
1354 *result = orig_result; 1360 *result = orig_result;
1355 if (orig_result >= 0) 1361 if (orig_result >= 0)
1356 RecordReadResult(cache_type_, READ_RESULT_SUCCESS); 1362 RecordReadResult(cache_type_, READ_RESULT_SUCCESS);
1357 else 1363 else
1358 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE); 1364 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE);
1359 } else { 1365 } else {
1360 RecordReadResult(cache_type_, READ_RESULT_SYNC_CHECKSUM_FAILURE); 1366 RecordReadResult(cache_type_, READ_RESULT_SYNC_CHECKSUM_FAILURE);
1361 } 1367 }
1362 if (net_log_.IsCapturing()) { 1368 if (net_log_.IsCapturing()) {
1363 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, 1369 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END,
1364 CreateNetLogReadWriteCompleteCallback(*result)); 1370 CreateNetLogReadWriteCompleteCallback(*result));
1365 } 1371 }
1366 1372
1367 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, 1373 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_,
1368 sparse_data_size_); 1374 sparse_data_size_);
1369 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); 1375 EntryOperationComplete(completion_callback, entry_stat, std::move(result));
1370 } 1376 }
1371 1377
1372 void SimpleEntryImpl::CloseOperationComplete() { 1378 void SimpleEntryImpl::CloseOperationComplete() {
1373 DCHECK(!synchronous_entry_); 1379 DCHECK(!synchronous_entry_);
1374 DCHECK_EQ(0, open_count_); 1380 DCHECK_EQ(0, open_count_);
1375 DCHECK(STATE_IO_PENDING == state_ || STATE_FAILURE == state_ || 1381 DCHECK(STATE_IO_PENDING == state_ || STATE_FAILURE == state_ ||
1376 STATE_UNINITIALIZED == state_); 1382 STATE_UNINITIALIZED == state_);
1377 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_END); 1383 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_END);
1378 AdjustOpenEntryCountBy(cache_type_, -1); 1384 AdjustOpenEntryCountBy(cache_type_, -1);
1379 MakeUninitialized(); 1385 MakeUninitialized();
1380 RunNextOperationIfNeeded(); 1386 RunNextOperationIfNeeded();
1381 } 1387 }
1382 1388
1383 void SimpleEntryImpl::UpdateDataFromEntryStat( 1389 void SimpleEntryImpl::UpdateDataFromEntryStat(
1384 const SimpleEntryStat& entry_stat) { 1390 const SimpleEntryStat& entry_stat) {
1385 DCHECK(io_thread_checker_.CalledOnValidThread()); 1391 DCHECK(io_thread_checker_.CalledOnValidThread());
1386 DCHECK(synchronous_entry_); 1392 DCHECK(synchronous_entry_);
1387 DCHECK_EQ(STATE_READY, state_); 1393 DCHECK_EQ(STATE_READY, state_);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 } 1557 }
1552 crc32s_end_offset_[stream_index] = offset + length; 1558 crc32s_end_offset_[stream_index] = offset + length;
1553 } else if (offset < crc32s_end_offset_[stream_index]) { 1559 } else if (offset < crc32s_end_offset_[stream_index]) {
1554 // If a range for which the crc32 was already computed is rewritten, the 1560 // If a range for which the crc32 was already computed is rewritten, the
1555 // computation of the crc32 need to start from 0 again. 1561 // computation of the crc32 need to start from 0 again.
1556 crc32s_end_offset_[stream_index] = 0; 1562 crc32s_end_offset_[stream_index] = 0;
1557 } 1563 }
1558 } 1564 }
1559 1565
1560 } // namespace disk_cache 1566 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698