Bug 908031 - Remove Geolocation::PendingRequest. r=jdm
authorMichael Harrison <mjh563@yahoo.co.uk>
Mon, 09 Sep 2013 08:57:37 -0400
changeset 146187 dbe8e0e7c25070c06b16e5383286dede0f06502b
parent 146186 ea578c504f72e2de356bfaaebea991792d689443
child 146188 66c4c1a9b69709466f10038b3cd73235c7ad8404
push id25244
push userryanvm@gmail.com
push dateMon, 09 Sep 2013 20:03:14 +0000
treeherdermozilla-central@f320b8c034bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs908031
milestone26.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 908031 - Remove Geolocation::PendingRequest. r=jdm
dom/src/geolocation/nsGeolocation.cpp
dom/src/geolocation/nsGeolocation.h
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -1006,36 +1006,21 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoGeolocation)
   NS_INTERFACE_MAP_ENTRY(nsIDOMGeoGeolocation)
   NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(Geolocation)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(Geolocation)
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(Geolocation)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Geolocation)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedPosition)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-  tmp->mPendingRequests.Clear();
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingCallbacks)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mWatchingCallbacks)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Geolocation)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCachedPosition)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-  for (uint32_t i = 0; i < tmp->mPendingRequests.Length(); ++i)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingRequests[i].request)
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingCallbacks)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWatchingCallbacks)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Geolocation)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_4(Geolocation,
+                                        mCachedPosition,
+                                        mPendingCallbacks,
+                                        mWatchingCallbacks,
+                                        mPendingRequests)
 
 Geolocation::Geolocation()
 : mLastWatchId(0)
 {
   SetIsDOMBinding();
 }
 
 Geolocation::~Geolocation()
@@ -1243,18 +1228,17 @@ Geolocation::GetCurrentPosition(GeoPosit
     return NS_OK;
   }
 
   if (!mOwner && !nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_FAILURE;
   }
 
   if (sGeoInitPending) {
-    PendingRequest req = { request, PendingRequest::GetCurrentPosition };
-    mPendingRequests.AppendElement(req);
+    mPendingRequests.AppendElement(request);
     return NS_OK;
   }
 
   return GetCurrentPositionReady(request);
 }
 
 nsresult
 Geolocation::GetCurrentPositionReady(nsGeolocationRequest* aRequest)
@@ -1337,18 +1321,17 @@ Geolocation::WatchPosition(GeoPositionCa
     return NS_OK;
   }
 
   if (!mOwner && !nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_FAILURE;
   }
 
   if (sGeoInitPending) {
-    PendingRequest req = { request, PendingRequest::WatchPosition };
-    mPendingRequests.AppendElement(req);
+    mPendingRequests.AppendElement(request);
     return NS_OK;
   }
 
   return WatchPositionReady(request);
 }
 
 nsresult
 Geolocation::WatchPositionReady(nsGeolocationRequest* aRequest)
@@ -1382,39 +1365,35 @@ Geolocation::ClearWatch(int32_t aWatchId
       RemoveRequest(mWatchingCallbacks[i]);
       break;
     }
   }
 
   // make sure we also search through the pending requests lists for
   // watches to clear...
   for (uint32_t i = 0, length = mPendingRequests.Length(); i < length; ++i) {
-    if ((mPendingRequests[i].type == PendingRequest::WatchPosition) &&
-        (mPendingRequests[i].request->WatchId() == aWatchId)) {
-      mPendingRequests[i].request->Shutdown();
+    if (mPendingRequests[i]->IsWatch() &&
+        (mPendingRequests[i]->WatchId() == aWatchId)) {
+      mPendingRequests[i]->Shutdown();
       mPendingRequests.RemoveElementAt(i);
       break;
     }
   }
 
   return NS_OK;
 }
 
 void
 Geolocation::ServiceReady()
 {
   for (uint32_t length = mPendingRequests.Length(); length > 0; --length) {
-    switch (mPendingRequests[0].type) {
-      case PendingRequest::GetCurrentPosition:
-        GetCurrentPositionReady(mPendingRequests[0].request);
-        break;
-
-      case PendingRequest::WatchPosition:
-        WatchPositionReady(mPendingRequests[0].request);
-        break;
+    if (mPendingRequests[0]->IsWatch()) {
+      WatchPositionReady(mPendingRequests[0]);
+    } else {
+      GetCurrentPositionReady(mPendingRequests[0]);
     }
 
     mPendingRequests.RemoveElementAt(0);
   }
 }
 
 bool
 Geolocation::WindowOwnerStillExists()
--- a/dom/src/geolocation/nsGeolocation.h
+++ b/dom/src/geolocation/nsGeolocation.h
@@ -204,28 +204,18 @@ private:
   nsRefPtr<nsGeolocationService> mService;
 
   // cached Position wrapper
   nsRefPtr<Position> mCachedPosition;
 
   // Watch ID
   uint32_t mLastWatchId;
 
-  // Pending requests are used when the service is not ready:
-  class PendingRequest
-  {
-  public:
-    nsRefPtr<nsGeolocationRequest> request;
-    enum {
-      GetCurrentPosition,
-      WatchPosition
-    } type;
-  };
-
-  nsTArray<PendingRequest> mPendingRequests;
+  // Pending requests are used when the service is not ready
+  nsTArray<nsRefPtr<nsGeolocationRequest> > mPendingRequests;
 };
 
 class PositionError MOZ_FINAL : public nsIDOMGeoPositionError,
                                 public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PositionError)