Commit b590da56 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Chromium LUCI CQ

[AppCache] Add feature to always fallback requests to the network.

This adds a (default enabled) feature AppCacheAlwaysFallbackToNetwork,
when enabled chrome will behave as if every manifest file included a
NETWORK: * line, indicating that all requests should fall back to the
network.

Bug: 1152226
Change-Id: I02f126a91d7061183274a66ad759cde58da533cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2594235Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843607}
parent 3b9708f1
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h"
#include "content/browser/appcache/appcache.h" #include "content/browser/appcache/appcache.h"
#include "content/browser/appcache/appcache_backend_impl.h" #include "content/browser/appcache/appcache_backend_impl.h"
#include "content/browser/appcache/appcache_host.h" #include "content/browser/appcache/appcache_host.h"
...@@ -29,6 +30,12 @@ ...@@ -29,6 +30,12 @@
namespace content { namespace content {
// If this feature is enabled, we behave as if all manifests include a
// NETWORK: * line, indicating that all requests should fall back to the
// network.
const base::Feature kAppCacheAlwaysFallbackToNetwork{
"AppCacheAlwaysFallbackToNetwork", base::FEATURE_ENABLED_BY_DEFAULT};
namespace { namespace {
bool g_running_in_tests = false; bool g_running_in_tests = false;
...@@ -153,7 +160,8 @@ AppCacheURLLoader* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( ...@@ -153,7 +160,8 @@ AppCacheURLLoader* AppCacheRequestHandler::MaybeLoadFallbackForRedirect(
DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_,
found_manifest_url_, true, found_manifest_url_, true,
found_namespace_entry_url_); found_namespace_entry_url_);
} else if (!found_network_namespace_) { } else if (!found_network_namespace_ &&
!base::FeatureList::IsEnabled(kAppCacheAlwaysFallbackToNetwork)) {
// 7.9.6, step 6: Fail the resource load. // 7.9.6, step 6: Fail the resource load.
loader = CreateLoader(network_delegate); loader = CreateLoader(network_delegate);
DeliverErrorResponse(); DeliverErrorResponse();
...@@ -515,7 +523,8 @@ void AppCacheRequestHandler::ContinueMaybeLoadSubResource() { ...@@ -515,7 +523,8 @@ void AppCacheRequestHandler::ContinueMaybeLoadSubResource() {
return; return;
} }
if (found_network_namespace_) { if (found_network_namespace_ ||
base::FeatureList::IsEnabled(kAppCacheAlwaysFallbackToNetwork)) {
// Step 3 and 5: Fetch the resource normally. // Step 3 and 5: Fetch the resource normally.
DCHECK(!found_entry_.has_response_id() && DCHECK(!found_entry_.has_response_id() &&
!found_fallback_entry_.has_response_id()); !found_fallback_entry_.has_response_id());
......
...@@ -36,6 +36,8 @@ class AppCacheRequest; ...@@ -36,6 +36,8 @@ class AppCacheRequest;
class AppCacheRequestHandlerTest; class AppCacheRequestHandlerTest;
class AppCacheHost; class AppCacheHost;
CONTENT_EXPORT extern const base::Feature kAppCacheAlwaysFallbackToNetwork;
// An instance is created for each net::URLRequest. The instance survives all // An instance is created for each net::URLRequest. The instance survives all
// http transactions involved in the processing of its net::URLRequest, and is // http transactions involved in the processing of its net::URLRequest, and is
// given the opportunity to hijack the request along the way. Callers // given the opportunity to hijack the request along the way. Callers
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/browser/appcache/appcache.h" #include "content/browser/appcache/appcache.h"
...@@ -64,6 +65,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test { ...@@ -64,6 +65,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test {
// Test harness -------------------------------------------------- // Test harness --------------------------------------------------
AppCacheRequestHandlerTest() : host_(nullptr), request_(nullptr) { AppCacheRequestHandlerTest() : host_(nullptr), request_(nullptr) {
feature_list_.InitAndEnableFeature(kAppCacheAlwaysFallbackToNetwork);
AppCacheRequestHandler::SetRunningInTests(true); AppCacheRequestHandler::SetRunningInTests(true);
} }
...@@ -369,7 +371,9 @@ class AppCacheRequestHandlerTest : public ::testing::Test { ...@@ -369,7 +371,9 @@ class AppCacheRequestHandlerTest : public ::testing::Test {
void SubResource_Miss_WithCacheSelected() { void SubResource_Miss_WithCacheSelected() {
// A sub-resource load where the resource is not in an appcache, or // A sub-resource load where the resource is not in an appcache, or
// in a network or fallback namespace, should result in a failed request. // in a network or fallback namespace, should result in a fallback to the
// network rather than an error, as we treat all network namespaces as
// including '*'.
host_->AssociateCompleteCache(MakeNewCache()); host_->AssociateCompleteCache(MakeNewCache());
CreateRequestAndHandler(GURL("http://blah/"), host_, CreateRequestAndHandler(GURL("http://blah/"), host_,
...@@ -377,8 +381,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test { ...@@ -377,8 +381,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test {
EXPECT_TRUE(handler_.get()); EXPECT_TRUE(handler_.get());
SetAppCacheURLLoader(handler_->MaybeLoadResource(nullptr)); SetAppCacheURLLoader(handler_->MaybeLoadResource(nullptr));
EXPECT_TRUE(loader()); EXPECT_FALSE(loader());
EXPECT_TRUE(loader()->IsDeliveringErrorResponse());
SetAppCacheURLLoader(handler_->MaybeLoadFallbackForRedirect( SetAppCacheURLLoader(handler_->MaybeLoadFallbackForRedirect(
nullptr, GURL("http://blah/redirect"))); nullptr, GURL("http://blah/redirect")));
...@@ -406,7 +409,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test { ...@@ -406,7 +409,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test {
host_->FinishCacheSelection(cache.get(), nullptr, base::DoNothing()); host_->FinishCacheSelection(cache.get(), nullptr, base::DoNothing());
EXPECT_FALSE(loader()->IsWaiting()); EXPECT_FALSE(loader()->IsWaiting());
EXPECT_TRUE(loader()->IsDeliveringErrorResponse()); EXPECT_TRUE(loader()->IsDeliveringNetworkResponse());
SetAppCacheURLLoader(handler_->MaybeLoadFallbackForRedirect( SetAppCacheURLLoader(handler_->MaybeLoadFallbackForRedirect(
nullptr, GURL("http://blah/redirect"))); nullptr, GURL("http://blah/redirect")));
...@@ -707,6 +710,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test { ...@@ -707,6 +710,7 @@ class AppCacheRequestHandlerTest : public ::testing::Test {
} }
// Data members -------------------------------------------------- // Data members --------------------------------------------------
base::test::ScopedFeatureList feature_list_;
BrowserTaskEnvironment task_environment_; BrowserTaskEnvironment task_environment_;
base::OnceClosure test_finished_cb_; base::OnceClosure test_finished_cb_;
......
...@@ -594,7 +594,8 @@ ...@@ -594,7 +594,8 @@
{ {
"prefix": "appcache-origin-trial", "prefix": "appcache-origin-trial",
"bases": ["http/tests/appcache"], "bases": ["http/tests/appcache"],
"args": ["--enable-features=AppCacheRequireOriginTrial"] "args": ["--enable-features=AppCacheRequireOriginTrial",
"--disable-features=AppCacheAlwaysFallbackToNetwork"]
}, },
{ {
"prefix": "async-script-scheduling-finished-parsing", "prefix": "async-script-scheduling-finished-parsing",
......
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