| 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_synchronous_entry.h" | 5 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 int buf_len_p) | 251 int buf_len_p) |
| 252 : sparse_offset(sparse_offset_p), buf_len(buf_len_p) {} | 252 : sparse_offset(sparse_offset_p), buf_len(buf_len_p) {} |
| 253 | 253 |
| 254 // static | 254 // static |
| 255 void SimpleSynchronousEntry::OpenEntry( | 255 void SimpleSynchronousEntry::OpenEntry( |
| 256 net::CacheType cache_type, | 256 net::CacheType cache_type, |
| 257 const FilePath& path, | 257 const FilePath& path, |
| 258 const std::string& key, | 258 const std::string& key, |
| 259 const uint64_t entry_hash, | 259 const uint64_t entry_hash, |
| 260 const bool had_index, | 260 const bool had_index, |
| 261 const base::TimeTicks& time_enqueued, |
| 261 SimpleEntryCreationResults* out_results) { | 262 SimpleEntryCreationResults* out_results) { |
| 262 base::ElapsedTimer open_time; | 263 base::TimeTicks start_sync_open_entry = base::TimeTicks::Now(); |
| 264 SIMPLE_CACHE_UMA(TIMES, "QueueLatency.OpenEntry", cache_type, |
| 265 (start_sync_open_entry - time_enqueued)); |
| 266 |
| 263 SimpleSynchronousEntry* sync_entry = | 267 SimpleSynchronousEntry* sync_entry = |
| 264 new SimpleSynchronousEntry(cache_type, path, key, entry_hash, had_index); | 268 new SimpleSynchronousEntry(cache_type, path, key, entry_hash, had_index); |
| 265 out_results->result = sync_entry->InitializeForOpen( | 269 out_results->result = sync_entry->InitializeForOpen( |
| 266 &out_results->entry_stat, &out_results->stream_0_data, | 270 &out_results->entry_stat, &out_results->stream_0_data, |
| 267 &out_results->stream_0_crc32); | 271 &out_results->stream_0_crc32); |
| 268 if (out_results->result != net::OK) { | 272 if (out_results->result != net::OK) { |
| 269 sync_entry->Doom(); | 273 sync_entry->Doom(); |
| 270 delete sync_entry; | 274 delete sync_entry; |
| 271 out_results->sync_entry = NULL; | 275 out_results->sync_entry = NULL; |
| 272 out_results->stream_0_data = NULL; | 276 out_results->stream_0_data = NULL; |
| 273 return; | 277 return; |
| 274 } | 278 } |
| 275 UMA_HISTOGRAM_TIMES("SimpleCache.DiskOpenLatency", open_time.Elapsed()); | 279 SIMPLE_CACHE_UMA(TIMES, "DiskOpenLatency", cache_type, |
| 280 base::TimeTicks::Now() - start_sync_open_entry); |
| 276 out_results->sync_entry = sync_entry; | 281 out_results->sync_entry = sync_entry; |
| 277 } | 282 } |
| 278 | 283 |
| 279 // static | 284 // static |
| 280 void SimpleSynchronousEntry::CreateEntry( | 285 void SimpleSynchronousEntry::CreateEntry( |
| 281 net::CacheType cache_type, | 286 net::CacheType cache_type, |
| 282 const FilePath& path, | 287 const FilePath& path, |
| 283 const std::string& key, | 288 const std::string& key, |
| 284 const uint64_t entry_hash, | 289 const uint64_t entry_hash, |
| 285 const bool had_index, | 290 const bool had_index, |
| 291 const base::TimeTicks& time_enqueued, |
| 286 SimpleEntryCreationResults* out_results) { | 292 SimpleEntryCreationResults* out_results) { |
| 287 DCHECK_EQ(entry_hash, GetEntryHashKey(key)); | 293 DCHECK_EQ(entry_hash, GetEntryHashKey(key)); |
| 294 base::TimeTicks start_sync_create_entry = base::TimeTicks::Now(); |
| 295 SIMPLE_CACHE_UMA(TIMES, "QueueLatency.CreateEntry", cache_type, |
| 296 (start_sync_create_entry - time_enqueued)); |
| 297 |
| 288 SimpleSynchronousEntry* sync_entry = | 298 SimpleSynchronousEntry* sync_entry = |
| 289 new SimpleSynchronousEntry(cache_type, path, key, entry_hash, had_index); | 299 new SimpleSynchronousEntry(cache_type, path, key, entry_hash, had_index); |
| 290 out_results->result = | 300 out_results->result = |
| 291 sync_entry->InitializeForCreate(&out_results->entry_stat); | 301 sync_entry->InitializeForCreate(&out_results->entry_stat); |
| 292 if (out_results->result != net::OK) { | 302 if (out_results->result != net::OK) { |
| 293 if (out_results->result != net::ERR_FILE_EXISTS) | 303 if (out_results->result != net::ERR_FILE_EXISTS) |
| 294 sync_entry->Doom(); | 304 sync_entry->Doom(); |
| 295 delete sync_entry; | 305 delete sync_entry; |
| 296 out_results->sync_entry = NULL; | 306 out_results->sync_entry = NULL; |
| 297 return; | 307 return; |
| 298 } | 308 } |
| 299 out_results->sync_entry = sync_entry; | 309 out_results->sync_entry = sync_entry; |
| 310 SIMPLE_CACHE_UMA(TIMES, "DiskCreateLatency", cache_type, |
| 311 base::TimeTicks::Now() - start_sync_create_entry); |
| 300 } | 312 } |
| 301 | 313 |
| 302 // static | 314 // static |
| 303 int SimpleSynchronousEntry::DoomEntry(const FilePath& path, | 315 int SimpleSynchronousEntry::DoomEntry(const FilePath& path, |
| 304 uint64_t entry_hash) { | 316 uint64_t entry_hash) { |
| 305 const bool deleted_well = DeleteFilesForEntryHash(path, entry_hash); | 317 const bool deleted_well = DeleteFilesForEntryHash(path, entry_hash); |
| 306 return deleted_well ? net::OK : net::ERR_FAILED; | 318 return deleted_well ? net::OK : net::ERR_FAILED; |
| 307 } | 319 } |
| 308 | 320 |
| 309 // static | 321 // static |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } else { | 370 } else { |
| 359 *out_result = net::ERR_CACHE_READ_FAILURE; | 371 *out_result = net::ERR_CACHE_READ_FAILURE; |
| 360 Doom(); | 372 Doom(); |
| 361 } | 373 } |
| 362 } | 374 } |
| 363 | 375 |
| 364 void SimpleSynchronousEntry::WriteData(const EntryOperationData& in_entry_op, | 376 void SimpleSynchronousEntry::WriteData(const EntryOperationData& in_entry_op, |
| 365 net::IOBuffer* in_buf, | 377 net::IOBuffer* in_buf, |
| 366 SimpleEntryStat* out_entry_stat, | 378 SimpleEntryStat* out_entry_stat, |
| 367 int* out_result) { | 379 int* out_result) { |
| 380 base::ElapsedTimer write_time; |
| 368 DCHECK(initialized_); | 381 DCHECK(initialized_); |
| 369 DCHECK_NE(0, in_entry_op.index); | 382 DCHECK_NE(0, in_entry_op.index); |
| 370 int index = in_entry_op.index; | 383 int index = in_entry_op.index; |
| 371 int file_index = GetFileIndexFromStreamIndex(index); | 384 int file_index = GetFileIndexFromStreamIndex(index); |
| 372 if (header_and_key_check_needed_[file_index] && | 385 if (header_and_key_check_needed_[file_index] && |
| 373 !empty_file_omitted_[file_index] && !CheckHeaderAndKey(file_index)) { | 386 !empty_file_omitted_[file_index] && !CheckHeaderAndKey(file_index)) { |
| 374 *out_result = net::ERR_FAILED; | 387 *out_result = net::ERR_FAILED; |
| 375 Doom(); | 388 Doom(); |
| 376 return; | 389 return; |
| 377 } | 390 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 int file_eof_offset = | 451 int file_eof_offset = |
| 439 out_entry_stat->GetLastEOFOffsetInFile(key_.size(), index); | 452 out_entry_stat->GetLastEOFOffsetInFile(key_.size(), index); |
| 440 if (!files_[file_index].SetLength(file_eof_offset)) { | 453 if (!files_[file_index].SetLength(file_eof_offset)) { |
| 441 RecordWriteResult(cache_type_, WRITE_RESULT_TRUNCATE_FAILURE); | 454 RecordWriteResult(cache_type_, WRITE_RESULT_TRUNCATE_FAILURE); |
| 442 Doom(); | 455 Doom(); |
| 443 *out_result = net::ERR_CACHE_WRITE_FAILURE; | 456 *out_result = net::ERR_CACHE_WRITE_FAILURE; |
| 444 return; | 457 return; |
| 445 } | 458 } |
| 446 } | 459 } |
| 447 | 460 |
| 461 SIMPLE_CACHE_UMA(TIMES, "DiskWriteLatency", cache_type_, |
| 462 write_time.Elapsed()); |
| 448 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); | 463 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); |
| 449 base::Time modification_time = Time::Now(); | 464 base::Time modification_time = Time::Now(); |
| 450 out_entry_stat->set_last_used(modification_time); | 465 out_entry_stat->set_last_used(modification_time); |
| 451 out_entry_stat->set_last_modified(modification_time); | 466 out_entry_stat->set_last_modified(modification_time); |
| 452 *out_result = buf_len; | 467 *out_result = buf_len; |
| 453 } | 468 } |
| 454 | 469 |
| 455 void SimpleSynchronousEntry::ReadSparseData( | 470 void SimpleSynchronousEntry::ReadSparseData( |
| 456 const EntryOperationData& in_entry_op, | 471 const EntryOperationData& in_entry_op, |
| 457 net::IOBuffer* out_buf, | 472 net::IOBuffer* out_buf, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 Doom(); | 694 Doom(); |
| 680 return; | 695 return; |
| 681 } | 696 } |
| 682 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_SUCCESS); | 697 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_SUCCESS); |
| 683 } | 698 } |
| 684 | 699 |
| 685 void SimpleSynchronousEntry::Close( | 700 void SimpleSynchronousEntry::Close( |
| 686 const SimpleEntryStat& entry_stat, | 701 const SimpleEntryStat& entry_stat, |
| 687 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write, | 702 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write, |
| 688 net::GrowableIOBuffer* stream_0_data) { | 703 net::GrowableIOBuffer* stream_0_data) { |
| 704 base::ElapsedTimer close_time; |
| 689 DCHECK(stream_0_data); | 705 DCHECK(stream_0_data); |
| 690 | 706 |
| 691 for (std::vector<CRCRecord>::const_iterator it = crc32s_to_write->begin(); | 707 for (std::vector<CRCRecord>::const_iterator it = crc32s_to_write->begin(); |
| 692 it != crc32s_to_write->end(); ++it) { | 708 it != crc32s_to_write->end(); ++it) { |
| 693 const int stream_index = it->index; | 709 const int stream_index = it->index; |
| 694 const int file_index = GetFileIndexFromStreamIndex(stream_index); | 710 const int file_index = GetFileIndexFromStreamIndex(stream_index); |
| 695 if (empty_file_omitted_[file_index]) | 711 if (empty_file_omitted_[file_index]) |
| 696 continue; | 712 continue; |
| 697 | 713 |
| 698 if (stream_index == 0) { | 714 if (stream_index == 0) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 } | 781 } |
| 766 | 782 |
| 767 if (sparse_file_open()) | 783 if (sparse_file_open()) |
| 768 sparse_file_.Close(); | 784 sparse_file_.Close(); |
| 769 | 785 |
| 770 if (files_created_) { | 786 if (files_created_) { |
| 771 const int stream2_file_index = GetFileIndexFromStreamIndex(2); | 787 const int stream2_file_index = GetFileIndexFromStreamIndex(2); |
| 772 SIMPLE_CACHE_UMA(BOOLEAN, "EntryCreatedAndStream2Omitted", cache_type_, | 788 SIMPLE_CACHE_UMA(BOOLEAN, "EntryCreatedAndStream2Omitted", cache_type_, |
| 773 empty_file_omitted_[stream2_file_index]); | 789 empty_file_omitted_[stream2_file_index]); |
| 774 } | 790 } |
| 791 SIMPLE_CACHE_UMA(TIMES, "DiskCloseLatency", cache_type_, |
| 792 close_time.Elapsed()); |
| 775 RecordCloseResult(cache_type_, CLOSE_RESULT_SUCCESS); | 793 RecordCloseResult(cache_type_, CLOSE_RESULT_SUCCESS); |
| 776 have_open_files_ = false; | 794 have_open_files_ = false; |
| 777 delete this; | 795 delete this; |
| 778 } | 796 } |
| 779 | 797 |
| 780 SimpleSynchronousEntry::SimpleSynchronousEntry(net::CacheType cache_type, | 798 SimpleSynchronousEntry::SimpleSynchronousEntry(net::CacheType cache_type, |
| 781 const FilePath& path, | 799 const FilePath& path, |
| 782 const std::string& key, | 800 const std::string& key, |
| 783 const uint64_t entry_hash, | 801 const uint64_t entry_hash, |
| 784 const bool had_index) | 802 const bool had_index) |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 range.offset = offset; | 1618 range.offset = offset; |
| 1601 range.length = len; | 1619 range.length = len; |
| 1602 range.data_crc32 = data_crc32; | 1620 range.data_crc32 = data_crc32; |
| 1603 range.file_offset = data_file_offset; | 1621 range.file_offset = data_file_offset; |
| 1604 sparse_ranges_.insert(std::make_pair(offset, range)); | 1622 sparse_ranges_.insert(std::make_pair(offset, range)); |
| 1605 | 1623 |
| 1606 return true; | 1624 return true; |
| 1607 } | 1625 } |
| 1608 | 1626 |
| 1609 } // namespace disk_cache | 1627 } // namespace disk_cache |
| OLD | NEW |