Bug 1410620 - Change CacheInfo interfaces in network to use ACString. r=michal,froydnj
authorTom Schuster <evilpies@gmail.com>
Sun, 29 Oct 2017 12:19:48 +0100
changeset 388923 3f387c200939b3dc99a477cd2d5c448adc877131
parent 388922 3311f58e8915e359437f6ce1e3627667ffe1e882
child 388924 c1c3b82079a559138c75facbdce0c14351e90ebc
push id32770
push userarchaeopteryx@coole-files.de
push dateSun, 29 Oct 2017 21:53:37 +0000
treeherdermozilla-central@1e4d6c984772 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal, froydnj
bugs1410620
milestone58.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 1410620 - Change CacheInfo interfaces in network to use ACString. r=michal,froydnj
netwerk/cache/nsCache.cpp
netwerk/cache/nsCache.h
netwerk/cache/nsCacheEntry.cpp
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache/nsDiskCacheDevice.cpp
netwerk/cache/nsDiskCacheDeviceSQL.cpp
netwerk/cache/nsDiskCacheEntry.cpp
netwerk/cache/nsICacheVisitor.idl
netwerk/cache/nsMemoryCacheDevice.cpp
netwerk/cache2/OldWrappers.cpp
--- a/netwerk/cache/nsCache.cpp
+++ b/netwerk/cache/nsCache.cpp
@@ -44,54 +44,48 @@ PRTimeFromSeconds(uint32_t seconds)
 {
   int64_t intermediateResult = seconds;
   PRTime prTime = intermediateResult * PR_USEC_PER_SEC;
   return prTime;
 }
 
 
 nsresult
-ClientIDFromCacheKey(const nsACString&  key, char ** result)
+ClientIDFromCacheKey(const nsACString& key, nsACString& result)
 {
-    nsresult  rv = NS_OK;
-    *result = nullptr;
-
     nsReadingIterator<char> colon;
     key.BeginReading(colon);
 
     nsReadingIterator<char> start;
     key.BeginReading(start);
 
     nsReadingIterator<char> end;
     key.EndReading(end);
 
     if (FindCharInReadable(':', colon, end)) {
-        *result = ToNewCString( Substring(start, colon));
-        if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
-    } else {
-        NS_ASSERTION(false, "FindCharInRead failed to find ':'");
-        rv = NS_ERROR_UNEXPECTED;
+        result.Assign(Substring(start, colon));
+        return NS_OK;
     }
-    return rv;
+
+    NS_ASSERTION(false, "FindCharInRead failed to find ':'");
+    return NS_ERROR_UNEXPECTED;
 }
 
 
 nsresult
 ClientKeyFromCacheKey(const nsCString& key, nsACString &result)
 {
-    nsresult  rv = NS_OK;
-
     nsReadingIterator<char> start;
     key.BeginReading(start);
 
     nsReadingIterator<char> end;
     key.EndReading(end);
 
     if (FindCharInReadable(':', start, end)) {
         ++start;  // advance past clientID ':' delimiter
         result.Assign(Substring(start, end));
-    } else {
-        NS_ASSERTION(false, "FindCharInRead failed to find ':'");
-        rv = NS_ERROR_UNEXPECTED;
-        result.Truncate(0);
+        return NS_OK;
     }
-    return rv;
+
+    NS_ASSERTION(false, "FindCharInRead failed to find ':'");
+    result.Truncate(0);
+    return NS_ERROR_UNEXPECTED;
 }
