Bug 972799 - Show file-base and memory-base blob-url report in about:memory. r=njn

This commit is contained in:
Jerry Shih 2014-03-03 14:35:00 -05:00
Родитель ee44fc09c2
Коммит d7e95b8bc5
5 изменённых файлов: 66 добавлений и 19 удалений

Просмотреть файл

@ -380,6 +380,8 @@ public:
NS_IMETHOD GetInternalStream(nsIInputStream**) MOZ_OVERRIDE;
NS_IMETHOD_(bool) IsMemoryFile(void) MOZ_OVERRIDE;
protected:
// Create slice
nsDOMMemoryFile(const nsDOMMemoryFile* aOther, uint64_t aStart,

Просмотреть файл

@ -54,6 +54,9 @@ public:
static void RemoveDataEntry(const nsACString& aUri);
static nsIPrincipal* GetDataEntryPrincipal(const nsACString& aUri);
static void Traverse(const nsACString& aUri, nsCycleCollectionTraversalCallback& aCallback);
private:
static void Init(void);
};
class nsBlobProtocolHandler : public nsHostObjectProtocolHandler

Просмотреть файл

@ -26,7 +26,7 @@ interface nsIURI;
interface nsIPrincipal;
interface nsIDOMBlob;
[scriptable, builtinclass, uuid(52d22585-7737-460e-9731-c658df03304a)]
[scriptable, builtinclass, uuid(b1723fac-4814-4429-82cb-dc54ba0d46d6)]
interface nsIDOMBlob : nsISupports
{
readonly attribute unsigned long long size;
@ -57,9 +57,12 @@ interface nsIDOMBlob : nsISupports
// Called before the blob is stored in a database to decide if it can be
// shared or needs to be copied. It can be called on any thread.
[notxpcom] FileInfo getFileInfo(in FileManager aFileManager);
// Return true if this blob is a memory file.
[notxpcom] bool isMemoryFile();
};
[scriptable, builtinclass, uuid(0acb4135-9f79-4516-ba92-b5fba5203620)]
[scriptable, builtinclass, uuid(4e7d1a8b-e2d5-4304-a753-4affb731660c)]
interface nsIDOMFile : nsIDOMBlob
{
readonly attribute DOMString name;

Просмотреть файл

@ -443,6 +443,12 @@ nsDOMFileBase::SetMutable(bool aMutable)
return rv;
}
NS_IMETHODIMP_(bool)
nsDOMFileBase::IsMemoryFile(void)
{
return false;
}
////////////////////////////////////////////////////////////////////////////
// nsDOMFile implementation
@ -636,6 +642,12 @@ nsDOMMemoryFile::GetInternalStream(nsIInputStream **aStream)
return DataOwnerAdapter::Create(mDataOwner, mStart, mLength, aStream);
}
NS_IMETHODIMP_(bool)
nsDOMMemoryFile::IsMemoryFile(void)
{
return true;
}
/* static */ StaticMutex
nsDOMMemoryFile::DataOwner::sDataOwnerMutex;

Просмотреть файл

@ -166,7 +166,7 @@ class BlobURLsReporter MOZ_FINAL : public nsIMemoryReporter
"invalidated with URL.revokeObjectURL.");
nsAutoCString path, url, owner, specialDesc;
nsCOMPtr<nsIURI> principalURI;
uint64_t size;
uint64_t size = 0;
uint32_t refCount = 1;
DebugOnly<bool> blobWasCounted;
@ -174,11 +174,15 @@ class BlobURLsReporter MOZ_FINAL : public nsIMemoryReporter
MOZ_ASSERT(blobWasCounted);
MOZ_ASSERT(refCount > 0);
if (NS_FAILED(blob->GetSize(&size))) {
size = 0;
bool isMemoryFile = blob->IsMemoryFile();
if (isMemoryFile) {
if (NS_FAILED(blob->GetSize(&size))) {
size = 0;
}
}
path = "blob-urls/";
path = isMemoryFile ? "memory-blob-urls/" : "file-blob-urls/";
if (NS_SUCCEEDED(aInfo->mPrincipal->GetURI(getter_AddRefs(principalURI))) &&
principalURI != nullptr &&
NS_SUCCEEDED(principalURI->GetSpec(owner)) &&
@ -211,19 +215,35 @@ class BlobURLsReporter MOZ_FINAL : public nsIMemoryReporter
specialDesc += addrStr;
specialDesc += ") has ";
specialDesc.AppendInt(refCount);
specialDesc += " URLs; its size is divided ";
specialDesc += refCount > 2 ? "among" : "between";
specialDesc += " them in this report.";
specialDesc += " URLs.";
if (isMemoryFile) {
specialDesc += " Its size is divided ";
specialDesc += refCount > 2 ? "among" : "between";
specialDesc += " them in this report.";
}
}
const nsACString& descString = specialDesc.IsEmpty()
? static_cast<const nsACString&>(desc)
: static_cast<const nsACString&>(specialDesc);
if (isMemoryFile) {
envp->mCallback->Callback(EmptyCString(),
path,
KIND_OTHER,
UNITS_BYTES,
size / refCount,
descString,
envp->mData);
}
else {
envp->mCallback->Callback(EmptyCString(),
path,
KIND_OTHER,
UNITS_COUNT,
1,
descString,
envp->mData);
}
envp->mCallback->Callback(EmptyCString(),
path,
KIND_OTHER,
UNITS_BYTES,
size / refCount,
(specialDesc.IsEmpty()
? static_cast<const nsACString&>(desc)
: static_cast<const nsACString&>(specialDesc)),
envp->mData);
}
return PL_DHASH_NEXT;
}
@ -233,7 +253,8 @@ NS_IMPL_ISUPPORTS1(BlobURLsReporter, nsIMemoryReporter)
}
nsHostObjectProtocolHandler::nsHostObjectProtocolHandler()
void
nsHostObjectProtocolHandler::Init(void)
{
static bool initialized = false;
@ -244,6 +265,10 @@ nsHostObjectProtocolHandler::nsHostObjectProtocolHandler()
}
}
nsHostObjectProtocolHandler::nsHostObjectProtocolHandler()
{
Init();
}
nsresult
nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aScheme,
@ -251,6 +276,8 @@ nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aScheme,
nsIPrincipal* aPrincipal,
nsACString& aUri)
{
Init();
nsresult rv = GenerateURIString(aScheme, aUri);
NS_ENSURE_SUCCESS(rv, rv);