Bug 874069 - Use one geolocation instance object per ContentParent. r=jdm
☠☠ backed out by b2c600be7e90 ☠ ☠
authorManu Chaudhary <manu_talkin@yahoo.com>
Wed, 05 Jun 2013 17:55:34 -0400
changeset 134162 201d347cda5dd0a4e3f72652e569e62ed19740bd
parent 134161 44465f14b9826ac1e6f9006987df7fd5200e4713
child 134163 8382b3aa1bf207ad7fb544f18e163912eba4b238
push id29076
push userryanvm@gmail.com
push dateWed, 05 Jun 2013 21:55:25 +0000
treeherdermozilla-inbound@8382b3aa1bf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs874069
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 874069 - Use one geolocation instance object per ContentParent. r=jdm
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1047,16 +1047,18 @@ ContentParent::ContentParent(mozIApplica
     , mIsDestroyed(false)
     , mSendPermissionUpdates(false)
     , mIsForBrowser(aIsForBrowser)
 {
     // No more than one of !!aApp, aIsForBrowser, and aIsForPreallocated should
     // be true.
     MOZ_ASSERT(!!aApp + aIsForBrowser + aIsForPreallocated <= 1);
 
+    mGeo = do_CreateInstance("@mozilla.org/geolocation;1");
+
     // Insert ourselves into the global linked list of ContentParent objects.
     sContentParents.insertBack(this);
 
     if (aApp) {
         aApp->GetManifestURL(mAppManifestURL);
         aApp->GetName(mAppName);
     } else if (aIsForPreallocated) {
         mAppManifestURL = MAGIC_PREALLOCATED_APP_MANIFEST_URL;
@@ -2363,28 +2365,27 @@ ContentParent::RecvFilePathUpdateNotify(
     if (!obs) {
         return false;
     }
     obs->NotifyObservers(dsf, "file-watcher-update",
                          NS_ConvertASCIItoUTF16(aReason).get());
     return true;
 }
 
-static int32_t
-AddGeolocationListener(nsIDOMGeoPositionCallback* watcher, bool highAccuracy)
+int32_t
+ContentParent::AddGeolocationListener(bool highAccuracy)
 {
-  nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
-  if (!geo) {
+  if (!mGeo) {
     return -1;
   }
 
   GeoPositionOptions* options = new GeoPositionOptions();
   options->enableHighAccuracy = highAccuracy;
   int32_t retval = 1;
-  geo->WatchPosition(watcher, nullptr, options, &retval);
+  mGeo->WatchPosition(this, nullptr, options, &retval);
   return retval;
 }
 
 bool
 ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
                                           const bool& aHighAccuracy)
 {
 #ifdef MOZ_PERMISSIONS
@@ -2432,42 +2433,41 @@ ContentParent::RecvAddGeolocationListene
       return true;
     }
   }
 #endif
 
   // To ensure no geolocation updates are skipped, we always force the
   // creation of a new listener.
   RecvRemoveGeolocationListener();
-  mGeolocationWatchID = AddGeolocationListener(this, aHighAccuracy);
+  mGeolocationWatchID = AddGeolocationListener(aHighAccuracy);
   return true;
 }
 
 bool
 ContentParent::RecvRemoveGeolocationListener()
 {
   if (mGeolocationWatchID != -1) {
-    nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
-    if (!geo) {
+    if (!mGeo) {
       return true;
     }
-    geo->ClearWatch(mGeolocationWatchID);
+    mGeo->ClearWatch(mGeolocationWatchID);
     mGeolocationWatchID = -1;
   }
   return true;
 }
 
 bool
 ContentParent::RecvSetGeolocationHigherAccuracy(const bool& aEnable)
 {
   // This should never be called without a listener already present,
   // so this check allows us to forgo securing privileges.
   if (mGeolocationWatchID != -1) {
     RecvRemoveGeolocationListener();
-    mGeolocationWatchID = AddGeolocationListener(this, aEnable);
+    mGeolocationWatchID = AddGeolocationListener(aEnable);
   }
   return true;
 }
 
 NS_IMETHODIMP
 ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
 {
   unused << SendGeolocationUpdate(GeoPosition(postion));
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -21,25 +21,27 @@
 #include "nsFrameMessageManager.h"
 #include "nsIObserver.h"
 #include "nsIThreadInternal.h"
 #include "nsNetUtil.h"
 #include "nsIPermissionManager.h"
 #include "nsIDOMGeoPositionCallback.h"
 #include "nsIMemoryReporter.h"
 #include "nsCOMArray.h"
+#include "nsCOMPtr.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "PermissionMessageUtils.h"
 
 #define CHILD_PROCESS_SHUTDOWN_MESSAGE NS_LITERAL_STRING("child-process-shutdown")
 
 class mozIApplication;
 class nsConsoleService;
 class nsIDOMBlob;
+class nsIDOMGeoGeolocation;
 
 namespace mozilla {
 
 namespace ipc {
 class OptionalURIParams;
 class URIParams;
 class TestShellParent;
 } // namespace ipc
@@ -170,20 +172,22 @@ protected:
     void OnChannelConnected(int32_t pid) MOZ_OVERRIDE;
     virtual void ActorDestroy(ActorDestroyReason why);
 
 private:
     static nsDataHashtable<nsStringHashKey, ContentParent*> *sAppContentParents;
     static nsTArray<ContentParent*>* sNonAppContentParents;
     static nsTArray<ContentParent*>* sPrivateContent;
     static LinkedList<ContentParent> sContentParents;
+    nsCOMPtr<nsIDOMGeoGeolocation> mGeo;
 
     static void JoinProcessesIOThread(const nsTArray<ContentParent*>* aProcesses,
                                       Monitor* aMonitor, bool* aDone);
 
+    int32_t AddGeolocationListener(bool highAccuracy);
     // Take the preallocated process and transform it into a "real" app process,
     // for the specified manifest URL.  If there is no preallocated process (or
     // if it's dead), this returns false.
     static already_AddRefed<ContentParent>
     MaybeTakePreallocatedAppProcess(const nsAString& aAppManifestURL,
                                     ChildPrivileges aPrivs,
                                     hal::ProcessPriority aInitialPriority);