Bug 1493292 - Remove len from nsTransferable. r=smaug
☠☠ backed out by 4b0554a10847 ☠ ☠
authorTom Schuster <evilpies@gmail.com>
Tue, 20 Nov 2018 14:47:09 +0000
changeset 506441 f2cabd69c568bd5e6f50f7f3f5d6f5d55c6b7222
parent 506440 71430fceb4a3f1641b2d786e4f66e83c87149946
child 506442 6487aa307123e63554a714e0cece6273e57017b1
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1493292
milestone65.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 1493292 - Remove len from nsTransferable. r=smaug Depends on D11202 Differential Revision: https://phabricator.services.mozilla.com/D11203
widget/nsTransferable.cpp
widget/nsTransferable.h
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -37,17 +37,16 @@ Notes to self:
 #include "mozilla/UniquePtr.h"
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS(nsTransferable, nsITransferable)
 
 DataStruct::DataStruct(DataStruct&& aRHS)
   : mData(aRHS.mData.forget())
-  , mDataLen(aRHS.mDataLen)
   , mCacheFD(aRHS.mCacheFD)
   , mFlavor(aRHS.mFlavor)
 {
   aRHS.mCacheFD = nullptr;
 }
 
 //-------------------------------------------------------------------------
 DataStruct::~DataStruct()
@@ -55,76 +54,72 @@ DataStruct::~DataStruct()
   if (mCacheFD) {
     PR_Close(mCacheFD);
   }
 }
 
 //-------------------------------------------------------------------------
 
 void
-DataStruct::SetData(nsISupports* aData, uint32_t aDataLen, bool aIsPrivateData)
+DataStruct::SetData(nsISupports* aData, 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.
   // File IO is not allowed in content processes.
   if (!aIsPrivateData && XRE_IsParentProcess()) {
     void* data = nullptr;
     uint32_t dataLen = 0;
     nsPrimitiveHelpers::CreateDataFromPrimitive(mFlavor, aData, &data, &dataLen);
 
     if (dataLen > kLargeDatasetSize) {
       // Too large, cache it to disk instead of memory.
       if (NS_SUCCEEDED(WriteCache(data, dataLen))) {
         free(data);
         // Clear previously set small data.
         mData = nullptr;
-        mDataLen = 0;
         return;
       }
 
       NS_WARNING("Oh no, couldn't write data to the cache file");
     }
 
     free(data);
   }
 
   if (mCacheFD) {
     // Clear previously set big data.
     PR_Close(mCacheFD);
     mCacheFD = nullptr;
   }
 
   mData = aData;
-  mDataLen = aDataLen;
 }
 
 //-------------------------------------------------------------------------
 void
-DataStruct::GetData(nsISupports** aData, uint32_t* aDataLen)
+DataStruct::GetData(nsISupports** aData)
 {
   // 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))) {
       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;
   }
 
   nsCOMPtr<nsISupports> data = mData;
   data.forget(aData);
