Bug 1475065 part 10. Remove nsIDOMOfflineResourceList::SwapCache. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 11 Jul 2018 18:41:28 -0700
changeset 1564021 2d954e4f6fd6cf85698d3d291763ef5bc7e3a819
parent 1564020 9e7ba58adbf2f695dcd5f5f49176108caf9dde71
child 1564022 8cf74d5801084dcc4f5acf02ab1ac25357ff0eca
push id283952
push userbzbarsky@mozilla.com
push dateThu, 12 Jul 2018 06:01:37 +0000
treeherdertry@3f386196ace6 [default view] [failures only]
reviewersmystor
bugs1475065
milestone63.0a1
Bug 1475065 part 10. Remove nsIDOMOfflineResourceList::SwapCache. r=mystor
dom/interfaces/offline/nsIDOMOfflineResourceList.idl
dom/offline/nsDOMOfflineResourceList.cpp
dom/offline/nsDOMOfflineResourceList.h
--- a/dom/interfaces/offline/nsIDOMOfflineResourceList.idl
+++ b/dom/interfaces/offline/nsIDOMOfflineResourceList.idl
@@ -7,15 +7,9 @@
 
 [uuid(6044702d-e4a9-420c-b711-558b7d6a3b9f)]
 interface nsIDOMOfflineResourceList : nsISupports
 {
   /**
    * Get the list of dynamically-managed entries.
    */
   readonly attribute nsISupports mozItems;
-
-  /**
-   * Swap in the newest version of the application cache, or disassociate
-   * from the cache if the cache group is obsolete.
-   */
-  void swapCache();
 };
--- a/dom/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/offline/nsDOMOfflineResourceList.cpp
@@ -553,62 +553,72 @@ nsDOMOfflineResourceList::Update(ErrorRe
   rv = updateService->ScheduleUpdate(mManifestURI, mDocumentURI, mLoadingPrincipal,
                                      window, getter_AddRefs(update));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     aRv.Throw(rv);
     return;
   }
 }
 
-NS_IMETHODIMP
-nsDOMOfflineResourceList::SwapCache()
+void
+nsDOMOfflineResourceList::SwapCache(ErrorResult& aRv)
 {
   nsresult rv = Init();
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
+    return;
+  }
 
   if (!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
-    return NS_ERROR_DOM_SECURITY_ERR;
+    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
+    return;
   }
 
   nsCOMPtr<nsIApplicationCache> currentAppCache = GetDocumentAppCache();
   if (!currentAppCache) {
-    return NS_ERROR_DOM_INVALID_STATE_ERR;
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return;
   }
 
   // Check the current and potentially newly available cache are not identical.
   if (mAvailableApplicationCache == currentAppCache) {
-    return NS_ERROR_DOM_INVALID_STATE_ERR;
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return;
   }
 
   if (mAvailableApplicationCache) {
     nsCString currClientId, availClientId;
     currentAppCache->GetClientID(currClientId);
     mAvailableApplicationCache->GetClientID(availClientId);
-    if (availClientId == currClientId)
-      return NS_ERROR_DOM_INVALID_STATE_ERR;
+    if (availClientId == currClientId) {
+      aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+      return;
+    }
   } else if (mStatus != OfflineResourceList_Binding::OBSOLETE) {
-    return NS_ERROR_DOM_INVALID_STATE_ERR;
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return;
   }
 
   ClearCachedKeys();
 
   nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer =
     GetDocumentAppCacheContainer();
 
   // In the case of an obsolete cache group, newAppCache might be null.
   // We will disassociate from the cache in that case.
   if (appCacheContainer) {
     rv = appCacheContainer->SetApplicationCache(mAvailableApplicationCache);
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      aRv.Throw(rv);
+      return;
+    }
   }
 
   mAvailableApplicationCache = nullptr;
   mStatus = OfflineResourceList_Binding::IDLE;
-
-  return NS_OK;
 }
 
 void
 nsDOMOfflineResourceList::FirePendingEvents()
 {
   for (int32_t i = 0; i < mPendingEvents.Count(); ++i) {
     RefPtr<Event> event = mPendingEvents[i];
     DispatchEvent(*event);
--- a/dom/offline/nsDOMOfflineResourceList.h
+++ b/dom/offline/nsDOMOfflineResourceList.h
@@ -67,20 +67,17 @@ public:
   }
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   uint16_t GetStatus(ErrorResult& aRv);
 
   void Update(ErrorResult& aRv);
 
-  void SwapCache(ErrorResult& aRv)
-  {
-    aRv = SwapCache();
-  }
+  void SwapCache(ErrorResult& aRv);
 
   IMPL_EVENT_HANDLER(checking)
   IMPL_EVENT_HANDLER(error)
   IMPL_EVENT_HANDLER(noupdate)
   IMPL_EVENT_HANDLER(downloading)
   IMPL_EVENT_HANDLER(progress)
   IMPL_EVENT_HANDLER(cached)
   IMPL_EVENT_HANDLER(updateready)