Bug 1499821 - Some general code style fixes for nsTransferable. r=smaug
authorTom Schuster <evilpies@gmail.com>
Tue, 23 Oct 2018 12:17:02 +0000
changeset 490937 51b0078af6385a478f640ca30c87c74586e70d32
parent 490936 75b79428f0fa2670c6b1865b38f09ab2589cb232
child 490938 52569b2e27a8018e945ea0e2ade37b0b325458c6
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerssmaug
bugs1499821
milestone65.0a1
Bug 1499821 - Some general code style fixes for nsTransferable. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D9496
widget/nsTransferable.cpp
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -98,32 +98,31 @@ DataStruct::SetData(nsISupports* aData, 
 //-------------------------------------------------------------------------
 void
 DataStruct::GetData(nsISupports** aData, uint32_t* aDataLen)
 {
   // check here to see if the data is cached on disk
   if (mCacheFD) {
     // if so, read it in and pass it back
     // ReadCache creates memory and copies the data into it.
-    if (NS_SUCCEEDED(ReadCache(aData, aDataLen)))
-      return;
-    else {
-      // oh shit, something went horribly wrong here.
-      NS_WARNING("Oh no, couldn't read data in from the cache file");
-      *aData = nullptr;
-      *aDataLen = 0;
-      PR_Close(mCacheFD);
-      mCacheFD = nullptr;
+    if (NS_SUCCEEDED(ReadCache(aData, aDataLen))) {
       return;
     }
+
+    // oh shit, something went horribly wrong here.
+    NS_WARNING("Oh no, couldn't read data in from the cache file");
+    *aData = nullptr;
+    *aDataLen = 0;
+    PR_Close(mCacheFD);
+    mCacheFD = nullptr;
+    return;
   }
 
-  *aData = mData;
-  if (mData)
-    NS_ADDREF(*aData);
+  nsCOMPtr<nsISupports> data = mData;
+  data.forget(aData);
   *aDataLen = mDataLen;
 }
 
 //-------------------------------------------------------------------------
 nsresult
 DataStruct::WriteCache(nsISupports* aData, uint32_t aDataLen)
 {
   nsresult rv;
@@ -333,18 +332,16 @@ nsTransferable::GetTransferData(const ch
 //
 NS_IMETHODIMP
 nsTransferable::GetAnyTransferData(nsACString& aFlavor,
                                    nsISupports** aData,
                                    uint32_t* aDataLen)
 {
   MOZ_ASSERT(mInitialized);
 
-  NS_ENSURE_ARG_POINTER(aData && aDataLen);
-
   for (size_t i = 0; i < mDataArray.Length(); ++i) {
     DataStruct& data = mDataArray.ElementAt(i);
     if (data.IsDataAvailable()) {
       aFlavor.Assign(data.GetFlavor());
       data.GetData(aData, aDataLen);
       return NS_OK;
     }
   }
@@ -359,18 +356,16 @@ nsTransferable::GetAnyTransferData(nsACS
 //
 NS_IMETHODIMP
 nsTransferable::SetTransferData(const char* aFlavor,
                                 nsISupports* aData,
                                 uint32_t aDataLen)
 {
   MOZ_ASSERT(mInitialized);
 
-  NS_ENSURE_ARG(aFlavor);
-
   // first check our intrinsic flavors to see if one has been registered.
   for (size_t i = 0; i < mDataArray.Length(); ++i) {
     DataStruct& data = mDataArray.ElementAt(i);
     if (data.GetFlavor().Equals(aFlavor)) {
       data.SetData(aData, aDataLen, mPrivateData);
       return NS_OK;
     }
   }
@@ -394,35 +389,36 @@ nsTransferable::SetTransferData(const ch
         data.SetData(ConvertedData, ConvertedLen, mPrivateData);
         return NS_OK;
       }
     }
   }
 
   // Can't set data neither directly nor through converter. Just add this flavor
   // and try again
-  nsresult result = NS_ERROR_FAILURE;
-  if (NS_SUCCEEDED(AddDataFlavor(aFlavor)))
-    result = SetTransferData(aFlavor, aData, aDataLen);
+  if (NS_SUCCEEDED(AddDataFlavor(aFlavor))) {
+    return SetTransferData(aFlavor, aData, aDataLen);
+  }
 
-  return result;
+  return NS_ERROR_FAILURE;
 }
 
 //
 // AddDataFlavor
 //
 // Adds a data flavor to our list with no data. Error if it already exists.
 //
 NS_IMETHODIMP
 nsTransferable::AddDataFlavor(const char* aDataFlavor)
 {
   MOZ_ASSERT(mInitialized);
 
-  if (GetDataForFlavor(mDataArray, aDataFlavor) != mDataArray.NoIndex)
+  if (GetDataForFlavor(mDataArray, aDataFlavor) != mDataArray.NoIndex) {
     return NS_ERROR_FAILURE;
+  }
 
   // Create a new "slot" for the data
   mDataArray.AppendElement(DataStruct(aDataFlavor));
 
   return NS_OK;
 }
 
 //
@@ -439,42 +435,32 @@ nsTransferable::RemoveDataFlavor(const c
   size_t idx = GetDataForFlavor(mDataArray, aDataFlavor);
   if (idx != mDataArray.NoIndex) {
     mDataArray.RemoveElementAt(idx);
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
 }
 
-
-/**
- *
- *
- */
 NS_IMETHODIMP
 nsTransferable::SetConverter(nsIFormatConverter* aConverter)
 {
   MOZ_ASSERT(mInitialized);
 
   mFormatConv = aConverter;
   return NS_OK;
 }
 
-/**
- *
- *
- */
 NS_IMETHODIMP
 nsTransferable::GetConverter(nsIFormatConverter** aConverter)
 {
   MOZ_ASSERT(mInitialized);
 
-  NS_ENSURE_ARG_POINTER(aConverter);
-  *aConverter = mFormatConv;
-  NS_IF_ADDREF(*aConverter);
+  nsCOMPtr<nsIFormatConverter> converter = mFormatConv;
+  converter.forget(aConverter);
   return NS_OK;
 }
 
 //
 // FlavorsTransferableCanImport
 //
 // Computes a list of flavors that the transferable can accept into it, either
 // through intrinsic knowledge or input data converters.
@@ -512,17 +498,16 @@ nsTransferable::FlavorsTransferableCanIm
 // Computes a list of flavors that the transferable can export, either through
 // intrinsic knowledge or output data converters.
 //
 NS_IMETHODIMP
 nsTransferable::FlavorsTransferableCanExport(nsTArray<nsCString>& aFlavors)
 {
   MOZ_ASSERT(mInitialized);
 
-
   // Get the flavor list, and on to the end of it, append the list of flavors we
   // can also get to through a converter. This is so that we can just walk the
   // list in one go, looking for the desired flavor.
   GetTransferDataFlavors(aFlavors);
 
   if (mFormatConv) {
     nsTArray<nsCString> convertedList;
     mFormatConv->GetOutputDataFlavors(convertedList);
@@ -540,53 +525,57 @@ nsTransferable::FlavorsTransferableCanEx
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTransferable::GetIsPrivateData(bool* aIsPrivateData)
 {
   MOZ_ASSERT(mInitialized);
 
-  NS_ENSURE_ARG_POINTER(aIsPrivateData);
-
   *aIsPrivateData = mPrivateData;
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTransferable::SetIsPrivateData(bool aIsPrivateData)
 {
   MOZ_ASSERT(mInitialized);
 
   mPrivateData = aIsPrivateData;
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTransferable::GetRequestingPrincipal(nsIPrincipal** outRequestingPrincipal)
+nsTransferable::GetRequestingPrincipal(nsIPrincipal** aRequestingPrincipal)
 {
-  NS_IF_ADDREF(*outRequestingPrincipal = mRequestingPrincipal);
+  MOZ_ASSERT(mInitialized);
+
+  nsCOMPtr<nsIPrincipal> principal = mRequestingPrincipal;
+  principal.forget(aRequestingPrincipal);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTransferable::SetRequestingPrincipal(nsIPrincipal* aRequestingPrincipal)
 {
+  MOZ_ASSERT(mInitialized);
+
   mRequestingPrincipal = aRequestingPrincipal;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTransferable::GetContentPolicyType(nsContentPolicyType* outContentPolicyType)
+nsTransferable::GetContentPolicyType(nsContentPolicyType* aContentPolicyType)
 {
-  NS_ENSURE_ARG_POINTER(outContentPolicyType);
-  *outContentPolicyType = mContentPolicyType;
+  MOZ_ASSERT(mInitialized);
+
+  *aContentPolicyType = mContentPolicyType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTransferable::SetContentPolicyType(nsContentPolicyType aContentPolicyType)
 {
+  MOZ_ASSERT(mInitialized);
+
   mContentPolicyType = aContentPolicyType;
   return NS_OK;
 }