Bug 815847 - Part 1: Remove nsXULPrototypeCache::gStartupCache; r=bsmedberg
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 03 Jan 2013 16:38:08 -0500
changeset 126653 1871463a0542b3d641ba7f76cbc8186f1a8ca0cf
parent 126652 2453fdb37bf45e71eb5767f3d3464364ec626785
child 126654 1d59903b166f6bba9ee765968d0e871d221ec6a9
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs815847
milestone20.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 815847 - Part 1: Remove nsXULPrototypeCache::gStartupCache; r=bsmedberg There is no good reason why this variable should be used.
content/xul/document/src/nsXULPrototypeCache.cpp
content/xul/document/src/nsXULPrototypeCache.h
--- a/content/xul/document/src/nsXULPrototypeCache.cpp
+++ b/content/xul/document/src/nsXULPrototypeCache.cpp
@@ -50,17 +50,16 @@ DisableXULCacheChangedCallback(const cha
     if (cache)
         cache->Flush();
 
     return 0;
 }
 
 //----------------------------------------------------------------------
 
-StartupCache*   nsXULPrototypeCache::gStartupCache = nullptr;
 nsXULPrototypeCache*  nsXULPrototypeCache::sInstance = nullptr;
 
 
 nsXULPrototypeCache::nsXULPrototypeCache()
 {
 }
 
 
@@ -100,22 +99,16 @@ nsXULPrototypeCache::GetInstance()
             obsSvc->AddObserver(p, "chrome-flush-caches", false);
             obsSvc->AddObserver(p, "startupcache-invalidate", false);
         }
 		
     }
     return sInstance;
 }
 
