Title: [183909] trunk/Source
Revision
183909
Author
dba...@webkit.org
Date
2015-05-06 20:23:57 -0700 (Wed, 06 May 2015)

Log Message

[iOS][WK2] Pause/resume database thread when UIProcess enters/leaves the background
https://bugs.webkit.org/show_bug.cgi?id=144657
<rdar://problem/18894598>

Reviewed by Andy Estes.

Source/WebCore:

Export WebCore functionality to pause and resume the database thread so that we can
make use of this functionality from WebKit2.

* Modules/webdatabase/AbstractDatabaseServer.h:
* Modules/webdatabase/DatabaseManager.cpp:
(WebCore::DatabaseManager::setPauseAllDatabases): Added; turns around and calls DatabaseServer::setPauseAllDatabases().
* Modules/webdatabase/DatabaseManager.h:
* Modules/webdatabase/DatabaseServer.cpp:
(WebCore::DatabaseServer::setPauseAllDatabases): Added; turns around and calls
DatabaseTracker::tracker().setDatabasesPaused() to pause or resume the database thread.
For now, we guard this call with PLATFORM(IOS). We'll look to remove this guard once
we fix <https://bugs.webkit.org/show_bug.cgi?id=144660>.
* Modules/webdatabase/DatabaseServer.h:

Source/WebKit2:

Pause and resume the database thread when the UIProcess enters and leaves the background,
respectively, so that we avoid WebProcess termination due to holding a locked SQLite
database file when the WebProcess is suspended. This behavior matches the analagous
behavior in Legacy WebKit.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentView.mm:
(-[WKContentView _applicationDidEnterBackground:]): Call WebPageProxy::applicationDidEnterBackground()
when the UIProcess enters the background.
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applicationDidEnterBackground): Added; notify the WebProcess to pause the database thread.
We temporarily take out background assertion on the WebProcess before sending this notification to ensure that the
WebProcess is running to receive it. We'll release this assertion when the WebProcess replies that it received the
notification.
* WebProcess/WebCoreSupport/WebDatabaseManager.cpp:
(WebKit::WebDatabaseManager::setPauseAllDatabases): Added; turns around and calls DatabaseManager::setPauseAllDatabases().
* WebProcess/WebCoreSupport/WebDatabaseManager.h:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Add message ApplicationDidEnterBackground(). Also,
add empty lines to help demarcate this message and the other UIKit application lifecycle-related
messages from the rest of the list of messages.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applicationWillEnterForeground): Resume the database thread.
(WebKit::WebPage::applicationDidEnterBackground): Pause the database thread.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (183908 => 183909)


--- trunk/Source/WebCore/ChangeLog	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebCore/ChangeLog	2015-05-07 03:23:57 UTC (rev 183909)
@@ -1,3 +1,25 @@
+2015-05-06  Daniel Bates  <daba...@apple.com>
+
+        [iOS][WK2] Pause/resume database thread when UIProcess enters/leaves the background
+        https://bugs.webkit.org/show_bug.cgi?id=144657
+        <rdar://problem/18894598>
+
+        Reviewed by Andy Estes.
+
+        Export WebCore functionality to pause and resume the database thread so that we can
+        make use of this functionality from WebKit2.
+
+        * Modules/webdatabase/AbstractDatabaseServer.h:
+        * Modules/webdatabase/DatabaseManager.cpp:
+        (WebCore::DatabaseManager::setPauseAllDatabases): Added; turns around and calls DatabaseServer::setPauseAllDatabases().
+        * Modules/webdatabase/DatabaseManager.h:
+        * Modules/webdatabase/DatabaseServer.cpp:
+        (WebCore::DatabaseServer::setPauseAllDatabases): Added; turns around and calls
+        DatabaseTracker::tracker().setDatabasesPaused() to pause or resume the database thread.
+        For now, we guard this call with PLATFORM(IOS). We'll look to remove this guard once
+        we fix <https://bugs.webkit.org/show_bug.cgi?id=144660>.
+        * Modules/webdatabase/DatabaseServer.h:
+
 2015-05-06  Brent Fulgham  <bfulg...@apple.com>
 
         Scroll-snap points do not handle margins and padding propertly

Modified: trunk/Source/WebCore/Modules/webdatabase/AbstractDatabaseServer.h (183908 => 183909)


--- trunk/Source/WebCore/Modules/webdatabase/AbstractDatabaseServer.h	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebCore/Modules/webdatabase/AbstractDatabaseServer.h	2015-05-07 03:23:57 UTC (rev 183909)
@@ -71,6 +71,8 @@
     virtual bool deleteOrigin(SecurityOrigin*) = 0;
     virtual bool deleteDatabase(SecurityOrigin*, const String& name) = 0;
 
