Bug 997166 - Avoid starting up the seer service if we don't have to. r=mcmanus
authorNicholas Hurley <hurley@todesschaf.org>
Thu, 17 Apr 2014 10:41:17 -0700
changeset 179474 c0d6c8a242e55d86f997e915fe64484ad2a083d4
parent 179473 7ee8d408e364def75e316ba70c09c0c63e32efe4
child 179475 caf503c905c024715145b014bf02245d117b357f
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmcmanus
bugs997166
milestone31.0a1
Bug 997166 - Avoid starting up the seer service if we don't have to. r=mcmanus
netwerk/base/src/Seer.cpp
--- a/netwerk/base/src/Seer.cpp
+++ b/netwerk/base/src/Seer.cpp
@@ -2731,38 +2731,50 @@ EnsureGlobalSeer(nsINetworkSeer **aSeer)
   NS_IF_ADDREF(*aSeer = seer);
   return NS_OK;
 }
 
 nsresult
 SeerPredict(nsIURI *targetURI, nsIURI *sourceURI, SeerPredictReason reason,
             nsILoadContext *loadContext, nsINetworkSeerVerifier *verifier)
 {
+  if (!IsNullOrHttp(targetURI) || !IsNullOrHttp(sourceURI)) {
+    return NS_OK;
+  }
+
   nsCOMPtr<nsINetworkSeer> seer;
   nsresult rv = EnsureGlobalSeer(getter_AddRefs(seer));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return seer->Predict(targetURI, sourceURI, reason, loadContext, verifier);
 }
 
 nsresult
 SeerLearn(nsIURI *targetURI, nsIURI *sourceURI, SeerLearnReason reason,
           nsILoadContext *loadContext)
 {
+  if (!IsNullOrHttp(targetURI) || !IsNullOrHttp(sourceURI)) {
+    return NS_OK;
+  }
+
   nsCOMPtr<nsINetworkSeer> seer;
   nsresult rv = EnsureGlobalSeer(getter_AddRefs(seer));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return seer->Learn(targetURI, sourceURI, reason, loadContext);
 }
 
 nsresult
 SeerLearn(nsIURI *targetURI, nsIURI *sourceURI, SeerLearnReason reason,
           nsILoadGroup *loadGroup)
 {
+  if (!IsNullOrHttp(targetURI) || !IsNullOrHttp(sourceURI)) {
+    return NS_OK;
+  }
+
   nsCOMPtr<nsINetworkSeer> seer;
   nsresult rv = EnsureGlobalSeer(getter_AddRefs(seer));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoadContext> loadContext;
 
   if (loadGroup) {
     nsCOMPtr<nsIInterfaceRequestor> callbacks;
@@ -2774,16 +2786,20 @@ SeerLearn(nsIURI *targetURI, nsIURI *sou
 
   return seer->Learn(targetURI, sourceURI, reason, loadContext);
 }
 
 nsresult
 SeerLearn(nsIURI *targetURI, nsIURI *sourceURI, SeerLearnReason reason,
           nsIDocument *document)
 {
+  if (!IsNullOrHttp(targetURI) || !IsNullOrHttp(sourceURI)) {
+    return NS_OK;
+  }
+
   nsCOMPtr<nsINetworkSeer> seer;
   nsresult rv = EnsureGlobalSeer(getter_AddRefs(seer));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoadContext> loadContext;
 
   if (document) {
     loadContext = document->GetLoadContext();
@@ -2791,30 +2807,34 @@ SeerLearn(nsIURI *targetURI, nsIURI *sou
 
   return seer->Learn(targetURI, sourceURI, reason, loadContext);
 }
 
 nsresult
 SeerLearnRedirect(nsIURI *targetURI, nsIChannel *channel,
                   nsILoadContext *loadContext)
 {
-  nsCOMPtr<nsINetworkSeer> seer;
-  nsresult rv = EnsureGlobalSeer(getter_AddRefs(seer));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsIURI> sourceURI;
-  rv = channel->GetOriginalURI(getter_AddRefs(sourceURI));
+  nsresult rv = channel->GetOriginalURI(getter_AddRefs(sourceURI));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool sameUri;
   rv = targetURI->Equals(sourceURI, &sameUri);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (sameUri) {
     return NS_OK;
   }
 
+  if (!IsNullOrHttp(targetURI) || !IsNullOrHttp(sourceURI)) {
+    return NS_OK;
+  }
+
+  nsCOMPtr<nsINetworkSeer> seer;
+  rv = EnsureGlobalSeer(getter_AddRefs(seer));
+  NS_ENSURE_SUCCESS(rv, rv);
+
   return seer->Learn(targetURI, sourceURI,
                      nsINetworkSeer::LEARN_LOAD_REDIRECT, loadContext);
 }
 
 } // ::mozilla::net
 } // ::mozilla