Bug 746018 - Part 4 - More cache logging, r=jduell
authorBrian Smith <bsmith@mozilla.com>
Thu, 31 May 2012 15:20:03 -0700
changeset 97631 d13cd8ffde897c1bd0765bb9e861e8c612730a1f
parent 97630 aa61440b072f0f2c3d99ebc26e4385f09015e4c7
child 97632 0f3f9ff4439dc17f8c45289475c95d755d7dca9a
push idunknown
push userunknown
push dateunknown
reviewersjduell
bugs746018
milestone15.0a1
Bug 746018 - Part 4 - More cache logging, r=jduell
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache/nsDiskCacheBlockFile.cpp
netwerk/cache/nsDiskCacheMap.cpp
netwerk/cache/nsDiskCacheStreams.cpp
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -537,17 +537,17 @@ nsInputStreamWrapper::LazyInit()
     nsCacheEntry* cacheEntry = mDescriptor->CacheEntry();
     if (!cacheEntry) return NS_ERROR_NOT_AVAILABLE;
 
     rv = nsCacheService::OpenInputStreamForEntry(cacheEntry, mode,
                                                  mStartOffset,
                                                  getter_AddRefs(mInput));
 
     CACHE_LOG_DEBUG(("nsInputStreamWrapper::LazyInit "
-                      "[entry=%p, wrapper=%p, mInput=%p, rv=%d",
+                      "[entry=%p, wrapper=%p, mInput=%p, rv=%d]",
                       mDescriptor, this, mInput.get(), PRIntn(rv)));
 
     if (NS_FAILED(rv)) return rv;
 
     mInitialized = true;
     return NS_OK;
 }
 