+    virtual void setPauseAllDatabases(bool) = 0;
+
     virtual void interruptAllDatabasesForContext(const DatabaseContext*) = 0;
 
 protected:

Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp (183908 => 183909)


--- trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp	2015-05-07 03:23:57 UTC (rev 183909)
@@ -397,6 +397,11 @@
     return m_server->deleteDatabase(origin, name);
 }
 
+void DatabaseManager::setPauseAllDatabases(bool pauseAllDatabases)
+{
+    m_server->setPauseAllDatabases(pauseAllDatabases);
+}
+
 void DatabaseManager::interruptAllDatabasesForContext(ScriptExecutionContext* context)
 {
     RefPtr<DatabaseContext> databaseContext = existingDatabaseContextFor(context);

Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h (183908 => 183909)


--- trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseManager.h	2015-05-07 03:23:57 UTC (rev 183909)
@@ -103,6 +103,8 @@
     WEBCORE_EXPORT bool deleteOrigin(SecurityOrigin*);
     WEBCORE_EXPORT bool deleteDatabase(SecurityOrigin*, const String& name);
 
+    WEBCORE_EXPORT void setPauseAllDatabases(bool);
+
     void interruptAllDatabasesForContext(ScriptExecutionContext*);
 
 private:

Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseServer.cpp (183908 => 183909)


--- trunk/Source/WebCore/Modules/webdatabase/DatabaseServer.cpp	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseServer.cpp	2015-05-07 03:23:57 UTC (rev 183909)
@@ -108,6 +108,15 @@
     return DatabaseTracker::tracker().deleteDatabase(origin, name);
 }
 
+void DatabaseServer::setPauseAllDatabases(bool pauseAllDatabases)
+{
+#if PLATFORM(IOS)
+    DatabaseTracker::tracker().setDatabasesPaused(pauseAllDatabases);
+#else
+    UNUSED_PARAM(pauseAllDatabases);
+#endif
+}
+
 void DatabaseServer::interruptAllDatabasesForContext(const DatabaseContext* context)
 {
     DatabaseTracker::tracker().interruptAllDatabasesForContext(context);

Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseServer.h (183908 => 183909)


--- trunk/Source/WebCore/Modules/webdatabase/DatabaseServer.h	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseServer.h	2015-05-07 03:23:57 UTC (rev 183909)
@@ -60,6 +60,8 @@
     virtual bool deleteOrigin(SecurityOrigin*);
     virtual bool deleteDatabase(SecurityOrigin*, const String& name);
 
+    void setPauseAllDatabases(bool) override;
+
     virtual void interruptAllDatabasesForContext(const DatabaseContext*);
 
 protected:

Modified: trunk/Source/WebKit2/ChangeLog (183908 => 183909)


--- trunk/Source/WebKit2/ChangeLog	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/ChangeLog	2015-05-07 03:23:57 UTC (rev 183909)
@@ -1,3 +1,36 @@
+2015-05-06  Daniel Bates  <daba...@apple.com>
+
+        [iOS][WK2] Pause/resume database thread when UIProcess enters/leaves the background
+        https://bugs.webkit.org/show_bug.cgi?id=144657
+        <rdar://problem/18894598>
+
+        Reviewed by Andy Estes.
+
+        Pause and resume the database thread when the UIProcess enters and leaves the background,
+        respectively, so that we avoid WebProcess termination due to holding a locked SQLite
+        database file when the WebProcess is suspended. This behavior matches the analagous
+        behavior in Legacy WebKit.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _applicationDidEnterBackground:]): Call WebPageProxy::applicationDidEnterBackground()
+        when the UIProcess enters the background.
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applicationDidEnterBackground): Added; notify the WebProcess to pause the database thread.
+        We temporarily take out background assertion on the WebProcess before sending this notification to ensure that the
+        WebProcess is running to receive it. We'll release this assertion when the WebProcess replies that it received the
+        notification.
+        * WebProcess/WebCoreSupport/WebDatabaseManager.cpp:
+        (WebKit::WebDatabaseManager::setPauseAllDatabases): Added; turns around and calls DatabaseManager::setPauseAllDatabases().
+        * WebProcess/WebCoreSupport/WebDatabaseManager.h:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Add message ApplicationDidEnterBackground(). Also,
+        add empty lines to help demarcate this message and the other UIKit application lifecycle-related
+        messages from the rest of the list of messages.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::applicationWillEnterForeground): Resume the database thread.
+        (WebKit::WebPage::applicationDidEnterBackground): Pause the database thread.
+
 2015-05-06  Ryuan Choi  <ryuan.c...@navercorp.com>
 
         [EFL] ewk_view_page_contents_get() API test is flaky

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (183908 => 183909)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-05-07 03:23:57 UTC (rev 183909)
@@ -493,9 +493,12 @@
     void setAssistedNodeValue(const String&);
     void setAssistedNodeValueAsNumber(double);
     void setAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection = false);
