Bug 1033274 - SendLocation is not considering the PositionOptions.maximumAge. r=kanru
authorGarvan Keeley <garvankeeley@gmail.com>
Thu, 21 Aug 2014 15:26:00 -0400
changeset 202069 87f9cc55a56917349f791255dbd91dbf5a9be34f
parent 202068 cd0b358f86fc536aea6143e7565306a9a479c232
child 202070 82acd6f569ec652a09b390c4a82a761fcab3b91e
push id27390
push usercbook@mozilla.com
push dateThu, 28 Aug 2014 11:07:34 +0000
treeherdermozilla-central@2a15dc07ddaa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskanru
bugs1033274
milestone34.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 1033274 - SendLocation is not considering the PositionOptions.maximumAge. r=kanru The first patch for this bug adds a cached location within the GPS provider, which may get used as part of a watch request. If the watch request has a maximumAge option specified, then SendLocation should only send locations to the DOM that meet this condition.
dom/src/geolocation/nsGeolocation.cpp
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -491,16 +491,27 @@ nsGeolocationRequest::StopTimeoutTimer()
 void
 nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
 {
   if (mShutdown) {
     // Ignore SendLocationEvents issued before we were cleared.
     return;
   }
 
+  if (mOptions && mOptions->mMaximumAge > 0) {
+    DOMTimeStamp positionTime_ms;
+    aPosition->GetTimestamp(&positionTime_ms);
+    const uint32_t maximumAge_ms = mOptions->mMaximumAge;
+    const bool isTooOld =
+        DOMTimeStamp(PR_Now() / PR_USEC_PER_MSEC - maximumAge_ms) > positionTime_ms;
+    if (isTooOld) {
+      return;
+    }
+  }
+
   nsRefPtr<Position> wrapped;
 
   if (aPosition) {
     nsCOMPtr<nsIDOMGeoPositionCoords> coords;
     aPosition->GetCoords(getter_AddRefs(coords));
     if (coords) {
       wrapped = new Position(ToSupports(mLocator), aPosition);
     }