Bug 1237831 - Update GonkGPSGeolocationProvider.cpp to use B2G-style. r=jst
authorArthur Edelstein <arthuredelstein@gmail.com>
Mon, 04 Jan 2016 09:46:17 -0800
changeset 282304 7cfbfa3139b409532c1066682546d7fead2d4a65
parent 282303 d8329476b632ddbf9ed7124ef305ee4c075b106e
child 282305 2abc599b04648bb5de1473e5629270a539b0e1e3
push id29955
push userkwierso@gmail.com
push dateFri, 29 Jan 2016 21:12:10 +0000
treeherdermozilla-central@08eddf3af531 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs1237831
milestone47.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 1237831 - Update GonkGPSGeolocationProvider.cpp to use B2G-style. r=jst
dom/system/gonk/GonkGPSGeolocationProvider.cpp
--- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp
@@ -51,16 +51,23 @@
 #endif
 
 #ifdef AGPS_TYPE_INVALID
 #define AGPS_HAVE_DUAL_APN
 #endif
 
 #define FLUSH_AIDE_DATA 0
 
+#undef LOG
+#undef ERR
+#undef DBG
+#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO,  "GonkGPSGeolocationProvider", ## args)
+#define ERR(args...)  __android_log_print(ANDROID_LOG_ERROR, "GonkGPSGeolocationProvider", ## args)
+#define DBG(args...)  __android_log_print(ANDROID_LOG_DEBUG, "GonkGPSGeolocationProvider" , ## args)
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static const int kDefaultPeriod = 1000; // ms
 static bool gDebug_isLoggingEnabled = false;
 static bool gDebug_isGPSLocationIgnored = false;
 #ifdef MOZ_B2G_RIL
 static const char* kNetworkConnStateChangedTopic = "network-connection-state-changed";
@@ -134,20 +141,20 @@ GonkGPSGeolocationProvider::LocationCall
                                                         PR_Now() / PR_USEC_PER_MSEC);
   // Note above: Can't use location->timestamp as the time from the satellite is a
   // minimum of 16 secs old (see http://leapsecond.com/java/gpsclock.htm).
   // All code from this point on expects the gps location to be timestamped with the
   // current time, most notably: the geolocation service which respects maximumAge
   // set in the DOM JS.
 
   if (gDebug_isLoggingEnabled) {
-    nsContentUtils::LogMessageToConsole("geo: GPS got a fix (%f, %f). accuracy: %f",
-                                        location->latitude,
-                                        location->longitude,
-                                        location->accuracy);
+    DBG("geo: GPS got a fix (%f, %f). accuracy: %f",
+        location->latitude,
+        location->longitude,
+        location->accuracy);
   }
 
   RefPtr<UpdateLocationEvent> event = new UpdateLocationEvent(somewhere);
   NS_DispatchToMainThread(event);
 
 #ifdef MOZ_B2G_RIL
   MozStumble(somewhere);
 #endif
