Bug 1497476 - Clang-format nsTransferable.cpp. r=froydnj
authorTom Schuster <evilpies@gmail.com>
Wed, 17 Oct 2018 16:48:43 +0000
changeset 490588 507a9e5aaeea48bcf83b11022568a07718ca321a
parent 490587 93381671f883b445bf985bece8645d7f3940ca88
child 490589 b2a4b8894c2a0c396ebe118a52490f514f3a5bb2
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersfroydnj
bugs1497476
milestone64.0a1
Bug 1497476 - Clang-format nsTransferable.cpp. r=froydnj Running clang-format makes this code at least a bit more pleasant to look at. Differential Revision: https://phabricator.services.mozilla.com/D8074
widget/nsTransferable.cpp
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -7,17 +7,16 @@
 Notes to self:
 
 - at some point, strings will be accessible from JS, so we won't have to wrap
    flavors in an nsISupportsCString. Until then, we're kinda stuck with
    this crappy API of nsIArrays.
 
 */
 
-
 #include "nsTransferable.h"
 #include "nsAnonymousTemporaryFile.h"
 #include "nsArray.h"
 #include "nsArrayUtils.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsTArray.h"
 #include "nsIFormatConverter.h"
@@ -35,47 +34,48 @@ Notes to self:
 #include "nsIOutputStream.h"
 #include "nsIInputStream.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsILoadContext.h"
 #include "mozilla/UniquePtr.h"
 
 NS_IMPL_ISUPPORTS(nsTransferable, nsITransferable)
 
-size_t GetDataForFlavor (const nsTArray<DataStruct>& aArray,
-                           const char* aDataFlavor)
+size_t
+GetDataForFlavor(const nsTArray<DataStruct>& aArray, const char* aDataFlavor)
 {
-  for (size_t i = 0 ; i < aArray.Length () ; ++i) {
-    if (aArray[i].GetFlavor().Equals (aDataFlavor))
+  for (size_t i = 0; i < aArray.Length(); ++i) {
+    if (aArray[i].GetFlavor().Equals(aDataFlavor)) {
       return i;
+    }
   }
 
   return aArray.NoIndex;
 }
 
 DataStruct::DataStruct(DataStruct&& aRHS)
-  : mData(aRHS.mData.forget()),
-    mDataLen(aRHS.mDataLen),
-    mCacheFD(aRHS.mCacheFD),
-    mFlavor(aRHS.mFlavor)
+  : mData(aRHS.mData.forget())
+  , mDataLen(aRHS.mDataLen)
+  , mCacheFD(aRHS.mCacheFD)
+  , mFlavor(aRHS.mFlavor)
 {
   aRHS.mCacheFD = nullptr;
 }
 
 //-------------------------------------------------------------------------
 DataStruct::~DataStruct()
 {
   if (mCacheFD) {
     PR_Close(mCacheFD);
   }
 }
 
 //-------------------------------------------------------------------------
 void
-DataStruct::SetData ( nsISupports* aData, uint32_t aDataLen, bool aIsPrivateData )
+DataStruct::SetData(nsISupports* aData, uint32_t aDataLen, bool aIsPrivateData)
 {
   // Now, check to see if we consider the data to be "too large"
   // as well as ensuring that private browsing mode is disabled
   if (aDataLen > kLargeDatasetSize && !aIsPrivateData) {
     // if so, cache it to disk instead of memory
     if (NS_SUCCEEDED(WriteCache(aData, aDataLen))) {
       // Clear previously set small data.
       mData = nullptr;
@@ -86,49 +86,47 @@ DataStruct::SetData ( nsISupports* aData
   }
 
   if (mCacheFD) {
     // Clear previously set big data.
     PR_Close(mCacheFD);
     mCacheFD = nullptr;
   }
 
-  mData    = aData;
+  mData = aData;
   mDataLen = aDataLen;
 }
 
-
 //-------------------------------------------------------------------------
 void
-DataStruct::GetData ( nsISupports** aData, uint32_t *aDataLen )
+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)) )
+    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;
       return;
     }
   }
 
   *aData = mData;
-  if ( mData )
+  if (mData)
     NS_ADDREF(*aData);
   *aDataLen = mDataLen;
 }
 
