[iOS] We should not take a background assertion for the UIProcess when app is MobileMail
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Apr 2017 22:41:56 +0000 (22:41 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Apr 2017 22:41:56 +0000 (22:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171435
<rdar://problem/31132330>

Reviewed by Geoffrey Garen.

Add SPI to disable taking on background process assertions in the UIProcess.
This is useful for MobileMail.

* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
* UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
(-[_WKProcessPoolConfiguration shouldTakeUIBackgroundAssertion]):
(-[_WKProcessPoolConfiguration setShouldTakeUIBackgroundAssertion:]):
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::NetworkProcessProxy):
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::setClient):
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::ProcessThrottler):
(WebKit::m_shouldTakeUIBackgroundAssertion):
(WebKit::ProcessThrottler::didConnectToProcess):
* UIProcess/ProcessThrottler.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::WebProcessPool):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::WebProcessProxy):

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

12 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/ProcessAssertion.h
Source/WebKit2/UIProcess/ProcessThrottler.cpp
Source/WebKit2/UIProcess/ProcessThrottler.h
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/UIProcess/WebProcessPool.h
Source/WebKit2/UIProcess/WebProcessProxy.cpp

index 49c76e0..8b1ba27 100644 (file)
@@ -1,5 +1,38 @@
 2017-04-28  Chris Dumez  <cdumez@apple.com>
 
+        [iOS] We should not take a background assertion for the UIProcess when app is MobileMail
+        https://bugs.webkit.org/show_bug.cgi?id=171435
+        <rdar://problem/31132330>
+
+        Reviewed by Geoffrey Garen.
+
+        Add SPI to disable taking on background process assertions in the UIProcess.
+        This is useful for MobileMail.
+
+        * UIProcess/API/APIProcessPoolConfiguration.cpp:
+        (API::ProcessPoolConfiguration::copy):
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.h:
+        * UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm:
+        (-[_WKProcessPoolConfiguration shouldTakeUIBackgroundAssertion]):
+        (-[_WKProcessPoolConfiguration setShouldTakeUIBackgroundAssertion:]):
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::NetworkProcessProxy):
+        * UIProcess/ProcessAssertion.h:
+        (WebKit::ProcessAssertion::setClient):
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::ProcessThrottler):
+        (WebKit::m_shouldTakeUIBackgroundAssertion):
+        (WebKit::ProcessThrottler::didConnectToProcess):
+        * UIProcess/ProcessThrottler.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::WebProcessPool):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy):
+
+2017-04-28  Chris Dumez  <cdumez@apple.com>
+
         Unreviewed attempt to fix iOS build after r215943.
 
         * Configurations/Base.xcconfig:
index d76dfbb..2338ba3 100644 (file)
@@ -118,6 +118,7 @@ Ref<ProcessPoolConfiguration> ProcessPoolConfiguration::copy()
     copy->m_sourceApplicationBundleIdentifier = this->m_sourceApplicationBundleIdentifier;
     copy->m_sourceApplicationSecondaryIdentifier = this->m_sourceApplicationSecondaryIdentifier;
     copy->m_alwaysRunsAtBackgroundPriority = this->m_alwaysRunsAtBackgroundPriority;
+    copy->m_shouldTakeUIBackgroundAssertion = this->m_shouldTakeUIBackgroundAssertion;
     copy->m_shouldCaptureAudioInUIProcess = this->m_shouldCaptureAudioInUIProcess;
 #if PLATFORM(IOS)
     copy->m_ctDataConnectionServiceType = this->m_ctDataConnectionServiceType;
index 713c91f..e442b13 100644 (file)
@@ -120,6 +120,9 @@ public:
     bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
     void setAlwaysRunsAtBackgroundPriority(bool alwaysRunsAtBackgroundPriority) { m_alwaysRunsAtBackgroundPriority = alwaysRunsAtBackgroundPriority; }
 
+    bool shouldTakeUIBackgroundAssertion() const { return m_shouldTakeUIBackgroundAssertion; }
+    void setShouldTakeUIBackgroundAssertion(bool shouldTakeUIBackgroundAssertion) { m_shouldTakeUIBackgroundAssertion = shouldTakeUIBackgroundAssertion; }
+
     bool shouldCaptureAudioInUIProcess() const { return m_shouldCaptureAudioInUIProcess; }
     void setShouldCaptureAudioInUIProcess(bool shouldCaptureAudioInUIProcess) { m_shouldCaptureAudioInUIProcess = shouldCaptureAudioInUIProcess; }
 
