[watchOS] Add more assertions to NetworkProximityAssertion
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2018 23:20:51 +0000 (23:20 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2018 23:20:51 +0000 (23:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188721

Reviewed by Wenson Hsieh.

* NetworkProcess/watchos/NetworkProximityAssertion.mm:
(WebKit::NetworkProximityAssertion::hold):
(WebKit::NetworkProximityAssertion::release):
(WebKit::NetworkProximityAssertion::releaseTimerFired):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235012 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.mm

index f09c645..2c61090 100644 (file)
@@ -1,3 +1,15 @@
+2018-08-18  Andy Estes  <aestes@apple.com>
+
+        [watchOS] Add more assertions to NetworkProximityAssertion
+        https://bugs.webkit.org/show_bug.cgi?id=188721
+
+        Reviewed by Wenson Hsieh.
+
+        * NetworkProcess/watchos/NetworkProximityAssertion.mm:
+        (WebKit::NetworkProximityAssertion::hold):
+        (WebKit::NetworkProximityAssertion::release):
+        (WebKit::NetworkProximityAssertion::releaseTimerFired):
+
 2018-08-18  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] Paste is missing from callout bar when pasteboard only contains custom data
index 1e71c6c..178f3b4 100644 (file)
@@ -57,20 +57,27 @@ void NetworkProximityAssertion::hold()
     }
 
     if (m_releaseTimer.isActive()) {
+        ASSERT(m_isHoldingAssertion);
         m_releaseTimer.stop();
         return;
     }
 
-    if (m_assertionCount == 1)
+    if (m_assertionCount == 1) {
+        ASSERT(!m_isHoldingAssertion);
         holdNow();
+    }
+
+    ASSERT(m_isHoldingAssertion);
 }
 
 void NetworkProximityAssertion::release()
 {
     ASSERT(m_assertionCount);
-    if (!m_assertionCount || --m_assertionCount)
+    if (!m_assertionCount)
         return;
 
+    --m_assertionCount;
+
     if (m_state == State::Suspended) {
         ASSERT(!m_isHoldingAssertion);
         ASSERT(!m_releaseTimer.isActive());
@@ -78,7 +85,10 @@ void NetworkProximityAssertion::release()
         return;
     }
 
-    m_releaseTimer.restart();
+    ASSERT(m_isHoldingAssertion);
+    ASSERT(!m_releaseTimer.isActive());
+    if (!m_assertionCount)
+        m_releaseTimer.restart();
 }
 
 void NetworkProximityAssertion::resume(ResumptionReason)
@@ -135,9 +145,10 @@ void NetworkProximityAssertion::suspendNow()
 
 void NetworkProximityAssertion::releaseTimerFired()
 {
-    ASSERT(!m_releaseTimer.isActive());
-    ASSERT(!m_assertionCount);
+    ASSERT(m_isHoldingAssertion);
     ASSERT(m_state != State::Suspended);
+    ASSERT(!m_assertionCount);
+    ASSERT(!m_releaseTimer.isActive());
     releaseNow();
 }