--- a/netwerk/cache/nsCache.h
+++ b/netwerk/cache/nsCache.h
@@ -30,13 +30,13 @@ void   CacheLogPrintPath(mozilla::LogLev
 #define CACHE_LOG_PATH(level, format, item) \
                                 CacheLogPrintPath(level, format, item)
 
 
 extern uint32_t  SecondsFromPRTime(PRTime prTime);
 extern PRTime    PRTimeFromSeconds(uint32_t seconds);
 
 
-extern nsresult  ClientIDFromCacheKey(const nsACString&  key, char ** result);
-extern nsresult  ClientKeyFromCacheKey(const nsCString& key, nsACString &result);
+extern nsresult  ClientIDFromCacheKey(const nsACString& key, nsACString& result);
+extern nsresult  ClientKeyFromCacheKey(const nsCString& key, nsACString& result);
 
 
 #endif // _nsCache_h
--- a/netwerk/cache/nsCacheEntry.cpp
+++ b/netwerk/cache/nsCacheEntry.cpp
@@ -267,33 +267,37 @@ nsCacheEntry::GetDescriptors(
 /******************************************************************************
  * nsCacheEntryInfo - for implementing about:cache
  *****************************************************************************/
 
 NS_IMPL_ISUPPORTS(nsCacheEntryInfo, nsICacheEntryInfo)
 
 
 NS_IMETHODIMP
-nsCacheEntryInfo::GetClientID(char ** clientID)
+nsCacheEntryInfo::GetClientID(nsACString& aClientID)
 {
-    NS_ENSURE_ARG_POINTER(clientID);
-    if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
+    if (!mCacheEntry) {
+        aClientID.Truncate();
+        return NS_ERROR_NOT_AVAILABLE;
+    }
 
-    return ClientIDFromCacheKey(*mCacheEntry->Key(), clientID);
+    return ClientIDFromCacheKey(*mCacheEntry->Key(), aClientID);
 }
 
 
 NS_IMETHODIMP
-nsCacheEntryInfo::GetDeviceID(char ** deviceID)
+nsCacheEntryInfo::GetDeviceID(nsACString& aDeviceID)
 {
-    NS_ENSURE_ARG_POINTER(deviceID);
-    if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
+    if (!mCacheEntry) {
+        aDeviceID.Truncate();
+        return NS_ERROR_NOT_AVAILABLE;
+    }
 
-    *deviceID = NS_strdup(mCacheEntry->GetDeviceID());
-    return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    aDeviceID.Assign(mCacheEntry->GetDeviceID());
+    return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsCacheEntryInfo::GetKey(nsACString &key)
 {
     if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
 
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -106,42 +106,39 @@ nsCacheEntryDescriptor::~nsCacheEntryDes
     NS_ASSERTION(!mOutputWrapper, "We have still an output wrapper!");
 
     nsCacheService * service = nsCacheService::GlobalInstance();
     NS_RELEASE(service);
 }
 
 
 NS_IMETHODIMP
-nsCacheEntryDescriptor::GetClientID(char ** result)
+nsCacheEntryDescriptor::GetClientID(nsACString& aClientID)
 {
-    NS_ENSURE_ARG_POINTER(result);
+    nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCLIENTID));
+    if (!mCacheEntry) {
+        aClientID.Truncate();
+        return NS_ERROR_NOT_AVAILABLE;
+    }
 
-    nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETCLIENTID));
-    if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
-
-    return ClientIDFromCacheKey(*(mCacheEntry->Key()), result);
+    return ClientIDFromCacheKey(*(mCacheEntry->Key()), aClientID);
 }
 
 
 NS_IMETHODIMP
-nsCacheEntryDescriptor::GetDeviceID(char ** aDeviceID)
+nsCacheEntryDescriptor::GetDeviceID(nsACString& aDeviceID)
 {
-    NS_ENSURE_ARG_POINTER(aDeviceID);
     nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETDEVICEID));
-    if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
-
-    const char* deviceID = mCacheEntry->GetDeviceID();
-    if (!deviceID) {
-        *aDeviceID = nullptr;
-        return NS_OK;
+    if (!mCacheEntry) {
+        aDeviceID.Truncate();
+        return NS_ERROR_NOT_AVAILABLE;
     }
 
-    *aDeviceID = NS_strdup(deviceID);
-    return *aDeviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    aDeviceID.Assign(mCacheEntry->GetDeviceID());
+    return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsCacheEntryDescriptor::GetKey(nsACString &result)
 {
     nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_GETKEY));
     if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
--- a/netwerk/cache/nsDiskCacheDevice.cpp
+++ b/netwerk/cache/nsDiskCacheDevice.cpp
@@ -192,26 +192,24 @@ public:
 private:
     virtual ~nsDiskCacheDeviceInfo() {}
 
     nsDiskCacheDevice* mDevice;
 };
 
 NS_IMPL_ISUPPORTS(nsDiskCacheDeviceInfo, nsICacheDeviceInfo)
 
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetDescription(char ** aDescription)
+NS_IMETHODIMP nsDiskCacheDeviceInfo::GetDescription(nsACString& aDescription)
 {
-    NS_ENSURE_ARG_POINTER(aDescription);
-    *aDescription = NS_strdup("Disk cache device");
-    return *aDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    aDescription.AssignLiteral("Disk cache device");
+    return NS_OK;
 }
 
