Bug 825807 (part 2) - Improve the style of nsNetworkManagerListener.{h,cpp}. r=bz.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 06 Jan 2013 16:08:31 -0800
changeset 126932 4dbd963117b96d3f99ac791f014d83f00506dc8a
parent 126931 928eb7835982097c15260682479e379ac4daf676
child 126933 de6f3b7fc084059b085322992330a906cc660f67
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs825807
milestone20.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 825807 (part 2) - Improve the style of nsNetworkManagerListener.{h,cpp}. r=bz.
toolkit/system/dbus/nsNetworkManagerListener.cpp
toolkit/system/dbus/nsNetworkManagerListener.h
--- a/toolkit/system/dbus/nsNetworkManagerListener.cpp
+++ b/toolkit/system/dbus/nsNetworkManagerListener.cpp
@@ -1,180 +1,193 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim:expandtab:shiftwidth=4:tabstop=4:
- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- 
+
 #include "nsNetworkManagerListener.h"
 
 #include "nsNetCID.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIObserverService.h"
 #include "nsStringAPI.h"
 #include "nsCRT.h"
 
 // Define NetworkManager API constants. This avoids a dependency on
 // NetworkManager-devel.
 #define NM_DBUS_SERVICE                 "org.freedesktop.NetworkManager"
-#define NM_DBUS_PATH                            "/org/freedesktop/NetworkManager"
-#define NM_DBUS_INTERFACE                       "org.freedesktop.NetworkManager"
-#define NM_DBUS_SIGNAL_STATE_CHANGE             "StateChange" /* Deprecated in 0.7.x */
-#define NM_DBUS_SIGNAL_STATE_CHANGED            "StateChanged"
+#define NM_DBUS_PATH                    "/org/freedesktop/NetworkManager"
+#define NM_DBUS_INTERFACE               "org.freedesktop.NetworkManager"
+#define NM_DBUS_SIGNAL_STATE_CHANGE     "StateChange" /* Deprecated in 0.7.x */
+#define NM_DBUS_SIGNAL_STATE_CHANGED    "StateChanged"
 
 #define NM_STATE_CONNECTED_OLD    3 /* Before NM 0.9.0 */
 #define NM_STATE_CONNECTED_LOCAL  50
 #define NM_STATE_CONNECTED_SITE   60
 #define NM_STATE_CONNECTED_GLOBAL 70
 
-nsNetworkManagerListener::nsNetworkManagerListener() :
-    mLinkUp(true), mNetworkManagerActive(false),
+nsNetworkManagerListener::nsNetworkManagerListener()
+  : mLinkUp(true), mNetworkManagerActive(false),
     mOK(true)
 {
 }
 
