summaryrefslogtreecommitdiff
path: root/chromium/net/disk_cache/blockfile/sparse_control.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-06-18 14:10:49 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2015-06-18 13:53:24 +0000
commit813fbf95af77a531c57a8c497345ad2c61d475b3 (patch)
tree821b2c8de8365f21b6c9ba17a236fb3006a1d506 /chromium/net/disk_cache/blockfile/sparse_control.cc
parentaf6588f8d723931a298c995fa97259bb7f7deb55 (diff)
downloadqtwebengine-chromium-813fbf95af77a531c57a8c497345ad2c61d475b3.tar.gz
BASELINE: Update chromium to 44.0.2403.47
Change-Id: Ie056fedba95cf5e5c76b30c4b2c80fca4764aa2f Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/net/disk_cache/blockfile/sparse_control.cc')
-rw-r--r--chromium/net/disk_cache/blockfile/sparse_control.cc67
1 files changed, 41 insertions, 26 deletions
diff --git a/chromium/net/disk_cache/blockfile/sparse_control.cc b/chromium/net/disk_cache/blockfile/sparse_control.cc
index 30ea836fc7f..926cf360f19 100644
--- a/chromium/net/disk_cache/blockfile/sparse_control.cc
+++ b/chromium/net/disk_cache/blockfile/sparse_control.cc
@@ -161,7 +161,7 @@ net::NetLog::EventType GetSparseEventType(
void LogChildOperationEnd(const net::BoundNetLog& net_log,
disk_cache::SparseControl::SparseOperation operation,
int result) {
- if (net_log.IsLogging()) {
+ if (net_log.IsCapturing()) {
net::NetLog::EventType event_type;
switch (operation) {
case disk_cache::SparseControl::kReadOperation:
@@ -275,7 +275,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
finished_ = false;
abort_ = false;
- if (entry_->net_log().IsLogging()) {
+ if (entry_->net_log().IsCapturing()) {
entry_->net_log().BeginEvent(
GetSparseEventType(operation_),
CreateNetLogSparseOperationCallback(offset_, buf_len_));
@@ -483,7 +483,7 @@ bool SparseControl::OpenChild() {
return KillChildAndContinue(key, false);
if (child_data_.header.last_block_len < 0 ||
- child_data_.header.last_block_len > kBlockSize) {
+ child_data_.header.last_block_len >= kBlockSize) {
// Make sure these values are always within range.
child_data_.header.last_block_len = 0;
child_data_.header.last_block = -1;
@@ -590,7 +590,7 @@ bool SparseControl::VerifyRange() {
if (child_map_.FindNextBit(&start, last_bit, false)) {
// Something is not here.
DCHECK_GE(child_data_.header.last_block_len, 0);
- DCHECK_LT(child_data_.header.last_block_len, kMaxEntrySize);
+ DCHECK_LT(child_data_.header.last_block_len, kBlockSize);
int partial_block_len = PartialBlockLength(start);
if (start == child_offset_ >> 10) {
// It looks like we don't have anything.
@@ -615,7 +615,7 @@ void SparseControl::UpdateRange(int result) {
return;
DCHECK_GE(child_data_.header.last_block_len, 0);
- DCHECK_LT(child_data_.header.last_block_len, kMaxEntrySize);
+ DCHECK_LT(child_data_.header.last_block_len, kBlockSize);
// Write the bitmap.
int first_bit = child_offset_ >> 10;
@@ -651,11 +651,6 @@ int SparseControl::PartialBlockLength(int block_index) const {
if (block_index == child_data_.header.last_block)
return child_data_.header.last_block_len;
- // This may be the last stored index.
- int entry_len = child_->GetDataSize(kSparseData);
- if (block_index == entry_len >> 10)
- return entry_len & (kBlockSize - 1);
-
// This is really empty.
return 0;
}
@@ -683,15 +678,13 @@ void SparseControl::DoChildrenIO() {
// Range operations are finished synchronously, often without setting
// |finished_| to true.
- if (kGetRangeOperation == operation_ &&
- entry_->net_log().IsLogging()) {
+ if (kGetRangeOperation == operation_ && entry_->net_log().IsCapturing()) {
entry_->net_log().EndEvent(
net::NetLog::TYPE_SPARSE_GET_RANGE,
CreateNetLogGetAvailableRangeResultCallback(offset_, result_));
}
if (finished_) {
- if (kGetRangeOperation != operation_ &&
- entry_->net_log().IsLogging()) {
+ if (kGetRangeOperation != operation_ && entry_->net_log().IsCapturing()) {
entry_->net_log().EndEvent(GetSparseEventType(operation_));
}
if (pending_)
@@ -721,7 +714,7 @@ bool SparseControl::DoChildIO() {
int rv = 0;
switch (operation_) {
case kReadOperation:
- if (entry_->net_log().IsLogging()) {
+ if (entry_->net_log().IsCapturing()) {
entry_->net_log().BeginEvent(
net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
CreateNetLogSparseReadWriteCallback(child_->net_log().source(),
@@ -731,7 +724,7 @@ bool SparseControl::DoChildIO() {
child_len_, callback);
break;
case kWriteOperation:
- if (entry_->net_log().IsLogging()) {
+ if (entry_->net_log().IsCapturing()) {
entry_->net_log().BeginEvent(
net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
CreateNetLogSparseReadWriteCallback(child_->net_log().source(),
@@ -769,27 +762,49 @@ int SparseControl::DoGetAvailableRange() {
if (!child_)
return child_len_; // Move on to the next child.
- // Check that there are no holes in this range.
- int last_bit = (child_offset_ + child_len_ + 1023) >> 10;
+ // Bits on the bitmap should only be set when the corresponding block was
+ // fully written (it's really being used). If a block is partially used, it
+ // has to start with valid data, the length of the valid data is saved in
+ // |header.last_block_len| and the block itself should match
+ // |header.last_block|.
+ //
+ // In other words, (|header.last_block| + |header.last_block_len|) is the
+ // offset where the last write ended, and data in that block (which is not
+ // marked as used because it is not full) will only be reused if the next
+ // write continues at that point.
+ //
+ // This code has to find if there is any data between child_offset_ and
+ // child_offset_ + child_len_.
+ int last_bit = (child_offset_ + child_len_ + kBlockSize - 1) >> 10;
int start = child_offset_ >> 10;
int partial_start_bytes = PartialBlockLength(start);
int found = start;
int bits_found = child_map_.FindBits(&found, last_bit, true);
+ bool is_last_block_in_range = start < child_data_.header.last_block &&
+ child_data_.header.last_block < last_bit;
- // We don't care if there is a partial block in the middle of the range.
int block_offset = child_offset_ & (kBlockSize - 1);
- if (!bits_found && partial_start_bytes <= block_offset)
- return child_len_;
+ if (!bits_found && partial_start_bytes <= block_offset) {
+ if (!is_last_block_in_range)
+ return child_len_;
+ found = last_bit - 1; // There are some bytes here.
+ }
// We are done. Just break the loop and reset result_ to our real result.
range_found_ = true;
- // found now points to the first 1. Lets see if we have zeros before it.
- int empty_start = std::max((found << 10) - child_offset_, 0);
-
int bytes_found = bits_found << 10;
bytes_found += PartialBlockLength(found + bits_found);
+ // found now points to the first bytes. Lets see if we have data before it.
+ int empty_start = std::max((found << 10) - child_offset_, 0);
+ if (empty_start >= child_len_)
+ return child_len_;
+
+ // At this point we have bytes_found stored after (found << 10), and we want
+ // child_len_ bytes after child_offset_. The first empty_start bytes after
+ // child_offset_ are invalid.
+
if (start == found)
bytes_found -= block_offset;
@@ -798,7 +813,7 @@ int SparseControl::DoGetAvailableRange() {
// query that we have to subtract from the range that we searched.
result_ = std::min(bytes_found, child_len_ - empty_start);
- if (!bits_found) {
+ if (partial_start_bytes) {
result_ = std::min(partial_start_bytes - block_offset, child_len_);
empty_start = 0;
}
@@ -839,7 +854,7 @@ void SparseControl::OnChildIOCompleted(int result) {
// We'll return the current result of the operation, which may be less than
// the bytes to read or write, but the user cancelled the operation.
abort_ = false;
- if (entry_->net_log().IsLogging()) {
+ if (entry_->net_log().IsCapturing()) {
entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED);
entry_->net_log().EndEvent(GetSparseEventType(operation_));
}