Bug 1613497 - Get rid of URIParams in the predictor code r=dragana

Differential Revision: https://phabricator.services.mozilla.com/D61748

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2020-02-07 10:55:53 +00:00
Родитель 6c3dc38ad9
Коммит 8277bba048
6 изменённых файлов: 52 добавлений и 86 удалений

Просмотреть файл

@ -418,29 +418,9 @@ nsresult Predictor::Init() {
} }
namespace { namespace {
class PredictorThreadShutdownRunner : public Runnable {
public:
PredictorThreadShutdownRunner(bool success)
: Runnable("net::PredictorThreadShutdownRunner"), mSuccess(success) {}
~PredictorThreadShutdownRunner() = default;
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread(), "Shutting down io thread off main thread!");
if (mSuccess) {
// This means the cleanup happened. Mark so we don't try in the
// future.
Preferences::SetBool(PREDICTOR_CLEANED_UP_PREF, true);
}
return NS_OK;
}
private:
bool mSuccess;
};
class PredictorOldCleanupRunner : public Runnable { class PredictorOldCleanupRunner : public Runnable {
public: public:
PredictorOldCleanupRunner(nsIFile* dbFile) explicit PredictorOldCleanupRunner(nsIFile* dbFile)
: Runnable("net::PredictorOldCleanupRunner"), mDBFile(dbFile) {} : Runnable("net::PredictorOldCleanupRunner"), mDBFile(dbFile) {}
~PredictorOldCleanupRunner() = default; ~PredictorOldCleanupRunner() = default;
@ -448,9 +428,12 @@ class PredictorOldCleanupRunner : public Runnable {
NS_IMETHOD Run() override { NS_IMETHOD Run() override {
MOZ_ASSERT(!NS_IsMainThread(), "Cleaning up old files on main thread!"); MOZ_ASSERT(!NS_IsMainThread(), "Cleaning up old files on main thread!");
nsresult rv = CheckForAndDeleteOldDBFiles(); nsresult rv = CheckForAndDeleteOldDBFiles();
RefPtr<PredictorThreadShutdownRunner> runner =
new PredictorThreadShutdownRunner(NS_SUCCEEDED(rv)); if (NS_SUCCEEDED(rv)) {
NS_DispatchToMainThread(runner); NS_DispatchToMainThread(NS_NewRunnableFunction(
"net::PredictorOldCleanupMainThread",
[]() { Preferences::SetBool(PREDICTOR_CLEANED_UP_PREF, true); }));
}
return NS_OK; return NS_OK;
} }
@ -495,7 +478,9 @@ class PredictorLearnRunnable final : public Runnable {
mTargetURI(targetURI), mTargetURI(targetURI),
mSourceURI(sourceURI), mSourceURI(sourceURI),
mReason(reason), mReason(reason),
mOA(oa) {} mOA(oa) {
MOZ_DIAGNOSTIC_ASSERT(targetURI, "Must have a target URI");
}
~PredictorLearnRunnable() = default; ~PredictorLearnRunnable() = default;
@ -508,14 +493,8 @@ class PredictorLearnRunnable final : public Runnable {
return NS_OK; return NS_OK;
} }
ipc::URIParams serTargetURI;
SerializeURI(mTargetURI, serTargetURI);
Maybe<ipc::URIParams> serSourceURI;
SerializeURI(mSourceURI, serSourceURI);
PREDICTOR_LOG(("predictor::learn (async) forwarding to parent")); PREDICTOR_LOG(("predictor::learn (async) forwarding to parent"));
gNeckoChild->SendPredLearn(serTargetURI, serSourceURI, mReason, mOA); gNeckoChild->SendPredLearn(mTargetURI, mSourceURI, mReason, mOA);
return NS_OK; return NS_OK;
} }
@ -624,11 +603,6 @@ Predictor::PredictNative(nsIURI* targetURI, nsIURI* sourceURI,
MOZ_DIAGNOSTIC_ASSERT(gNeckoChild); MOZ_DIAGNOSTIC_ASSERT(gNeckoChild);
PREDICTOR_LOG((" called on child process")); PREDICTOR_LOG((" called on child process"));
Maybe<ipc::URIParams> serTargetURI, serSourceURI;
SerializeURI(targetURI, serTargetURI);
SerializeURI(sourceURI, serSourceURI);
// If two different threads are predicting concurently, this will be // If two different threads are predicting concurently, this will be
// overwritten. Thankfully, we only use this in tests, which will // overwritten. Thankfully, we only use this in tests, which will
// overwrite mVerifier perhaps multiple times for each individual test; // overwrite mVerifier perhaps multiple times for each individual test;
@ -639,8 +613,8 @@ Predictor::PredictNative(nsIURI* targetURI, nsIURI* sourceURI,
mChildVerifier = verifier; mChildVerifier = verifier;
} }
PREDICTOR_LOG((" forwarding to parent process")); PREDICTOR_LOG((" forwarding to parent process"));
gNeckoChild->SendPredPredict(serTargetURI, serSourceURI, reason, gNeckoChild->SendPredPredict(targetURI, sourceURI, reason, originAttributes,
originAttributes, verifier); verifier);
return NS_OK; return NS_OK;
} }
@ -2206,15 +2180,14 @@ Predictor::OnPredictPrefetch(nsIURI* aURI, uint32_t httpStatus) {
return NS_OK; return NS_OK;
} }
ipc::URIParams serURI; MOZ_DIAGNOSTIC_ASSERT(aURI, "aURI must not be null");
SerializeURI(aURI, serURI);
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) { for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
PNeckoParent* neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent()); PNeckoParent* neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent());
if (!neckoParent) { if (!neckoParent) {
continue; continue;
} }
if (!neckoParent->SendPredOnPredictPrefetch(serURI, httpStatus)) { if (!neckoParent->SendPredOnPredictPrefetch(aURI, httpStatus)) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
} }
@ -2234,15 +2207,14 @@ Predictor::OnPredictPreconnect(nsIURI* aURI) {
return NS_OK; return NS_OK;
} }
ipc::URIParams serURI; MOZ_DIAGNOSTIC_ASSERT(aURI, "aURI must not be null");
SerializeURI(aURI, serURI);
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) { for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
PNeckoParent* neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent()); PNeckoParent* neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent());
if (!neckoParent) { if (!neckoParent) {
continue; continue;
} }
if (!neckoParent->SendPredOnPredictPreconnect(serURI)) { if (!neckoParent->SendPredOnPredictPreconnect(aURI)) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
} }
@ -2262,15 +2234,14 @@ Predictor::OnPredictDNS(nsIURI* aURI) {
return NS_OK; return NS_OK;
} }
ipc::URIParams serURI; MOZ_DIAGNOSTIC_ASSERT(aURI, "aURI must not be null");
SerializeURI(aURI, serURI);
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) { for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
PNeckoParent* neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent()); PNeckoParent* neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent());
if (!neckoParent) { if (!neckoParent) {
continue; continue;
} }
if (!neckoParent->SendPredOnPredictDNS(serURI)) { if (!neckoParent->SendPredOnPredictDNS(aURI)) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
} }

