Bug 493783 - Fix some Places warnings.
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 10 May 2011 03:10:25 +0200
changeset 68849 f625e8ddfe6faaa166bdfc154cd1969508efb351
parent 68848 f1f0632c172f9efbdb9a3728530b2ee4f1111524
child 69229 df4fb5243b1b5918b6133c9ba73f6017a35f4e31
push id171
push usermak77@bonardo.net
push dateTue, 10 May 2011 01:18:02 +0000
bugs493783
milestone6.0a1
Bug 493783 - Fix some Places warnings. r=sdwilsh
storage/public/mozIStorageStatement.idl
toolkit/components/places/Helpers.cpp
toolkit/components/places/History.cpp
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsNavHistoryQuery.cpp
toolkit/components/places/nsPlacesImportExportService.cpp
--- a/storage/public/mozIStorageStatement.idl
+++ b/storage/public/mozIStorageStatement.idl
@@ -35,16 +35,19 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozIStorageBaseStatement.idl"
+%{C++
+#include "mozilla/Util.h"
+%}
 
 [ptr] native octetPtr(PRUint8);
 
 /**
  * A SQL statement that can be used for both synchronous and asynchronous
  * purposes.
  */
 [scriptable, uuid(57ec7be1-36cf-4510-b938-7d1c9ee8cec5)]
@@ -260,67 +263,67 @@ interface mozIStorageStatement : mozISto
    * Getters for native code that return their values as
    * the return type, for convenience and sanity.
    *
    * Not virtual; no vtable bloat.
    */
 
   inline PRInt32 AsInt32(PRUint32 idx) {
     PRInt32 v = 0;
-    nsresult rv = GetInt32(idx, &v);
+    mozilla::DebugOnly<nsresult> rv = GetInt32(idx, &v);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
                       "Getting value failed, wrong column index?");
     return v;
   }
 
   inline PRInt64 AsInt64(PRUint32 idx) {
     PRInt64 v = 0;
-    nsresult rv = GetInt64(idx, &v);
+    mozilla::DebugOnly<nsresult> rv = GetInt64(idx, &v);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
                       "Getting value failed, wrong column index?");
     return v;
   }
 
   inline double AsDouble(PRUint32 idx) {
     double v = 0.0;
-    nsresult rv = GetDouble(idx, &v);
+    mozilla::DebugOnly<nsresult> rv = GetDouble(idx, &v);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
                       "Getting value failed, wrong column index?");
     return v;
   }
 
   inline const char* AsSharedUTF8String(PRUint32 idx, PRUint32 *len) {
     const char *str = nsnull;
     *len = 0;
-    nsresult rv = GetSharedUTF8String(idx, len, &str);
+    mozilla::DebugOnly<nsresult> rv = GetSharedUTF8String(idx, len, &str);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
                       "Getting value failed, wrong column index?");
     return str;
   }
 
   inline const PRUnichar* AsSharedWString(PRUint32 idx, PRUint32 *len) {
     const PRUnichar *str = nsnull;
     *len = 0;
-    nsresult rv = GetSharedString(idx, len, &str);
+    mozilla::DebugOnly<nsresult> rv = GetSharedString(idx, len, &str);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
                       "Getting value failed, wrong column index?");
     return str;
   }
 
   inline const PRUint8* AsSharedBlob(PRUint32 idx, PRUint32 *len) {
     const PRUint8 *blob = nsnull;
     *len = 0;
-    nsresult rv = GetSharedBlob(idx, len, &blob);
+    mozilla::DebugOnly<nsresult> rv = GetSharedBlob(idx, len, &blob);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) || IsNull(idx),
                       "Getting value failed, wrong column index?");
     return blob;
   }
 
   inline PRBool IsNull(PRUint32 idx) {
     PRBool b = PR_FALSE;
-    nsresult rv = GetIsNull(idx, &b);
+    mozilla::DebugOnly<nsresult> rv = GetIsNull(idx, &b);
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv),
                       "Getting value failed, wrong column index?");
     return b;
   }
 
 %}
 };
