Title: [218846] trunk/Source
Revision
218846
Author
cdu...@apple.com
Date
2017-06-27 14:49:04 -0700 (Tue, 27 Jun 2017)

Log Message

[iOS] Avoid taking / releasing process assertions too quickly due to database activity
https://bugs.webkit.org/show_bug.cgi?id=173879
<rdar://problem/32412701>

Reviewed by Antti Koivisto.

Source/WebCore:

Add HysteresisActivity to WebSQLiteDatabaseTrackerClient to avoid taking / releasing
process assertion too quickly due to database activity.

* platform/ios/WebSQLiteDatabaseTrackerClient.h:
* platform/ios/WebSQLiteDatabaseTrackerClient.mm:
(WebCore::WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient):
(WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction):
(WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction):
(WebCore::WebSQLiteDatabaseTrackerClient::hysteresisUpdated):

Source/WebKit2:

Specify an activity name when taking the process assertion to facilitate
debugging in the future. It took me a while to figure out this assertion
was the one that was too aggressive because it was anonymous.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setUpSQLiteDatabaseTrackerClient]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (218845 => 218846)


--- trunk/Source/WebCore/ChangeLog	2017-06-27 21:37:46 UTC (rev 218845)
+++ trunk/Source/WebCore/ChangeLog	2017-06-27 21:49:04 UTC (rev 218846)
@@ -1,3 +1,21 @@
+2017-06-27  Chris Dumez  <cdu...@apple.com>
+
+        [iOS] Avoid taking / releasing process assertions too quickly due to database activity
+        https://bugs.webkit.org/show_bug.cgi?id=173879
+        <rdar://problem/32412701>
+
+        Reviewed by Antti Koivisto.
+
+        Add HysteresisActivity to WebSQLiteDatabaseTrackerClient to avoid taking / releasing
+        process assertion too quickly due to database activity.
+
+        * platform/ios/WebSQLiteDatabaseTrackerClient.h:
+        * platform/ios/WebSQLiteDatabaseTrackerClient.mm:
+        (WebCore::WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient):
+        (WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction):
+        (WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction):
+        (WebCore::WebSQLiteDatabaseTrackerClient::hysteresisUpdated):
+
 2017-06-27  Youenn Fablet  <you...@apple.com>
 
         Using public logging for WebRTC release logging

Modified: trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h (218845 => 218846)


--- trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h	2017-06-27 21:37:46 UTC (rev 218845)
+++ trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.h	2017-06-27 21:49:04 UTC (rev 218846)
@@ -29,6 +29,7 @@
 
 #if PLATFORM(IOS)
 
+#include "HysteresisActivity.h"
 #include "SQLiteDatabaseTrackerClient.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/Noncopyable.h>
@@ -40,13 +41,17 @@
 public:
     WEBCORE_EXPORT static WebSQLiteDatabaseTrackerClient& sharedWebSQLiteDatabaseTrackerClient();
 
-    void willBeginFirstTransaction() override;
-    void didFinishLastTransaction() override;
+    void willBeginFirstTransaction() final;
+    void didFinishLastTransaction() final;
 
 private:
     friend class NeverDestroyed<WebSQLiteDatabaseTrackerClient>;
     WebSQLiteDatabaseTrackerClient();
     virtual ~WebSQLiteDatabaseTrackerClient();
+
+    void hysteresisUpdated(HysteresisState);
+
+    HysteresisActivity m_hysteresis;
 };
 
 }

Modified: trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm (218845 => 218846)


--- trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm	2017-06-27 21:37:46 UTC (rev 218845)
+++ trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm	2017-06-27 21:49:04 UTC (rev 218846)
@@ -31,6 +31,7 @@
 #import "WebBackgroundTaskController.h"
 #import <WebCore/DatabaseTracker.h>
 #import <WebCore/SQLiteDatabaseTracker.h>
+#import <wtf/MainThread.h>
 #import <wtf/NeverDestroyed.h>
 
 @interface WebDatabaseTransactionBackgroundTaskController : NSObject
@@ -40,6 +41,8 @@
 
 namespace WebCore {
 
+const double hysteresisDuration = 2; // 2 seconds.
+
 WebSQLiteDatabaseTrackerClient& WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient()
 {
     static NeverDestroyed<WebSQLiteDatabaseTrackerClient> client;
@@ -47,6 +50,7 @@
 }
 
 WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient()
+    : m_hysteresis([this](HysteresisState state) { hysteresisUpdated(state); }, hysteresisDuration)
 {
 }
 
@@ -56,16 +60,28 @@
 
 void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction()
 {
-    [WebDatabaseTransactionBackgroundTaskController startBackgroundTask];
+    callOnMainThread([this] {
+        m_hysteresis.start();
+    });
 }
 
 void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
 {
-    [WebDatabaseTransactionBackgroundTaskController endBackgroundTask];
+    callOnMainThread([this] {
+        m_hysteresis.stop();
+    });
 }
 
+void WebSQLiteDatabaseTrackerClient::hysteresisUpdated(HysteresisState state)
+{
+    if (state == HysteresisState::Started)
+        [WebDatabaseTransactionBackgroundTaskController startBackgroundTask];
+    else
+        [WebDatabaseTransactionBackgroundTaskController endBackgroundTask];
 }
 
+}
+
 static Lock& transactionBackgroundTaskIdentifierLock()
 {
     static NeverDestroyed<Lock> mutex;

Modified: trunk/Source/WebKit2/ChangeLog (218845 => 218846)


--- trunk/Source/WebKit2/ChangeLog	2017-06-27 21:37:46 UTC (rev 218845)
+++ trunk/Source/WebKit2/ChangeLog	2017-06-27 21:49:04 UTC (rev 218846)
@@ -1,3 +1,18 @@
+2017-06-27  Chris Dumez  <cdu...@apple.com>
+
+        [iOS] Avoid taking / releasing process assertions too quickly due to database activity
+        https://bugs.webkit.org/show_bug.cgi?id=173879
+        <rdar://problem/32412701>
+
+        Reviewed by Antti Koivisto.
+
+        Specify an activity name when taking the process assertion to facilitate
+        debugging in the future. It took me a while to figure out this assertion
+        was the one that was too aggressive because it was anonymous.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setUpSQLiteDatabaseTrackerClient]):
+
 2017-06-27  Don Olmstead  <don.olmst...@sony.com>
 
         [PAL] Add symbol export macros for PAL

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (218845 => 218846)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-06-27 21:37:46 UTC (rev 218845)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-06-27 21:49:04 UTC (rev 218846)
@@ -602,7 +602,7 @@
 
     controller.backgroundTaskStartBlock = ^NSUInteger (void (^expirationHandler)())
     {
-        return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
+        return [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"com.apple.WebKit.DatabaseActivity" expirationHandler:expirationHandler];
     };
     controller.backgroundTaskEndBlock = ^(UIBackgroundTaskIdentifier taskIdentifier)
     {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to