Просмотреть файл

@ -293,12 +293,13 @@ mozilla::ipc::IPCResult NeckoChild::RecvAsyncAuthPromptForNestedFrame(
/* Predictor Messages */ /* Predictor Messages */
mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictPrefetch( mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictPrefetch(
const URIParams& aURI, const uint32_t& aHttpStatus) { nsIURI* aURI, const uint32_t& aHttpStatus) {
MOZ_ASSERT(NS_IsMainThread(), MOZ_ASSERT(NS_IsMainThread(),
"PredictorChild::RecvOnPredictPrefetch " "PredictorChild::RecvOnPredictPrefetch "
"off main thread."); "off main thread.");
if (!aURI) {
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI); return IPC_FAIL(this, "aURI is null");
}
// Get the current predictor // Get the current predictor
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -306,43 +307,41 @@ mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictPrefetch(
do_GetService("@mozilla.org/network/predictor;1", &rv); do_GetService("@mozilla.org/network/predictor;1", &rv);
NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this)); NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this));
predictor->OnPredictPrefetch(uri, aHttpStatus); predictor->OnPredictPrefetch(aURI, aHttpStatus);
return IPC_OK(); return IPC_OK();
} }
mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictPreconnect( mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictPreconnect(nsIURI* aURI) {
const URIParams& aURI) {
MOZ_ASSERT(NS_IsMainThread(), MOZ_ASSERT(NS_IsMainThread(),
"PredictorChild::RecvOnPredictPreconnect " "PredictorChild::RecvOnPredictPreconnect "
"off main thread."); "off main thread.");
if (!aURI) {
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI); return IPC_FAIL(this, "aURI is null");
}
// Get the current predictor // Get the current predictor
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsINetworkPredictorVerifier> predictor = nsCOMPtr<nsINetworkPredictorVerifier> predictor =
do_GetService("@mozilla.org/network/predictor;1", &rv); do_GetService("@mozilla.org/network/predictor;1", &rv);
NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this)); NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this));
predictor->OnPredictPreconnect(uri); predictor->OnPredictPreconnect(aURI);
return IPC_OK(); return IPC_OK();
} }
mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictDNS( mozilla::ipc::IPCResult NeckoChild::RecvPredOnPredictDNS(nsIURI* aURI) {
const URIParams& aURI) {
MOZ_ASSERT(NS_IsMainThread(), MOZ_ASSERT(NS_IsMainThread(),
"PredictorChild::RecvOnPredictDNS off " "PredictorChild::RecvOnPredictDNS off "
"main thread."); "main thread.");
if (!aURI) {
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI); return IPC_FAIL(this, "aURI is null");
}
// Get the current predictor // Get the current predictor
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsINetworkPredictorVerifier> predictor = nsCOMPtr<nsINetworkPredictorVerifier> predictor =
do_GetService("@mozilla.org/network/predictor;1", &rv); do_GetService("@mozilla.org/network/predictor;1", &rv);
NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this)); NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this));
predictor->OnPredictDNS(uri); predictor->OnPredictDNS(aURI);
return IPC_OK(); return IPC_OK();
} }