-
 //-------------------------------------------------------------------------
 nsresult
 DataStruct::WriteCache(nsISupports* aData, uint32_t aDataLen)
 {
   nsresult rv;
   if (!mCacheFD) {
     rv = NS_OpenAnonymousTemporaryFile(&mCacheFD);
     if (NS_FAILED(rv)) {
@@ -148,17 +146,16 @@ DataStruct::WriteCache(nsISupports* aDat
       return NS_OK;
     }
   }
   PR_Close(mCacheFD);
   mCacheFD = nullptr;
   return NS_ERROR_FAILURE;
 }
 
-
 //-------------------------------------------------------------------------
 nsresult
 DataStruct::ReadCache(nsISupports** aData, uint32_t* aDataLen)
 {
   if (!mCacheFD) {
     return NS_ERROR_FAILURE;
   }
 
@@ -176,22 +173,22 @@ DataStruct::ReadCache(nsISupports** aDat
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   uint32_t actual = PR_Read(mCacheFD, data.get(), fileSize);
   if (actual != fileSize) {
     return NS_ERROR_FAILURE;
   }
 
-  nsPrimitiveHelpers::CreatePrimitiveForData(mFlavor, data.get(), fileSize, aData);
+  nsPrimitiveHelpers::CreatePrimitiveForData(
+    mFlavor, data.get(), fileSize, aData);
   *aDataLen = fileSize;
   return NS_OK;
 }
 
-
 //-------------------------------------------------------------------------
 //
 // Transferable constructor
 //
 //-------------------------------------------------------------------------
 nsTransferable::nsTransferable()
   : mPrivateData(false)
   , mContentPolicyType(nsIContentPolicy::TYPE_OTHER)
@@ -201,20 +198,17 @@ nsTransferable::nsTransferable()
 {
 }
 
 //-------------------------------------------------------------------------
 //
 // Transferable destructor
 //
 //-------------------------------------------------------------------------
-nsTransferable::~nsTransferable()
-{
-}
-
+nsTransferable::~nsTransferable() {}
 
 NS_IMETHODIMP
 nsTransferable::Init(nsILoadContext* aContext)
 {
   MOZ_ASSERT(!mInitialized);
 
   if (aContext) {
     mPrivateData = aContext->UsePrivateBrowsing();
@@ -237,109 +231,113 @@ nsTransferable::GetTransferDataFlavors(n
   MOZ_ASSERT(mInitialized);
 
   for (size_t i = 0; i < mDataArray.Length(); ++i) {
     DataStruct& data = mDataArray.ElementAt(i);
     aFlavors.AppendElement(data.GetFlavor());
   }
 }
 
-
 //
 // GetTransferData
 //
-// Returns the data of the requested flavor, obtained from either having the data on hand or
-// using a converter to get it. The data is wrapped in a nsISupports primitive so that it is
-// accessible from JS.
+// Returns the data of the requested flavor, obtained from either having the
+// data on hand or using a converter to get it. The data is wrapped in a
+// nsISupports primitive so that it is accessible from JS.
 //
 NS_IMETHODIMP
-nsTransferable::GetTransferData(const char *aFlavor, nsISupports **aData, uint32_t *aDataLen)
+nsTransferable::GetTransferData(const char* aFlavor,
+                                nsISupports** aData,
+                                uint32_t* aDataLen)
 {
   MOZ_ASSERT(mInitialized);
 
   NS_ENSURE_ARG_POINTER(aFlavor && aData && aDataLen);
 
   nsresult rv = NS_OK;
   nsCOMPtr<nsISupports> savedData;
 
   // first look and see if the data is present in one of the intrinsic flavors
   for (size_t i = 0; i < mDataArray.Length(); ++i) {
     DataStruct& data = mDataArray.ElementAt(i);
-    if ( data.GetFlavor().Equals(aFlavor) ) {
+    if (data.GetFlavor().Equals(aFlavor)) {
       nsCOMPtr<nsISupports> dataBytes;
       uint32_t len;
       data.GetData(getter_AddRefs(dataBytes), &len);
       if (len == kFlavorHasDataProvider && dataBytes) {
         // do we have a data provider?
-        nsCOMPtr<nsIFlavorDataProvider> dataProvider = do_QueryInterface(dataBytes);
+        nsCOMPtr<nsIFlavorDataProvider> dataProvider =
+          do_QueryInterface(dataBytes);
         if (dataProvider) {
-          rv = dataProvider->GetFlavorData(this, aFlavor,
-                                           getter_AddRefs(dataBytes), &len);
+          rv = dataProvider->GetFlavorData(
+            this, aFlavor, getter_AddRefs(dataBytes), &len);
           if (NS_FAILED(rv))
-            break;    // the provider failed. fall into the converter code below.
+            break; // the provider failed. fall into the converter code below.
         }
       }
       if (dataBytes && len > 0) { // XXXmats why is zero length not ok?
         *aDataLen = len;
         dataBytes.forget(aData);
         return NS_OK;
       }
-      savedData = dataBytes;  // return this if format converter fails
+      savedData = dataBytes; // return this if format converter fails
       break;
     }
   }
 
   bool found = false;
 
   // if not, try using a format converter to get the requested flavor
-  if ( mFormatConv ) {
+  if (mFormatConv) {
     for (size_t i = 0; i < mDataArray.Length(); ++i) {
       DataStruct& data = mDataArray.ElementAt(i);
       bool canConvert = false;
       mFormatConv->CanConvert(data.GetFlavor().get(), aFlavor, &canConvert);
-      if ( canConvert ) {
+      if (canConvert) {
         nsCOMPtr<nsISupports> dataBytes;
         uint32_t len;
         data.GetData(getter_AddRefs(dataBytes), &len);
         if (len == kFlavorHasDataProvider && dataBytes) {
           // do we have a data provider?
-          nsCOMPtr<nsIFlavorDataProvider> dataProvider = do_QueryInterface(dataBytes);
+          nsCOMPtr<nsIFlavorDataProvider> dataProvider =
+            do_QueryInterface(dataBytes);
           if (dataProvider) {
-            rv = dataProvider->GetFlavorData(this, aFlavor,
-                                             getter_AddRefs(dataBytes), &len);
+            rv = dataProvider->GetFlavorData(
+              this, aFlavor, getter_AddRefs(dataBytes), &len);
             if (NS_FAILED(rv))
-              break;  // give up
+              break; // give up
           }
         }
-        mFormatConv->Convert(data.GetFlavor().get(), dataBytes, len, aFlavor, aData, aDataLen);
+        mFormatConv->Convert(
+          data.GetFlavor().get(), dataBytes, len, aFlavor, aData, aDataLen);
         found = true;
         break;
       }
     }
   }
 
   // for backward compatibility
   if (!found) {
     savedData.forget(aData);
     *aDataLen = 0;
   }
 
   return found ? NS_OK : NS_ERROR_FAILURE;
 }
 
-
 //
 // GetAnyTransferData
 //
-// Returns the data of the first flavor found. Caller is responsible for deleting the
-// flavor string.
+// Returns the data of the first flavor found. Caller is responsible for
+// deleting the flavor string.
 //
 NS_IMETHODIMP
-nsTransferable::GetAnyTransferData(nsACString& aFlavor, nsISupports **aData,
-                                   uint32_t *aDataLen)
+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()) {
@@ -347,161 +345,164 @@ nsTransferable::GetAnyTransferData(nsACS
       data.GetData(aData, aDataLen);
       return NS_OK;
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
-
 //
 // SetTransferData
 //
 //
 //
 NS_IMETHODIMP
-nsTransferable::SetTransferData(const char *aFlavor, nsISupports *aData, uint32_t aDataLen)
+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 );
+    if (data.GetFlavor().Equals(aFlavor)) {
+      data.SetData(aData, aDataLen, mPrivateData);
       return NS_OK;
     }
   }
 
   // if not, try using a format converter to find a flavor to put the data in
-  if ( mFormatConv ) {
+  if (mFormatConv) {
     for (size_t i = 0; i < mDataArray.Length(); ++i) {
       DataStruct& data = mDataArray.ElementAt(i);
       bool canConvert = false;
       mFormatConv->CanConvert(aFlavor, data.GetFlavor().get(), &canConvert);
 
-      if ( canConvert ) {
+      if (canConvert) {
         nsCOMPtr<nsISupports> ConvertedData;
         uint32_t ConvertedLen;
-        mFormatConv->Convert(aFlavor, aData, aDataLen, data.GetFlavor().get(), getter_AddRefs(ConvertedData), &ConvertedLen);
+        mFormatConv->Convert(aFlavor,
+                             aData,
+                             aDataLen,
+                             data.GetFlavor().get(),
+                             getter_AddRefs(ConvertedData),
+                             &ConvertedLen);
         data.SetData(ConvertedData, ConvertedLen, mPrivateData);
         return NS_OK;
       }
     }
   }
 
-  // Can't set data neither directly nor through converter. Just add this flavor and try again
+  // 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)))
+    result = SetTransferData(aFlavor, aData, aDataLen);
 
   return result;
 }
 
-
 //
 // AddDataFlavor
 //
 // Adds a data flavor to our list with no data. Error if it already exists.
 //
 NS_IMETHODIMP
-nsTransferable::AddDataFlavor(const char *aDataFlavor)
+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 ));
+  mDataArray.AppendElement(DataStruct(aDataFlavor));
 
   return NS_OK;
 }
 
-
 //
 // RemoveDataFlavor
 //
 // Removes a data flavor (and causes the data to be destroyed). Error if
 // the requested flavor is not present.
 //
 NS_IMETHODIMP
-nsTransferable::RemoveDataFlavor(const char *aDataFlavor)
+nsTransferable::RemoveDataFlavor(const char* aDataFlavor)
 {
   MOZ_ASSERT(mInitialized);
 
   size_t idx = GetDataForFlavor(mDataArray, aDataFlavor);
   if (idx != mDataArray.NoIndex) {
-    mDataArray.RemoveElementAt (idx);
+    mDataArray.RemoveElementAt(idx);
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
 }
 
-
 /**
-  *
-  *
-  */
+ *
+ *
+ */
 NS_IMETHODIMP
-nsTransferable::IsLargeDataSet(bool *_retval)
+nsTransferable::IsLargeDataSet(bool* _retval)
 {
   MOZ_ASSERT(mInitialized);
 
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = false;
   return NS_OK;
 }
 
-
 /**
-  *
-  *
-  */
-NS_IMETHODIMP nsTransferable::SetConverter(nsIFormatConverter * aConverter)
+ *
+ *
+ */
+NS_IMETHODIMP
+nsTransferable::SetConverter(nsIFormatConverter* aConverter)
 {
   MOZ_ASSERT(mInitialized);
 
   mFormatConv = aConverter;
   return NS_OK;
 }
 
-
 /**
-  *
-  *
-  */
-NS_IMETHODIMP nsTransferable::GetConverter(nsIFormatConverter * *aConverter)
+ *
+ *
+ */
+NS_IMETHODIMP
+nsTransferable::GetConverter(nsIFormatConverter** aConverter)
 {
   MOZ_ASSERT(mInitialized);
 
   NS_ENSURE_ARG_POINTER(aConverter);
   *aConverter = mFormatConv;
   NS_IF_ADDREF(*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.
+// Computes a list of flavors that the transferable can accept into it, either
+// through intrinsic knowledge or input data converters.
 //
 NS_IMETHODIMP
 nsTransferable::FlavorsTransferableCanImport(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.
+  // 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->GetInputDataFlavors(convertedList);
 
     for (uint32_t i = 0; i < convertedList.Length(); ++i) {
       nsCString& flavorStr = convertedList[i];
@@ -511,32 +512,31 @@ nsTransferable::FlavorsTransferableCanIm
         aFlavors.AppendElement(flavorStr);
       }
     }
   }
 
   return NS_OK;
 }
 
-
 //
 // FlavorsTransferableCanExport
 //
 // 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.
+  // 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);
 
     for (uint32_t i = 0; i < convertedList.Length(); ++i) {
       nsCString& flavorStr = convertedList[i];
@@ -547,17 +547,17 @@ nsTransferable::FlavorsTransferableCanEx
       }
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTransferable::GetIsPrivateData(bool *aIsPrivateData)
+nsTransferable::GetIsPrivateData(bool* aIsPrivateData)
 {
   MOZ_ASSERT(mInitialized);
 
   NS_ENSURE_ARG_POINTER(aIsPrivateData);
 
   *aIsPrivateData = mPrivateData;
 
   return NS_OK;