| OLD | NEW |
| 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/backend_worker_v3.h" | 5 #include "net/disk_cache/blockfile/backend_worker_v3.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 410 |
| 411 if (data_->header.num_entries < 0) { | 411 if (data_->header.num_entries < 0) { |
| 412 LOG(ERROR) << "Invalid number of entries"; | 412 LOG(ERROR) << "Invalid number of entries"; |
| 413 return false; | 413 return false; |
| 414 } | 414 } |
| 415 | 415 |
| 416 if (!mask_) | 416 if (!mask_) |
| 417 mask_ = data_->header.table_len - 1; | 417 mask_ = data_->header.table_len - 1; |
| 418 | 418 |
| 419 // Load the table into memory with a single read. | 419 // Load the table into memory with a single read. |
| 420 scoped_ptr<char[]> buf(new char[current_size]); | 420 std::unique_ptr<char[]> buf(new char[current_size]); |
| 421 return index_->Read(buf.get(), current_size, 0); | 421 return index_->Read(buf.get(), current_size, 0); |
| 422 } | 422 } |
| 423 | 423 |
| 424 bool BackendImpl::InitStats() { | 424 bool BackendImpl::InitStats() { |
| 425 Addr address(data_->header.stats); | 425 Addr address(data_->header.stats); |
| 426 int size = stats_.StorageSize(); | 426 int size = stats_.StorageSize(); |
| 427 | 427 |
| 428 if (!address.is_initialized()) { | 428 if (!address.is_initialized()) { |
| 429 FileType file_type = Addr::RequiredFileType(size); | 429 FileType file_type = Addr::RequiredFileType(size); |
| 430 DCHECK_NE(file_type, EXTERNAL); | 430 DCHECK_NE(file_type, EXTERNAL); |
| 431 int num_blocks = Addr::RequiredBlocks(size, file_type); | 431 int num_blocks = Addr::RequiredBlocks(size, file_type); |
| 432 | 432 |
| 433 if (!CreateBlock(file_type, num_blocks, &address)) | 433 if (!CreateBlock(file_type, num_blocks, &address)) |
| 434 return false; | 434 return false; |
| 435 return stats_.Init(NULL, 0, address); | 435 return stats_.Init(NULL, 0, address); |
| 436 } | 436 } |
| 437 | 437 |
| 438 if (!address.is_block_file()) { | 438 if (!address.is_block_file()) { |
| 439 NOTREACHED(); | 439 NOTREACHED(); |
| 440 return false; | 440 return false; |
| 441 } | 441 } |
| 442 | 442 |
| 443 // Load the required data. | 443 // Load the required data. |
| 444 size = address.num_blocks() * address.BlockSize(); | 444 size = address.num_blocks() * address.BlockSize(); |
| 445 MappedFile* file = File(address); | 445 MappedFile* file = File(address); |
| 446 if (!file) | 446 if (!file) |
| 447 return false; | 447 return false; |
| 448 | 448 |
| 449 scoped_ptr<char[]> data(new char[size]); | 449 std::unique_ptr<char[]> data(new char[size]); |
| 450 size_t offset = address.start_block() * address.BlockSize() + | 450 size_t offset = address.start_block() * address.BlockSize() + |
| 451 kBlockHeaderSize; | 451 kBlockHeaderSize; |
| 452 if (!file->Read(data.get(), size, offset)) | 452 if (!file->Read(data.get(), size, offset)) |
| 453 return false; | 453 return false; |
| 454 | 454 |
| 455 if (!stats_.Init(data.get(), size, address)) | 455 if (!stats_.Init(data.get(), size, address)) |
| 456 return false; | 456 return false; |
| 457 if (cache_type_ == net::DISK_CACHE && ShouldReportAgain()) | 457 if (cache_type_ == net::DISK_CACHE && ShouldReportAgain()) |
| 458 stats_.InitSizeHistogram(); | 458 stats_.InitSizeHistogram(); |
| 459 return true; | 459 return true; |
| 460 } | 460 } |
| 461 | 461 |
| 462 #endif // defined(V3_NOT_JUST_YET_READY). | 462 #endif // defined(V3_NOT_JUST_YET_READY). |
| 463 | 463 |
| 464 int BackendImplV3::Worker::Init(const CompletionCallback& callback) { | 464 int BackendImplV3::Worker::Init(const CompletionCallback& callback) { |
| 465 return net::ERR_FAILED; | 465 return net::ERR_FAILED; |
| 466 } | 466 } |
| 467 | 467 |
| 468 BackendImplV3::Worker::~Worker() { | 468 BackendImplV3::Worker::~Worker() { |
| 469 } | 469 } |
| 470 | 470 |
| 471 } // namespace disk_cache | 471 } // namespace disk_cache |
| OLD | NEW |