Bug 1244122 P1 Always support SW intercept even when http cache is disabled. r=mayhemer
authorBen Kelly <ben@wanderview.com>
Tue, 02 Feb 2016 10:03:20 -0800
changeset 320996 40a7c388a4b5714116243730672e1d4067f349df
parent 320995 5ca8eeaa2a214830515a7c79f1e5384c53f52487
child 320997 b8e2ef4983a96c39c8c1bf18d3efa6e582e710c7
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1244122
milestone47.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 1244122 P1 Always support SW intercept even when http cache is disabled. r=mayhemer
netwerk/cache2/CacheStorage.cpp
netwerk/cache2/nsICacheStorage.idl
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/cache2/CacheStorage.cpp
+++ b/netwerk/cache2/CacheStorage.cpp
@@ -43,22 +43,24 @@ CacheStorage::~CacheStorage()
 NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI *aURI,
                                          const nsACString & aIdExtension,
                                          uint32_t aFlags,
                                          nsICacheEntryOpenCallback *aCallback)
 {
   if (!CacheStorageService::Self())
     return NS_ERROR_NOT_INITIALIZED;
 
-  if (MOZ_UNLIKELY(!CacheObserver::UseDiskCache()) && mWriteToDisk) {
+  if (MOZ_UNLIKELY(!CacheObserver::UseDiskCache()) && mWriteToDisk &&
+                   !(aFlags & OPEN_INTERCEPTED)) {
     aCallback->OnCacheEntryAvailable(nullptr, false, nullptr, NS_ERROR_NOT_AVAILABLE);
     return NS_OK;
   }
 
-  if (MOZ_UNLIKELY(!CacheObserver::UseMemoryCache()) && !mWriteToDisk) {
+  if (MOZ_UNLIKELY(!CacheObserver::UseMemoryCache()) && !mWriteToDisk &&
+                   !(aFlags & OPEN_INTERCEPTED)) {
     aCallback->OnCacheEntryAvailable(nullptr, false, nullptr, NS_ERROR_NOT_AVAILABLE);
     return NS_OK;
   }
 
   NS_ENSURE_ARG(aURI);
   NS_ENSURE_ARG(aCallback);
 
   nsresult rv;
--- a/netwerk/cache2/nsICacheStorage.idl
+++ b/netwerk/cache2/nsICacheStorage.idl
@@ -52,16 +52,22 @@ interface nsICacheStorage : nsISupports
   const uint32_t CHECK_MULTITHREADED = 1 << 4;
 
   /**
    * Don't automatically update any 'last used' metadata of the entry.
    */
   const uint32_t OPEN_SECRETLY = 1 << 5;
 
   /**
+   * Entry is being opened as part of a service worker interception.  Do not
+   * allow the cache to be disabled in this case.
+   */
+  const uint32_t OPEN_INTERCEPTED = 1 << 6;
+
+  /**
    * Asynchronously opens a cache entry for the specified URI.
    * Result is fetched asynchronously via the callback.
    *
    * @param aURI
    *    The URI to search in cache or to open for writting.
    * @param aIdExtension
    *    Any string that will extend (distinguish) the entry.  Two entries
    *    with the same aURI but different aIdExtension will be comletely
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -2986,16 +2986,17 @@ nsHttpChannel::OpenCacheEntry(bool isHtt
         nsCOMPtr<nsINetworkInterceptController> controller;
         GetCallback(controller);
 
         RefPtr<InterceptedChannelChrome> intercepted =
                 new InterceptedChannelChrome(this, controller, entry);
         intercepted->NotifyController();
     } else {
         if (mInterceptCache == INTERCEPTED) {
+            cacheEntryOpenFlags |= nsICacheStorage::OPEN_INTERCEPTED;
             DebugOnly<bool> exists;
             MOZ_ASSERT(NS_SUCCEEDED(cacheStorage->Exists(openURI, extension, &exists)) && exists,
                        "The entry must exist in the cache after we create it here");
         }
         rv = cacheStorage->AsyncOpenURI(openURI, extension, cacheEntryOpenFlags, this);
         NS_ENSURE_SUCCESS(rv, rv);
     }