⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245904 in webkit


Ignore:
Timestamp:
May 30, 2019, 2:00:57 PM (7 years ago)
Author:
sihui_liu@apple.com
Message:

Stop StorageManager when network process is ready to suspend
https://bugs.webkit.org/show_bug.cgi?id=198201
<rdar://problem/49683172>

Reviewed by Youenn Fablet.

Source/WebKit:

To avoid local storage database operations that can hold lock to database files, suspend thread of
StorageManager when network process is about to suspend.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::actualPrepareToSuspend):
(WebKit::NetworkProcess::resume):

  • NetworkProcess/NetworkSession.cpp:

(WebKit::NetworkSession::~NetworkSession):

  • NetworkProcess/WebStorage/StorageManager.cpp:

(WebKit::StorageManager::suspend):
(WebKit::StorageManager::resume):

  • NetworkProcess/WebStorage/StorageManager.h:

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:

(TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/local-storage-process-suspends-1.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/local-storage-process-suspends-2.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245902 r245904  
     12019-05-30  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Stop StorageManager when network process is ready to suspend
     4        https://bugs.webkit.org/show_bug.cgi?id=198201
     5        <rdar://problem/49683172>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        To avoid local storage database operations that can hold lock to database files, suspend thread of
     10        StorageManager when network process is about to suspend.
     11
     12        * NetworkProcess/NetworkProcess.cpp:
     13        (WebKit::NetworkProcess::actualPrepareToSuspend):
     14        (WebKit::NetworkProcess::resume):
     15        * NetworkProcess/NetworkSession.cpp:
     16        (WebKit::NetworkSession::~NetworkSession):
     17        * NetworkProcess/WebStorage/StorageManager.cpp:
     18        (WebKit::StorageManager::suspend):
     19        (WebKit::StorageManager::resume):
     20        * NetworkProcess/WebStorage/StorageManager.h:
     21
    1222019-05-30  Wenson Hsieh  <wenson_hsieh@apple.com>
    223
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r245796 r245904  
    20392039        server->startSuspension([delayedTaskCounter] { });
    20402040#endif
     2041
     2042    for (auto& session : m_networkSessions)
     2043        session.value->storageManager().suspend([delayedTaskCounter] { });
    20412044}
    20422045
     
    21072110        server->resume();
    21082111#endif
     2112
     2113    for (auto& session : m_networkSessions)
     2114        session.value->storageManager().resume();
    21092115}
    21102116
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r245540 r245904  
    9191NetworkSession::~NetworkSession()
    9292{
     93    m_storageManager->resume();
    9394    m_storageManager->waitUntilWritesFinished();
    9495}
  • trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManager.cpp

    r245891 r245904  
    945945}
    946946
     947void StorageManager::suspend(CompletionHandler<void()>&& completionHandler)
     948{
     949    if (m_isEphemeral)
     950        return;
     951
     952    Locker<Lock> stateLocker(m_stateLock);
     953    if (m_state != State::Running)
     954        return;
     955    m_state = State::WillSuspend;
     956
     957    m_queue->dispatch([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] () mutable {
     958        Locker<Lock> stateLocker(m_stateLock);
     959        ASSERT(m_state != State::Suspended);
     960
     961        completionHandler();
     962
     963        if (m_state != State::WillSuspend)
     964            return;
     965        m_state = State::Suspended;
     966        while (m_state == State::Suspended)
     967            m_stateChangeCondition.wait(m_stateLock);
     968        ASSERT(m_state == State::Running);
     969    });
     970}
     971
     972void StorageManager::resume()
     973{
     974    if (m_isEphemeral)
     975        return;
     976
     977    Locker<Lock> stateLocker(m_stateLock);
     978    auto previousState = m_state;
     979    m_state = State::Running;
     980    if (previousState == State::Suspended)
     981        m_stateChangeCondition.notifyOne();
     982}
     983
    947984StorageManager::StorageArea* StorageManager::findStorageArea(IPC::Connection& connection, uint64_t storageMapID) const
    948985{
  • trunk/Source/WebKit/NetworkProcess/WebStorage/StorageManager.h

    r245891 r245904  
    5959    void processDidCloseConnection(IPC::Connection&);
    6060    void waitUntilWritesFinished();
     61    void suspend(CompletionHandler<void()>&&);
     62    void resume();
    6163
    6264    void getSessionStorageOrigins(Function<void(HashSet<WebCore::SecurityOriginData>&&)>&& completionHandler);
     
    114116    HashMap<WebCore::SecurityOriginData, Ref<WebCore::StorageMap>> m_ephemeralStorage;
    115117    bool m_isEphemeral { false };
     118
     119    enum class State {
     120        Running,
     121        WillSuspend,
     122        Suspended
     123    };
     124    State m_state;
     125    Lock m_stateLock;
     126    Condition m_stateChangeCondition;
    116127};
    117128
  • trunk/Tools/ChangeLog

    r245901 r245904  
     12019-05-30  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Stop StorageManager when network process is ready to suspend
     4        https://bugs.webkit.org/show_bug.cgi?id=198201
     5        <rdar://problem/49683172>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     11        (TEST):
     12        * TestWebKitAPI/Tests/WebKitCocoa/local-storage-process-suspends-1.html: Added.
     13        * TestWebKitAPI/Tests/WebKitCocoa/local-storage-process-suspends-2.html: Added.
     14
    1152019-05-30  David Quesada  <david_quesada@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r245671 r245904  
    651651                9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
    652652                93625D271CD9741C006DC1F1 /* large-video-without-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93625D261CD973AF006DC1F1 /* large-video-without-audio.html */; };
     653                9368A25E229EFB4700A829CA /* local-storage-process-suspends-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */; };
     654                9368A25F229EFB4700A829CA /* local-storage-process-suspends-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9368A25C229EFB3A00A829CA /* local-storage-process-suspends-2.html */; };
    653655                936F72801CD7D9EC0068A0FB /* large-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */; };
    654656                936F72811CD7D9EC0068A0FB /* large-video-with-audio.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */; };
     
    12321234                                57901FB11CAF142D00ED64F9 /* LoadInvalidURLRequest.html in Copy Resources */,
    12331235                                CA7787FF228CEFDB00E50463 /* local-storage-process-crashes.html in Copy Resources */,
     1236                                9368A25E229EFB4700A829CA /* local-storage-process-suspends-1.html in Copy Resources */,
     1237                                9368A25F229EFB4700A829CA /* local-storage-process-suspends-2.html in Copy Resources */,
    12341238                                8C10AF98206467920018FD90 /* localstorage-empty-string-value.html in Copy Resources */,
    12351239                                51E6A8961D2F1CA700C004B6 /* LocalStorageClear.html in Copy Resources */,
     
    19121916                9361002814DC957B0061379D /* lots-of-iframes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "lots-of-iframes.html"; sourceTree = "<group>"; };
    19131917                93625D261CD973AF006DC1F1 /* large-video-without-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-without-audio.html"; sourceTree = "<group>"; };
     1918                9368A25C229EFB3A00A829CA /* local-storage-process-suspends-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "local-storage-process-suspends-2.html"; sourceTree = "<group>"; };
     1919                9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "local-storage-process-suspends-1.html"; sourceTree = "<group>"; };
    19141920                936F727E1CD7D9D00068A0FB /* large-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-with-audio.html"; sourceTree = "<group>"; };
    19151921                936F727F1CD7D9D00068A0FB /* large-video-with-audio.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "large-video-with-audio.mp4"; sourceTree = "<group>"; };
     
    30593065                                F46128D1211E2D2500D9FADB /* link-in-iframe-and-input.html */,
    30603066                                CA7787FE228CEFC700E50463 /* local-storage-process-crashes.html */,
     3067                                9368A25D229EFB3A00A829CA /* local-storage-process-suspends-1.html */,
     3068                                9368A25C229EFB3A00A829CA /* local-storage-process-suspends-2.html */,
    30613069                                8C10AF97206467830018FD90 /* localstorage-empty-string-value.html */,
    30623070                                51E6A8951D2F1C7700C004B6 /* LocalStorageClear.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm

    r245649 r245904  
    9999}
    100100
     101TEST(WKWebView, LocalStorageProcessSuspends)
     102{
     103    readyToContinue = false;
     104    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
     105        readyToContinue = true;
     106    }];
     107    TestWebKitAPI::Util::run(&readyToContinue);
     108
     109    RetainPtr<LocalStorageMessageHandler> handler = adoptNS([[LocalStorageMessageHandler alloc] init]);
     110    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     111    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
     112    RetainPtr<WKProcessPool> processPool = adoptNS([[WKProcessPool alloc] init]);
     113    [configuration setProcessPool:processPool.get()];
     114
     115    RetainPtr<WKWebView> webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     116    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"local-storage-process-suspends-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     117    [webView1 loadRequest:request];
     118
     119    receivedScriptMessage = false;
     120    TestWebKitAPI::Util::run(&receivedScriptMessage);
     121    EXPECT_WK_STREQ(@"value", [lastScriptMessage body]);
     122   
     123    RetainPtr<WKWebView> webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     124    request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"local-storage-process-suspends-2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     125    [webView2 loadRequest:request];
     126
     127    receivedScriptMessage = false;
     128    TestWebKitAPI::Util::run(&receivedScriptMessage);
     129    EXPECT_WK_STREQ(@"value", [lastScriptMessage body]);
     130
     131    [processPool.get() _sendNetworkProcessWillSuspendImminently];
     132
     133    readyToContinue = false;
     134    [webView1 evaluateJavaScript:@"window.localStorage.setItem('key', 'newValue')" completionHandler:^(id, NSError *) {
     135        readyToContinue = true;
     136    }];
     137    TestWebKitAPI::Util::run(&readyToContinue);
     138   
     139    readyToContinue = false;
     140    [webView2 evaluateJavaScript:@"window.localStorage.getItem('key')" completionHandler:^(id result, NSError *) {
     141        EXPECT_TRUE([@"value" isEqualToString:result]);
     142        readyToContinue = true;
     143    }];
     144    TestWebKitAPI::Util::run(&readyToContinue);
     145   
     146    [processPool.get() _sendNetworkProcessDidResume];
     147
     148    receivedScriptMessage = false;
     149    TestWebKitAPI::Util::run(&receivedScriptMessage);
     150    EXPECT_WK_STREQ(@"newValue", [lastScriptMessage body]);
     151}
     152
    101153TEST(WKWebView, LocalStorageEmptyString)
    102154{
Note: See TracChangeset for help on using the changeset viewer.