@@ -157,6 +160,7 @@ private:
     WTF::String m_sourceApplicationSecondaryIdentifier;
     bool m_allowsCellularAccess { true };
     bool m_alwaysRunsAtBackgroundPriority { false };
+    bool m_shouldTakeUIBackgroundAssertion { true };
     bool m_shouldCaptureAudioInUIProcess { false };
 #if PLATFORM(IOS)
     WTF::String m_ctDataConnectionServiceType;
index 74cbdba..eb52dd2 100644 (file)
@@ -54,6 +54,7 @@ WK_CLASS_AVAILABLE(macosx(10.10), ios(8.0))
 #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));
+@property (nonatomic) BOOL shouldTakeUIBackgroundAssertion WK_API_AVAILABLE(ios(WK_IOS_TBA));
 #endif
 
 
index f1bc5b2..10d2812 100644 (file)
 {
     _processPoolConfiguration->setAlwaysRunsAtBackgroundPriority(alwaysRunsAtBackgroundPriority);
 }
+
+- (BOOL)shouldTakeUIBackgroundAssertion
+{
+    return _processPoolConfiguration->shouldTakeUIBackgroundAssertion();
+}
+
+- (void)setShouldTakeUIBackgroundAssertion:(BOOL)shouldTakeUIBackgroundAssertion
+{
+    return _processPoolConfiguration->setShouldTakeUIBackgroundAssertion(shouldTakeUIBackgroundAssertion);
+}
 #endif
 
 - (NSString *)description
index a8ea8c7..db15995 100644 (file)
@@ -69,7 +69,7 @@ NetworkProcessProxy::NetworkProcessProxy(WebProcessPool& processPool)
     , m_processPool(processPool)
     , m_numPendingConnectionRequests(0)
     , m_customProtocolManagerProxy(this, processPool)
-    , m_throttler(*this)
+    , m_throttler(*this, processPool.shouldTakeUIBackgroundAssertion())
 {
     connect();
 }
index e054aff..fac8632 100644 (file)
@@ -52,13 +52,13 @@ public:
 class ProcessAssertion {
 public:
     ProcessAssertion(pid_t, AssertionState, Function<void()>&& invalidationCallback = { });
-    ~ProcessAssertion();
+    virtual ~ProcessAssertion();
 
-    void setClient(ProcessAssertionClient& client) { m_client = &client; }
+    virtual void setClient(ProcessAssertionClient& client) { m_client = &client; }
     ProcessAssertionClient* client() { return m_client; }
 
     AssertionState state() const { return m_assertionState; }
-    void setState(AssertionState);
+    virtual void setState(AssertionState);
 
 #if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
 protected:
@@ -80,14 +80,14 @@ private:
     ProcessAssertionClient* m_client { nullptr };
 };
     