+
     void applicationWillEnterForeground();
+    void applicationDidEnterBackground();
     void applicationWillResignActive();
     void applicationDidBecomeActive();
+
     void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale);
     void commitPotentialTapFailed();
     void didNotHandleTapAsClick(const WebCore::IntPoint&);

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (183908 => 183909)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2015-05-07 03:23:57 UTC (rev 183909)
@@ -551,6 +551,7 @@
 - (void)_applicationDidEnterBackground:(NSNotification*)notification
 {
     _isBackground = YES;
+    _page->applicationDidEnterBackground();
     _page->viewStateDidChange(ViewState::AllFlags & ~ViewState::IsInWindow);
 }
 

Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (183908 => 183909)


--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2015-05-07 03:23:57 UTC (rev 183909)
@@ -598,6 +598,12 @@
     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(), m_pageID);
 }
 
+void WebPageProxy::applicationDidEnterBackground()
+{
+    uint64_t callbackID = m_callbacks.put(VoidCallback::create([](CallbackBase::Error) { }, m_process->throttler().backgroundActivityToken()));
+    m_process->send(Messages::WebPage::ApplicationDidEnterBackground(callbackID), m_pageID);
+}
+
 void WebPageProxy::applicationWillResignActive()
 {
     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_pageID);

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDatabaseManager.cpp (183908 => 183909)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDatabaseManager.cpp	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDatabaseManager.cpp	2015-05-07 03:23:57 UTC (rev 183909)
@@ -137,6 +137,11 @@
     DatabaseManager::singleton().deleteAllDatabases();
 }
 
+void WebDatabaseManager::setPauseAllDatabases(bool pauseAllDatabases)
+{
+    DatabaseManager::singleton().setPauseAllDatabases(pauseAllDatabases);
+}
+
 void WebDatabaseManager::setQuotaForOrigin(const String& originIdentifier, unsigned long long quota) const
 {
     // If the quota is set to a value lower than the current usage, that quota will

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDatabaseManager.h (183908 => 183909)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDatabaseManager.h	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDatabaseManager.h	2015-05-07 03:23:57 UTC (rev 183909)
@@ -46,6 +46,8 @@
     void setQuotaForOrigin(const String& originIdentifier, unsigned long long quota) const;
     void deleteAllDatabases() const;
 
+    void setPauseAllDatabases(bool);
+
 private:
     // WebProcessSupplement
     virtual void initialize(const WebProcessCreationParameters&) override;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (183908 => 183909)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-05-07 03:23:57 UTC (rev 183909)
@@ -786,9 +786,12 @@
     void updateVisibleContentRects(const VisibleContentRectUpdateInfo&, double oldestTimestamp);
     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
     void willStartUserTriggeredZooming();
+
     void applicationWillResignActive();
     void applicationWillEnterForeground();
+    void applicationDidEnterBackground(uint64_t callbackID);
     void applicationDidBecomeActive();
+
     void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale);
     void completePendingSyntheticClickForContentChangeObserver();
 #endif

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (183908 => 183909)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-05-07 03:23:57 UTC (rev 183909)
@@ -87,9 +87,12 @@
     SetAssistedNodeValue(String value)
     SetAssistedNodeValueAsNumber(double value)
     SetAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
+
     ApplicationWillResignActive()
     ApplicationWillEnterForeground()
+    ApplicationDidEnterBackground(uint64_t callbackID)
     ApplicationDidBecomeActive()
+
     ContentSizeCategoryDidChange(String contentSizeCategory)
     ExecuteEditCommandWithCallback(String name, uint64_t callbackID)
     GetLookupContextAtPoint(WebCore::IntPoint point, uint64_t callbackID)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (183908 => 183909)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-05-07 03:19:42 UTC (rev 183908)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-05-07 03:23:57 UTC (rev 183909)
@@ -42,6 +42,7 @@
 #import "WKAccessibilityWebPageObjectIOS.h"
 #import "WebChromeClient.h"
 #import "WebCoreArgumentCoders.h"
+#import "WebDatabaseManager.h"
 #import "WebFrame.h"
 #import "WebImage.h"
 #import "WebKitSystemInterface.h"
@@ -2720,9 +2721,16 @@
 
 void WebPage::applicationWillEnterForeground()
 {
+    WebProcess::singleton().supplement<WebDatabaseManager>()->setPauseAllDatabases(false);
     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil];
 }
 
+void WebPage::applicationDidEnterBackground(uint64_t callbackID)
+{
+    WebProcess::singleton().supplement<WebDatabaseManager>()->setPauseAllDatabases(true);
+    send(Messages::WebPageProxy::VoidCallback(callbackID));
+}
+
 void WebPage::applicationDidBecomeActive()
 {
     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationDidBecomeActiveNotification object:nil];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to