Bug 1285508 - Fixing memory report for BlobURLs, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 09 Jul 2016 13:19:46 +0200
changeset 344426 a60cf1b7124aa067e96cdd751ac526008f96ff8a
parent 344425 ff117266d9de99e0bafa5cf147948cc8dc054949
child 344427 df69a26957d3104517da062650291f77d402645e
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1285508
milestone50.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 1285508 - Fixing memory report for BlobURLs, r=smaug
dom/base/nsHostObjectProtocolHandler.cpp
--- a/dom/base/nsHostObjectProtocolHandler.cpp
+++ b/dom/base/nsHostObjectProtocolHandler.cpp
@@ -25,17 +25,17 @@
 using mozilla::dom::BlobImpl;
 using mozilla::ErrorResult;
 using mozilla::net::LoadInfo;
 
 // -----------------------------------------------------------------------
 // Hash table
 struct DataInfo
 {
-  // mObject is expected to be an nsIDOMBlob, DOMMediaStream, or MediaSource
+  // mObject is expected to be an BlobImpl, DOMMediaStream, or MediaSource
   nsCOMPtr<nsISupports> mObject;
   nsCOMPtr<nsIPrincipal> mPrincipal;
   nsCString mStack;
 };
 
 static nsClassHashtable<nsCStringHashKey, DataInfo>* gDataTable;
 
 // Memory reporting for the hash table.
@@ -68,69 +68,65 @@ class BlobURLsReporter final : public ns
 
   NS_IMETHOD CollectReports(nsIHandleReportCallback* aCallback,
                             nsISupports* aData, bool aAnonymize) override
   {
     if (!gDataTable) {
       return NS_OK;
     }
 
-    nsDataHashtable<nsPtrHashKey<nsIDOMBlob>, uint32_t> refCounts;
+    nsDataHashtable<nsPtrHashKey<BlobImpl>, uint32_t> refCounts;
 
-    // Determine number of URLs per blob, to handle the case where it's > 1.
+    // Determine number of URLs per BlobImpl, to handle the case where it's > 1.
     for (auto iter = gDataTable->Iter(); !iter.Done(); iter.Next()) {
-      nsCOMPtr<nsIDOMBlob> blob =
-        do_QueryInterface(iter.UserData()->mObject);
-      if (blob) {
-        refCounts.Put(blob, refCounts.Get(blob) + 1);
+      nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(iter.UserData()->mObject);
+      if (blobImpl) {
+        refCounts.Put(blobImpl, refCounts.Get(blobImpl) + 1);
       }
     }
 
     for (auto iter = gDataTable->Iter(); !iter.Done(); iter.Next()) {
       nsCStringHashKey::KeyType key = iter.Key();
       DataInfo* info = iter.UserData();
 
-      nsCOMPtr<nsIDOMBlob> tmp = do_QueryInterface(info->mObject);
-      RefPtr<mozilla::dom::Blob> blob =
-        static_cast<mozilla::dom::Blob*>(tmp.get());
-
-      if (blob) {
+      nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(iter.UserData()->mObject);
+      if (blobImpl) {
         NS_NAMED_LITERAL_CSTRING(desc,
           "A blob URL allocated with URL.createObjectURL; the referenced "
           "blob cannot be freed until all URLs for it have been explicitly "
           "invalidated with URL.revokeObjectURL.");
         nsAutoCString path, url, owner, specialDesc;
         nsCOMPtr<nsIURI> principalURI;
         uint64_t size = 0;
         uint32_t refCount = 1;
-        DebugOnly<bool> blobWasCounted;
+        DebugOnly<bool> blobImplWasCounted;
 
-        blobWasCounted = refCounts.Get(blob, &refCount);
-        MOZ_ASSERT(blobWasCounted);
+        blobImplWasCounted = refCounts.Get(blobImpl, &refCount);
+        MOZ_ASSERT(blobImplWasCounted);
         MOZ_ASSERT(refCount > 0);
 
-        bool isMemoryFile = blob->IsMemoryFile();
+        bool isMemoryFile = blobImpl->IsMemoryFile();
 
         if (isMemoryFile) {
           ErrorResult rv;
-          size = blob->GetSize(rv);
+          size = blobImpl->GetSize(rv);
           if (NS_WARN_IF(rv.Failed())) {
             rv.SuppressException();
             size = 0;
           }
         }
 
         path = isMemoryFile ? "memory-blob-urls/" : "file-blob-urls/";
         BuildPath(path, key, info, aAnonymize);
 
         if (refCount > 1) {
           nsAutoCString addrStr;
 
           addrStr = "0x";
-          addrStr.AppendInt((uint64_t)(nsIDOMBlob*)blob, 16);
+          addrStr.AppendInt((uint64_t)(BlobImpl*)blobImpl, 16);
 
           path += " ";
           path.AppendInt(refCount);
           path += "@";
           path += addrStr;
 
           specialDesc = desc;
           specialDesc += "\n\nNOTE: This blob (address ";
@@ -319,16 +315,25 @@ nsHostObjectProtocolHandler::nsHostObjec
 }
 
 nsresult
 nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aScheme,
                                           nsISupports* aObject,
                                           nsIPrincipal* aPrincipal,
                                           nsACString& aUri)
 {
+#ifdef DEBUG
+  nsCOMPtr<BlobImpl> blobImpl(do_QueryInterface(aObject));
+  nsCOMPtr<MediaSource> mediaSource(do_QueryInterface(aObject));
+  nsCOMPtr<DOMMediaStream> mediaStream(do_QueryInterface(aObject));
+
+  // We support only these types.
+  MOZ_ASSERT(blobImpl || mediaSource || mediaStream);
+#endif
+
   Init();
 
   nsresult rv = GenerateURIString(aScheme, aPrincipal, aUri);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!gDataTable) {
     gDataTable = new nsClassHashtable<nsCStringHashKey, DataInfo>;
   }