-class ProcessAndUIAssertion : public ProcessAssertion {
+class ProcessAndUIAssertion final : public ProcessAssertion {
 public:
     ProcessAndUIAssertion(pid_t, AssertionState);
     ~ProcessAndUIAssertion();
 
-    void setClient(ProcessAssertionClient&);
+    void setClient(ProcessAssertionClient&) final;
 
-    void setState(AssertionState);
+    void setState(AssertionState) final;
 
 #if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
 private:
index 093863c..66f44df 100644 (file)
@@ -33,12 +33,12 @@ namespace WebKit {
     
 static const Seconds processSuspensionTimeout { 30_s };
     
-ProcessThrottler::ProcessThrottler(ProcessThrottlerClient& process)
+ProcessThrottler::ProcessThrottler(ProcessThrottlerClient& process, bool shouldTakeUIBackgroundAssertion)
     : m_process(process)
     , m_suspendTimer(RunLoop::main(), this, &ProcessThrottler::suspendTimerFired)
     , m_foregroundCounter([this](RefCounterEvent) { updateAssertion(); })
     , m_backgroundCounter([this](RefCounterEvent) { updateAssertion(); })
-    , m_suspendMessageCount(0)
+    , m_shouldTakeUIBackgroundAssertion(shouldTakeUIBackgroundAssertion)
 {
 }
     
@@ -94,7 +94,10 @@ void ProcessThrottler::updateAssertion()
 void ProcessThrottler::didConnectToProcess(pid_t pid)
 {
     m_suspendTimer.stop();
-    m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, assertionState());
+    if (m_shouldTakeUIBackgroundAssertion)
+        m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, assertionState());
+    else
+        m_assertion = std::make_unique<ProcessAssertion>(pid, assertionState());
     m_process.didSetAssertionState(assertionState());
     m_assertion->setClient(*this);
 }
index 29f58a1..cb1a4f2 100644 (file)
@@ -51,7 +51,7 @@ public:
     typedef RefCounter<BackgroundActivityCounterType> BackgroundActivityCounter;
     typedef BackgroundActivityCounter::Token BackgroundActivityToken;
 
-    ProcessThrottler(ProcessThrottlerClient&);
+    ProcessThrottler(ProcessThrottlerClient&, bool shouldTakeUIBackgroundAssertion);
 
     inline ForegroundActivityToken foregroundActivityToken() const;
     inline BackgroundActivityToken backgroundActivityToken() const;
@@ -70,11 +70,12 @@ private:
     void assertionWillExpireImminently() override;
 
     ProcessThrottlerClient& m_process;
-    std::unique_ptr<ProcessAndUIAssertion> m_assertion;
+    std::unique_ptr<ProcessAssertion> m_assertion;
     RunLoop::Timer<ProcessThrottler> m_suspendTimer;
     ForegroundActivityCounter m_foregroundCounter;
     BackgroundActivityCounter m_backgroundCounter;
-    int m_suspendMessageCount;
+    int m_suspendMessageCount { 0 };
+    bool m_shouldTakeUIBackgroundAssertion;
 };
 
 inline ProcessThrottler::ForegroundActivityToken ProcessThrottler::foregroundActivityToken() const
index 45292f0..9b17ed3 100644 (file)
@@ -241,6 +241,7 @@ WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration)
     , m_didNetworkProcessCrash(false)
     , m_memoryCacheDisabled(false)
     , m_alwaysRunsAtBackgroundPriority(m_configuration->alwaysRunsAtBackgroundPriority())
+    , m_shouldTakeUIBackgroundAssertion(m_configuration->shouldTakeUIBackgroundAssertion())
     , m_userObservablePageCounter([this](RefCounterEvent) { updateProcessSuppressionState(); })
     , m_processSuppressionDisabledForPageCounter([this](RefCounterEvent) { updateProcessSuppressionState(); })
     , m_hiddenPageThrottlingAutoIncreasesCounter([this](RefCounterEvent) { m_hiddenPageThrottlingTimer.startOneShot(0_s); })
index 4562600..b53cd81 100644 (file)
@@ -394,7 +394,8 @@ public:
     bool resourceLoadStatisticsEnabled() { return m_resourceLoadStatisticsEnabled; }
     void setResourceLoadStatisticsEnabled(bool enabled) { m_resourceLoadStatisticsEnabled = enabled; }
 
-    bool alwaysRunsAtBackgroundPriority() { return m_alwaysRunsAtBackgroundPriority; }
+    bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
+    bool shouldTakeUIBackgroundAssertion() const { return m_shouldTakeUIBackgroundAssertion; }
 
 #if ENABLE(GAMEPAD)
     void gamepadConnected(const UIGamepad&);
@@ -574,6 +575,7 @@ private:
     bool m_resourceLoadStatisticsEnabled { false };
     bool m_javaScriptConfigurationFileEnabled { false };
     bool m_alwaysRunsAtBackgroundPriority;
+    bool m_shouldTakeUIBackgroundAssertion;
 
     UserObservablePageCounter m_userObservablePageCounter;
     ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;
index d15114d..38f67fe 100644 (file)
@@ -102,7 +102,7 @@ WebProcessProxy::WebProcessProxy(WebProcessPool& processPool, WebsiteDataStore&
     , m_processPool(processPool)
     , m_mayHaveUniversalFileReadSandboxExtension(false)
     , m_numberOfTimesSuddenTerminationWasDisabled(0)
-    , m_throttler(*this)
+    , m_throttler(*this, processPool.shouldTakeUIBackgroundAssertion())
     , m_isResponsive(NoOrMaybe::Maybe)
     , m_visiblePageCounter([this](RefCounterEvent) { updateBackgroundResponsivenessTimer(); })
     , m_websiteDataStore(websiteDataStore)