-nsNetworkManagerListener::~nsNetworkManagerListener() {
+nsNetworkManagerListener::~nsNetworkManagerListener()
+{
   if (mDBUS) {
     mDBUS->RemoveClient(this);
   }
 }
 
 NS_IMPL_ISUPPORTS1(nsNetworkManagerListener, nsINetworkLinkService)
 
 nsresult
-nsNetworkManagerListener::GetIsLinkUp(bool* aIsUp) {
+nsNetworkManagerListener::GetIsLinkUp(bool* aIsUp)
+{
   *aIsUp = mLinkUp;
   return NS_OK;
 }
 
 nsresult
-nsNetworkManagerListener::GetLinkStatusKnown(bool* aKnown) {
+nsNetworkManagerListener::GetLinkStatusKnown(bool* aKnown)
+{
   *aKnown = mNetworkManagerActive;
   return NS_OK;
 }
 
 nsresult
 nsNetworkManagerListener::GetLinkType(uint32_t *aLinkType)
 {
   NS_ENSURE_ARG_POINTER(aLinkType);
 
   // XXX This function has not yet been implemented for this platform
   *aLinkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN;
   return NS_OK;
 }
 
 nsresult
-nsNetworkManagerListener::Init() {
+nsNetworkManagerListener::Init()
+{
   mDBUS = nsDBusService::Get();
-  if (!mDBUS)
+  if (!mDBUS) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
   nsresult rv = mDBUS->AddClient(this);
   if (NS_FAILED(rv)) {
     mDBUS = nullptr;
     return rv;
   }
-  if (!mOK)
+  if (!mOK) {
     return NS_ERROR_FAILURE;
+  }
   return NS_OK;
 }
 
 static void
-NetworkStatusNotify(DBusPendingCall *pending, void* user_data) {
+NetworkStatusNotify(DBusPendingCall *pending, void* user_data)
+{
   DBusMessage* msg = dbus_pending_call_steal_reply(pending);
-  if (!msg)
+  if (!msg) {
     return;
+  }
   if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
     static_cast<nsNetworkManagerListener*>(user_data)->UpdateNetworkStatus(msg);
   }
   dbus_message_unref(msg);
 }
 
 void
-nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection) {
+nsNetworkManagerListener::RegisterWithConnection(DBusConnection* connection)
+{
   DBusError error;
   dbus_error_init(&error);
-  
+
   dbus_bus_add_match(connection,
                      "type='signal',"
                      "interface='" NM_DBUS_INTERFACE "',"
                      "sender='" NM_DBUS_SERVICE "',"
                      "path='" NM_DBUS_PATH "'", &error);
   mOK = !dbus_error_is_set(&error);
   dbus_error_free(&error);
-  if (!mOK)
+  if (!mOK) {
     return;
-  
+  }
   DBusMessage* msg =
     dbus_message_new_method_call(NM_DBUS_SERVICE, NM_DBUS_PATH,
                                  NM_DBUS_INTERFACE, "state");
   if (!msg) {
     mOK = false;
     return;
   }
-  
+
   DBusPendingCall* reply = mDBUS->SendWithReply(this, msg);
   if (!reply) {
     mOK = false;
     return;
   }
 
   dbus_pending_call_set_notify(reply, NetworkStatusNotify, this, NULL);
   dbus_pending_call_unref(reply);
 }
 
 void
 nsNetworkManagerListener::NotifyNetworkStatusObservers() {
   nsCOMPtr<nsIObserverService> observerService =
     do_GetService("@mozilla.org/observer-service;1");
-  if (!observerService)
+  if (!observerService) {
     return;
-    
+  }
   const PRUnichar* status;
   if (mNetworkManagerActive) {
     status = mLinkUp ? NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_UP).get()
                      : NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_DOWN).get();
   } else {
     status = NS_LITERAL_STRING(NS_NETWORK_LINK_DATA_UNKNOWN).get();
   }
 
   observerService->NotifyObservers(static_cast<nsISupports*>(this),
                                    NS_NETWORK_LINK_TOPIC, status);
 }
 
 void
-nsNetworkManagerListener::UnregisterWithConnection(DBusConnection* connection) {
+nsNetworkManagerListener::UnregisterWithConnection(DBusConnection* connection)
+{
   mNetworkManagerActive = false;
   NotifyNetworkStatusObservers();
 }
 
 bool
-nsNetworkManagerListener::HandleMessage(DBusMessage* message) {
+nsNetworkManagerListener::HandleMessage(DBusMessage* message)
+{
   if (dbus_message_is_signal(message, NM_DBUS_INTERFACE,
                              NM_DBUS_SIGNAL_STATE_CHANGE) ||
       dbus_message_is_signal(message, NM_DBUS_INTERFACE,
                              NM_DBUS_SIGNAL_STATE_CHANGED)) {
     UpdateNetworkStatus(message);
     return true;
   }
   return false;
 }
 
 void
-nsNetworkManagerListener::UpdateNetworkStatus(DBusMessage* msg) {
+nsNetworkManagerListener::UpdateNetworkStatus(DBusMessage* msg)
+{
   int32_t result;
   if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &result,
-                             DBUS_TYPE_INVALID))
+                             DBUS_TYPE_INVALID)) {
     return;
+  }
 
   mNetworkManagerActive = true;
-  
+
   bool wasUp = mLinkUp;
   mLinkUp = result == NM_STATE_CONNECTED_OLD ||
             result == NM_STATE_CONNECTED_LOCAL ||
             result == NM_STATE_CONNECTED_SITE ||
             result == NM_STATE_CONNECTED_GLOBAL;
-  if (wasUp == mLinkUp)
+  if (wasUp == mLinkUp) {
     return;
+  }
 
   NotifyNetworkStatusObservers();
 }
 
--- a/toolkit/system/dbus/nsNetworkManagerListener.h
+++ b/toolkit/system/dbus/nsNetworkManagerListener.h
@@ -1,11 +1,10 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim:expandtab:shiftwidth=4:tabstop=4:
- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NSNETWORKMANAGERLISTENER_H_
 #define NSNETWORKMANAGERLISTENER_H_
 
 #include "nsINetworkLinkService.h"