@@ -194,17 +201,17 @@ GonkGPSGeolocationProvider::StatusCallba
       msgStream = "geo: GPS_STATUS_ENGINE_OFF\n";
       NS_DispatchToMainThread(new NotifyObserversGPSTask( MOZ_UTF16("GPSShutdown")));
       break;
     default:
       msgStream = "geo: Unknown GPS status\n";
       break;
   }
   if (gDebug_isLoggingEnabled){
-    nsContentUtils::LogMessageToConsole(msgStream);
+    DBG("%s", msgStream);
   }
 }
 
 void
 GonkGPSGeolocationProvider::SvStatusCallback(GpsSvStatus* sv_info)
 {
   if (gDebug_isLoggingEnabled) {
     static int numSvs = 0;
@@ -235,35 +242,34 @@ GonkGPSGeolocationProvider::SvStatusCall
     }
 
     // Log the message only if the the status changed.
     if (sv_info->num_svs != numSvs ||
         svAlmanacCount != numAlmanac ||
         svEphemerisCount != numEphemeris ||
         svUsedCount != numUsedInFix) {
 
-      nsContentUtils::LogMessageToConsole(
+      LOG(
         "geo: Number of SVs have (visibility, almanac, ephemeris): (%d, %d, %d)."
         "  %d of these SVs were used in fix.\n",
         sv_info->num_svs, svAlmanacCount, svEphemerisCount, svUsedCount);
 
       numSvs = sv_info->num_svs;
       numAlmanac = svAlmanacCount;
       numEphemeris = svEphemerisCount;
       numUsedInFix = svUsedCount;
     }
   }
 }
 
 void
 GonkGPSGeolocationProvider::NmeaCallback(GpsUtcTime timestamp, const char* nmea, int length)
 {
   if (gDebug_isLoggingEnabled) {
-    nsContentUtils::LogMessageToConsole("geo: NMEA: timestamp:\t%lld, length: %d, %s",
-                                        timestamp, length, nmea);
+    DBG("NMEA: timestamp:\t%lld, length: %d, %s", timestamp, length, nmea);
   }
 }
 
 void
 GonkGPSGeolocationProvider::SetCapabilitiesCallback(uint32_t capabilities)
 {
   class UpdateCapabilitiesEvent : public nsRunnable {
   public:
@@ -527,25 +533,23 @@ GonkGPSGeolocationProvider::RequestSetti
   if (!ss) {
     MOZ_ASSERT(ss);
     return;
   }
 
   nsCOMPtr<nsISettingsServiceLock> lock;
   nsresult rv = ss->CreateLock(nullptr, getter_AddRefs(lock));
   if (NS_FAILED(rv)) {
-    nsContentUtils::LogMessageToConsole(
-      "geo: error while createLock setting '%s': %d\n", aKey, rv);
+    ERR("error while createLock setting '%s': %d\n", aKey, rv);
     return;
   }
 
   rv = lock->Get(aKey, this);
   if (NS_FAILED(rv)) {
-    nsContentUtils::LogMessageToConsole(
-      "geo: error while get setting '%s': %d\n", aKey, rv);
+    ERR("error while get setting '%s': %d\n", aKey, rv);
     return;
   }
 }
 
 #ifdef MOZ_B2G_RIL
 void
 GonkGPSGeolocationProvider::RequestDataConnection()
 {
@@ -634,18 +638,18 @@ ConvertToGpsRefLocationType(const nsAStr
 
   for (auto type: UMTS_TYPES) {
     if (aConnectionType.EqualsASCII(type)) {
       return AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
     }
   }
 
   if (gDebug_isLoggingEnabled) {
-    nsContentUtils::LogMessageToConsole("geo: Unsupported connection type %s\n",
-                                        NS_ConvertUTF16toUTF8(aConnectionType).get());
+    DBG("geo: Unsupported connection type %s\n",
+        NS_ConvertUTF16toUTF8(aConnectionType).get());
   }
   return AGPS_REF_LOCATION_TYPE_GSM_CELLID;
 }
 } // namespace
 
 void
 GonkGPSGeolocationProvider::SetReferenceLocation()
 {
@@ -739,18 +743,17 @@ GonkGPSGeolocationProvider::SetReference
 #endif // MOZ_B2G_RIL
 
 void
 GonkGPSGeolocationProvider::InjectLocation(double latitude,
                                            double longitude,
                                            float accuracy)
 {
   if (gDebug_isLoggingEnabled) {
-    nsContentUtils::LogMessageToConsole("geo: injecting location (%f, %f) accuracy: %f",
-                                        latitude, longitude, accuracy);
+    DBG("injecting location (%f, %f) accuracy: %f", latitude, longitude, accuracy);
   }
 
   MOZ_ASSERT(NS_IsMainThread());
   if (!mGpsInterface) {
     return;
   }
 
   mGpsInterface->inject_location(latitude, longitude, accuracy);
@@ -942,24 +945,22 @@ GonkGPSGeolocationProvider::NetworkLocat
   const bool isGPSFullyInactive = diff_ms > 1000 * 60 * 2; // two mins
   const bool isGPSTempInactive = diff_ms > 1000 * 10; // 10 secs
 
   if (provider->mLocationCallback) {
     if (isGPSFullyInactive ||
        (isGPSTempInactive && delta > kMinMLSCoordChangeInMeters))
     {
       if (gDebug_isLoggingEnabled) {
-        nsContentUtils::LogMessageToConsole("geo: Using MLS, GPS age:%fs, MLS Delta:%fm\n",
-                                            diff_ms / 1000.0, delta);
+        DBG("Using MLS, GPS age:%fs, MLS Delta:%fm\n", diff_ms / 1000.0, delta);
       }
       provider->mLocationCallback->Update(position);
     } else if (provider->mLastGPSPosition) {
       if (gDebug_isLoggingEnabled) {
-        nsContentUtils::LogMessageToConsole("geo: Using old GPS age:%fs\n",
-                                            diff_ms / 1000.0);
+        DBG("Using old GPS age:%fs\n", diff_ms / 1000.0);
       }
 
       // This is a fallback case so that the GPS provider responds with its last
       // location rather than waiting for a more recent GPS or network location.
       // The service decides if the location is too old, not the provider.
       provider->mLocationCallback->Update(provider->mLastGPSPosition);
     }
   }
@@ -1180,26 +1181,25 @@ GonkGPSGeolocationProvider::Observe(nsIS
   if (!strcmp(aTopic, kMozSettingsChangedTopic)) {
     // Read changed setting value
     RootedDictionary<SettingChangeNotification> setting(nsContentUtils::RootingCx());
     if (!WrappedJSToDictionary(aSubject, setting)) {
       return NS_OK;
     }
 
     if (setting.mKey.EqualsASCII(kSettingDebugGpsIgnored)) {
-      nsContentUtils::LogMessageToConsole("geo: received mozsettings-changed: ignoring\n");
+      LOG("received mozsettings-changed: ignoring\n");
       gDebug_isGPSLocationIgnored =
         setting.mValue.isBoolean() ? setting.mValue.toBoolean() : false;
       if (gDebug_isLoggingEnabled) {
-        nsContentUtils::LogMessageToConsole("geo: Debug: GPS ignored %d\n",
-                                            gDebug_isGPSLocationIgnored);
+        DBG("GPS ignored %d\n", gDebug_isGPSLocationIgnored);
       }
       return NS_OK;
     } else if (setting.mKey.EqualsASCII(kSettingDebugEnabled)) {
-      nsContentUtils::LogMessageToConsole("geo: received mozsettings-changed: logging\n");
+      LOG("received mozsettings-changed: logging\n");
       gDebug_isLoggingEnabled =
         setting.mValue.isBoolean() ? setting.mValue.toBoolean() : false;
       return NS_OK;
     }
 #ifdef MOZ_B2G_RIL
     else if (setting.mKey.EqualsASCII(kSettingRilDefaultServiceId)) {
       if (!setting.mValue.isNumber() ||
           !IsValidRilServiceId(setting.mValue.toNumber())) {