Adopt new assertion SPI for process suppression on Mac
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Dec 2012 05:57:47 +0000 (05:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Dec 2012 05:57:47 +0000 (05:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=105378

Patch by Kiran Muppala <cmuppala@apple.com> on 2012-12-19
Reviewed by Mark Rowe.

Source/WebKit2:

Process suppression for WebKit2 child processes is currently enabled or disabled using AutomaticTermination.
This should be replaced with a new assertion SPI specific to process suppression.

* Shared/ChildProcess.cpp:
(WebKit::ChildProcess::ChildProcess): Remove unused member variable m_applicationIsOccluded.
* Shared/ChildProcess.h:
(WebKit::ChildProcess::applicationIsOccluded): Infer occlusion state from m_processVisibleAssertion.
* Shared/mac/ChildProcessMac.mm:
(WebKit::ChildProcess::setApplicationIsOccluded): Use applicationIsOccluded() accessor to check if the
occlusion state has changed and take or release a process visible assertion accordingly.
(WebKit::ChildProcess::platformInitialize): Remove call to initializeTimerCoalescingPolicy(), since taking
a process visible assertion also sets the timer coalescing policy appropriately.  Set the occlusion
state to false on initialization.

WebKitLibraries:

Add WKNSProcessInfoProcessAssertionWithTypes().

* WebKitSystemInterface.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/ChildProcess.cpp
Source/WebKit2/Shared/ChildProcess.h
Source/WebKit2/Shared/mac/ChildProcessMac.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h

index 80553c5..11b0420 100644 (file)
@@ -1,3 +1,24 @@
+2012-12-19  Kiran Muppala  <cmuppala@apple.com>
+
+        Adopt new assertion SPI for process suppression on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=105378
+
+        Reviewed by Mark Rowe.
+
+        Process suppression for WebKit2 child processes is currently enabled or disabled using AutomaticTermination.
+        This should be replaced with a new assertion SPI specific to process suppression.
+
+        * Shared/ChildProcess.cpp:
+        (WebKit::ChildProcess::ChildProcess): Remove unused member variable m_applicationIsOccluded.
+        * Shared/ChildProcess.h:
+        (WebKit::ChildProcess::applicationIsOccluded): Infer occlusion state from m_processVisibleAssertion.
+        * Shared/mac/ChildProcessMac.mm:
+        (WebKit::ChildProcess::setApplicationIsOccluded): Use applicationIsOccluded() accessor to check if the
+        occlusion state has changed and take or release a process visible assertion accordingly.
+        (WebKit::ChildProcess::platformInitialize): Remove call to initializeTimerCoalescingPolicy(), since taking
+        a process visible assertion also sets the timer coalescing policy appropriately.  Set the occlusion
+        state to false on initialization.
+
 2012-12-19  Alexey Proskuryakov  <ap@apple.com>
 
         <rdar://problem/12890242> [WK2 NetworkProcess] Client doesn't receive SSL certificates
index eff475f..9b99a37 100644 (file)
@@ -60,9 +60,6 @@ ChildProcess::ChildProcess()
     : m_terminationTimeout(0)
     , m_terminationCounter(0)
     , m_terminationTimer(RunLoop::main(), this, &ChildProcess::terminationTimerFired)
-#if PLATFORM(MAC)
-    , m_applicationIsOccluded(false)
-#endif
 {
     // FIXME: The termination timer should not be scheduled on the main run loop.
     // It won't work with the threaded mode, but it's not really useful anyway as is.
index 0422628..815b9f0 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "Connection.h"
 #include <WebCore/RunLoop.h>
+#include <wtf/RetainPtr.h>
 
 #if PLATFORM(MAC)
 OBJC_CLASS NSString;
@@ -62,7 +63,7 @@ public:
     };
 
 #if PLATFORM(MAC)
-    bool applicationIsOccluded() const { return m_applicationIsOccluded; }
+    bool applicationIsOccluded() const { return !m_processVisibleAssertion; }
     void setApplicationIsOccluded(bool);
 #endif
 
@@ -80,13 +81,6 @@ private:
     virtual bool shouldTerminate() = 0;
     virtual void terminate();
 
-#if PLATFORM(MAC)
-    void disableProcessSuppression(NSString *reason);
-    void enableProcessSuppression(NSString *reason);
-
-    static NSString * const processSuppressionVisibleApplicationReason;
-#endif
-
     void platformInitialize();
 
     // The timeout, in seconds, before this process will be terminated if termination
@@ -100,7 +94,7 @@ private:
     WebCore::RunLoop::Timer<ChildProcess> m_terminationTimer;
 
 #if PLATFORM(MAC)
-    bool m_applicationIsOccluded;
+    RetainPtr<id> m_processVisibleAssertion;
 #endif
 };
 
index 8b54163..b764354 100644 (file)
 #import "config.h"
 #import "ChildProcess.h"
 
+#import "WebKitSystemInterface.h"
 #import <mach/task.h>
 
 namespace WebKit {
 
-NSString * const ChildProcess::processSuppressionVisibleApplicationReason = @"Application is Visible";
-
 void ChildProcess::setApplicationIsOccluded(bool applicationIsOccluded)
 {
-    if (m_applicationIsOccluded == applicationIsOccluded)
+    if (this->applicationIsOccluded() == applicationIsOccluded)
         return;
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    m_applicationIsOccluded = applicationIsOccluded;
-    if (m_applicationIsOccluded)
-        enableProcessSuppression(processSuppressionVisibleApplicationReason);
+    if (applicationIsOccluded)
+        m_processVisibleAssertion.clear();
     else
-        disableProcessSuppression(processSuppressionVisibleApplicationReason);
-#endif
-}
-
-void ChildProcess::disableProcessSuppression(NSString *reason)
-{
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    // The following assumes that a process enabling AutomaticTerminationSupport also
-    // takes a AutomaticTermination assertion for the lifetime of the process.
-    [[NSProcessInfo processInfo] disableAutomaticTermination:reason];
-#endif
-}
-
-void ChildProcess::enableProcessSuppression(NSString *reason)
-{
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    // The following assumes that a process enabling AutomaticTerminationSupport also
-    // takes a AutomaticTermination assertion for the lifetime of the process.
-    [[NSProcessInfo processInfo] enableAutomaticTermination:reason];
+        m_processVisibleAssertion = WKNSProcessInfoProcessAssertionWithTypes(WKProcessAssertionTypeVisible);
 #endif
 }
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-static void initializeTimerCoalescingPolicy()
-{
-    // Set task_latency and task_throughput QOS tiers as appropriate for a visible application.
-    struct task_qos_policy qosinfo = { LATENCY_QOS_TIER_0, THROUGHPUT_QOS_TIER_0 };
-    kern_return_t kr = task_policy_set(mach_task_self(), TASK_BASE_QOS_POLICY, (task_policy_t)&qosinfo, TASK_QOS_POLICY_COUNT);
-    ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
-}
-#endif
-
 void ChildProcess::platformInitialize()
 {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     setpriority(PRIO_DARWIN_PROCESS, 0, 0);
-    initializeTimerCoalescingPolicy();
 #endif
-    disableProcessSuppression(processSuppressionVisibleApplicationReason);
+    setApplicationIsOccluded(false);
 }
 
 }
index 9e7c465..7d931ed 100644 (file)
@@ -1,3 +1,14 @@
+2012-12-19  Kiran Muppala  <cmuppala@apple.com>
+
+        Adopt new assertion SPI for process suppression on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=105378
+
+        Reviewed by Mark Rowe.
+
+        Add WKNSProcessInfoProcessAssertionWithTypes().
+
+        * WebKitSystemInterface.h:
+
 2012-12-19  Alexis Menard  <alexis@webkit.org>
 
         Implement CSS parsing for CSS transitions unprefixed.
index 4b01bf8..ab1820a 100644 (file)
@@ -530,6 +530,13 @@ typedef void (*WKOcclusionNotificationHandler)(uint32_t, void*, uint32_t, void*,
 
 bool WKRegisterOcclusionNotificationHandler(WKOcclusionNotificationType, WKOcclusionNotificationHandler);
 bool WKUnregisterOcclusionNotificationHandler(WKOcclusionNotificationType, WKOcclusionNotificationHandler);
+
+enum {
+    WKProcessAssertionTypeVisible = (1UL << 10)
+};
+
+typedef NSUInteger WKProcessAssertionTypes;
+id WKNSProcessInfoProcessAssertionWithTypes(WKProcessAssertionTypes);
 #endif
 
 bool WKIsJavaPlugInActive(void);