Просмотреть файл

@ -76,9 +76,9 @@ class NeckoChild : public PNeckoChild {
/* Predictor Messsages */ /* Predictor Messsages */
mozilla::ipc::IPCResult RecvPredOnPredictPrefetch( mozilla::ipc::IPCResult RecvPredOnPredictPrefetch(
const URIParams& aURI, const uint32_t& aHttpStatus); nsIURI* aURI, const uint32_t& aHttpStatus);
mozilla::ipc::IPCResult RecvPredOnPredictPreconnect(const URIParams& aURI); mozilla::ipc::IPCResult RecvPredOnPredictPreconnect(nsIURI* aURI);
mozilla::ipc::IPCResult RecvPredOnPredictDNS(const URIParams& aURI); mozilla::ipc::IPCResult RecvPredOnPredictDNS(nsIURI* aURI);
mozilla::ipc::IPCResult RecvSpeculativeConnectRequest(); mozilla::ipc::IPCResult RecvSpeculativeConnectRequest();
mozilla::ipc::IPCResult RecvNetworkChangeNotification(nsCString const& type); mozilla::ipc::IPCResult RecvNetworkChangeNotification(nsCString const& type);

Просмотреть файл

@ -751,12 +751,8 @@ mozilla::ipc::IPCResult NeckoParent::RecvOnAuthCancelled(
/* Predictor Messages */ /* Predictor Messages */
mozilla::ipc::IPCResult NeckoParent::RecvPredPredict( mozilla::ipc::IPCResult NeckoParent::RecvPredPredict(
const Maybe<ipc::URIParams>& aTargetURI, nsIURI* aTargetURI, nsIURI* aSourceURI, const uint32_t& aReason,
const Maybe<ipc::URIParams>& aSourceURI, const uint32_t& aReason,
const OriginAttributes& aOriginAttributes, const bool& hasVerifier) { const OriginAttributes& aOriginAttributes, const bool& hasVerifier) {
nsCOMPtr<nsIURI> targetURI = DeserializeURI(aTargetURI);
nsCOMPtr<nsIURI> sourceURI = DeserializeURI(aSourceURI);
// Get the current predictor // Get the current predictor
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsINetworkPredictor> predictor = nsCOMPtr<nsINetworkPredictor> predictor =
@ -767,16 +763,17 @@ mozilla::ipc::IPCResult NeckoParent::RecvPredPredict(
if (hasVerifier) { if (hasVerifier) {
verifier = do_QueryInterface(predictor); verifier = do_QueryInterface(predictor);
} }
predictor->PredictNative(targetURI, sourceURI, aReason, aOriginAttributes, predictor->PredictNative(aTargetURI, aSourceURI, aReason, aOriginAttributes,
verifier); verifier);
return IPC_OK(); return IPC_OK();
} }
mozilla::ipc::IPCResult NeckoParent::RecvPredLearn( mozilla::ipc::IPCResult NeckoParent::RecvPredLearn(
const ipc::URIParams& aTargetURI, const Maybe<ipc::URIParams>& aSourceURI, nsIURI* aTargetURI, nsIURI* aSourceURI, const uint32_t& aReason,
const uint32_t& aReason, const OriginAttributes& aOriginAttributes) { const OriginAttributes& aOriginAttributes) {
nsCOMPtr<nsIURI> targetURI = DeserializeURI(aTargetURI); if (!aTargetURI) {
nsCOMPtr<nsIURI> sourceURI = DeserializeURI(aSourceURI); return IPC_FAIL(this, "aTargetURI is null");
}
// Get the current predictor // Get the current predictor
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -784,7 +781,7 @@ mozilla::ipc::IPCResult NeckoParent::RecvPredLearn(
do_GetService("@mozilla.org/network/predictor;1", &rv); do_GetService("@mozilla.org/network/predictor;1", &rv);
NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this)); NS_ENSURE_SUCCESS(rv, IPC_FAIL_NO_REASON(this));
predictor->LearnNative(targetURI, sourceURI, aReason, aOriginAttributes); predictor->LearnNative(aTargetURI, aSourceURI, aReason, aOriginAttributes);
return IPC_OK(); return IPC_OK();
} }

Просмотреть файл

@ -208,13 +208,12 @@ class NeckoParent : public PNeckoParent {
/* Predictor Messages */ /* Predictor Messages */
mozilla::ipc::IPCResult RecvPredPredict( mozilla::ipc::IPCResult RecvPredPredict(
const Maybe<ipc::URIParams>& aTargetURI, nsIURI* aTargetURI, nsIURI* aSourceURI,
const Maybe<ipc::URIParams>& aSourceURI,
const PredictorPredictReason& aReason, const PredictorPredictReason& aReason,
const OriginAttributes& aOriginAttributes, const bool& hasVerifier); const OriginAttributes& aOriginAttributes, const bool& hasVerifier);
mozilla::ipc::IPCResult RecvPredLearn( mozilla::ipc::IPCResult RecvPredLearn(
const ipc::URIParams& aTargetURI, const Maybe<ipc::URIParams>& aSourceURI, nsIURI* aTargetURI, nsIURI* aSourceURI,
const PredictorPredictReason& aReason, const PredictorPredictReason& aReason,
const OriginAttributes& aOriginAttributes); const OriginAttributes& aOriginAttributes);
mozilla::ipc::IPCResult RecvPredReset(); mozilla::ipc::IPCResult RecvPredReset();

Просмотреть файл

@ -95,10 +95,10 @@ parent:
async PWebSocketEventListener(uint64_t aInnerWindowID); async PWebSocketEventListener(uint64_t aInnerWindowID);
/* Predictor Methods */ /* Predictor Methods */
async PredPredict(URIParams? targetURI, URIParams? sourceURI, async PredPredict(nsIURI targetURI, nsIURI sourceURI,
uint32_t reason, OriginAttributes originAttributes, uint32_t reason, OriginAttributes originAttributes,
bool hasVerifier); bool hasVerifier);
async PredLearn(URIParams targetURI, URIParams? sourceURI, async PredLearn(nsIURI targetURI, nsIURI sourceURI,
uint32_t reason, OriginAttributes originAttributes); uint32_t reason, OriginAttributes originAttributes);
async PredReset(); async PredReset();
@ -166,9 +166,9 @@ child:
nsString realm, uint64_t callbackId); nsString realm, uint64_t callbackId);
/* Predictor Methods */ /* Predictor Methods */
async PredOnPredictPrefetch(URIParams uri, uint32_t httpStatus); async PredOnPredictPrefetch(nsIURI uri, uint32_t httpStatus);
async PredOnPredictPreconnect(URIParams uri); async PredOnPredictPreconnect(nsIURI uri);
async PredOnPredictDNS(URIParams uri); async PredOnPredictDNS(nsIURI uri);
async SpeculativeConnectRequest(); async SpeculativeConnectRequest();