Commit 17b09525 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[bfcache] Add a feature to delay history navigations.

This will allow us to measure the performance difference and see
the difference in the user engagement metrics and extrapolate to
estimate the usefulness of bfcache.

One-pager:
https://docs.google.com/document/d/10Ff_5oq7k-oYuXTTKdN0v_JKG3bU1GPgAWWF7i4nMvs/edit#

R=creis@chromium.org
BUG=954271

Change-Id: Id31309a9e4926073b10b0e983ed193cf207ec9f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574798
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652435}
parent 1ceb102b
......@@ -887,6 +887,8 @@ jumbo_source_set("browser") {
"frame_host/frame_tree_node.h",
"frame_host/frame_tree_node_blame_context.cc",
"frame_host/frame_tree_node_blame_context.h",
"frame_host/history_navigation_ablation_study_navigation_throttle.cc",
"frame_host/history_navigation_ablation_study_navigation_throttle.h",
"frame_host/input/input_injector_impl.cc",
"frame_host/input/input_injector_impl.h",
"frame_host/interstitial_page_impl.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/frame_host/history_navigation_ablation_study_navigation_throttle.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/rand_util.h"
#include "content/public/browser/navigation_handle.h"
#include "ui/base/page_transition_types.h"
namespace content {
namespace {
constexpr base::Feature kDelayHistoryNavigationsAblationStudy{
"DelayHistoryNavigationsAblationStudy", base::FEATURE_DISABLED_BY_DEFAULT};
constexpr base::FeatureParam<double> kProbability{
&kDelayHistoryNavigationsAblationStudy, "delay_probability", 0.0};
constexpr base::FeatureParam<int> kDelay{&kDelayHistoryNavigationsAblationStudy,
"delay_ms", 0};
constexpr base::TimeDelta kMaxDelay = base::TimeDelta::FromSeconds(15);
} // namespace
HistoryNavigationAblationStudyNavigationThrottle::
HistoryNavigationAblationStudyNavigationThrottle(
NavigationHandle* navigation_handle)
: NavigationThrottle(navigation_handle),
probability_(kProbability.Get()),
delay_(std::min(base::TimeDelta::FromMilliseconds(kDelay.Get()),
kMaxDelay)) {}
// static
std::unique_ptr<HistoryNavigationAblationStudyNavigationThrottle>
HistoryNavigationAblationStudyNavigationThrottle::MaybeCreateForNavigation(
NavigationHandle* navigation_handle) {
if (!base::FeatureList::IsEnabled(kDelayHistoryNavigationsAblationStudy))
return nullptr;
bool is_history_navigation =
navigation_handle->GetPageTransition() & ui::PAGE_TRANSITION_FORWARD_BACK;
if (!is_history_navigation)
return nullptr;
return std::make_unique<HistoryNavigationAblationStudyNavigationThrottle>(
navigation_handle);
}
NavigationThrottle::ThrottleCheckResult
HistoryNavigationAblationStudyNavigationThrottle::WillStartRequest() {
if (base::RandDouble() >= probability_)
return PROCEED;
delay_timer_.Start(
FROM_HERE, delay_,
base::BindOnce(&HistoryNavigationAblationStudyNavigationThrottle::Resume,
AsWeakPtr()));
return DEFER;
}
const char*
HistoryNavigationAblationStudyNavigationThrottle::GetNameForLogging() {
return "HistoryNavigationAblationStudyNavigationThrottle";
}
} // namespace content
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_FRAME_HOST_HISTORY_NAVIGATION_ABLATION_STUDY_NAVIGATION_THROTTLE_H_
#define CONTENT_BROWSER_FRAME_HOST_HISTORY_NAVIGATION_ABLATION_STUDY_NAVIGATION_THROTTLE_H_
#include <memory>
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "content/public/browser/navigation_throttle.h"
namespace content {
// This navigation throttle delays a navigation for a certain duration
// when an experiment is enabled to allow us to run A/B ablation study
// and measure the impact on the top-level user engagement metrics.
// TODO(altimin, crbug.com/954271): Clean up after the end of the study.
class HistoryNavigationAblationStudyNavigationThrottle
: public NavigationThrottle,
public base::SupportsWeakPtr<
HistoryNavigationAblationStudyNavigationThrottle> {
public:
explicit HistoryNavigationAblationStudyNavigationThrottle(
NavigationHandle* navigation_handle);
~HistoryNavigationAblationStudyNavigationThrottle() override = default;
// Create a NavigationThrottle if the relevant experiment is enabled.
static std::unique_ptr<HistoryNavigationAblationStudyNavigationThrottle>
MaybeCreateForNavigation(NavigationHandle* navigation_handle);
// NavigationThrottle methods:
ThrottleCheckResult WillStartRequest() override;
const char* GetNameForLogging() override;
private:
const double probability_;
const base::TimeDelta delay_;
base::OneShotTimer delay_timer_;
};
} // namespace content
#endif // CONTENT_BROWSER_FRAME_HOST_HISTORY_NAVIGATION_ABLATION_STUDY_NAVIGATION_THROTTLE_H_
......@@ -8,6 +8,7 @@
#include "content/browser/frame_host/ancestor_throttle.h"
#include "content/browser/frame_host/blocked_scheme_navigation_throttle.h"
#include "content/browser/frame_host/form_submission_throttle.h"
#include "content/browser/frame_host/history_navigation_ablation_study_navigation_throttle.h"
#include "content/browser/frame_host/mixed_content_navigation_throttle.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/browser/frame_host/navigator_delegate.h"
......@@ -118,6 +119,10 @@ void NavigationThrottleRunner::RegisterNavigationThrottles() {
AddThrottle(std::move(throttle));
}
// Delay navigation for an ablation study (if needed).
AddThrottle(HistoryNavigationAblationStudyNavigationThrottle::
MaybeCreateForNavigation(handle));
// Insert all testing NavigationThrottles last.
throttles_.insert(throttles_.end(),
std::make_move_iterator(testing_throttles.begin()),
......
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