Add API to restrict WebKit processes to background priority
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2016 18:06:47 +0000 (18:06 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2016 18:06:47 +0000 (18:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163363

Reviewed by Anders Carlson.

Add API on _WKProcessPoolConfiguration to flag a process pool as 'alwaysRunsAtBackgroundPriority'.
WebContent and Networking processes associated with that pool will only run a background priority,
when they otherwise would have run at foreground priority.

* UIProcess/API/APIProcessPoolConfiguration.h:
    - Add m_alwaysRunsAtBackgroundPriority flag to pool configuration object.
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration alwaysRunsAtBackgroundPriority]):
(-[_WKProcessPoolConfiguration setAlwaysRunsAtBackgroundPriority:]):
    - Expose new configuration property through API.
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::alwaysRunsAtBackgroundPriority):
* UIProcess/Network/NetworkProcessProxy.h:
    - Support ProcessThrottlerClient interface to check if alwaysRunsAtBackgroundPriority is set.
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::assertionState):
    - When determining whether to take a foreground exception check alwaysRunsAtBackgroundPriority.
* UIProcess/ProcessThrottlerClient.h:
    - Add interface to access alwaysRunsAtBackgroundPriority state of WebProcess of NetworkProcess.
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::WebProcessPool):
* UIProcess/WebProcessPool.h:
    - Add m_alwaysRunsAtBackgroundPriority, set by configuration.
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::alwaysRunsAtBackgroundPriority):
* UIProcess/WebProcessProxy.h:
    - Support ProcessThrottlerClient interface to check if alwaysRunsAtBackgroundPriority is set.

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

13 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.cpp
Source/WebKit2/UIProcess/API/APIProcessPoolConfiguration.h
Source/WebKit2/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h
Source/WebKit2/UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm
Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit2/UIProcess/ProcessThrottler.cpp
Source/WebKit2/UIProcess/ProcessThrottlerClient.h
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/UIProcess/WebProcessPool.h
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.h

index 7d12238..94ed432 100644 (file)
@@ -1,3 +1,39 @@
+2016-10-14  Gavin Barraclough  <barraclough@apple.com>
+
+        Add API to restrict WebKit processes to background priority
+        https://bugs.webkit.org/show_bug.cgi?id=163363
+
+        Reviewed by Anders Carlson.
+
+        Add API on _WKProcessPoolConfiguration to flag a process pool as 'alwaysRunsAtBackgroundPriority'.
+        WebContent and Networking processes associated with that pool will only run a background priority,
+        when they otherwise would have run at foreground priority.
+
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+            - Add m_alwaysRunsAtBackgroundPriority flag to pool configuration object.
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        (-[_WKProcessPoolConfiguration alwaysRunsAtBackgroundPriority]):
+        (-[_WKProcessPoolConfiguration setAlwaysRunsAtBackgroundPriority:]):
+            - Expose new configuration property through API.
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::alwaysRunsAtBackgroundPriority):
+        * UIProcess/Network/NetworkProcessProxy.h:
+            - Support ProcessThrottlerClient interface to check if alwaysRunsAtBackgroundPriority is set.
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::assertionState):
+            - When determining whether to take a foreground exception check alwaysRunsAtBackgroundPriority.
+        * UIProcess/ProcessThrottlerClient.h:
+            - Add interface to access alwaysRunsAtBackgroundPriority state of WebProcess of NetworkProcess.
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::WebProcessPool):
+        * UIProcess/WebProcessPool.h:
+            - Add m_alwaysRunsAtBackgroundPriority, set by configuration.
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::alwaysRunsAtBackgroundPriority):
+        * UIProcess/WebProcessProxy.h:
+            - Support ProcessThrottlerClient interface to check if alwaysRunsAtBackgroundPriority is set.
+
 2016-10-14  Youenn Fablet  <youenn@apple.com>
 
         Make NetworkCache aware of fetch cache mode
