Should not take background task assertion for NetworkProcess
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jul 2014 01:12:45 +0000 (01:12 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jul 2014 01:12:45 +0000 (01:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134622

Reviewed by Tim Horton.

When the WebContent wants to complete a task in the background we take a process assertion on the child process, and also need to prevent the UI process from suspending.
However for the NetworkProcess we always just hold a process assertion, and don't want this to interfere with UIApp suspension.

* Platform/IPC/mac/ConnectionMac.mm:
(IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
    - ProcessAssertion -> ProcessAndUIAssertion
* UIProcess/ProcessAssertion.cpp:
(WebKit::ProcessAssertion::ProcessAssertion):
    - assignment -> initializer list.
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::setState):
    - added no-op implementation.
(WebKit::ProcessAssertion::~ProcessAssertion): Deleted.
* UIProcess/ProcessAssertion.h:
    - removed ~ProcessAssertion, added ProcessAndUIAssertion class.
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::didConnnectToProcess):
    - ProcessAssertion -> ProcessAndUIAssertion
* UIProcess/ProcessThrottler.h:
    - ProcessAssertion -> ProcessAndUIAssertion
* UIProcess/ios/ProcessAssertionIOS.mm:
(WebKit::ProcessAssertion::ProcessAssertion):
    - assignment -> initializer list.
    - moved code to manage WKProcessAssertionBackgroundTaskManager
(WebKit::ProcessAssertion::setState):
    - moved code to manage WKProcessAssertionBackgroundTaskManager
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::setState):
    - moved code to manage WKProcessAssertionBackgroundTaskManager from ProcessAssertion.
(WebKit::ProcessAssertion::~ProcessAssertion): Deleted.
    - delete - moved code to manage WKProcessAssertionBackgroundTaskManager

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

Source/WebKit2/ChangeLog
Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm
Source/WebKit2/UIProcess/ProcessAssertion.cpp
Source/WebKit2/UIProcess/ProcessAssertion.h
Source/WebKit2/UIProcess/ProcessThrottler.cpp
Source/WebKit2/UIProcess/ProcessThrottler.h
Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm

index 2cd969f..0c189ca 100644 (file)
@@ -1,3 +1,44 @@
+2014-07-03  Gavin Barraclough  <baraclough@apple.com>
+
+        Should not take background task assertion for NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=134622
+
+        Reviewed by Tim Horton.
+
+        When the WebContent wants to complete a task in the background we take a process assertion on the child process, and also need to prevent the UI process from suspending.
+        However for the NetworkProcess we always just hold a process assertion, and don't want this to interfere with UIApp suspension.
+
+        * Platform/IPC/mac/ConnectionMac.mm:
+        (IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
+            - ProcessAssertion -> ProcessAndUIAssertion
+        * UIProcess/ProcessAssertion.cpp:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+            - assignment -> initializer list.
+        (WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
+        (WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
+        (WebKit::ProcessAndUIAssertion::setState):
+            - added no-op implementation.
+        (WebKit::ProcessAssertion::~ProcessAssertion): Deleted.
+        * UIProcess/ProcessAssertion.h:
+            - removed ~ProcessAssertion, added ProcessAndUIAssertion class.
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::didConnnectToProcess):
+            - ProcessAssertion -> ProcessAndUIAssertion
+        * UIProcess/ProcessThrottler.h:
+            - ProcessAssertion -> ProcessAndUIAssertion
+        * UIProcess/ios/ProcessAssertionIOS.mm:
+        (WebKit::ProcessAssertion::ProcessAssertion):
+            - assignment -> initializer list.
+            - moved code to manage WKProcessAssertionBackgroundTaskManager
+        (WebKit::ProcessAssertion::setState):
+            - moved code to manage WKProcessAssertionBackgroundTaskManager
+        (WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
+        (WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
+        (WebKit::ProcessAndUIAssertion::setState):
+            - moved code to manage WKProcessAssertionBackgroundTaskManager from ProcessAssertion.
+        (WebKit::ProcessAssertion::~ProcessAssertion): Deleted.
+            - delete - moved code to manage WKProcessAssertionBackgroundTaskManager
+
 2014-07-03  Simon Fraser  <simon.fraser@apple.com>
 
         Clean up Brady's mess on iOS.
index e3f5770..d00dd51 100644 (file)
@@ -85,7 +85,7 @@ private:
         : m_xpcConnection(xpcConnection)
         , m_watchdogTimer(RunLoop::main(), this, &ConnectionTerminationWatchdog::watchdogTimerFired)
 #if PLATFORM(IOS)
-        , m_assertion(std::make_unique<WebKit::ProcessAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), WebKit::AssertionState::Background))
+        , m_assertion(std::make_unique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), WebKit::AssertionState::Background))
 #endif
     {
         m_watchdogTimer.startOneShot(intervalInSeconds);
@@ -102,7 +102,7 @@ private:
     XPCPtr<xpc_connection_t> m_xpcConnection;
     RunLoop::Timer<ConnectionTerminationWatchdog> m_watchdogTimer;
 #if PLATFORM(IOS)
-    std::unique_ptr<WebKit::ProcessAssertion> m_assertion;
+    std::unique_ptr<WebKit::ProcessAndUIAssertion> m_assertion;
 #endif
 };
     
index 10f1757..f8533b4 100644 (file)
 namespace WebKit {
 
 ProcessAssertion::ProcessAssertion(pid_t, AssertionState assertionState)
-{
-    m_assertionState = assertionState;
-}
-
-ProcessAssertion::~ProcessAssertion()
+    : m_assertionState(assertionState)
 {
 }
 
@@ -47,6 +43,20 @@ void ProcessAssertion::setState(AssertionState assertionState)
     m_assertionState = assertionState;
 }
     
+ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, AssertionState assertionState)
+    : ProcessAssertion(pid, assertionState)
+{
+}
+
+ProcessAndUIAssertion::~ProcessAndUIAssertion()
+{
+}
+
+void ProcessAndUIAssertion::setState(AssertionState assertionState)
+{
+    ProcessAssertion::setState(assertionState);
+}
+    
 }
 
 #endif // !PLATFORM(IOS)
index bd0e486..c0937ab 100644 (file)
@@ -42,7 +42,6 @@ enum class AssertionState {
 class ProcessAssertion {
 public:
     ProcessAssertion(pid_t, AssertionState);
-    ~ProcessAssertion();
     
     AssertionState state() const { return m_assertionState; }
     
@@ -55,6 +54,14 @@ private:
     AssertionState m_assertionState;
 };
     
+class ProcessAndUIAssertion : public ProcessAssertion {
+public:
+    ProcessAndUIAssertion(pid_t, AssertionState);
+    ~ProcessAndUIAssertion();
+    
+    void setState(AssertionState);
+};
+    
 }
 
 #endif // ProcessAssertion_h
index 6f6c32d..b9b6d86 100644 (file)
@@ -113,7 +113,7 @@ void ProcessThrottler::updateAssertion()
 void ProcessThrottler::didConnnectToProcess(pid_t pid)
 {
     m_suspendTimer.stop();
-    m_assertion = std::make_unique<ProcessAssertion>(pid, assertionState());
+    m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, assertionState());
 }
     
 void ProcessThrottler::suspendTimerFired(WebCore::Timer<ProcessThrottler>*)
index 5f2f68f..c7129cc 100644 (file)
@@ -73,7 +73,7 @@ private:
     
     WebProcessProxy* m_process;
     WeakPtrFactory<ProcessThrottler> m_weakPtrFactory;
-    std::unique_ptr<ProcessAssertion> m_assertion;
+    std::unique_ptr<ProcessAndUIAssertion> m_assertion;
     WebCore::Timer<ProcessThrottler> m_suspendTimer;
     unsigned m_foregroundCount;
     unsigned m_backgroundCount;
index f388f64..04277c7 100644 (file)
@@ -150,29 +150,38 @@ ProcessAssertion::ProcessAssertion(pid_t pid, AssertionState assertionState)
         }
     };
     m_assertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:pid flags:flagsForState(assertionState) reason:BKSProcessAssertionReasonExtension name:@"Web content visible" withHandler:handler]);
+}
+
+void ProcessAssertion::setState(AssertionState assertionState)
+{
+    if (m_assertionState == assertionState)
+        return;
+
+    m_assertionState = assertionState;
+    [m_assertion setFlags:flagsForState(assertionState)];
+}
 
-    if (m_assertionState != AssertionState::Suspended)
+ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, AssertionState assertionState)
+    : ProcessAssertion(pid, assertionState)
+{
+    if (assertionState != AssertionState::Suspended)
         [[WKProcessAssertionBackgroundTaskManager shared] incrementNeedsToRunInBackgroundCount];
 }
 
-ProcessAssertion::~ProcessAssertion()
+ProcessAndUIAssertion::~ProcessAndUIAssertion()
 {
-    if (m_assertionState != AssertionState::Suspended)
+    if (state() != AssertionState::Suspended)
         [[WKProcessAssertionBackgroundTaskManager shared] decrementNeedsToRunInBackgroundCount];
 }
 
-void ProcessAssertion::setState(AssertionState assertionState)
+void ProcessAndUIAssertion::setState(AssertionState assertionState)
 {
-    if (m_assertionState == assertionState)
-        return;
-
-    if ((m_assertionState != AssertionState::Suspended) && (assertionState == AssertionState::Suspended))
-        [[WKProcessAssertionBackgroundTaskManager shared] decrementNeedsToRunInBackgroundCount];
-    if ((m_assertionState == AssertionState::Suspended) && (assertionState != AssertionState::Suspended))
+    if ((state() == AssertionState::Suspended) && (assertionState != AssertionState::Suspended))
         [[WKProcessAssertionBackgroundTaskManager shared] incrementNeedsToRunInBackgroundCount];
+    if ((state() != AssertionState::Suspended) && (assertionState == AssertionState::Suspended))
+        [[WKProcessAssertionBackgroundTaskManager shared] decrementNeedsToRunInBackgroundCount];
 
-    m_assertionState = assertionState;
-    [m_assertion setFlags:flagsForState(assertionState)];
+    ProcessAssertion::setState(assertionState);
 }
 
 } // namespace WebKit
@@ -182,17 +191,27 @@ void ProcessAssertion::setState(AssertionState assertionState)
 namespace WebKit {
 
 ProcessAssertion::ProcessAssertion(pid_t, AssertionState assertionState)
+    : m_assertionState(assertionState)
+{
+}
+
+void ProcessAssertion::setState(AssertionState assertionState)
 {
     m_assertionState = assertionState;
 }
 
-ProcessAssertion::~ProcessAssertion()
+ProcessAndUIAssertion::ProcessAndUIAssertion(pid_t pid, AssertionState assertionState)
+    : ProcessAssertion(pid, assertionState)
 {
 }
 
-void ProcessAssertion::setState(AssertionState assertionState)
+ProcessAndUIAssertion::~ProcessAndUIAssertion()
 {
-    m_assertionState = assertionState;
+}
+
+void ProcessAndUIAssertion::setState(AssertionState assertionState)
+{
+    ProcessAssertion::setState(assertionState);
 }
 
 } // namespace WebKit