-/* static */ StartupCache*
-nsXULPrototypeCache::GetStartupCache()
-{
-    return gStartupCache;
-}
-
 //----------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsXULPrototypeCache::Observe(nsISupports* aSubject,
                              const char *aTopic,
                              const PRUnichar *aData)
 {
     if (!strcmp(aTopic, "chrome-flush-skin-caches")) {
@@ -361,21 +354,16 @@ nsXULPrototypeCache::RemoveFromCacheSet(
     mCacheURITable.Remove(aURI);
 }
 
 nsresult
 nsXULPrototypeCache::WritePrototype(nsXULPrototypeDocument* aPrototypeDocument)
 {
     nsresult rv = NS_OK, rv2 = NS_OK;
 
-    // We're here before the startupcache service has been initialized, probably because
-    // of the profile manager. Bail quietly, don't worry, we'll be back later.
-    if (!gStartupCache)
-        return NS_OK;
-
     nsCOMPtr<nsIURI> protoURI = aPrototypeDocument->GetURI();
 
     // Remove this document from the cache table. We use the table's
     // emptiness instead of a counter to decide when the caching process 
     // has completed.
     RemoveFromCacheSet(protoURI);
 
     nsCOMPtr<nsIObjectOutputStream> oos;
@@ -394,21 +382,22 @@ nsXULPrototypeCache::GetInputStream(nsIU
     nsAutoCString spec(kXULCachePrefix);
     nsresult rv = PathifyURI(uri, spec);
     if (NS_FAILED(rv)) 
         return NS_ERROR_NOT_AVAILABLE;
     
     nsAutoArrayPtr<char> buf;
     uint32_t len;
     nsCOMPtr<nsIObjectInputStream> ois;
-    if (!gStartupCache)
+    StartupCache* sc = StartupCache::GetSingleton();
+    if (!sc)
         return NS_ERROR_NOT_AVAILABLE;
-    
-    rv = gStartupCache->GetBuffer(spec.get(), getter_Transfers(buf), &len);
-    if (NS_FAILED(rv)) 
+
+    rv = sc->GetBuffer(spec.get(), getter_Transfers(buf), &len);
+    if (NS_FAILED(rv))
         return NS_ERROR_NOT_AVAILABLE;
 
     rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
     NS_ENSURE_SUCCESS(rv, rv);
     buf.forget();
 
     mInputStreamTable.Put(uri, ois);
     
@@ -445,19 +434,20 @@ nsXULPrototypeCache::GetOutputStream(nsI
     NS_ADDREF(*stream = objectOutput);
     return NS_OK;
 }
 
 nsresult
 nsXULPrototypeCache::FinishOutputStream(nsIURI* uri) 
 {
     nsresult rv;
-    if (!gStartupCache)
+    StartupCache* sc = StartupCache::GetSingleton();
+    if (!sc)
         return NS_ERROR_NOT_AVAILABLE;
-    
+
     nsCOMPtr<nsIStorageStream> storageStream;
     bool found = mOutputStreamTable.Get(uri, getter_AddRefs(storageStream));
     if (!found)
         return NS_ERROR_UNEXPECTED;
     nsCOMPtr<nsIOutputStream> outputStream
         = do_QueryInterface(storageStream);
     outputStream->Close();
     
@@ -466,17 +456,17 @@ nsXULPrototypeCache::FinishOutputStream(
     rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf), 
                                     &len);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoCString spec(kXULCachePrefix);
     rv = PathifyURI(uri, spec);
     if (NS_FAILED(rv))
         return NS_ERROR_NOT_AVAILABLE;
-    rv = gStartupCache->PutBuffer(spec.get(), buf, len);
+    rv = sc->PutBuffer(spec.get(), buf, len);
     if (NS_SUCCEEDED(rv))
         mOutputStreamTable.Remove(uri);
     
     return rv;
 }
 
 // We have data if we're in the middle of writing it or we already
 // have it in the cache.
@@ -490,29 +480,22 @@ nsXULPrototypeCache::HasData(nsIURI* uri
     nsAutoCString spec(kXULCachePrefix);
     nsresult rv = PathifyURI(uri, spec);
     if (NS_FAILED(rv)) {
         *exists = false;
         return NS_OK;
     }
     nsAutoArrayPtr<char> buf;
     uint32_t len;
-    if (gStartupCache)
-        rv = gStartupCache->GetBuffer(spec.get(), getter_Transfers(buf), 
-                                      &len);
+    StartupCache* sc = StartupCache::GetSingleton();
+    if (sc)
+        rv = sc->GetBuffer(spec.get(), getter_Transfers(buf), &len);
     else {
-        // We don't have everything we need to call BeginCaching and set up
-        // gStartupCache right now, but we just need to check the cache for 
-        // this URI.
-        StartupCache* sc = StartupCache::GetSingleton();
-        if (!sc) {
-            *exists = false;
-            return NS_OK;
-        }
-        rv = sc->GetBuffer(spec.get(), getter_Transfers(buf), &len);
+        *exists = false;
+        return NS_OK;
     }
     *exists = NS_SUCCEEDED(rv);
     return NS_OK;
 }
 
 static int
 CachePrefChangedCallback(const char* aPref, void* aClosure)
 {
@@ -535,31 +518,16 @@ nsXULPrototypeCache::BeginCaching(nsIURI
 {
     nsresult rv, tmp;
 
     nsAutoCString path;
     aURI->GetPath(path);
     if (!StringEndsWith(path, NS_LITERAL_CSTRING(".xul")))
         return NS_ERROR_NOT_AVAILABLE;
 
-    // Test gStartupCache to decide whether this is the first nsXULDocument
-    // participating in the serialization.  If gStartupCache is non-null, this document
-    // must not be first, but it can join the process.  Examples of
-    // multiple master documents participating include hiddenWindow.xul and
-    // navigator.xul on the Mac, and multiple-app-component (e.g., mailnews
-    // and browser) startup due to command-line arguments.
-    //
-    if (gStartupCache) {
-        mCacheURITable.Put(aURI, 1);
-
-        return NS_OK;
-    }
-
-    // Use a local to refer to the service till we're sure we succeeded, then
-    // commit to gStartupCache.
     StartupCache* startupCache = StartupCache::GetSingleton();
     if (!startupCache)
         return NS_ERROR_FAILURE;
 
     gDisableXULDiskCache =
         Preferences::GetBool(kDisableXULCachePref, gDisableXULDiskCache);
 
     Preferences::RegisterCallback(CachePrefChangedCallback,
@@ -674,17 +642,16 @@ nsXULPrototypeCache::BeginCaching(nsIURI
             return NS_ERROR_FAILURE;
         }
     }
 
     // Success!  Insert this URI into the mCacheURITable
     // and commit locals to globals.
     mCacheURITable.Put(aURI, 1);
 
-    gStartupCache = startupCache;
     return NS_OK;
 }
 
 static PLDHashOperator
 MarkXBLInCCGeneration(nsIURI* aKey, nsRefPtr<nsXBLDocumentInfo> &aDocInfo,
                       void* aClosure)
 {
     uint32_t* gen = static_cast<uint32_t*>(aClosure);
--- a/content/xul/document/src/nsXULPrototypeCache.h
+++ b/content/xul/document/src/nsXULPrototypeCache.h
@@ -106,18 +106,16 @@ public:
      * startupCache.
      */
     nsresult GetInputStream(nsIURI* aURI, nsIObjectInputStream** objectInput);
     nsresult FinishInputStream(nsIURI* aURI);
     nsresult GetOutputStream(nsIURI* aURI, nsIObjectOutputStream** objectOutput);
     nsresult FinishOutputStream(nsIURI* aURI);
     nsresult HasData(nsIURI* aURI, bool* exists);
 
-    static mozilla::scache::StartupCache* GetStartupCache();
-
     static nsXULPrototypeCache* GetInstance();
 
     static void ReleaseGlobals()
     {
         NS_IF_RELEASE(sInstance);
     }
 
     void MarkInCCGeneration(uint32_t aGeneration);
@@ -138,17 +136,16 @@ protected:
     nsDataHashtable<nsURIHashKey,CacheScriptEntry>         mScriptTable;
     nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo>  mXBLDocTable;
 
     ///////////////////////////////////////////////////////////////////////////
     // StartupCache
     // this is really a hash set, with a dummy data parameter
     nsDataHashtable<nsURIHashKey,uint32_t> mCacheURITable;
 
-    static mozilla::scache::StartupCache* gStartupCache;
     nsInterfaceHashtable<nsURIHashKey, nsIStorageStream> mOutputStreamTable;
     nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable;
  
     // Bootstrap caching service
     nsresult BeginCaching(nsIURI* aDocumentURI);
 };
 
 #endif // nsXULPrototypeCache_h__