@@ -568,19 +568,24 @@ nsInputStreamWrapper::Available(PRUint32
 
     return mInput->Available(avail);
 }
 
 nsresult nsCacheEntryDescriptor::
 nsInputStreamWrapper::Read(char *buf, PRUint32 count, PRUint32 *countRead)
 {
     nsresult rv = EnsureInit();
-    if (NS_FAILED(rv)) return rv;
+    if (NS_SUCCEEDED(rv))
+        rv = mInput->Read(buf, count, countRead);
 
-    return mInput->Read(buf, count, countRead);
+    CACHE_LOG_DEBUG(("nsInputStreamWrapper::Read "
+                      "[entry=%p, wrapper=%p, mInput=%p, rv=%d]",
+                      mDescriptor, this, mInput.get(), rv));
+
+    return rv;
 }
 
 nsresult nsCacheEntryDescriptor::
 nsInputStreamWrapper::ReadSegments(nsWriteSegmentFun writer, void *closure,
                                    PRUint32 count, PRUint32 *countRead)
 {
     // cache stream not buffered
     return NS_ERROR_NOT_IMPLEMENTED;
--- a/netwerk/cache/nsDiskCacheBlockFile.cpp
+++ b/netwerk/cache/nsDiskCacheBlockFile.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "nsCache.h"
 #include "nsDiskCache.h"
 #include "nsDiskCacheBlockFile.h"
 #include "mozilla/FileUtils.h"
 
 using namespace mozilla;
 
 /******************************************************************************
  * nsDiskCacheBlockFile - 
@@ -26,24 +27,25 @@ nsDiskCacheBlockFile::Open(nsILocalFile 
         return NS_ERROR_INVALID_ARG;
 
     mBlockSize = blockSize;
     mBitMapWords = bitMapSize / 32;
     PRUint32 bitMapBytes = mBitMapWords * 4;
     
     // open the file - restricted to user, the data could be confidential
     nsresult rv = blockFile->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE, 00600, &mFD);
-    if (NS_FAILED(rv))  return rv;  // unable to open or create file
+    if (NS_FAILED(rv)) {
+        CACHE_LOG_DEBUG(("CACHE: nsDiskCacheBlockFile::Open "
+                         "[this=%p] unable to open or create file: %d",
+                         this, rv));
+        return rv;  // unable to open or create file
+    }
     
     // allocate bit map buffer
     mBitMap = new PRUint32[mBitMapWords];
-    if (!mBitMap) {
-        rv = NS_ERROR_OUT_OF_MEMORY;
-        goto error_exit;
-    }
     
     // check if we just creating the file
     mFileSize = PR_Available(mFD);
     if (mFileSize < 0) {
         // XXX an error occurred. We could call PR_GetError(), but how would that help?
         rv = NS_ERROR_UNEXPECTED;
         goto error_exit;
     }
@@ -74,19 +76,23 @@ nsDiskCacheBlockFile::Open(nsILocalFile 
         // little bit smaller than used blocks times blocksize,
         // because the last block will generally not be 'whole'.
         const PRUint32  estimatedSize = CalcBlockFileSize();
         if ((PRUint32)mFileSize + blockSize < estimatedSize) {
             rv = NS_ERROR_UNEXPECTED;
             goto error_exit;
         }
     }
+    CACHE_LOG_DEBUG(("CACHE: nsDiskCacheBlockFile::Open [this=%p] succeeded",
+                      this));
     return NS_OK;
 
 error_exit:
+    CACHE_LOG_DEBUG(("CACHE: nsDiskCacheBlockFile::Open [this=%p] failed with "
+                     "error %d", this, rv));
     Close(false);
     return rv;
 }
 
 
 /******************************************************************************
  *  Close
  *****************************************************************************/
@@ -229,16 +235,19 @@ nsDiskCacheBlockFile::ReadBlocks( void *
 
     // read the blocks
     PRInt32 bytesToRead = *bytesRead;
     if ((bytesToRead <= 0) || ((PRUint32)bytesToRead > mBlockSize * numBlocks)) {
         bytesToRead = mBlockSize * numBlocks;
     }
     *bytesRead = PR_Read(mFD, buffer, bytesToRead);
     
+    CACHE_LOG_DEBUG(("CACHE: nsDiskCacheBlockFile::Read [this=%p] "
+                     "returned %d / %d bytes", this, *bytesRead, bytesToRead));
+
     return NS_OK;
 }
 
 
 /******************************************************************************
  *  FlushBitMap
  *****************************************************************************/
 nsresult
--- a/netwerk/cache/nsDiskCacheMap.cpp
+++ b/netwerk/cache/nsDiskCacheMap.cpp
@@ -72,16 +72,18 @@ nsDiskCacheMap::Open(nsILocalFile *  cac
             goto error_exit;
         }
     } else if (mapSize >= sizeof(nsDiskCacheHeader)) {  // read existing _CACHE_MAP_
         
         // if _CACHE_MAP_ exists, so should the block files
         if (!cacheFilesExist)
             goto error_exit;
 
+        CACHE_LOG_DEBUG(("CACHE: nsDiskCacheMap::Open [this=%p] reading map", this));
+
         // read the header
         PRUint32 bytesRead = PR_Read(mMapFD, &mHeader, sizeof(nsDiskCacheHeader));
         if (sizeof(nsDiskCacheHeader) != bytesRead)  goto error_exit;
         mHeader.Unswap();
 
         if (mHeader.mIsDirty || (mHeader.mVersion != nsDiskCache::kCurrentVersion))
             goto error_exit;
 
@@ -681,17 +683,21 @@ nsDiskCacheMap::ReadDiskCacheEntry(nsDis
         // open and read the file
         nsCOMPtr<nsILocalFile> file;
         rv = GetLocalFileForDiskCacheRecord(record,
                                             nsDiskCache::kMetaData,
                                             false,
                                             getter_AddRefs(file));
         NS_ENSURE_SUCCESS(rv, nsnull);
 
+        CACHE_LOG_DEBUG(("CACHE: nsDiskCacheMap::ReadDiskCacheEntry"
+                         "[this=%p] reading disk cache entry", this));
+
         PRFileDesc * fd = nsnull;
+
         // open the file - restricted to user, the data could be confidential
         rv = file->OpenNSPRFileDesc(PR_RDONLY, 00600, &fd);
         NS_ENSURE_SUCCESS(rv, nsnull);
         
         PRInt32 fileSize = PR_Available(fd);
         if (fileSize < 0) {
             // an error occurred. We could call PR_GetError(), but how would that help?
             rv = NS_ERROR_UNEXPECTED;
--- a/netwerk/cache/nsDiskCacheStreams.cpp
+++ b/netwerk/cache/nsDiskCacheStreams.cpp
@@ -698,16 +698,18 @@ nsDiskCacheStreamIO::UpdateFileSize()
 }
 
 
 nsresult
 nsDiskCacheStreamIO::OpenCacheFile(PRIntn flags, PRFileDesc ** fd)
 {
     NS_ENSURE_ARG_POINTER(fd);
     
+    CACHE_LOG_DEBUG(("nsDiskCacheStreamIO::OpenCacheFile"));
+
     nsresult         rv;
     nsDiskCacheMap * cacheMap = mDevice->CacheMap();
     
     rv = cacheMap->GetLocalFileForDiskCacheRecord(&mBinding->mRecord,
                                                   nsDiskCache::kData,
                                                   !!(flags & PR_CREATE_FILE),
                                                   getter_AddRefs(mLocalFile));
     if (NS_FAILED(rv))  return rv;