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

Side by Side Diff: net/disk_cache/blockfile/entry_impl_v3.cc

Issue 1499423004: Remove kint32max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint9
Patch Set: rebase Created 5 years 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
« no previous file with comments | « net/disk_cache/blockfile/entry_impl_v3.h ('k') | net/disk_cache/blockfile/eviction.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/blockfile/entry_impl_v3.h" 5 #include "net/disk_cache/blockfile/entry_impl_v3.h"
6 6
7 #include <limits>
8
7 #include "base/hash.h" 9 #include "base/hash.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
12 #include "net/disk_cache/blockfile/backend_impl_v3.h" 14 #include "net/disk_cache/blockfile/backend_impl_v3.h"
13 #include "net/disk_cache/blockfile/bitmap.h" 15 #include "net/disk_cache/blockfile/bitmap.h"
14 #include "net/disk_cache/blockfile/disk_format_v3.h" 16 #include "net/disk_cache/blockfile/disk_format_v3.h"
15 #include "net/disk_cache/blockfile/histogram_macros_v3.h" 17 #include "net/disk_cache/blockfile/histogram_macros_v3.h"
16 #include "net/disk_cache/cache_util.h" 18 #include "net/disk_cache/cache_util.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 read_only_(read_only), 252 read_only_(read_only),
251 dirty_(true), 253 dirty_(true),
252 modified_(false) { 254 modified_(false) {
253 for (int i = 0; i < kNumStreams; i++) { 255 for (int i = 0; i < kNumStreams; i++) {
254 unreported_size_[i] = 0; 256 unreported_size_[i] = 0;
255 } 257 }
256 } 258 }
257 259
258 #if defined(V3_NOT_JUST_YET_READY) 260 #if defined(V3_NOT_JUST_YET_READY)
259 261
260 bool EntryImplV3::CreateEntry(Addr node_address, const std::string& key, 262 bool EntryImplV3::CreateEntry(Addr node_address,
261 uint32 hash) { 263 const std::string& key,
264 uint32_t hash) {
262 Trace("Create entry In"); 265 Trace("Create entry In");
263 EntryStore* entry_store = entry_.Data(); 266 EntryStore* entry_store = entry_.Data();
264 RankingsNode* node = node_.Data(); 267 RankingsNode* node = node_.Data();
265 memset(entry_store, 0, sizeof(EntryStore) * entry_.address().num_blocks()); 268 memset(entry_store, 0, sizeof(EntryStore) * entry_.address().num_blocks());
266 memset(node, 0, sizeof(RankingsNode)); 269 memset(node, 0, sizeof(RankingsNode));
267 if (!node_.LazyInit(backend_->File(node_address), node_address)) 270 if (!node_.LazyInit(backend_->File(node_address), node_address))
268 return false; 271 return false;
269 272
270 entry_store->rankings_node = node_address.value(); 273 entry_store->rankings_node = node_address.value();
271 node->contents = entry_.address().value(); 274 node->contents = entry_.address().value();
272 275
273 entry_store->hash = hash; 276 entry_store->hash = hash;
274 entry_store->creation_time = Time::Now().ToInternalValue(); 277 entry_store->creation_time = Time::Now().ToInternalValue();
275 entry_store->key_len = static_cast<int32>(key.size()); 278 entry_store->key_len = static_cast<int32_t>(key.size());
276 if (entry_store->key_len > kMaxInternalKeyLength) { 279 if (entry_store->key_len > kMaxInternalKeyLength) {
277 Addr address(0); 280 Addr address(0);
278 if (!CreateBlock(entry_store->key_len + 1, &address)) 281 if (!CreateBlock(entry_store->key_len + 1, &address))
279 return false; 282 return false;
280 283
281 entry_store->long_key = address.value(); 284 entry_store->long_key = address.value();
282 File* key_file = GetBackingFile(address, kKeyFileIndex); 285 File* key_file = GetBackingFile(address, kKeyFileIndex);
283 key_ = key; 286 key_ = key;
284 287
285 size_t offset = 0; 288 size_t offset = 0;
286 if (address.is_block_file()) 289 if (address.is_block_file())
287 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize; 290 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
288 291
289 if (!key_file || !key_file->Write(key.data(), key.size(), offset)) { 292 if (!key_file || !key_file->Write(key.data(), key.size(), offset)) {
290 DeleteData(address, kKeyFileIndex); 293 DeleteData(address, kKeyFileIndex);
291 return false; 294 return false;
292 } 295 }
293 296
294 if (address.is_separate_file()) 297 if (address.is_separate_file())
295 key_file->SetLength(key.size() + 1); 298 key_file->SetLength(key.size() + 1);
296 } else { 299 } else {
297 memcpy(entry_store->key, key.data(), key.size()); 300 memcpy(entry_store->key, key.data(), key.size());
298 entry_store->key[key.size()] = '\0'; 301 entry_store->key[key.size()] = '\0';
299 } 302 }
300 backend_->ModifyStorageSize(0, static_cast<int32>(key.size())); 303 backend_->ModifyStorageSize(0, static_cast<int32_t>(key.size()));
301 CACHE_UMA(COUNTS, "KeySize", 0, static_cast<int32>(key.size())); 304 CACHE_UMA(COUNTS, "KeySize", 0, static_cast<int32_t>(key.size()));
302 node->dirty = backend_->GetCurrentEntryId(); 305 node->dirty = backend_->GetCurrentEntryId();
303 Log("Create Entry "); 306 Log("Create Entry ");
304 return true; 307 return true;
305 } 308 }
306 309
307 uint32 EntryImplV3::GetHash() { 310 uint32_t EntryImplV3::GetHash() {
308 return entry_.Data()->hash; 311 return entry_.Data()->hash;
309 } 312 }
310 313
311 bool EntryImplV3::IsSameEntry(const std::string& key, uint32 hash) { 314 bool EntryImplV3::IsSameEntry(const std::string& key, uint32_t hash) {
312 if (entry_.Data()->hash != hash || 315 if (entry_.Data()->hash != hash ||
313 static_cast<size_t>(entry_.Data()->key_len) != key.size()) 316 static_cast<size_t>(entry_.Data()->key_len) != key.size())
314 return false; 317 return false;
315 318
316 return (key.compare(GetKey()) == 0); 319 return (key.compare(GetKey()) == 0);
317 } 320 }
318 321
319 void EntryImplV3::InternalDoom() { 322 void EntryImplV3::InternalDoom() {
320 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM); 323 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM);
321 DCHECK(node_.HasData()); 324 DCHECK(node_.HasData());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 Time EntryImplV3::GetLastUsed() const { 509 Time EntryImplV3::GetLastUsed() const {
507 CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_); 510 CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_);
508 return Time::FromInternalValue(node->Data()->last_used); 511 return Time::FromInternalValue(node->Data()->last_used);
509 } 512 }
510 513
511 Time EntryImplV3::GetLastModified() const { 514 Time EntryImplV3::GetLastModified() const {
512 CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_); 515 CacheRankingsBlock* node = const_cast<CacheRankingsBlock*>(&node_);
513 return Time::FromInternalValue(node->Data()->last_modified); 516 return Time::FromInternalValue(node->Data()->last_modified);
514 } 517 }
515 518
516 int32 EntryImplV3::GetDataSize(int index) const { 519 int32_t EntryImplV3::GetDataSize(int index) const {
517 if (index < 0 || index >= kNumStreams) 520 if (index < 0 || index >= kNumStreams)
518 return 0; 521 return 0;
519 522
520 CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_); 523 CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_);
521 return entry->Data()->data_size[index]; 524 return entry->Data()->data_size[index];
522 } 525 }
523 526
524 int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len, 527 int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len,
525 const CompletionCallback& callback) { 528 const CompletionCallback& callback) {
526 if (callback.is_null()) 529 if (callback.is_null())
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 truncate); 598 truncate);
596 599
597 if (result != net::ERR_IO_PENDING && net_log_.IsCapturing()) { 600 if (result != net::ERR_IO_PENDING && net_log_.IsCapturing()) {
598 net_log_.EndEvent( 601 net_log_.EndEvent(
599 net::NetLog::TYPE_ENTRY_WRITE_DATA, 602 net::NetLog::TYPE_ENTRY_WRITE_DATA,
600 CreateNetLogReadWriteCompleteCallback(result)); 603 CreateNetLogReadWriteCompleteCallback(result));
601 } 604 }
602 return result; 605 return result;
603 } 606 }
604 607
605 int EntryImplV3::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, 608 int EntryImplV3::ReadSparseData(int64_t offset,
609 IOBuffer* buf,
610 int buf_len,
606 const CompletionCallback& callback) { 611 const CompletionCallback& callback) {
607 if (callback.is_null()) 612 if (callback.is_null())
608 return ReadSparseDataImpl(offset, buf, buf_len, callback); 613 return ReadSparseDataImpl(offset, buf, buf_len, callback);
609 614
610 if (!background_queue_) 615 if (!background_queue_)
611 return net::ERR_UNEXPECTED; 616 return net::ERR_UNEXPECTED;
612 617
613 background_queue_->ReadSparseData(this, offset, buf, buf_len, callback); 618 background_queue_->ReadSparseData(this, offset, buf, buf_len, callback);
614 return net::ERR_IO_PENDING; 619 return net::ERR_IO_PENDING;
615 } 620 }
616 621
617 int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, 622 int EntryImpl::ReadSparseDataImpl(int64_t offset,
623 IOBuffer* buf,
624 int buf_len,
618 const CompletionCallback& callback) { 625 const CompletionCallback& callback) {
619 DCHECK(node_.Data()->dirty || read_only_); 626 DCHECK(node_.Data()->dirty || read_only_);
620 int result = InitSparseData(); 627 int result = InitSparseData();
621 if (net::OK != result) 628 if (net::OK != result)
622 return result; 629 return result;
623 630
624 TimeTicks start = TimeTicks::Now(); 631 TimeTicks start = TimeTicks::Now();
625 result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len, 632 result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len,
626 callback); 633 callback);
627 ReportIOTime(kSparseRead, start); 634 ReportIOTime(kSparseRead, start);
628 return result; 635 return result;
629 } 636 }
630 637
631 int EntryImplV3::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, 638 int EntryImplV3::WriteSparseData(int64_t offset,
639 IOBuffer* buf,
640 int buf_len,
632 const CompletionCallback& callback) { 641 const CompletionCallback& callback) {
633 if (callback.is_null()) 642 if (callback.is_null())
634 return WriteSparseDataImpl(offset, buf, buf_len, callback); 643 return WriteSparseDataImpl(offset, buf, buf_len, callback);
635 644
636 if (!background_queue_) 645 if (!background_queue_)
637 return net::ERR_UNEXPECTED; 646 return net::ERR_UNEXPECTED;
638 647
639 background_queue_->WriteSparseData(this, offset, buf, buf_len, callback); 648 background_queue_->WriteSparseData(this, offset, buf, buf_len, callback);
640 return net::ERR_IO_PENDING; 649 return net::ERR_IO_PENDING;
641 } 650 }
642 651
643 int EntryImpl::WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, 652 int EntryImpl::WriteSparseDataImpl(int64_t offset,
653 IOBuffer* buf,
654 int buf_len,
644 const CompletionCallback& callback) { 655 const CompletionCallback& callback) {
645 DCHECK(node_.Data()->dirty || read_only_); 656 DCHECK(node_.Data()->dirty || read_only_);
646 int result = InitSparseData(); 657 int result = InitSparseData();
647 if (net::OK != result) 658 if (net::OK != result)
648 return result; 659 return result;
649 660
650 TimeTicks start = TimeTicks::Now(); 661 TimeTicks start = TimeTicks::Now();
651 result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf, 662 result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf,
652 buf_len, callback); 663 buf_len, callback);
653 ReportIOTime(kSparseWrite, start); 664 ReportIOTime(kSparseWrite, start);
654 return result; 665 return result;
655 } 666 }
656 667
657 int EntryImplV3::GetAvailableRange(int64 offset, int len, int64* start, 668 int EntryImplV3::GetAvailableRange(int64_t offset,
669 int len,
670 int64_t* start,
658 const CompletionCallback& callback) { 671 const CompletionCallback& callback) {
659 if (!background_queue_) 672 if (!background_queue_)
660 return net::ERR_UNEXPECTED; 673 return net::ERR_UNEXPECTED;
661 674
662 background_queue_->GetAvailableRange(this, offset, len, start, callback); 675 background_queue_->GetAvailableRange(this, offset, len, start, callback);
663 return net::ERR_IO_PENDING; 676 return net::ERR_IO_PENDING;
664 } 677 }
665 678
666 int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) { 679 int EntryImpl::GetAvailableRangeImpl(int64_t offset, int len, int64_t* start) {
667 int result = InitSparseData(); 680 int result = InitSparseData();
668 if (net::OK != result) 681 if (net::OK != result)
669 return result; 682 return result;
670 683
671 return sparse_->GetAvailableRange(offset, len, start); 684 return sparse_->GetAvailableRange(offset, len, start);
672 } 685 }
673 686
674 bool EntryImplV3::CouldBeSparse() const { 687 bool EntryImplV3::CouldBeSparse() const {
675 if (sparse_.get()) 688 if (sparse_.get())
676 return true; 689 return true;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 if (!backend_) 881 if (!backend_)
869 return net::ERR_UNEXPECTED; 882 return net::ERR_UNEXPECTED;
870 883
871 int max_file_size = backend_->MaxFileSize(); 884 int max_file_size = backend_->MaxFileSize();
872 885
873 // offset or buf_len could be negative numbers. 886 // offset or buf_len could be negative numbers.
874 if (offset > max_file_size || buf_len > max_file_size || 887 if (offset > max_file_size || buf_len > max_file_size ||
875 offset + buf_len > max_file_size) { 888 offset + buf_len > max_file_size) {
876 int size = offset + buf_len; 889 int size = offset + buf_len;
877 if (size <= max_file_size) 890 if (size <= max_file_size)
878 size = kint32max; 891 size = std::numeric_limits<int32_t>::max();
879 backend_->TooMuchStorageRequested(size); 892 backend_->TooMuchStorageRequested(size);
880 return net::ERR_FAILED; 893 return net::ERR_FAILED;
881 } 894 }
882 895
883 TimeTicks start = TimeTicks::Now(); 896 TimeTicks start = TimeTicks::Now();
884 897
885 // Read the size at this point (it may change inside prepare). 898 // Read the size at this point (it may change inside prepare).
886 int entry_size = entry_.Data()->data_size[index]; 899 int entry_size = entry_.Data()->data_size[index];
887 bool extending = entry_size < offset + buf_len; 900 bool extending = entry_size < offset + buf_len;
888 truncate = truncate && entry_size > offset + buf_len; 901 truncate = truncate && entry_size > offset + buf_len;
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 1326
1314 // Use a local variable so that sparse_ never goes from 'valid' to NULL. 1327 // Use a local variable so that sparse_ never goes from 'valid' to NULL.
1315 scoped_ptr<SparseControl> sparse(new SparseControl(this)); 1328 scoped_ptr<SparseControl> sparse(new SparseControl(this));
1316 int result = sparse->Init(); 1329 int result = sparse->Init();
1317 if (net::OK == result) 1330 if (net::OK == result)
1318 sparse_.swap(sparse); 1331 sparse_.swap(sparse);
1319 1332
1320 return result; 1333 return result;
1321 } 1334 }
1322 1335
1323 void EntryImpl::SetEntryFlags(uint32 flags) { 1336 void EntryImpl::SetEntryFlags(uint32_t flags) {
1324 entry_.Data()->flags |= flags; 1337 entry_.Data()->flags |= flags;
1325 entry_.set_modified(); 1338 entry_.set_modified();
1326 } 1339 }
1327 1340
1328 uint32 EntryImpl::GetEntryFlags() { 1341 uint32_t EntryImpl::GetEntryFlags() {
1329 return entry_.Data()->flags; 1342 return entry_.Data()->flags;
1330 } 1343 }
1331 1344
1332 void EntryImpl::GetData(int index, char** buffer, Addr* address) { 1345 void EntryImpl::GetData(int index, char** buffer, Addr* address) {
1333 DCHECK(backend_); 1346 DCHECK(backend_);
1334 if (user_buffers_[index].get() && user_buffers_[index]->Size() && 1347 if (user_buffers_[index].get() && user_buffers_[index]->Size() &&
1335 !user_buffers_[index]->Start()) { 1348 !user_buffers_[index]->Start()) {
1336 // The data is already in memory, just copy it and we're done. 1349 // The data is already in memory, just copy it and we're done.
1337 int data_len = entry_.Data()->data_size[index]; 1350 int data_len = entry_.Data()->data_size[index];
1338 if (data_len <= user_buffers_[index]->Size()) { 1351 if (data_len <= user_buffers_[index]->Size()) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 } 1421 }
1409 1422
1410 Time EntryImplV3::GetLastUsed() const { 1423 Time EntryImplV3::GetLastUsed() const {
1411 return Time(); 1424 return Time();
1412 } 1425 }
1413 1426
1414 Time EntryImplV3::GetLastModified() const { 1427 Time EntryImplV3::GetLastModified() const {
1415 return Time(); 1428 return Time();
1416 } 1429 }
1417 1430
1418 int32 EntryImplV3::GetDataSize(int index) const { 1431 int32_t EntryImplV3::GetDataSize(int index) const {
1419 return 0; 1432 return 0;
1420 } 1433 }
1421 1434
1422 int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len, 1435 int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len,
1423 const CompletionCallback& callback) { 1436 const CompletionCallback& callback) {
1424 return net::ERR_FAILED; 1437 return net::ERR_FAILED;
1425 } 1438 }
1426 1439
1427 int EntryImplV3::WriteData(int index, int offset, IOBuffer* buf, int buf_len, 1440 int EntryImplV3::WriteData(int index, int offset, IOBuffer* buf, int buf_len,
1428 const CompletionCallback& callback, bool truncate) { 1441 const CompletionCallback& callback, bool truncate) {
1429 return net::ERR_FAILED; 1442 return net::ERR_FAILED;
1430 } 1443 }
1431 1444
1432 int EntryImplV3::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, 1445 int EntryImplV3::ReadSparseData(int64_t offset,
1446 IOBuffer* buf,
1447 int buf_len,
1433 const CompletionCallback& callback) { 1448 const CompletionCallback& callback) {
1434 return net::ERR_FAILED; 1449 return net::ERR_FAILED;
1435 } 1450 }
1436 1451
1437 int EntryImplV3::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, 1452 int EntryImplV3::WriteSparseData(int64_t offset,
1453 IOBuffer* buf,
1454 int buf_len,
1438 const CompletionCallback& callback) { 1455 const CompletionCallback& callback) {
1439 return net::ERR_FAILED; 1456 return net::ERR_FAILED;
1440 } 1457 }
1441 1458
1442 int EntryImplV3::GetAvailableRange(int64 offset, int len, int64* start, 1459 int EntryImplV3::GetAvailableRange(int64_t offset,
1460 int len,
1461 int64_t* start,
1443 const CompletionCallback& callback) { 1462 const CompletionCallback& callback) {
1444 return net::ERR_FAILED; 1463 return net::ERR_FAILED;
1445 } 1464 }
1446 1465
1447 bool EntryImplV3::CouldBeSparse() const { 1466 bool EntryImplV3::CouldBeSparse() const {
1448 return false; 1467 return false;
1449 } 1468 }
1450 1469
1451 void EntryImplV3::CancelSparseIO() { 1470 void EntryImplV3::CancelSparseIO() {
1452 NOTIMPLEMENTED(); 1471 NOTIMPLEMENTED();
1453 } 1472 }
1454 1473
1455 int EntryImplV3::ReadyForSparseIO(const CompletionCallback& callback) { 1474 int EntryImplV3::ReadyForSparseIO(const CompletionCallback& callback) {
1456 return net::ERR_FAILED; 1475 return net::ERR_FAILED;
1457 } 1476 }
1458 1477
1459 EntryImplV3::~EntryImplV3() { 1478 EntryImplV3::~EntryImplV3() {
1460 NOTIMPLEMENTED(); 1479 NOTIMPLEMENTED();
1461 } 1480 }
1462 1481
1463 } // namespace disk_cache 1482 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/entry_impl_v3.h ('k') | net/disk_cache/blockfile/eviction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698