Title: [164914] trunk/Source/WebCore
Revision
164914
Author
[email protected]
Date
2014-03-01 01:01:58 -0800 (Sat, 01 Mar 2014)

Log Message

Change PageActivityAssertionToken to use a WeakPtr
https://bugs.webkit.org/show_bug.cgi?id=129526

Reviewed by Sam Weinig.

PageThrottler effectively implements a bespoke weak pointer mechanism; remove this & just use WeakPtr.

* page/PageActivityAssertionToken.cpp:
(WebCore::PageActivityAssertionToken::PageActivityAssertionToken):
(WebCore::PageActivityAssertionToken::~PageActivityAssertionToken):
    - addActivityToken->incrementActivityCount, removeActivityToken->decrementActivityCount
* page/PageActivityAssertionToken.h:
    - removed invalidate, made m_throttler a WeakPtr
* page/PageThrottler.cpp:
(WebCore::PageThrottler::PageThrottler):
    - initialize m_weakPtrFactory, m_activityCount.
(WebCore::PageThrottler::~PageThrottler):
    - removed called to invalidate.
(WebCore::PageThrottler::startThrottleHysteresisTimer):
    - m_activityTokens.size()->m_activityCount
(WebCore::PageThrottler::throttleHysteresisTimerFired):
    - m_activityTokens.size()->m_activityCount
(WebCore::PageThrottler::incrementActivityCount):
    - m_activityTokens.add->++
(WebCore::PageThrottler::decrementActivityCount):
    - m_activityTokens.remove->--
* page/PageThrottler.h:
(WebCore::PageThrottler::weakPtr):
    - replaced HashSet with WeakPtrFactory & count.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (164913 => 164914)


--- trunk/Source/WebCore/ChangeLog	2014-03-01 08:49:34 UTC (rev 164913)
+++ trunk/Source/WebCore/ChangeLog	2014-03-01 09:01:58 UTC (rev 164914)
@@ -1,5 +1,37 @@
 2014-03-01  Gavin Barraclough  <[email protected]>
 
+        Change PageActivityAssertionToken to use a WeakPtr
+        https://bugs.webkit.org/show_bug.cgi?id=129526
+
+        Reviewed by Sam Weinig.
+
+        PageThrottler effectively implements a bespoke weak pointer mechanism; remove this & just use WeakPtr.
+
+        * page/PageActivityAssertionToken.cpp:
+        (WebCore::PageActivityAssertionToken::PageActivityAssertionToken):
+        (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken):
+            - addActivityToken->incrementActivityCount, removeActivityToken->decrementActivityCount
+        * page/PageActivityAssertionToken.h:
+            - removed invalidate, made m_throttler a WeakPtr
+        * page/PageThrottler.cpp:
+        (WebCore::PageThrottler::PageThrottler):
+            - initialize m_weakPtrFactory, m_activityCount.
+        (WebCore::PageThrottler::~PageThrottler):
+            - removed called to invalidate.
+        (WebCore::PageThrottler::startThrottleHysteresisTimer):
+            - m_activityTokens.size()->m_activityCount
+        (WebCore::PageThrottler::throttleHysteresisTimerFired):
+            - m_activityTokens.size()->m_activityCount
+        (WebCore::PageThrottler::incrementActivityCount):
+            - m_activityTokens.add->++
+        (WebCore::PageThrottler::decrementActivityCount):
+            - m_activityTokens.remove->--
+        * page/PageThrottler.h:
+        (WebCore::PageThrottler::weakPtr):
+            - replaced HashSet with WeakPtrFactory & count.
+
+2014-03-01  Gavin Barraclough  <[email protected]>
+
         Split UserActivity/CountedUserActivity
         https://bugs.webkit.org/show_bug.cgi?id=129520
 

Modified: trunk/Source/WebCore/page/PageActivityAssertionToken.cpp (164913 => 164914)


--- trunk/Source/WebCore/page/PageActivityAssertionToken.cpp	2014-03-01 08:49:34 UTC (rev 164913)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.cpp	2014-03-01 09:01:58 UTC (rev 164914)
@@ -31,22 +31,17 @@
 namespace WebCore {
 
 PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler& throttler)
-    : m_throttler(&throttler)
+    : m_throttler(throttler.weakPtr())
 {
-    m_throttler->addActivityToken(*this);
+    throttler.incrementActivityCount();
 }
 
 PageActivityAssertionToken::~PageActivityAssertionToken()
 {
-    if (m_throttler)
-        m_throttler->removeActivityToken(*this);
+    if (PageThrottler* throttler = m_throttler.get())
+        throttler->decrementActivityCount();
 }
 
