Backed out changeset 6f507c077b24 (bug 1121265) for OS X static analysis build Bustage on a CLOSED TREE
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Tue, 27 Jan 2015 09:18:03 +0100
changeset 239312 e28ef69841089b3a0498eec183ffdf68758ce23a
parent 239311 80b882dbd0ccf5c519cd0593d58f19bcd8f089e6
child 239313 52661fcbc1d87450a571cb580a8c2ce334b59707
push id497
push usermleibovic@mozilla.com
push dateWed, 28 Jan 2015 16:43:37 +0000
bugs1121265
milestone38.0a1
backs out6f507c077b24c45a283c500aea3b355c32d56e75
Backed out changeset 6f507c077b24 (bug 1121265) for OS X static analysis build Bustage on a CLOSED TREE
dom/system/mac/CoreLocationLocationProvider.h
dom/system/mac/CoreLocationLocationProvider.mm
--- a/dom/system/mac/CoreLocationLocationProvider.h
+++ b/dom/system/mac/CoreLocationLocationProvider.h
@@ -27,31 +27,14 @@ class CoreLocationLocationProvider
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIGEOLOCATIONPROVIDER
 
   CoreLocationLocationProvider();
   void NotifyError(uint16_t aErrorCode);
   void Update(nsIDOMGeoPosition* aSomewhere);
-  void CreateMLSFallbackProvider();
-  void CancelMLSFallbackProvider();
-
 private:
   virtual ~CoreLocationLocationProvider() {};
 
   CoreLocationObjects* mCLObjects;
   nsCOMPtr<nsIGeolocationUpdate> mCallback;
-  nsCOMPtr<nsIGeolocationProvider> mMLSFallbackProvider;
-
-  class MLSUpdate : public nsIGeolocationUpdate
-  {
-  public:
-    NS_DECL_ISUPPORTS
-    NS_DECL_NSIGEOLOCATIONUPDATE
-
-    MLSUpdate(CoreLocationLocationProvider& parentProvider);
-
-  private:
-    CoreLocationLocationProvider& mParentLocationProvider;
-    virtual ~MLSUpdate() {}
-  };
 };
--- a/dom/system/mac/CoreLocationLocationProvider.mm
+++ b/dom/system/mac/CoreLocationLocationProvider.mm
@@ -26,148 +26,80 @@
 using namespace mozilla;
 
 static const CLLocationAccuracy kHIGH_ACCURACY = kCLLocationAccuracyBest;
 static const CLLocationAccuracy kDEFAULT_ACCURACY = kCLLocationAccuracyNearestTenMeters;
 
 @interface LocationDelegate : NSObject <CLLocationManagerDelegate>
 {
   CoreLocationLocationProvider* mProvider;
-  NSTimer* mHandoffTimer;
 }
 
 - (id)init:(CoreLocationLocationProvider*)aProvider;
 - (void)locationManager:(CLLocationManager*)aManager
   didFailWithError:(NSError *)aError;
-- (void)locationManager:(CLLocationManager*)aManager didUpdateLocations:(NSArray*)locations;
 
+/* XXX (ggp) didUpdateToLocation is supposedly deprecated in favor of
+ * locationManager:didUpdateLocations, which is undocumented and didn't seem to
+ * work for me. This should be changed in the future, though.
+ */
+- (void)locationManager:(CLLocationManager*)aManager
+  didUpdateToLocation:(CLLocation *)aNewLocation
+  fromLocation:(CLLocation *)aOldLocation;
 @end
 
 @implementation LocationDelegate
 - (id) init:(CoreLocationLocationProvider*) aProvider
 {
   if (self = [super init]) {
     mProvider = aProvider;
   }
 
   return self;
 }
 
-- (void)shutdownHandoffTimer
-{
-  if (!mHandoffTimer) {
-    return;
-  }
-
-  [mHandoffTimer invalidate];
-  mHandoffTimer = nil;
-}
-
-- (void)handoffToGeoIPProvider
-{
-  // Single-shot timers are invalid once executed and are released by the run loop
-  mHandoffTimer = nil;
-
-  mProvider->CreateMLSFallbackProvider();
-}
-
 - (void)locationManager:(CLLocationManager*)aManager
   didFailWithError:(NSError *)aError
 {
   nsCOMPtr<nsIConsoleService> console =
     do_GetService(NS_CONSOLESERVICE_CONTRACTID);
 
   NS_ENSURE_TRUE_VOID(console);
 
   NSString* message =
     [@"Failed to acquire position: " stringByAppendingString: [aError localizedDescription]];
 
   console->LogStringMessage(NS_ConvertUTF8toUTF16([message UTF8String]).get());
 
+  uint16_t err = nsIDOMGeoPositionError::POSITION_UNAVAILABLE;
   if ([aError code] == kCLErrorDenied) {
-    mProvider->NotifyError(nsIDOMGeoPositionError::PERMISSION_DENIED);
-    return;
+    err = nsIDOMGeoPositionError::PERMISSION_DENIED;
   }
 
-  if (!mHandoffTimer) {
-    // The CL provider does not fallback to GeoIP, so use NetworkGeolocationProvider for this.
-    // The concept here is: on error, hand off geolocation to MLS, which will then report
-    // back a location or error. We can't call this with no delay however, as this method
-    // is called with an error code of 0 in both failed geolocation cases, and also when
-    // geolocation is not immediately available.
-    // The 2 sec delay is arbitrarily large enough that CL has a reasonable head start and
-    // if it is likely to succeed, it should complete before the MLS provider.
-    // Take note that in locationManager:didUpdateLocations: the handoff to MLS is stopped.
-    mHandoffTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
-                                                     target:self
-                                                   selector:@selector(handoffToGeoIPProvider)
-                                                   userInfo:nil
-                                                    repeats:NO];
-  }
+  mProvider->NotifyError(err);
 }
 
