Commit c4f914ec authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Delay IsolatedPrerender Canary Check until after browser start

See bug, but there's a slight regression in startup time for starting
the probe which isn't actually that useful for the first nav anyways.

Bug: 1113691
Change-Id: Idc50e39067bc54f5dc8263b89add6dc8b3cf1bb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346739Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796527}
parent 8d587fe3
......@@ -311,6 +311,10 @@ AvailabilityProber::~AvailabilityProber() {
network_connection_tracker_->RemoveNetworkConnectionObserver(this);
}
base::WeakPtr<AvailabilityProber> AvailabilityProber::AsWeakPtr() const {
return weak_factory_.GetWeakPtr();
}
// static
void AvailabilityProber::RegisterProfilePrefs(PrefRegistrySimple* registry) {
for (int i = static_cast<int>(
......
......@@ -163,6 +163,8 @@ class AvailabilityProber
// Clears the prefs used in this class.
static void ClearData(PrefService* pref_service);
base::WeakPtr<AvailabilityProber> AsWeakPtr() const;
// Sends a probe now if the prober is currently inactive. If the probe is
// active (i.e.: there are probes in flight), this is a no-op. If
// |send_only_in_foreground| is set, the probe will only be sent when the app
......
......@@ -7,9 +7,12 @@
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/task/post_task.h"
#include "chrome/browser/availability/availability_prober.h"
#include "chrome/browser/prerender/isolated/isolated_prerender_params.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/base/host_port_pair.h"
......@@ -98,6 +101,16 @@ OriginProbeDelegate* GetOriginProbeDelegate() {
return delegate.get();
}
// Allows probing to start after a delay so that browser start isn't slowed.
void StartCanaryCheck(base::WeakPtr<AvailabilityProber> canary_checker) {
// If there is no previously cached result for this network then one should be
// started. If the previous result is stale, the prober will start a probe
// during |LastProbeWasSuccessful|.
if (!canary_checker->LastProbeWasSuccessful().has_value()) {
canary_checker->SendNowIfInactive(false);
}
}
} // namespace
IsolatedPrerenderOriginProber::IsolatedPrerenderOriginProber(Profile* profile)
......@@ -148,12 +161,12 @@ IsolatedPrerenderOriginProber::IsolatedPrerenderOriginProber(Profile* profile)
traffic_annotation, 10 /* max_cache_entries */,
IsolatedPrerenderCanaryCheckCacheLifetime());
// If there is no previously cached result for this network then one should be
// started. If the previous result is stale, the prober will start a probe
// during |LastProbeWasSuccessful|.
if (!canary_check_->LastProbeWasSuccessful().has_value()) {
canary_check_->SendNowIfInactive(false);
}
// This code is running at browser startup. Start the canary check when we get
// the chance, but there's no point in it being ready for the first navigation
// since the check won't be done by then anyways.
content::GetUIThreadTaskRunner({base::TaskPriority::BEST_EFFORT})
->PostTask(FROM_HERE,
base::BindOnce(&StartCanaryCheck, canary_check_->AsWeakPtr()));
}
IsolatedPrerenderOriginProber::~IsolatedPrerenderOriginProber() = default;
......
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