-void PageActivityAssertionToken::invalidate()
-{
-    m_throttler = 0;
-}
-
 } // namespace WebCore
 
 

Modified: trunk/Source/WebCore/page/PageActivityAssertionToken.h (164913 => 164914)


--- trunk/Source/WebCore/page/PageActivityAssertionToken.h	2014-03-01 08:49:34 UTC (rev 164913)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.h	2014-03-01 09:01:58 UTC (rev 164914)
@@ -27,6 +27,7 @@
 #define PageActivityAssertionToken_h
 
 #include <wtf/Noncopyable.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -38,10 +39,8 @@
     PageActivityAssertionToken(PageThrottler&);
     ~PageActivityAssertionToken();
 
-    void invalidate();
-
 private:
-    PageThrottler* m_throttler;
+    WeakPtr<PageThrottler> m_throttler;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/PageThrottler.cpp (164913 => 164914)


--- trunk/Source/WebCore/page/PageThrottler.cpp	2014-03-01 08:49:34 UTC (rev 164913)
+++ trunk/Source/WebCore/page/PageThrottler.cpp	2014-03-01 09:01:58 UTC (rev 164914)
@@ -42,6 +42,8 @@
     , m_viewState(viewState)
     , m_throttleState(PageNotThrottledState)
     , m_throttleHysteresisTimer(this, &PageThrottler::throttleHysteresisTimerFired)
+    , m_weakPtrFactory(this)
+    , m_activityCount(0)
     , m_visuallyNonIdle("Page is not visually idle.")
     , m_pageActivity("Page is active.")
 {
@@ -54,9 +56,6 @@
 {
     m_page.setTimerThrottlingEnabled(false);
 
-    for (auto it = m_activityTokens.begin(), end = m_activityTokens.end(); it != end; ++it)
-        (*it)->invalidate();
-
     if (m_throttleState != PageThrottledState)
         m_pageActivity.decrement();
 }
@@ -150,24 +149,20 @@
 {
     if (m_throttleHysteresisTimer.isActive())
         m_throttleHysteresisTimer.stop();
-    if (!m_activityTokens.size())
+    if (!m_activityCount)
         m_throttleHysteresisTimer.startOneShot(kThrottleHysteresisSeconds);
 }
 
 void PageThrottler::throttleHysteresisTimerFired(Timer<PageThrottler>&)
 {
-    ASSERT(!m_activityTokens.size());
+    ASSERT(!m_activityCount);
     throttlePage();
 }
 
-void PageThrottler::addActivityToken(PageActivityAssertionToken& token)
+void PageThrottler::incrementActivityCount()
 {
-    ASSERT(!m_activityTokens.contains(&token));
-
-    m_activityTokens.add(&token);
-
     // If we've already got events that block throttling we can return early
-    if (m_activityTokens.size() > 1)
+    if (m_activityCount++)
         return;
 
     if (m_throttleState == PageNotThrottledState)
@@ -180,13 +175,9 @@
     stopThrottleHysteresisTimer();
 }
 
-void PageThrottler::removeActivityToken(PageActivityAssertionToken& token)
+void PageThrottler::decrementActivityCount()
 {
-    ASSERT(m_activityTokens.contains(&token));
-
-    m_activityTokens.remove(&token);
-
-    if (m_activityTokens.size())
+    if (--m_activityCount)
         return;
 
     if (m_throttleState == PageNotThrottledState)

Modified: trunk/Source/WebCore/page/PageThrottler.h (164913 => 164914)


--- trunk/Source/WebCore/page/PageThrottler.h	2014-03-01 08:49:34 UTC (rev 164913)
+++ trunk/Source/WebCore/page/PageThrottler.h	2014-03-01 09:01:58 UTC (rev 164914)
@@ -33,6 +33,7 @@
 #include <wtf/HashSet.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -61,8 +62,9 @@
     };
 
     friend class PageActivityAssertionToken;
-    void addActivityToken(PageActivityAssertionToken&);
-    void removeActivityToken(PageActivityAssertionToken&);
+    WeakPtr<PageThrottler> weakPtr() { return m_weakPtrFactory.createWeakPtr(); }
+    void incrementActivityCount();
+    void decrementActivityCount();
 
     void reportInterestingEvent();
 
@@ -80,7 +82,8 @@
     ViewState::Flags m_viewState;
     PageThrottleState m_throttleState;
     Timer<PageThrottler> m_throttleHysteresisTimer;
-    HashSet<PageActivityAssertionToken*> m_activityTokens;
+    WeakPtrFactory<PageThrottler> m_weakPtrFactory;
+    size_t m_activityCount;
     UserActivity m_visuallyNonIdle;
     CountedUserActivity m_pageActivity;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to