--- a/toolkit/components/places/Helpers.cpp
+++ b/toolkit/components/places/Helpers.cpp
@@ -336,19 +336,19 @@ IsValidGUID(const nsCString& aGUID)
 {
   nsCString::size_type len = aGUID.Length();
   if (len != GUID_LENGTH) {
     return false;
   }
 
   for (nsCString::size_type i = 0; i < len; i++ ) {
     char c = aGUID[i];
-    if (c >= 'a' && c <= 'z' || // a-z
-        c >= 'A' && c <= 'Z' || // A-Z
-        c >= '0' && c <= '9' || // 0-9
+    if ((c >= 'a' && c <= 'z') || // a-z
+        (c >= 'A' && c <= 'Z') || // A-Z
+        (c >= '0' && c <= '9') || // 0-9
         c == '-' || c == '_') { // - or _
       continue;
     }
     return false;
   }
   return true;
 }
 
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -50,16 +50,17 @@
 
 #include "mozilla/storage.h"
 #include "mozilla/dom/Link.h"
 #include "nsDocShellCID.h"
 #include "mozilla/Services.h"
 #include "nsThreadUtils.h"
 #include "nsNetUtil.h"
 #include "nsIXPConnect.h"
+#include "mozilla/Util.h"
 
 // Initial size for the cache holding visited status observers.
 #define VISIT_OBSERVERS_INITIAL_CACHE_SIZE 128
 
 // Topic used to notify that work in mozIAsyncHistory::updatePlaces is done.
 #define TOPIC_UPDATEPLACES_COMPLETE "places-updatePlaces-complete"
 
 using namespace mozilla::dom;
@@ -464,17 +465,18 @@ public:
       navHistory->NotifyOnVisit(uri, mPlace.visitId, mPlace.visitTime,
                                 mPlace.sessionId, mReferrer.visitId,
                                 mPlace.transitionType);
     }
 
     nsCOMPtr<nsIObserverService> obsService =
       mozilla::services::GetObserverService();
     if (obsService) {
-      nsresult rv = obsService->NotifyObservers(uri, URI_VISIT_SAVED, nsnull);
+      DebugOnly<nsresult> rv =
+        obsService->NotifyObservers(uri, URI_VISIT_SAVED, nsnull);
       NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Could not notify observers");
     }
 
     History::GetService()->NotifyVisited(uri);
 
     return NS_OK;
   }
 private:
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -77,22 +77,24 @@
 #include "nsPlacesIndexes.h"
 #include "nsPlacesTriggers.h"
 #include "nsPlacesMacros.h"
 #include "SQLFunctions.h"
 #include "Helpers.h"
 #include "History.h"
 
 #include "mozilla/FunctionTimer.h"
+#include "mozilla/Util.h"
 
 #ifdef MOZ_XUL
 #include "nsIAutoCompleteInput.h"
 #include "nsIAutoCompletePopup.h"
 #endif
 
+using namespace mozilla;
 using namespace mozilla::places;
 
 // The maximum number of things that we will store in the recent events list
 // before calling ExpireNonrecentEvents. This number should be big enough so it
 // is very difficult to get that many unconsumed events (for example, typed but
 // never visited) in the RECENT_EVENT_THRESHOLD. Otherwise, we'll start
 // checking each one for every page visit, which will be somewhat slower.
 #define RECENT_EVENT_QUEUE_MAX_LENGTH 128
@@ -328,17 +330,17 @@ private:
 };
 
 NS_IMETHODIMP
 AsyncStatementCallbackNotifier::HandleCompletion(PRUint16 aReason)
 {
   if (aReason != mozIStorageStatementCallback::REASON_FINISHED)
     return NS_ERROR_UNEXPECTED;
 
-  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (obs) {
     (void)obs->NotifyObservers(nsnull, mTopic, nsnull);
   }
 
   return NS_OK;
 }
 
 } // anonymouse namespace
@@ -4007,17 +4009,17 @@ nsNavHistory::BeginUpdateBatch()
 }
 
 // nsNavHistory::EndUpdateBatch
 nsresult
 nsNavHistory::EndUpdateBatch()
 {
   if (--mBatchLevel == 0) {
     if (mBatchDBTransaction) {
-      nsresult rv = mBatchDBTransaction->Commit();
+      DebugOnly<nsresult> rv = mBatchDBTransaction->Commit();
       NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Batch failed to commit transaction");
       delete mBatchDBTransaction;
       mBatchDBTransaction = nsnull;
     }
 
     NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
                      nsINavHistoryObserver, OnEndUpdateBatch());
   }