-NS_IMETHODIMP nsDiskCacheDeviceInfo::GetUsageReport(char ** usageReport)
+NS_IMETHODIMP nsDiskCacheDeviceInfo::GetUsageReport(nsACString& aUsageReport)
 {
-    NS_ENSURE_ARG_POINTER(usageReport);
     nsCString buffer;
 
     buffer.AssignLiteral("  <tr>\n"
                          "    <th>Cache Directory:</th>\n"
                          "    <td>");
     nsCOMPtr<nsIFile> cacheDir;
     nsAutoString path;
     mDevice->getCacheDirectory(getter_AddRefs(cacheDir));
@@ -219,19 +217,17 @@ NS_IMETHODIMP nsDiskCacheDeviceInfo::Get
     if (NS_SUCCEEDED(rv)) {
         AppendUTF16toUTF8(path, buffer);
     } else {
         buffer.AppendLiteral("directory unavailable");
     }
     buffer.AppendLiteral("</td>\n"
                          "  </tr>\n");
 
-    *usageReport = ToNewCString(buffer);
-    if (!*usageReport) return NS_ERROR_OUT_OF_MEMORY;
-
+    aUsageReport.Assign(buffer);
     return NS_OK;
 }
 
 NS_IMETHODIMP nsDiskCacheDeviceInfo::GetEntryCount(uint32_t *aEntryCount)
 {
     NS_ENSURE_ARG_POINTER(aEntryCount);
     *aEntryCount = mDevice->getEntryCount();
     return NS_OK;
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -343,24 +343,24 @@ private:
   ~nsOfflineCacheDeviceInfo() {}
 
   nsOfflineCacheDevice* mDevice;
 };
 
 NS_IMPL_ISUPPORTS(nsOfflineCacheDeviceInfo, nsICacheDeviceInfo)
 
 NS_IMETHODIMP