-  *aDataLen = mDataLen;
 }
 
 //-------------------------------------------------------------------------
 nsresult
 DataStruct::WriteCache(void* aData, uint32_t aDataLen)
 {
   MOZ_ASSERT(aData && aDataLen);
   MOZ_ASSERT(aDataLen <= std::numeric_limits<int32_t>::max(),
@@ -148,17 +143,17 @@ DataStruct::WriteCache(void* aData, uint
 
   PR_Close(mCacheFD);
   mCacheFD = nullptr;
   return NS_ERROR_FAILURE;
 }
 
 //-------------------------------------------------------------------------
 nsresult
-DataStruct::ReadCache(nsISupports** aData, uint32_t* aDataLen)
+DataStruct::ReadCache(nsISupports** aData)
 {
   if (!mCacheFD) {
     return NS_ERROR_FAILURE;
   }
 
   PRFileInfo fileInfo;
   if (PR_GetOpenFileInfo(mCacheFD, &fileInfo) != PR_SUCCESS) {
     return NS_ERROR_FAILURE;
@@ -175,17 +170,16 @@ DataStruct::ReadCache(nsISupports** aDat
 
   uint32_t actual = PR_Read(mCacheFD, data.get(), fileSize);
   if (actual != fileSize) {
     return NS_ERROR_FAILURE;
   }
 
   nsPrimitiveHelpers::CreatePrimitiveForData(
     mFlavor, data.get(), fileSize, aData);
-  *aDataLen = fileSize;
   return NS_OK;
 }
 
 //-------------------------------------------------------------------------
 //
 // Transferable constructor
 //
 //-------------------------------------------------------------------------
@@ -266,22 +260,22 @@ nsTransferable::GetTransferData(const ch
 
   *aData = nullptr;
 
   nsresult rv = NS_OK;
 
   // First look and see if the data is present in one of the intrinsic flavors.
   if (Maybe<size_t> index = FindDataFlavor(aFlavor)) {
     nsCOMPtr<nsISupports> dataBytes;
-    uint32_t len;
-    mDataArray[index.value()].GetData(getter_AddRefs(dataBytes), &len);
+    mDataArray[index.value()].GetData(getter_AddRefs(dataBytes));
 
     // Do we have a (lazy) data provider?
     if (nsCOMPtr<nsIFlavorDataProvider> dataProvider =
           do_QueryInterface(dataBytes)) {
+      uint32_t len;
       rv = dataProvider->GetFlavorData(this, aFlavor,
                                        getter_AddRefs(dataBytes), &len);
       if (NS_FAILED(rv)) {
         dataBytes = nullptr;
         // The provider failed, fall into the converter code below.
       }
     }
 
@@ -296,20 +290,20 @@ nsTransferable::GetTransferData(const ch
   // If not, try using a format converter to get the requested flavor.
   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) {
         nsCOMPtr<nsISupports> dataBytes;
-        uint32_t len;
-        data.GetData(getter_AddRefs(dataBytes), &len);
+        data.GetData(getter_AddRefs(dataBytes));
 
         // Do we have a (lazy) data provider?
+        uint32_t len;
         if (nsCOMPtr<nsIFlavorDataProvider> dataProvider =
               do_QueryInterface(dataBytes)) {
           rv = dataProvider->GetFlavorData(this, aFlavor,
                                            getter_AddRefs(dataBytes), &len);
           if (NS_FAILED(rv)) {
             // Give up.
             return rv;
           }
@@ -336,18 +330,17 @@ nsTransferable::GetAnyTransferData(nsACS
                                    nsISupports** aData)
 {
   MOZ_ASSERT(mInitialized);
 
   for (size_t i = 0; i < mDataArray.Length(); ++i) {
     DataStruct& data = mDataArray.ElementAt(i);
     if (data.IsDataAvailable()) {
       aFlavor.Assign(data.GetFlavor());
-      uint32_t dataLen;
-      data.GetData(aData, &dataLen);
+      data.GetData(aData);
       return NS_OK;
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
 //
@@ -359,17 +352,17 @@ NS_IMETHODIMP
 nsTransferable::SetTransferData(const char* aFlavor,
                                 nsISupports* aData)
 {
   MOZ_ASSERT(mInitialized);
 
   // first check our intrinsic flavors to see if one has been registered.
   if (Maybe<size_t> index = FindDataFlavor(aFlavor)) {
     DataStruct& data = mDataArray.ElementAt(index.value());
-    data.SetData(aData, 0, mPrivateData);
+    data.SetData(aData, mPrivateData);
     return NS_OK;
   }
 
   // if not, try using a format converter to find a flavor to put the data in
   if (mFormatConv) {
     for (size_t i = 0; i < mDataArray.Length(); ++i) {
       DataStruct& data = mDataArray.ElementAt(i);
       bool canConvert = false;
@@ -379,17 +372,17 @@ nsTransferable::SetTransferData(const ch
         nsCOMPtr<nsISupports> ConvertedData;
         uint32_t ConvertedLen;
         mFormatConv->Convert(aFlavor,
                              aData,
                              0,
                              data.GetFlavor().get(),
                              getter_AddRefs(ConvertedData),
                              &ConvertedLen);
-        data.SetData(ConvertedData, ConvertedLen, mPrivateData);
+        data.SetData(ConvertedData, mPrivateData);
         return NS_OK;
       }
     }
   }
 
   // Can't set data neither directly nor through converter. Just add this flavor
   // and try again
   if (NS_SUCCEEDED(AddDataFlavor(aFlavor))) {
--- a/widget/nsTransferable.h
+++ b/widget/nsTransferable.h
@@ -20,39 +20,38 @@ class nsIMutableArray;
 //
 // DataStruct
 //
 // Holds a flavor (a mime type) that describes the data and the associated data.
 //
 struct DataStruct
 {
   explicit DataStruct ( const char* aFlavor )
-    : mDataLen(0), mCacheFD(nullptr), mFlavor(aFlavor) { }
+    : mCacheFD(nullptr), mFlavor(aFlavor) { }
   DataStruct(DataStruct&& aRHS);
   ~DataStruct();
-  
+
   const nsCString& GetFlavor() const { return mFlavor; }
-  void SetData( nsISupports* inData, uint32_t inDataLen, bool aIsPrivateData );
-  void GetData( nsISupports** outData, uint32_t *outDataLen );
-  bool IsDataAvailable() const { return mData ? mDataLen > 0 : mCacheFD != nullptr; }
-  
+  void SetData(nsISupports* inData, bool aIsPrivateData);
+  void GetData(nsISupports** outData);
+  bool IsDataAvailable() const { return mData || mCacheFD; }
+
 protected:
 
   enum {
     // The size of data over which we write the data to disk rather than
     // keep it around in memory.
     kLargeDatasetSize = 1000000        // 1 million bytes
   };
-  
+
   nsresult WriteCache(void* aData, uint32_t aDataLen);
-  nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
-  
-  // mData + mDataLen OR mCacheFD should be used, not both.
+  nsresult ReadCache(nsISupports** aData);
+
+  // mData OR mCacheFD should be used, not both.
   nsCOMPtr<nsISupports> mData;   // OWNER - some varient of primitive wrapper
-  uint32_t mDataLen;
   PRFileDesc* mCacheFD;
   const nsCString mFlavor;
 
 private:
   DataStruct(const DataStruct&) = delete;
   DataStruct& operator=(const DataStruct&) = delete;
 
 };