index aca518e..244ff39 100644 (file)
@@ -113,6 +113,7 @@ Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::copy()
     copy->m_overrideLanguages = this->m_overrideLanguages;
     copy->m_sourceApplicationBundleIdentifier = this->m_sourceApplicationBundleIdentifier;
     copy->m_sourceApplicationSecondaryIdentifier = this->m_sourceApplicationSecondaryIdentifier;
+    copy->m_alwaysRunsAtBackgroundPriority = this->m_alwaysRunsAtBackgroundPriority;
 #if PLATFORM(IOS)
     copy->m_ctDataConnectionServiceType = this->m_ctDataConnectionServiceType;
 #endif
index f8dab68..10407da 100644 (file)
@@ -108,6 +108,9 @@ public:
     const WTF::String& sourceApplicationSecondaryIdentifier() const { return m_sourceApplicationSecondaryIdentifier; }
     void setSourceApplicationSecondaryIdentifier(const WTF::String& sourceApplicationSecondaryIdentifier) { m_sourceApplicationSecondaryIdentifier = sourceApplicationSecondaryIdentifier; }
 
+    bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
+    void setAlwaysRunsAtBackgroundPriority(bool alwaysRunsAtBackgroundPriority) { m_alwaysRunsAtBackgroundPriority = alwaysRunsAtBackgroundPriority; }
+
 #if PLATFORM(IOS)
     const WTF::String& ctDataConnectionServiceType() const { return m_ctDataConnectionServiceType; }
     void setCTDataConnectionServiceType(const WTF::String& ctDataConnectionServiceType) { m_ctDataConnectionServiceType = ctDataConnectionServiceType; }
@@ -138,6 +141,7 @@ private:
     Vector<WTF::String> m_overrideLanguages;
     WTF::String m_sourceApplicationBundleIdentifier;
     WTF::String m_sourceApplicationSecondaryIdentifier;
+    bool m_alwaysRunsAtBackgroundPriority { false };
 #if PLATFORM(IOS)
     WTF::String m_ctDataConnectionServiceType;
 #endif
index 42ececc..4d8e865 100644 (file)
@@ -49,6 +49,7 @@ WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0))
 @property (nonatomic, nullable, copy) NSString *sourceApplicationSecondaryIdentifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 #if TARGET_OS_IPHONE
 @property (nonatomic, nullable, copy) NSString *CTDataConnectionServiceType WK_API_AVAILABLE(ios(WK_IOS_TBA));
+@property (nonatomic) BOOL alwaysRunsAtBackgroundPriority WK_API_AVAILABLE(ios(WK_IOS_TBA));
 #endif
 
 @end
index 2a1746d..4d5670c 100644 (file)
 {
     _processPoolConfiguration->setCTDataConnectionServiceType(ctDataConnectionServiceType);
 }
+
+- (BOOL)alwaysRunsAtBackgroundPriority
+{
+    return _processPoolConfiguration->alwaysRunsAtBackgroundPriority();
+}
+
+- (void)setAlwaysRunsAtBackgroundPriority:(BOOL)alwaysRunsAtBackgroundPriority
+{
+    _processPoolConfiguration->setAlwaysRunsAtBackgroundPriority(alwaysRunsAtBackgroundPriority);
+}
 #endif
 
 - (NSString *)description
index 2e5d7bc..e26d574 100644 (file)
@@ -390,6 +390,11 @@ void NetworkProcessProxy::sendProcessDidResume()
         send(Messages::NetworkProcess::ProcessDidResume(), 0);
 }
 