-- (void)locationManager:(CLLocationManager*)aManager didUpdateLocations:(NSArray*)aLocations
+- (void)locationManager:(CLLocationManager*)aManager
+  didUpdateToLocation:(CLLocation *)aNewLocation
+  fromLocation:(CLLocation *)aOldLocation
 {
-  if (aLocations.count < 1) {
-    return;
-  }
-
-  [self shutdownHandoffTimer];
-  mProvider->CancelMLSFallbackProvider();
-
-  CLLocation* location = [aLocations objectAtIndex:0];
-
   nsCOMPtr<nsIDOMGeoPosition> geoPosition =
-    new nsGeoPosition(location.coordinate.latitude,
-                      location.coordinate.longitude,
-                      location.altitude,
-                      location.horizontalAccuracy,
-                      location.verticalAccuracy,
-                      location.course,
-                      location.speed,
+    new nsGeoPosition(aNewLocation.coordinate.latitude,
+                      aNewLocation.coordinate.longitude,
+                      aNewLocation.altitude,
+                      aNewLocation.horizontalAccuracy,
+                      aNewLocation.verticalAccuracy,
+                      aNewLocation.course,
+                      aNewLocation.speed,
                       PR_Now());
 
   mProvider->Update(geoPosition);
 }
 @end
 
-NS_IMPL_ISUPPORTS(CoreLocationLocationProvider::MLSUpdate, nsIGeolocationUpdate);
-
-CoreLocationLocationProvider::MLSUpdate::MLSUpdate(CoreLocationLocationProvider& parentProvider)
-  : mParentLocationProvider(parentProvider)
-{
-}
-
-NS_IMETHODIMP
-CoreLocationLocationProvider::MLSUpdate::Update(nsIDOMGeoPosition *position)
-{
-  nsCOMPtr<nsIDOMGeoPositionCoords> coords;
-  position->GetCoords(getter_AddRefs(coords));
-  if (!coords) {
-    return NS_ERROR_FAILURE;
-  }
-
-  mParentLocationProvider.Update(position);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CoreLocationLocationProvider::MLSUpdate::LocationUpdatePending()
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CoreLocationLocationProvider::MLSUpdate::NotifyError(uint16_t error)
-{
-  mParentLocationProvider.NotifyError(error);
-  return NS_OK;
-}
-
-
 class CoreLocationObjects {
 public:
   NS_METHOD Init(CoreLocationLocationProvider* aProvider) {
     mLocationManager = [[CLLocationManager alloc] init];
     NS_ENSURE_TRUE(mLocationManager, NS_ERROR_NOT_AVAILABLE);
 
     mLocationDelegate = [[LocationDelegate alloc] init:aProvider];
     NS_ENSURE_TRUE(mLocationDelegate, NS_ERROR_NOT_AVAILABLE);
@@ -190,17 +122,17 @@ public:
 
   LocationDelegate* mLocationDelegate;
   CLLocationManager* mLocationManager;
 };
 
 NS_IMPL_ISUPPORTS(CoreLocationLocationProvider, nsIGeolocationProvider)
 
 CoreLocationLocationProvider::CoreLocationLocationProvider()
-  : mCLObjects(nullptr), mMLSFallbackProvider(nullptr)
+  : mCLObjects(nullptr)
 {
 }
 
 NS_IMETHODIMP
 CoreLocationLocationProvider::Startup()
 {
   if (!mCLObjects) {
     nsAutoPtr<CoreLocationObjects> clObjs(new CoreLocationObjects());
@@ -226,27 +158,20 @@ CoreLocationLocationProvider::Watch(nsIG
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CoreLocationLocationProvider::Shutdown()
 {
   NS_ENSURE_STATE(mCLObjects);
 
-  [mCLObjects->mLocationDelegate shutdownHandoffTimer];
   [mCLObjects->mLocationManager stopUpdatingLocation];
 
   delete mCLObjects;
   mCLObjects = nullptr;
-
-  if (mMLSFallbackProvider) {
-    mMLSFallbackProvider->Shutdown();
-    mMLSFallbackProvider = nullptr;
-  }
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CoreLocationLocationProvider::SetHighAccuracy(bool aEnable)
 {
   NS_ENSURE_STATE(mCLObjects);
 
@@ -264,35 +189,8 @@ CoreLocationLocationProvider::Update(nsI
   }
 }
 
 void
 CoreLocationLocationProvider::NotifyError(uint16_t aErrorCode)
 {
   mCallback->NotifyError(aErrorCode);
 }
-
-void
-CoreLocationLocationProvider::CreateMLSFallbackProvider()
-{
-  if (mMLSFallbackProvider) {
-    return;
-  }
-
-  mMLSFallbackProvider = do_CreateInstance("@mozilla.org/geolocation/mls-provider;1");
-  if (mMLSFallbackProvider) {
-    nsresult rv = mMLSFallbackProvider->Startup();
-    if (NS_SUCCEEDED(rv)) {
-      mMLSFallbackProvider->Watch(new CoreLocationLocationProvider::MLSUpdate(*this));
-    }
-  }
-}
-
-void
-CoreLocationLocationProvider::CancelMLSFallbackProvider()
-{
-  if (!mMLSFallbackProvider) {
-    return;
-  }
-
-  mMLSFallbackProvider->Shutdown();
-  mMLSFallbackProvider = nullptr;
-}