Commit 4cc8e658 authored by rajendrant's avatar rajendrant Committed by Commit Bot

LiteVideo: Handle no-transform and missing CL

cache-control: no-transform should be respected and LiteVideo should not
throttle them. When content-length is missing in the response headers
it should throttle with minimal latency.

Bug: 1127059
Change-Id: I1a9055c40d7ca1a54c53696e2fec816e54a59f8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412703
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807565}
parent 883bd20d
...@@ -38,11 +38,20 @@ base::TimeDelta LiteVideoHintAgent::CalculateLatencyForResourceResponse( ...@@ -38,11 +38,20 @@ base::TimeDelta LiteVideoHintAgent::CalculateLatencyForResourceResponse(
if (!HasLiteVideoHint()) if (!HasLiteVideoHint())
return base::TimeDelta(); return base::TimeDelta();
if (ShouldDisableLiteVideoForCacheControlNoTransform() &&
response_head.headers &&
response_head.headers->HasHeaderValue("cache-control", "no-transform")) {
return base::TimeDelta();
}
int64_t recv_bytes = response_head.content_length; int64_t recv_bytes = response_head.content_length;
if (recv_bytes == -1) if (recv_bytes == -1)
recv_bytes = response_head.encoded_body_length; recv_bytes = response_head.encoded_body_length;
if (recv_bytes == -1) if (recv_bytes == -1 && !ShouldThrottleLiteVideoMissingContentLength()) {
return base::TimeDelta(); return base::TimeDelta();
} else if (recv_bytes == -1) {
recv_bytes = 0;
}
if (kilobytes_buffered_before_throttle_ < if (kilobytes_buffered_before_throttle_ <
*kilobytes_to_buffer_before_throttle_) { *kilobytes_to_buffer_before_throttle_) {
...@@ -52,9 +61,9 @@ base::TimeDelta LiteVideoHintAgent::CalculateLatencyForResourceResponse( ...@@ -52,9 +61,9 @@ base::TimeDelta LiteVideoHintAgent::CalculateLatencyForResourceResponse(
// The total RTT for this media response should be based on how much time it // The total RTT for this media response should be based on how much time it
// took to transfer the packet in the target bandwidth, and the per RTT // took to transfer the packet in the target bandwidth, and the per RTT
// latency. For example, assuming 100KBPS target bandwidth and target RTT of 1 // latency. For example, assuming 100KBPS target bandwidth and target RTT of
// second, an 400KB response should have total delay of 5 seconds // 1 second, an 400KB response should have total delay of 5 seconds (400/100
// (400/100 + 1). // + 1).
auto delay_for_throttled_response = auto delay_for_throttled_response =
base::TimeDelta::FromSecondsD( base::TimeDelta::FromSecondsD(
recv_bytes / (*target_downlink_bandwidth_kbps_ * 1024.0)) + recv_bytes / (*target_downlink_bandwidth_kbps_ * 1024.0)) +
......
...@@ -67,6 +67,21 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest { ...@@ -67,6 +67,21 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest {
scoped_feature_list_.InitAndDisableFeature(features::kLiteVideo); scoped_feature_list_.InitAndDisableFeature(features::kLiteVideo);
} }
void SetDisableForNoTransform() {
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeaturesAndParameters(
{{features::kLiteVideo,
{{"disable_for_cache_control_no_transform", "true"}}}},
{});
}
void SetDisableForMissingContentLength() {
scoped_feature_list_.Reset();
scoped_feature_list_.InitWithFeaturesAndParameters(
{{features::kLiteVideo, {{"throttle_missing_content_length", "true"}}}},
{});
}
std::unique_ptr<LiteVideoURLLoaderThrottle> CreateLiteVideoURLLoaderThrottle( std::unique_ptr<LiteVideoURLLoaderThrottle> CreateLiteVideoURLLoaderThrottle(
blink::mojom::RequestContextType request_context_type) { blink::mojom::RequestContextType request_context_type) {
blink::WebURLRequest request; blink::WebURLRequest request;
...@@ -79,7 +94,8 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest { ...@@ -79,7 +94,8 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest {
std::unique_ptr<MediaLoaderThrottleInfo> CreateThrottleAndSendResponse( std::unique_ptr<MediaLoaderThrottleInfo> CreateThrottleAndSendResponse(
net::HttpStatusCode response_code, net::HttpStatusCode response_code,
const std::string& mime_type, const std::string& mime_type,
int content_length) { int content_length,
bool set_cache_control_no_transform = false) {
auto throttle_info = std::make_unique<MediaLoaderThrottleInfo>( auto throttle_info = std::make_unique<MediaLoaderThrottleInfo>(
CreateLiteVideoURLLoaderThrottle( CreateLiteVideoURLLoaderThrottle(
blink::mojom::RequestContextType::FETCH)); blink::mojom::RequestContextType::FETCH));
...@@ -88,9 +104,13 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest { ...@@ -88,9 +104,13 @@ class LiteVideoHintAgentTest : public ChromeRenderViewTest {
response_head->mime_type = mime_type; response_head->mime_type = mime_type;
response_head->mime_type = mime_type; response_head->mime_type = mime_type;
response_head->content_length = content_length; response_head->content_length = content_length;
response_head->encoded_body_length = content_length;
response_head->network_accessed = true; response_head->network_accessed = true;
response_head->was_fetched_via_cache = false; response_head->was_fetched_via_cache = false;
if (set_cache_control_no_transform)
response_head->headers->SetHeader("Cache-Control", "no-transform");
throttle_info->SendResponse(response_head.get()); throttle_info->SendResponse(response_head.get());
return throttle_info; return throttle_info;
} }
...@@ -160,6 +180,60 @@ TEST_F(LiteVideoHintAgentTest, OnlyMediaMimeTypeThrottled) { ...@@ -160,6 +180,60 @@ TEST_F(LiteVideoHintAgentTest, OnlyMediaMimeTypeThrottled) {
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 0); histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 0);
} }
TEST_F(LiteVideoHintAgentTest, CacheControlNoTransformNotThrottled) {
histogram_tester().ExpectUniqueSample("LiteVideo.HintAgent.HasHint", true, 1);
// Initial k media bytes will not be throttled.
auto throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000);
EXPECT_FALSE(throttle_info->is_throttled());
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 0);
EXPECT_TRUE(GetActiveThrottledResponses().empty());
// Without the finch param, no-transform will get throttled.
throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000,
true /* set_cache_control_no_transform */);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 1);
EXPECT_TRUE(throttle_info->is_throttled());
task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(throttle_info->is_throttled());
// With the finch param, no-transform should not get throttled.
SetDisableForNoTransform();
throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000,
true /* set_cache_control_no_transform */);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 1);
EXPECT_FALSE(throttle_info->is_throttled());
}
TEST_F(LiteVideoHintAgentTest, MissingContentLengthResponseThrottled) {
histogram_tester().ExpectUniqueSample("LiteVideo.HintAgent.HasHint", true, 1);
// Initial k media bytes will not be throttled.
auto throttle_info =
CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", 11000);
EXPECT_FALSE(throttle_info->is_throttled());
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 0);
EXPECT_TRUE(GetActiveThrottledResponses().empty());
// Without the finch param, no-transform should not get throttled.
throttle_info = CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", -1);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 0);
EXPECT_FALSE(throttle_info->is_throttled());
// With the finch param, missing CL will get throttled.
SetDisableForMissingContentLength();
throttle_info = CreateThrottleAndSendResponse(net::HTTP_OK, "video/mp4", -1);
histogram_tester().ExpectTotalCount("LiteVideo.URLLoader.ThrottleLatency", 1);
EXPECT_TRUE(throttle_info->is_throttled());
task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(10));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(throttle_info->is_throttled());
}
TEST_F(LiteVideoHintAgentTest, FailedMediaResponseNotThrottled) { TEST_F(LiteVideoHintAgentTest, FailedMediaResponseNotThrottled) {
histogram_tester().ExpectUniqueSample("LiteVideo.HintAgent.HasHint", true, 1); histogram_tester().ExpectUniqueSample("LiteVideo.HintAgent.HasHint", true, 1);
......
...@@ -14,4 +14,14 @@ bool IsLiteVideoEnabled() { ...@@ -14,4 +14,14 @@ bool IsLiteVideoEnabled() {
blink::WebNetworkStateNotifier::SaveDataEnabled(); blink::WebNetworkStateNotifier::SaveDataEnabled();
} }
bool ShouldDisableLiteVideoForCacheControlNoTransform() {
return base::GetFieldTrialParamByFeatureAsBool(
::features::kLiteVideo, "disable_for_cache_control_no_transform", false);
}
bool ShouldThrottleLiteVideoMissingContentLength() {
return base::GetFieldTrialParamByFeatureAsBool(
::features::kLiteVideo, "throttle_missing_content_length", false);
}
} // namespace lite_video } // namespace lite_video
...@@ -10,6 +10,13 @@ namespace lite_video { ...@@ -10,6 +10,13 @@ namespace lite_video {
// Returns whether LiteVideo is enabled. // Returns whether LiteVideo is enabled.
bool IsLiteVideoEnabled(); bool IsLiteVideoEnabled();
// Returns whether LiteVideo should be disabled for cache-control: no-transform
// responses.
bool ShouldDisableLiteVideoForCacheControlNoTransform();
// Returns whether LiteVideo should throttle responses without content-length.
bool ShouldThrottleLiteVideoMissingContentLength();
} // namespace lite_video } // namespace lite_video
#endif // CHROME_RENDERER_LITE_VIDEO_LITE_VIDEO_UTIL_H_ #endif // CHROME_RENDERER_LITE_VIDEO_LITE_VIDEO_UTIL_H_
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