+bool NetworkProcessProxy::alwaysRunsAtBackgroundPriority()
+{
+    return m_processPool.alwaysRunsAtBackgroundPriority();
+}
+
 void NetworkProcessProxy::processReadyToSuspend()
 {
     m_throttler.processReadyToSuspend();
index b113a33..0c09ab1 100644 (file)
@@ -91,6 +91,7 @@ private:
     void sendPrepareToSuspend() override;
     void sendCancelPrepareToSuspend() override;
     void sendProcessDidResume() override;
+    bool alwaysRunsAtBackgroundPriority() override;
     void didSetAssertionState(AssertionState) override;
 
     // IPC::Connection::Client
index 77b0b8c..2275bb3 100644 (file)
@@ -47,7 +47,7 @@ AssertionState ProcessThrottler::assertionState()
     ASSERT(!m_suspendTimer.isActive());
     
     if (m_foregroundCounter.value())
-        return AssertionState::Foreground;
+        return m_process.alwaysRunsAtBackgroundPriority() ? AssertionState::Background : AssertionState::Foreground;
     if (m_backgroundCounter.value())
         return AssertionState::Background;
     return AssertionState::Suspended;
index 75ab757..7cc3eff 100644 (file)
@@ -38,7 +38,7 @@ public:
     virtual void sendPrepareToSuspend() = 0;
     virtual void sendCancelPrepareToSuspend() = 0;
     virtual void sendProcessDidResume() = 0;
-
+    virtual bool alwaysRunsAtBackgroundPriority() = 0;
     virtual void didSetAssertionState(AssertionState) = 0;
 };
 
index 85b4df7..7c4833f 100644 (file)
@@ -177,6 +177,7 @@ WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration)
     , m_canHandleHTTPSServerTrustEvaluation(true)
     , m_didNetworkProcessCrash(false)
     , m_memoryCacheDisabled(false)
+    , m_alwaysRunsAtBackgroundPriority(m_configuration->alwaysRunsAtBackgroundPriority())
     , m_userObservablePageCounter([this](RefCounterEvent) { updateProcessSuppressionState(); })
     , m_processSuppressionDisabledForPageCounter([this](RefCounterEvent) { updateProcessSuppressionState(); })
     , m_hiddenPageThrottlingAutoIncreasesCounter([this](RefCounterEvent) { m_hiddenPageThrottlingTimer.startOneShot(0); })
index ab70734..d1d2429 100644 (file)
@@ -366,6 +366,8 @@ public:
     bool resourceLoadStatisticsEnabled() { return m_resourceLoadStatisticsEnabled; }
     void setResourceLoadStatisticsEnabled(bool enabled) { m_resourceLoadStatisticsEnabled = enabled; }
 
+    bool alwaysRunsAtBackgroundPriority() { return m_alwaysRunsAtBackgroundPriority; }
+
 #if ENABLE(GAMEPAD)
     void gamepadConnected(const UIGamepad&);
     void gamepadDisconnected(const UIGamepad&);
@@ -533,6 +535,8 @@ private:
     bool m_memoryCacheDisabled;
     bool m_resourceLoadStatisticsEnabled { false };
 
+    bool m_alwaysRunsAtBackgroundPriority;
+
     UserObservablePageCounter m_userObservablePageCounter;
     ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;
     HiddenPageThrottlingAutoIncreasesCounter m_hiddenPageThrottlingAutoIncreasesCounter;
index 272f52b..b01a4eb 100644 (file)
@@ -927,6 +927,11 @@ void WebProcessProxy::sendProcessDidResume()
         send(Messages::WebProcess::ProcessDidResume(), 0);
 }
 
+bool WebProcessProxy::alwaysRunsAtBackgroundPriority()
+{
+    return m_processPool->alwaysRunsAtBackgroundPriority();
+}
+
 void WebProcessProxy::processReadyToSuspend()
 {
     m_throttler.processReadyToSuspend();
index b0bbfee..e8d6c3d 100644 (file)
@@ -208,6 +208,7 @@ private:
     void sendPrepareToSuspend() override;
     void sendCancelPrepareToSuspend() override;
     void sendProcessDidResume() override;
+    bool alwaysRunsAtBackgroundPriority() override;
     void didSetAssertionState(AssertionState) override;
 
     // ProcessLauncher::Client