-nsOfflineCacheDeviceInfo::GetDescription(char **aDescription)
+nsOfflineCacheDeviceInfo::GetDescription(nsACString& aDescription)
 {
-  *aDescription = NS_strdup("Offline cache device");
-  return *aDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+  aDescription.AssignLiteral("Offline cache device");
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsOfflineCacheDeviceInfo::GetUsageReport(char ** usageReport)
+nsOfflineCacheDeviceInfo::GetUsageReport(nsACString& aUsageReport)
 {
   nsAutoCString buffer;
   buffer.AssignLiteral("  <tr>\n"
                        "    <th>Cache Directory:</th>\n"
                        "    <td>");
   nsIFile *cacheDir = mDevice->CacheDirectory();
   if (!cacheDir)
     return NS_OK;
@@ -370,20 +370,17 @@ nsOfflineCacheDeviceInfo::GetUsageReport
   if (NS_SUCCEEDED(rv))
     AppendUTF16toUTF8(path, buffer);
   else
     buffer.AppendLiteral("directory unavailable");
 
   buffer.AppendLiteral("</td>\n"
                        "  </tr>\n");
 
-  *usageReport = ToNewCString(buffer);
-  if (!*usageReport)
-    return NS_ERROR_OUT_OF_MEMORY;
-
+  aUsageReport.Assign(buffer);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheDeviceInfo::GetEntryCount(uint32_t *aEntryCount)
 {
   *aEntryCount = mDevice->EntryCount();
   return NS_OK;
@@ -585,27 +582,27 @@ public:
   NS_DECL_NSICACHEENTRYINFO
 
   nsOfflineCacheRecord *mRec;
 };
 
 NS_IMPL_ISUPPORTS(nsOfflineCacheEntryInfo, nsICacheEntryInfo)
 
 NS_IMETHODIMP
-nsOfflineCacheEntryInfo::GetClientID(char **result)
+nsOfflineCacheEntryInfo::GetClientID(nsACString& aClientID)
 {
-  *result = NS_strdup(mRec->clientID);
-  return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+  aClientID.Assign(mRec->clientID);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsOfflineCacheEntryInfo::GetDeviceID(char ** deviceID)
+nsOfflineCacheEntryInfo::GetDeviceID(nsACString& aDeviceID)
 {
-  *deviceID = NS_strdup(OFFLINE_CACHE_DEVICE_ID);
-  return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+  aDeviceID.Assign(OFFLINE_CACHE_DEVICE_ID);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsOfflineCacheEntryInfo::GetKey(nsACString &clientKey)
 {
   clientKey.Assign(mRec->key);
   return NS_OK;
 }
--- a/netwerk/cache/nsDiskCacheEntry.cpp
+++ b/netwerk/cache/nsDiskCacheEntry.cpp
@@ -65,28 +65,26 @@ nsDiskCacheEntry::CreateCacheEntry(nsCac
 
 
 /******************************************************************************
  *  nsDiskCacheEntryInfo
  *****************************************************************************/
 
 NS_IMPL_ISUPPORTS(nsDiskCacheEntryInfo, nsICacheEntryInfo)
 
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
+NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(nsACString& aClientID)
 {
-    NS_ENSURE_ARG_POINTER(clientID);
-    return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientID);
+    return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), aClientID);
 }
 
 extern const char DISK_CACHE_DEVICE_ID[];
-NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
+NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(nsACString& aDeviceID)
 {
-    NS_ENSURE_ARG_POINTER(deviceID);
-    *deviceID = NS_strdup(mDeviceID);
-    return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+    aDeviceID.Assign(mDeviceID);
+    return NS_OK;
 }
 
 
 NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
 {
     return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientKey);
 }
 
--- a/netwerk/cache/nsICacheVisitor.idl
+++ b/netwerk/cache/nsICacheVisitor.idl
@@ -43,23 +43,23 @@ interface nsICacheVisitor : nsISupports
 
 
 [scriptable, uuid(31d1c294-1dd2-11b2-be3a-c79230dca297)]
 interface nsICacheDeviceInfo : nsISupports
 {
     /**
      * Get a human readable description of the cache device.
      */
-    readonly attribute string  description;
+    readonly attribute ACString  description;
     
     /**
      * Get a usage report, statistics, miscellaneous data about
      * the cache device.
      */
-    readonly attribute string  usageReport;
+    readonly attribute ACString  usageReport;
     
     /**
      * Get the number of stored cache entries.
      */
     readonly attribute unsigned long  entryCount;
     
     /**
      * Get the total size of the stored cache entries.
@@ -74,22 +74,22 @@ interface nsICacheDeviceInfo : nsISuppor
 
 
 [scriptable, uuid(fab51c92-95c3-4468-b317-7de4d7588254)]
 interface nsICacheEntryInfo : nsISupports
 {
     /**
      * Get the client id associated with this cache entry.
      */
-    readonly attribute string  clientID;
+    readonly attribute ACString clientID;
 
     /**
      * Get the id for the device that stores this cache entry.
      */
-    readonly attribute string deviceID;
+    readonly attribute ACString deviceID;
 
     /**
      * Get the key identifying the cache entry.
      */
     readonly attribute ACString key;
     
     /**
      * Get the number of times the cache entry has been opened.
--- a/netwerk/cache/nsMemoryCacheDevice.cpp
+++ b/netwerk/cache/nsMemoryCacheDevice.cpp
@@ -558,40 +558,36 @@ nsMemoryCacheDevice::CheckEntryCount()
  * nsMemoryCacheDeviceInfo - for implementing about:cache
  *****************************************************************************/
 
 
 NS_IMPL_ISUPPORTS(nsMemoryCacheDeviceInfo, nsICacheDeviceInfo)
 
 
 NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetDescription(char ** result)
+nsMemoryCacheDeviceInfo::GetDescription(nsACString& aDescription)
 {
-    NS_ENSURE_ARG_POINTER(result);
-    *result = NS_strdup("Memory cache device");
-    if (!*result) return NS_ERROR_OUT_OF_MEMORY;
+    aDescription.AssignLiteral("Memory cache device");
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
-nsMemoryCacheDeviceInfo::GetUsageReport(char ** result)
+nsMemoryCacheDeviceInfo::GetUsageReport(nsACString& aUsageReport)
 {
-    NS_ENSURE_ARG_POINTER(result);
-    nsCString  buffer;
+    nsCString buffer;
 
     buffer.AssignLiteral("  <tr>\n"
                          "    <th>Inactive storage:</th>\n"
                          "    <td>");
     buffer.AppendInt(mDevice->mInactiveSize / 1024);
     buffer.AppendLiteral(" KiB</td>\n"
                          "  </tr>\n");
 
-    *result = ToNewCString(buffer);
-    if (!*result) return NS_ERROR_OUT_OF_MEMORY;
+    aUsageReport.Assign(buffer);
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsMemoryCacheDeviceInfo::GetEntryCount(uint32_t * result)
 {
     NS_ENSURE_ARG_POINTER(result);
--- a/netwerk/cache2/OldWrappers.cpp
+++ b/netwerk/cache2/OldWrappers.cpp
@@ -202,18 +202,18 @@ NS_IMETHODIMP _OldVisitCallbackWrapper::
 {
   MOZ_ASSERT(!strcmp(deviceID, mDeviceID));
 
   nsresult rv;
 
   *_retval = true;
 
   // Read all informative properties from the entry.
-  nsCString clientId;
-  rv = entryInfo->GetClientID(getter_Copies(clientId));
+  nsAutoCString clientId;
+  rv = entryInfo->GetClientID(clientId);
   if (NS_FAILED(rv))
     return NS_OK;
 
   if (mLoadInfo->IsPrivate() !=
       StringBeginsWith(clientId, NS_LITERAL_CSTRING("HTTP-memory-only-PB"))) {
     return NS_OK;
   }