@@ -5431,17 +5433,17 @@ nsNavHistory::NotifyOnPageExpired(nsIURI
 
 NS_IMETHODIMP
 nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic,
                     const PRUnichar *aData)
 {
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
 
   if (strcmp(aTopic, TOPIC_PROFILE_TEARDOWN) == 0) {
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> os = services::GetObserverService();
     if (!os) {
       NS_WARNING("Unable to shutdown Places: Observer Service unavailable.");
       return NS_OK;
     }
 
     (void)os->RemoveObserver(this, TOPIC_PROFILE_TEARDOWN);
     (void)os->RemoveObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC);
     (void)os->RemoveObserver(this, TOPIC_IDLE_DAILY);
@@ -5466,17 +5468,17 @@ nsNavHistory::Observe(nsISupports *aSubj
     }
 
     // Notify all Places users that we are about to shutdown.
     (void)os->NotifyObservers(nsnull, TOPIC_PLACES_SHUTDOWN, nsnull);
   }
 
   else if (strcmp(aTopic, TOPIC_PROFILE_CHANGE) == 0) {
     // Fire internal shutdown notifications.
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> os = services::GetObserverService();
     if (os) {
       (void)os->RemoveObserver(this, TOPIC_PROFILE_CHANGE);
       // Double notification allows to correctly enqueue tasks without the need
       // to enqueue notification events to the main-thread.  There is no
       // guarantee that the event loop will spin before xpcom-shutdown indeed,
       // see bug 580892.
       (void)os->NotifyObservers(nsnull, TOPIC_PLACES_WILL_CLOSE_CONNECTION, nsnull);
       (void)os->NotifyObservers(nsnull, TOPIC_PLACES_CONNECTION_CLOSING, nsnull);
@@ -7204,32 +7206,32 @@ nsNavHistory::GetCollation()
   return mCollation;
 }
 
 nsIStringBundle *
 nsNavHistory::GetBundle()
 {
   if (!mBundle) {
     nsCOMPtr<nsIStringBundleService> bundleService =
-      mozilla::services::GetStringBundleService();
+      services::GetStringBundleService();
     NS_ENSURE_TRUE(bundleService, nsnull);
     nsresult rv = bundleService->CreateBundle(
         "chrome://places/locale/places.properties",
         getter_AddRefs(mBundle));
     NS_ENSURE_SUCCESS(rv, nsnull);
   }
   return mBundle;
 }
 
 nsIStringBundle *
 nsNavHistory::GetDateFormatBundle()
 {
   if (!mDateFormatBundle) {
     nsCOMPtr<nsIStringBundleService> bundleService =
-      mozilla::services::GetStringBundleService();
+      services::GetStringBundleService();
     NS_ENSURE_TRUE(bundleService, nsnull);
     nsresult rv = bundleService->CreateBundle(
         "chrome://global/locale/dateFormat.properties",
         getter_AddRefs(mDateFormatBundle));
     NS_ENSURE_SUCCESS(rv, nsnull);
   }
   return mDateFormatBundle;
 }
--- a/toolkit/components/places/nsNavHistoryQuery.cpp
+++ b/toolkit/components/places/nsNavHistoryQuery.cpp
@@ -46,16 +46,19 @@
 
 #include "nsNavHistory.h"
 #include "nsNavBookmarks.h"
 #include "nsEscape.h"
 #include "nsCOMArray.h"
 #include "nsNetUtil.h"
 #include "nsTArray.h"
 #include "prprf.h"
+#include "mozilla/Util.h"
+
+using namespace mozilla;
 
 class QueryKeyValuePair
 {
 public:
 
   // QueryKeyValuePair
   //
   //                  01234567890
@@ -445,17 +448,17 @@ nsNavHistory::QueriesToQueryString(nsINa
     // which is valid
     query->GetHasDomain(&hasIt);
     if (hasIt) {
       AppendBoolKeyValueIfTrue(queryString,
                                NS_LITERAL_CSTRING(QUERYKEY_DOMAIN_IS_HOST),
                                query, &nsINavHistoryQuery::GetDomainIsHost);
       nsCAutoString domain;
       nsresult rv = query->GetDomain(domain);
-      NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting value");
+      NS_ENSURE_SUCCESS(rv, rv);
       nsCString escapedDomain;
       PRBool success = NS_Escape(domain, escapedDomain, url_XAlphas);
       NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
 
       AppendAmpersandIfNonempty(queryString);
       queryString.Append(NS_LITERAL_CSTRING(QUERYKEY_DOMAIN "="));
       queryString.Append(escapedDomain);
     }
@@ -1649,17 +1652,17 @@ nsNavHistoryQueryOptions::Clone(nsNavHis
 // AppendBoolKeyValueIfTrue
 
 void // static
 AppendBoolKeyValueIfTrue(nsACString& aString, const nsCString& aName,
                          nsINavHistoryQuery* aQuery,
                          BoolQueryGetter getter)
 {
   PRBool value;
-  nsresult rv = (aQuery->*getter)(&value);
+  DebugOnly<nsresult> rv = (aQuery->*getter)(&value);
   NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting boolean value");
   if (value) {
     AppendAmpersandIfNonempty(aString);
     aString += aName;
     aString.AppendLiteral("=1");
   }
 }
 
@@ -1668,17 +1671,17 @@ AppendBoolKeyValueIfTrue(nsACString& aSt
 
 void // static
 AppendUint32KeyValueIfNonzero(nsACString& aString,
                               const nsCString& aName,
                               nsINavHistoryQuery* aQuery,
                               Uint32QueryGetter getter)
 {
   PRUint32 value;
-  nsresult rv = (aQuery->*getter)(&value);
+  DebugOnly<nsresult> rv = (aQuery->*getter)(&value);
   NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting value");
   if (value) {
     AppendAmpersandIfNonempty(aString);
     aString += aName;
 
     // AppendInt requires a concrete string
     nsCAutoString appendMe("=");
     appendMe.AppendInt(value);
@@ -1691,17 +1694,17 @@ AppendUint32KeyValueIfNonzero(nsACString
 
 void // static
 AppendInt64KeyValueIfNonzero(nsACString& aString,
                              const nsCString& aName,
                              nsINavHistoryQuery* aQuery,
                              Int64QueryGetter getter)
 {
   PRInt64 value;
-  nsresult rv = (aQuery->*getter)(&value);
+  DebugOnly<nsresult> rv = (aQuery->*getter)(&value);
   NS_ASSERTION(NS_SUCCEEDED(rv), "Failure getting value");
   if (value) {
     AppendAmpersandIfNonempty(aString);
     aString += aName;
     nsCAutoString appendMe("=");
     appendMe.AppendInt(value);
     aString.Append(appendMe);
   }
--- a/toolkit/components/places/nsPlacesImportExportService.cpp
+++ b/toolkit/components/places/nsPlacesImportExportService.cpp
@@ -101,16 +101,19 @@
 #include "nsIPrefService.h"
 #include "nsToolkitCompsCID.h"
 #include "nsIHTMLContentSink.h"
 #include "nsIParser.h"
 #include "prprf.h"
 #include "nsIObserverService.h"
 #include "nsISupportsPrimitives.h"
 #include "nsPlacesMacros.h"
+#include "mozilla/Util.h"
+
+using namespace mozilla;
 
 static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
 
 #define KEY_TOOLBARFOLDER_LOWER "personal_toolbar_folder"
 #define KEY_BOOKMARKSMENU_LOWER "bookmarks_menu"
 #define KEY_UNFILEDFOLDER_LOWER "unfiled_bookmarks_folder"
 #define KEY_PLACESROOT_LOWER "places_root"
 #define KEY_HREF_LOWER "href"
@@ -666,19 +669,18 @@ BookmarkContentSink::HandleContainerEnd(
   BookmarkImportFrame& frame = CurFrame();
   if (frame.mContainerNesting > 0)
     frame.mContainerNesting --;
   if (mFrames.Length() > 1 && frame.mContainerNesting == 0) {
     // we also need to re-set the imported last-modified date here. Otherwise
     // the addition of items will override the imported field.
     BookmarkImportFrame& prevFrame = PreviousFrame();
     if (prevFrame.mPreviousLastModifiedDate > 0) {
-      nsresult rv = mBookmarksService->SetItemLastModified(frame.mContainerID,
-                                                           prevFrame.mPreviousLastModifiedDate);
-      NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "SetItemLastModified failed");
+      (void)mBookmarksService->SetItemLastModified(frame.mContainerID,
+                                                   prevFrame.mPreviousLastModifiedDate);
     }
     PopFrame();
   }
 }
 
 
 // BookmarkContentSink::HandleHead1Begin
 //
@@ -694,18 +696,18 @@ BookmarkContentSink::HandleHead1Begin(co
     if (node.GetKeyAt(i).LowerCaseEqualsLiteral(KEY_PLACESROOT_LOWER)) {
       if (mFrames.Length() > 1) {
         NS_WARNING("Trying to set the places root from the middle of the hierarchy. "
                    "This can only be set at the beginning.");
         return;
       }
 
       PRInt64 placesRoot;
-      nsresult rv = mBookmarksService->GetPlacesRoot(&placesRoot);
-      NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "could not get placesRoot");
+      DebugOnly<nsresult> rv = mBookmarksService->GetPlacesRoot(&placesRoot);
+      NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "could not get placesRoot");
       CurFrame().mContainerID = placesRoot;
       break;
     }
   }
 }
 
 
 // BookmarkContentSink::HandleHeadBegin