Commit 6b3c617c authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Add ability to control StaleWhileRevalidate via OriginTrials

The implementation isn't there yet but this flag controls whether
the eventual implementation should do something or not.

BUG=348877

Change-Id: I72a5a0eb2873d0a06ae5ce84c494b4d24b91434d
Reviewed-on: https://chromium-review.googlesource.com/1100942
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567974}
parent 77a6bb63
......@@ -1938,6 +1938,7 @@ enum WebFeature {
kTextToSpeech_Speak = 2471,
kTextToSpeech_SpeakCrossOrigin = 2472,
kTextToSpeech_SpeakDisallowedByAutoplay = 2473,
kStaleWhileRevalidateEnabled = 2474,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -69,6 +69,7 @@
#include "third_party/blink/renderer/core/loader/resource/script_resource.h"
#include "third_party/blink/renderer/core/loader/subresource_filter.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trials.h"
#include "third_party/blink/renderer/core/page/frame_tree.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
......@@ -1115,6 +1116,14 @@ void DocumentLoader::InstallNewDocument(
OriginTrialContext::AddTokensFromHeader(
document, response_.HttpHeaderField(HTTPNames::Origin_Trial));
}
bool stale_while_revalidate_enabled =
OriginTrials::staleWhileRevalidateEnabled(document);
fetcher_->SetStaleWhileRevalidateEnabled(stale_while_revalidate_enabled);
// If stale while revalidate is enabled via Origin Trials count it as such.
if (stale_while_revalidate_enabled &&
!RuntimeEnabledFeatures::StaleWhileRevalidateEnabledByRuntimeFlag())
UseCounter::Count(frame_, WebFeature::kStaleWhileRevalidateEnabled);
parser_ = document->OpenForNavigation(parsing_policy, mime_type, encoding);
......
......@@ -357,7 +357,8 @@ ResourceFetcher::ResourceFetcher(FetchContext* new_context)
auto_load_images_(true),
images_enabled_(true),
allow_stale_resources_(false),
image_fetched_(false) {
image_fetched_(false),
stale_while_revalidate_enabled_(false) {
InstanceCounters::IncrementCounter(InstanceCounters::kResourceFetcherCounter);
if (IsMainThread())
MainThreadFetchersSet().insert(this);
......@@ -1716,6 +1717,10 @@ void ResourceFetcher::PrepareForLeakDetection() {
StopFetchingIncludingKeepaliveLoaders();
}
void ResourceFetcher::SetStaleWhileRevalidateEnabled(bool enabled) {
stale_while_revalidate_enabled_ = enabled;
}
void ResourceFetcher::StopFetchingInternal(StopFetchingTarget target) {
// TODO(toyoshim): May want to suspend scheduler while canceling loaders so
// that the cancellations below do not awake unnecessary scheduling.
......
......@@ -177,6 +177,8 @@ class PLATFORM_EXPORT ResourceFetcher
// counting.
void PrepareForLeakDetection();
void SetStaleWhileRevalidateEnabled(bool enabled);
using ResourceFetcherSet = PersistentHeapHashSet<WeakMember<ResourceFetcher>>;
static const ResourceFetcherSet& MainThreadFetchers();
......@@ -312,11 +314,12 @@ class PLATFORM_EXPORT ResourceFetcher
uint32_t inflight_keepalive_bytes_ = 0;
// 28 bits left
// 27 bits left
bool auto_load_images_ : 1;
bool images_enabled_ : 1;
bool allow_stale_resources_ : 1;
bool image_fetched_ : 1;
bool stale_while_revalidate_enabled_ : 1;
static constexpr uint32_t kKeepaliveInflightBytesQuota = 64 * 1024;
};
......
......@@ -1190,6 +1190,11 @@
name: "StackedCSSPropertyAnimations",
status: "experimental",
},
{
name: "StaleWhileRevalidate",
origin_trial_feature_name: "StaleWhileRevalidate",
status: "test",
},
{
name: "StopInBackground",
status: "test",
......
......@@ -19005,6 +19005,7 @@ Called by update_net_error_codes.py.-->
<int value="2471" label="TextToSpeech_Speak"/>
<int value="2472" label="TextToSpeech_SpeakCrossOrigin"/>
<int value="2473" label="TextToSpeech_SpeakDisallowedByAutoplay"/>
<int value="2474" label="StaleWhileRevalidateEnabled"/>
</enum>
<enum name="FeedbackSource">
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