Commit 03772bfd authored by hubbe's avatar hubbe Committed by Commit bot

media: Send chrome-cache: frfr on first request.

This allows flywheel to know when it's safe to switch resources.

BUG=504194

Review-Url: https://codereview.chromium.org/2842763003
Cr-Commit-Position: refs/heads/master@{#471139}
parent 7cf2f122
...@@ -292,6 +292,8 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal( ...@@ -292,6 +292,8 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal(
data = DataReductionProxyData::GetDataAndCreateIfNecessary(request); data = DataReductionProxyData::GetDataAndCreateIfNecessary(request);
if (data) if (data)
data->set_used_data_reduction_proxy(true); data->set_used_data_reduction_proxy(true);
headers->RemoveHeader(chrome_proxy_header());
VerifyHttpRequestHeaders(false, *headers); VerifyHttpRequestHeaders(false, *headers);
return; return;
} }
...@@ -319,6 +321,7 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal( ...@@ -319,6 +321,7 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendHeadersInternal(
lofi_decider->RemoveAcceptTransformHeader(headers); lofi_decider->RemoveAcceptTransformHeader(headers);
} }
RemoveChromeProxyECTHeader(headers); RemoveChromeProxyECTHeader(headers);
headers->RemoveHeader(chrome_proxy_header());
VerifyHttpRequestHeaders(false, *headers); VerifyHttpRequestHeaders(false, *headers);
return; return;
} }
......
...@@ -403,7 +403,7 @@ void MultibufferDataSource::ReadTask() { ...@@ -403,7 +403,7 @@ void MultibufferDataSource::ReadTask() {
bytes_read = bytes_read =
static_cast<int>(std::min<int64_t>(available, read_op_->size())); static_cast<int>(std::min<int64_t>(available, read_op_->size()));
bytes_read = reader_->TryRead(read_op_->data(), bytes_read); bytes_read = reader_->TryRead(read_op_->data(), bytes_read);
url_data_->AddBytesRead(bytes_read);
if (bytes_read == 0 && total_bytes_ == kPositionNotSpecified) { if (bytes_read == 0 && total_bytes_ == kPositionNotSpecified) {
// We've reached the end of the file and we didn't know the total size // We've reached the end of the file and we didn't know the total size
// before. Update the total size so Read()s past the end of the file will // before. Update the total size so Read()s past the end of the file will
......
...@@ -85,6 +85,15 @@ void ResourceMultiBufferDataProvider::Start() { ...@@ -85,6 +85,15 @@ void ResourceMultiBufferDataProvider::Start() {
WebString::FromUTF8( WebString::FromUTF8(
net::HttpByteRange::RightUnbounded(byte_pos()).GetHeaderValue())); net::HttpByteRange::RightUnbounded(byte_pos()).GetHeaderValue()));
if (url_data_->length() == kPositionNotSpecified &&
url_data_->CachedSize() == 0 && url_data_->BytesReadFromCache() == 0) {
// This lets the data reduction proxy know that we don't have anything
// previously cached data for this resource. We can only send it if this is
// the first request for this resource.
request.SetHTTPHeaderField(WebString::FromUTF8("chrome-proxy"),
WebString::FromUTF8("frfr"));
}
// We would like to send an if-match header with the request to // We would like to send an if-match header with the request to
// tell the remote server that we really can't handle files other // tell the remote server that we really can't handle files other
// than the one we already started playing. Unfortunately, doing // than the one we already started playing. Unfortunately, doing
......
...@@ -54,8 +54,16 @@ const int kHttpPartialContent = 206; ...@@ -54,8 +54,16 @@ const int kHttpPartialContent = 206;
enum NetworkState { NONE, LOADED, LOADING }; enum NetworkState { NONE, LOADED, LOADING };
static bool got_frfr = false;
// Predicate that tests that request disallows compressed data. // Predicate that tests that request disallows compressed data.
static bool CorrectAcceptEncoding(const blink::WebURLRequest& request) { static bool CorrectAcceptEncodingAndProxy(const blink::WebURLRequest& request) {
std::string chrome_proxy =
request.HttpHeaderField(WebString::FromUTF8("chrome-proxy")).Utf8();
if (chrome_proxy != (got_frfr ? "" : "frfr")) {
return false;
}
std::string value = request std::string value = request
.HttpHeaderField(WebString::FromUTF8( .HttpHeaderField(WebString::FromUTF8(
net::HttpRequestHeaders::kAcceptEncoding)) net::HttpRequestHeaders::kAcceptEncoding))
...@@ -105,8 +113,10 @@ class ResourceMultiBufferDataProviderTest : public testing::Test { ...@@ -105,8 +113,10 @@ class ResourceMultiBufferDataProviderTest : public testing::Test {
void Start() { void Start() {
InSequence s; InSequence s;
EXPECT_CALL(*url_loader_, got_frfr = false;
LoadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); EXPECT_CALL(
*url_loader_,
LoadAsynchronously(Truly(CorrectAcceptEncodingAndProxy), loader_));
loader_->Start(); loader_->Start();
} }
......
...@@ -80,6 +80,7 @@ void UrlData::MergeFrom(const scoped_refptr<UrlData>& other) { ...@@ -80,6 +80,7 @@ void UrlData::MergeFrom(const scoped_refptr<UrlData>& other) {
if (last_modified_.is_null()) { if (last_modified_.is_null()) {
last_modified_ = other->last_modified_; last_modified_ = other->last_modified_;
} }
bytes_read_from_cache_ += other->bytes_read_from_cache_;
multibuffer()->MergeFrom(other->multibuffer()); multibuffer()->MergeFrom(other->multibuffer());
} }
} }
......
...@@ -139,6 +139,9 @@ class MEDIA_BLINK_EXPORT UrlData : public base::RefCounted<UrlData> { ...@@ -139,6 +139,9 @@ class MEDIA_BLINK_EXPORT UrlData : public base::RefCounted<UrlData> {
// Accessor // Accessor
blink::WebFrame* frame() const { return frame_; } blink::WebFrame* frame() const { return frame_; }
void AddBytesRead(int64_t b) { bytes_read_from_cache_ += b; }
int64_t BytesReadFromCache() { return bytes_read_from_cache_; }
protected: protected:
UrlData(const GURL& url, UrlData(const GURL& url,
CORSMode cors_mode, CORSMode cors_mode,
...@@ -170,6 +173,9 @@ class MEDIA_BLINK_EXPORT UrlData : public base::RefCounted<UrlData> { ...@@ -170,6 +173,9 @@ class MEDIA_BLINK_EXPORT UrlData : public base::RefCounted<UrlData> {
// Length of resource this url points to. (in bytes) // Length of resource this url points to. (in bytes)
int64_t length_; int64_t length_;
// Number of bytes read from this resource.
int64_t bytes_read_from_cache_ = 0;
// Does the server support ranges? // Does the server support ranges?
bool range_supported_; bool range_supported_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment