<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[180349] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/180349">180349</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2015-02-19 10:45:53 -0800 (Thu, 19 Feb 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebsiteDataStore should ensure that local storage is written before exiting
https://bugs.webkit.org/show_bug.cgi?id=141798

Reviewed by Sam Weinig.

* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: Added.
(WebKit::dataStoresWithStorageManagers):
(WebKit::WebsiteDataStore::platformInitialize):
(WebKit::WebsiteDataStore::platformDestroy):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::WebsiteDataStore):
(WebKit::WebsiteDataStore::~WebsiteDataStore):
* UIProcess/WebsiteData/WebsiteDataStore.h:
* WebKit2.xcodeproj/project.pbxproj:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebsiteDataWebsiteDataStorecpp">trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebsiteDataWebsiteDataStoreh">trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/</li>
<li><a href="#trunkSourceWebKit2UIProcessWebsiteDataCocoaWebsiteDataStoreCocoamm">trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (180348 => 180349)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-02-19 18:41:24 UTC (rev 180348)
+++ trunk/Source/WebKit2/ChangeLog        2015-02-19 18:45:53 UTC (rev 180349)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2015-02-19  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        WebsiteDataStore should ensure that local storage is written before exiting
+        https://bugs.webkit.org/show_bug.cgi?id=141798
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: Added.
+        (WebKit::dataStoresWithStorageManagers):
+        (WebKit::WebsiteDataStore::platformInitialize):
+        (WebKit::WebsiteDataStore::platformDestroy):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::WebsiteDataStore):
+        (WebKit::WebsiteDataStore::~WebsiteDataStore):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        * WebKit2.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2015-02-18  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2][iOS] Fix NetworkCache build
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebsiteDataCocoaWebsiteDataStoreCocoamm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm (0 => 180349)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm        2015-02-19 18:45:53 UTC (rev 180349)
</span><span class="lines">@@ -0,0 +1,87 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;WebsiteDataStore.h&quot;
+
+#import &quot;StorageManager.h&quot;
+#import &lt;wtf/NeverDestroyed.h&gt;
+
+#if PLATFORM(IOS)
+#import &lt;UIKit/UIApplication.h&gt;
+#endif
+
+namespace WebKit {
+
+static id terminationObserver;
+
+static Vector&lt;WebsiteDataStore*&gt;&amp; dataStoresWithStorageManagers()
+{
+    static NeverDestroyed&lt;Vector&lt;WebsiteDataStore*&gt;&gt; dataStoresWithStorageManagers;
+
+    return dataStoresWithStorageManagers;
+}
+
+void WebsiteDataStore::platformInitialize()
+{
+    if (!m_storageManager)
+        return;
+
+    if (!terminationObserver) {
+        ASSERT(dataStoresWithStorageManagers().isEmpty());
+
+#if PLATFORM(MAC)
+        NSString *notificationName = NSApplicationWillTerminateNotification;
+#else
+        NSString *notificationName = UIApplicationWillTerminateNotification;
+#endif
+        terminationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:notificationName object:nil queue:nil usingBlock:^(NSNotification *note) {
+            for (auto&amp; dataStore : dataStoresWithStorageManagers())
+                dataStore-&gt;m_storageManager-&gt;applicationWillTerminate();
+        }];
+    }
+
+    ASSERT(!dataStoresWithStorageManagers().contains(this));
+    dataStoresWithStorageManagers().append(this);
+}
+
+void WebsiteDataStore::platformDestroy()
+{
+    if (!m_storageManager)
+        return;
+
+    // FIXME: Rename applicationWillTerminate to something that better indicates what StorageManager does (waits for pending writes to finish).
+    m_storageManager-&gt;applicationWillTerminate();
+
+    ASSERT(dataStoresWithStorageManagers().contains(this));
+    dataStoresWithStorageManagers().removeFirst(this);
+
+    if (dataStoresWithStorageManagers().isEmpty()) {
+        [[NSNotificationCenter defaultCenter] removeObserver:terminationObserver];
+        terminationObserver = nil;
+    }
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebsiteDataWebsiteDataStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp (180348 => 180349)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp        2015-02-19 18:41:24 UTC (rev 180348)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp        2015-02-19 18:45:53 UTC (rev 180349)
</span><span class="lines">@@ -62,16 +62,19 @@
</span><span class="cx">     , m_sessionID(WebCore::SessionID::defaultSessionID())
</span><span class="cx">     , m_storageManager(StorageManager::create(WTF::move(configuration.localStorageDirectory)))
</span><span class="cx"> {
</span><ins>+    platformInitialize();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebsiteDataStore::WebsiteDataStore(WebCore::SessionID sessionID)
</span><span class="cx">     : m_identifier(generateIdentifier())
</span><span class="cx">     , m_sessionID(sessionID)
</span><span class="cx"> {
</span><ins>+    platformInitialize();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebsiteDataStore::~WebsiteDataStore()
</span><span class="cx"> {
</span><ins>+    platformDestroy();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebsiteDataStore::cloneSessionData(WebPageProxy&amp; sourcePage, WebPageProxy&amp; newPage)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebsiteDataWebsiteDataStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h (180348 => 180349)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h        2015-02-19 18:41:24 UTC (rev 180348)
+++ trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h        2015-02-19 18:45:53 UTC (rev 180349)
</span><span class="lines">@@ -70,6 +70,9 @@
</span><span class="cx">     virtual void webPageDidCloseConnection(WebPageProxy&amp;, IPC::Connection&amp;) override;
</span><span class="cx">     virtual void webProcessDidCloseConnection(WebProcessProxy&amp;, IPC::Connection&amp;) override;
</span><span class="cx"> 
</span><ins>+    void platformInitialize();
+    void platformDestroy();
+
</ins><span class="cx">     const uint64_t m_identifier;
</span><span class="cx">     const WebCore::SessionID m_sessionID;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (180348 => 180349)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2015-02-19 18:41:24 UTC (rev 180348)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2015-02-19 18:45:53 UTC (rev 180349)
</span><span class="lines">@@ -247,6 +247,7 @@
</span><span class="cx">                 1A44B95716B737AA00B7BBD8 /* StorageNamespaceImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A17635416B1D5D000D88FD6 /* StorageNamespaceImpl.cpp */; };
</span><span class="cx">                 1A44B95B16B73F9F00B7BBD8 /* StorageManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A44B95916B73F9F00B7BBD8 /* StorageManager.cpp */; };
</span><span class="cx">                 1A44B95C16B73F9F00B7BBD8 /* StorageManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A44B95A16B73F9F00B7BBD8 /* StorageManager.h */; };
</span><ins>+                1A4832C31A965A3C008B4DFE /* WebsiteDataStoreCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A4832C11A965A3C008B4DFE /* WebsiteDataStoreCocoa.mm */; };
</ins><span class="cx">                 1A4A9C5512B816CF008FE984 /* NetscapePluginModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */; };
</span><span class="cx">                 1A4A9C5612B816CF008FE984 /* NetscapePluginModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */; };
</span><span class="cx">                 1A4A9C9A12B821CD008FE984 /* NetscapePluginModuleMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A9C9912B821CD008FE984 /* NetscapePluginModuleMac.mm */; };
</span><span class="lines">@@ -2321,6 +2322,7 @@
</span><span class="cx">                 1A445BA4184D5FDA004B3414 /* WKContextConnectionClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextConnectionClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A44B95916B73F9F00B7BBD8 /* StorageManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageManager.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A44B95A16B73F9F00B7BBD8 /* StorageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageManager.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                1A4832C11A965A3C008B4DFE /* WebsiteDataStoreCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebsiteDataStoreCocoa.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 1A4A9C5312B816CF008FE984 /* NetscapePluginModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePluginModule.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A4A9C5412B816CF008FE984 /* NetscapePluginModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetscapePluginModule.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A4A9C9912B821CD008FE984 /* NetscapePluginModuleMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapePluginModuleMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -4395,6 +4397,14 @@
</span><span class="cx">                         path = Storage;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="cx">                 };
</span><ins>+                1A4832C01A965A33008B4DFE /* Cocoa */ = {
+                        isa = PBXGroup;
+                        children = (
+                                1A4832C11A965A3C008B4DFE /* WebsiteDataStoreCocoa.mm */,
+                        );
+                        path = Cocoa;
+                        sourceTree = &quot;&lt;group&gt;&quot;;
+                };
</ins><span class="cx">                 1A4A9C5212B816CF008FE984 /* Netscape */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="lines">@@ -4460,20 +4470,13 @@
</span><span class="cx">                 1A53C2A31A325691004E8C70 /* WebsiteData */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><del>-                                1A53C2A81A325724004E8C70 /* Cocoa */,
</del><ins>+                                1A4832C01A965A33008B4DFE /* Cocoa */,
</ins><span class="cx">                                 1A53C2A41A32569F004E8C70 /* WebsiteDataStore.cpp */,
</span><span class="cx">                                 1A53C2A51A32569F004E8C70 /* WebsiteDataStore.h */,
</span><span class="cx">                         );
</span><span class="cx">                         path = WebsiteData;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="cx">                 };
</span><del>-                1A53C2A81A325724004E8C70 /* Cocoa */ = {
-                        isa = PBXGroup;
-                        children = (
-                        );
-                        path = Cocoa;
-                        sourceTree = &quot;&lt;group&gt;&quot;;
-                };
</del><span class="cx">                 1A6280CA19199754006AD9F9 /* WebKit2 Framework */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><span class="lines">@@ -9487,6 +9490,7 @@
</span><span class="cx">                                 1AA4792312A59FD9008236C3 /* PluginProcessMac.mm in Sources */,
</span><span class="cx">                                 BC82838C16B45F0700A278FE /* PluginProcessMain.mm in Sources */,
</span><span class="cx">                                 1A0EC604124A9F2C007EF4A5 /* PluginProcessManager.cpp in Sources */,
</span><ins>+                                1A4832C31A965A3C008B4DFE /* WebsiteDataStoreCocoa.mm in Sources */,
</ins><span class="cx">                                 2D3A65E61A7C3AA700CAC637 /* WKFrameInfoRef.cpp in Sources */,
</span><span class="cx">                                 9F54F8951648AE0F007DF81A /* PluginProcessManagerMac.mm in Sources */,
</span><span class="cx">                                 1A043CEB124FE38F00FFBFB5 /* PluginProcessMessageReceiver.cpp in Sources */,
</span></span></pre>
</div>
</div>

</body>
</html>