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

Unified Diff: net/http/partial_data.cc

Issue 1230113012: [net] Better StopCaching() handling for HttpCache::Transaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: net/http/partial_data.cc
diff --git a/net/http/partial_data.cc b/net/http/partial_data.cc
index 8e1eb0ab84658cc4f1e1f06c1abc289cfd19b7d7..7cf61a9ec6c2c6697d8afd05db8cd7cb838a68f1 100644
--- a/net/http/partial_data.cc
+++ b/net/http/partial_data.cc
@@ -4,6 +4,8 @@
#include "net/http/partial_data.h"
+#include <limits>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/format_macros.h"
@@ -24,6 +26,7 @@ namespace {
const char kLengthHeader[] = "Content-Length";
const char kRangeHeader[] = "Content-Range";
const int kDataStream = 1;
+const int64 kUnbounded = std::numeric_limits<int64>::max();
rvargas (doing something else) 2015/08/19 23:46:39 A recent chr-dev thread suggest this may use an st
asanka 2015/09/04 19:09:04 Done. I used basictypes.h instead of sttdint becau
} // namespace
@@ -60,8 +63,8 @@ bool PartialData::Init(const HttpRequestHeaders& headers) {
current_range_start_ = byte_range_.first_byte_position();
- DVLOG(1) << "Range start: " << current_range_start_ << " end: " <<
- byte_range_.last_byte_position();
+ DVLOG(1) << "Range start: " << current_range_start_
+ << " end: " << byte_range_.last_byte_position();
return true;
}
@@ -94,7 +97,7 @@ int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
DCHECK_GE(current_range_start_, 0);
// Scan the disk cache for the first cached portion within this range.
- int len = GetNextRangeLen();
+ int64 len = GetNextRangeLen();
if (!len)
return 0;
@@ -103,13 +106,17 @@ int PartialData::ShouldValidateCache(disk_cache::Entry* entry,
if (sparse_entry_) {
DCHECK(callback_.is_null());
int64* start = new int64;
+ // TODO(asanka): Use the full |len| when int64_t is plumbed all the way
+ // through.
+ int cached_len = std::min<int64>(std::numeric_limits<int32>::max(), len);
+
// This callback now owns "start". We make sure to keep it
// in a local variable since we want to use it later.
CompletionCallback cb =
base::Bind(&PartialData::GetAvailableRangeCompleted,
weak_factory_.GetWeakPtr(), base::Owned(start));
cached_min_len_ =
- entry->GetAvailableRange(current_range_start_, len, start, cb);
+ entry->GetAvailableRange(current_range_start_, cached_len, start, cb);
if (cached_min_len_ == ERR_IO_PENDING) {
callback_ = callback;
@@ -140,7 +147,9 @@ void PartialData::PrepareCacheValidation(disk_cache::Entry* entry,
DCHECK_GE(current_range_start_, 0);
DCHECK_GE(cached_min_len_, 0);
- int len = GetNextRangeLen();
+ int64 len = GetNextRangeLen();
+ // PrepareCacheValidation shouldn't have been called if ShouldValidateCache()
+ // returned 0.
DCHECK_NE(0, len);
range_present_ = false;
@@ -150,7 +159,7 @@ void PartialData::PrepareCacheValidation(disk_cache::Entry* entry,
// We don't have anything else stored.
final_range_ = true;
cached_start_ =
- byte_range_.HasLastBytePosition() ? current_range_start_ + len : 0;
+ byte_range_.HasLastBytePosition() ? current_range_start_ + len : 0;
}
if (current_range_start_ == cached_start_) {
@@ -163,6 +172,7 @@ void PartialData::PrepareCacheValidation(disk_cache::Entry* entry,
// This range is not in the cache.
current_range_end_ = cached_start_ - 1;
}
+
headers->SetHeader(
HttpRequestHeaders::kRange,
HttpByteRange::Bounded(current_range_start_, current_range_end_)
@@ -185,6 +195,8 @@ bool PartialData::UpdateFromStoredHeaders(const HttpResponseHeaders* headers,
DCHECK_EQ(headers->response_code(), 200);
// We don't have the real length and the user may be trying to create a
// sparse entry so let's not write to this entry.
+ std::string header_string;
+ headers->GetNormalizedHeaders(&header_string);
if (byte_range_.IsValid())
return false;
@@ -238,6 +250,16 @@ void PartialData::SetRangeToStartDownload() {
initial_validation_ = false;
}
+bool PartialData::SkipCacheForRemainder() {
+ if (GetNextRangeLen() == 0)
+ return false;
+
+ sparse_entry_ = false;
+ cached_start_ = 0;
+ cached_min_len_ = 0;
+ return true;
+}
+
bool PartialData::IsRequestedRangeOK() {
if (byte_range_.IsValid()) {
if (!byte_range_.ComputeBounds(resource_size_))
@@ -365,7 +387,7 @@ int PartialData::CacheRead(disk_cache::Entry* entry,
IOBuffer* data,
int data_len,
const CompletionCallback& callback) {
- int read_len = std::min(data_len, cached_min_len_);
+ int read_len = std::min<int64>(data_len, cached_min_len_);
if (!read_len)
return 0;
@@ -414,14 +436,10 @@ void PartialData::OnNetworkReadCompleted(int result) {
current_range_start_ += result;
}
-int PartialData::GetNextRangeLen() {
- int64 range_len =
- byte_range_.HasLastBytePosition() ?
- byte_range_.last_byte_position() - current_range_start_ + 1 :
- kint32max;
- if (range_len > kint32max)
- range_len = kint32max;
- return static_cast<int32>(range_len);
+int64 PartialData::GetNextRangeLen() {
+ return byte_range_.HasLastBytePosition()
+ ? byte_range_.last_byte_position() - current_range_start_ + 1
+ : kUnbounded;
}
void PartialData::GetAvailableRangeCompleted(int64* start, int result) {

Powered by Google App Engine
This is Rietveld 408576698