Bug 1348460 - make predictor::learn async. r=Ehsan
Serializing and sending IPC messages takes a lot of time, and it gets in the way of image loading. Making this functionality async gets out of the way of image loading (among other things). The test has been changed to pump the main thread after calling predictor.learn so the multiprocess version can actually run to completion. This isn't strictly necessary in the single process version, but it makes the code changes (which are already pretty invasive) simpler. MozReview-Commit-ID: 7jvhomlygbf
This commit is contained in:
@@ -691,6 +691,47 @@ private:
|
||||
nsCOMPtr<nsIFile> mDBFile;
|
||||
};
|
||||
|
||||
class PredictorLearnRunnable final : public Runnable {
|
||||
public:
|
||||
PredictorLearnRunnable(nsIURI *targetURI, nsIURI *sourceURI,
|
||||
PredictorLearnReason reason, const OriginAttributes &oa)
|
||||
: mTargetURI(targetURI)
|
||||
, mSourceURI(sourceURI)
|
||||
, mReason(reason)
|
||||
, mOA(oa)
|
||||
{ }
|
||||
|
||||
~PredictorLearnRunnable() { }
|
||||
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
if (!gNeckoChild) {
|
||||
// This may have gone away between when this runnable was dispatched and
|
||||
// when it actually runs, so let's be safe here, even though we asserted
|
||||
// earlier.
|
||||
PREDICTOR_LOG(("predictor::learn (async) gNeckoChild went away"));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ipc::URIParams serTargetURI;
|
||||
SerializeURI(mTargetURI, serTargetURI);
|
||||
|
||||
ipc::OptionalURIParams serSourceURI;
|
||||
SerializeURI(mSourceURI, serSourceURI);
|
||||
|
||||
PREDICTOR_LOG(("predictor::learn (async) forwarding to parent"));
|
||||
gNeckoChild->SendPredLearn(serTargetURI, serSourceURI, mReason, mOA);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIURI> mTargetURI;
|
||||
nsCOMPtr<nsIURI> mSourceURI;
|
||||
PredictorLearnReason mReason;
|
||||
const OriginAttributes mOA;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void
|
||||
@@ -1506,15 +1547,10 @@ Predictor::LearnNative(nsIURI *targetURI, nsIURI *sourceURI,
|
||||
|
||||
PREDICTOR_LOG((" called on child process"));
|
||||
|
||||
ipc::URIParams serTargetURI;
|
||||
SerializeURI(targetURI, serTargetURI);
|
||||
RefPtr<PredictorLearnRunnable> runnable = new PredictorLearnRunnable(
|
||||
targetURI, sourceURI, reason, originAttributes);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
|
||||
ipc::OptionalURIParams serSourceURI;
|
||||
SerializeURI(sourceURI, serSourceURI);
|
||||
|
||||
PREDICTOR_LOG((" forwarding to parent"));
|
||||
gNeckoChild->SendPredLearn(serTargetURI, serSourceURI, reason,
|
||||
originAttributes);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user