<!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>[42660] trunk/WebCore</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/42660">42660</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2009-04-19 15:47:19 -0700 (Sun, 19 Apr 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>2009-04-19  Darin Adler  &lt;darin@apple.com&gt;

        Reviewed by Sam Weinig.

        Add hoooks so sudden termination will not cause loss of icons or local storage.
        rdar://problem/5951701

        * loader/icon/IconDatabase.cpp: Marked various constants static to give them
        internal linkage.
        (WebCore::IconDatabase::IconDatabase): Added initial value for m_syncTimer.
        Removed unneeded initial value for m_defaultIconRecord. Changed assertion to
        work cross-platform.
        (WebCore::IconDatabase::wakeSyncThread): Added disableSuddenTermination, so
        we won't terminate until the sync thread has done its thing.
        (WebCore::IconDatabase::scheduleOrDeferSyncTimer): Added disableSuddenTermination,
        so we won't terminate if we have an outstanding sync timer.
        (WebCore::IconDatabase::syncTimerFired): Added enableSuddenTermination, to
        balance the one in scheduleOrDeferSyncTimer.
        (WebCore::IconDatabase::syncThreadMainLoop): Added enableSuddenTermination, to
        balance the one in wakeSyncThread.
        (WebCore::IconDatabase::deleteAllPreparedStatements): Use clear() instead of set(0).

        * loader/icon/IconDatabase.h: Use a Timer instead of an OwnPtr&lt;Timer&gt;.

        * storage/LocalStorageArea.cpp:
        (WebCore::LocalStorageArea::scheduleFinalSync): Added disableSuddenTermination.
        (WebCore::LocalStorageArea::scheduleItemForSync): Ditto.
        (WebCore::LocalStorageArea::scheduleClear): Ditto.
        (WebCore::LocalStorageArea::syncTimerFired): Added a disableSuddenTermination if
        we schedule a performSync callback for later and an unconditional
        enableSuddenTermination to balance the ones in the schedule calls above.
        (WebCore::LocalStorageArea::sync): Factored out the work of the sync function so it
        can continue to use early return idiom.
        (WebCore::LocalStorageArea::performSync): Added a call to enableSuddenTermination.

        * storage/LocalStorageArea.h: Added declaration of the sync function.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreloadericonIconDatabasecpp">trunk/WebCore/loader/icon/IconDatabase.cpp</a></li>
<li><a href="#trunkWebCoreloadericonIconDatabaseh">trunk/WebCore/loader/icon/IconDatabase.h</a></li>
<li><a href="#trunkWebCorestorageLocalStorageAreacpp">trunk/WebCore/storage/LocalStorageArea.cpp</a></li>
<li><a href="#trunkWebCorestorageLocalStorageAreah">trunk/WebCore/storage/LocalStorageArea.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (42659 => 42660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2009-04-19 22:26:00 UTC (rev 42659)
+++ trunk/WebCore/ChangeLog        2009-04-19 22:47:19 UTC (rev 42660)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2009-04-19  Darin Adler  &lt;darin@apple.com&gt;
+
+        Reviewed by Sam Weinig.
+
+        Add hoooks so sudden termination will not cause loss of icons or local storage.
+        rdar://problem/5951701
+
+        * loader/icon/IconDatabase.cpp: Marked various constants static to give them
+        internal linkage.
+        (WebCore::IconDatabase::IconDatabase): Added initial value for m_syncTimer.
+        Removed unneeded initial value for m_defaultIconRecord. Changed assertion to
+        work cross-platform.
+        (WebCore::IconDatabase::wakeSyncThread): Added disableSuddenTermination, so
+        we won't terminate until the sync thread has done its thing.
+        (WebCore::IconDatabase::scheduleOrDeferSyncTimer): Added disableSuddenTermination,
+        so we won't terminate if we have an outstanding sync timer.
+        (WebCore::IconDatabase::syncTimerFired): Added enableSuddenTermination, to
+        balance the one in scheduleOrDeferSyncTimer.
+        (WebCore::IconDatabase::syncThreadMainLoop): Added enableSuddenTermination, to
+        balance the one in wakeSyncThread.
+        (WebCore::IconDatabase::deleteAllPreparedStatements): Use clear() instead of set(0).
+
+        * loader/icon/IconDatabase.h: Use a Timer instead of an OwnPtr&lt;Timer&gt;.
+
+        * storage/LocalStorageArea.cpp:
+        (WebCore::LocalStorageArea::scheduleFinalSync): Added disableSuddenTermination.
+        (WebCore::LocalStorageArea::scheduleItemForSync): Ditto.
+        (WebCore::LocalStorageArea::scheduleClear): Ditto.
+        (WebCore::LocalStorageArea::syncTimerFired): Added a disableSuddenTermination if
+        we schedule a performSync callback for later and an unconditional
+        enableSuddenTermination to balance the ones in the schedule calls above.
+        (WebCore::LocalStorageArea::sync): Factored out the work of the sync function so it
+        can continue to use early return idiom.
+        (WebCore::LocalStorageArea::performSync): Added a call to enableSuddenTermination.
+
+        * storage/LocalStorageArea.h: Added declaration of the sync function.
+
</ins><span class="cx"> 2009-04-19  David Kilzer  &lt;ddkilzer@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Make FEATURE_DEFINES completely dynamic
</span></span></pre></div>
<a id="trunkWebCoreloadericonIconDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/loader/icon/IconDatabase.cpp (42659 => 42660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/loader/icon/IconDatabase.cpp        2009-04-19 22:26:00 UTC (rev 42659)
+++ trunk/WebCore/loader/icon/IconDatabase.cpp        2009-04-19 22:47:19 UTC (rev 42660)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -28,35 +28,20 @@
</span><span class="cx"> #include &quot;IconDatabase.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;AutodrainedPool.h&quot;
</span><del>-#include &quot;CString.h&quot;
</del><span class="cx"> #include &quot;DocumentLoader.h&quot;
</span><span class="cx"> #include &quot;FileSystem.h&quot;
</span><span class="cx"> #include &quot;IconDatabaseClient.h&quot;
</span><span class="cx"> #include &quot;IconRecord.h&quot;
</span><del>-#include &quot;Image.h&quot;
</del><span class="cx"> #include &quot;IntSize.h&quot;
</span><del>-#include &quot;KURL.h&quot;
</del><span class="cx"> #include &quot;Logging.h&quot;
</span><del>-#include &quot;PageURLRecord.h&quot;
</del><span class="cx"> #include &quot;SQLiteStatement.h&quot;
</span><span class="cx"> #include &quot;SQLiteTransaction.h&quot;
</span><ins>+#include &quot;SuddenTermination.h&quot;
</ins><span class="cx"> #include &lt;runtime/InitializeThreading.h&gt;
</span><span class="cx"> #include &lt;wtf/CurrentTime.h&gt;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="cx"> #include &lt;wtf/StdLibExtras.h&gt;
</span><span class="cx"> 
</span><del>-#if PLATFORM(WIN_OS)
-#include &lt;windows.h&gt;
-#include &lt;winbase.h&gt;
-#include &lt;shlobj.h&gt;
-#else
-#include &lt;sys/stat.h&gt;
-#endif
-
-#if PLATFORM(DARWIN)
-#include &lt;pthread.h&gt;
-#endif
-
</del><span class="cx"> // For methods that are meant to support API from the main thread - should not be called internally
</span><span class="cx"> #define ASSERT_NOT_SYNC_THREAD() ASSERT(!m_syncThreadRunning || !IS_ICON_SYNC_THREAD())
</span><span class="cx"> 
</span><span class="lines">@@ -77,12 +62,12 @@
</span><span class="cx"> // Currently, a mismatched schema causes the DB to be wiped and reset.  This isn't 
</span><span class="cx"> // so bad during development but in the future, we would need to write a conversion
</span><span class="cx"> // function to advance older released schemas to &quot;current&quot;
</span><del>-const int currentDatabaseVersion = 6;
</del><ins>+static const int currentDatabaseVersion = 6;
</ins><span class="cx"> 
</span><span class="cx"> // Icons expire once every 4 days
</span><del>-const int iconExpirationTime = 60*60*24*4; 
</del><ins>+static const int iconExpirationTime = 60*60*24*4; 
</ins><span class="cx"> 
</span><del>-const int updateTimerDelay = 5; 
</del><ins>+static const int updateTimerDelay = 5; 
</ins><span class="cx"> 
</span><span class="cx"> static bool checkIntegrityOnOpen = false;
</span><span class="cx"> 
</span><span class="lines">@@ -769,8 +754,8 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IconDatabase::IconDatabase()
</span><del>-    : m_syncThreadRunning(false)
-    , m_defaultIconRecord(0)
</del><ins>+    : m_syncTimer(this, &amp;IconDatabase::syncTimerFired)
+    , m_syncThreadRunning(false)
</ins><span class="cx">     , m_isEnabled(false)
</span><span class="cx">     , m_privateBrowsingEnabled(false)
</span><span class="cx">     , m_threadTerminationRequested(false)
</span><span class="lines">@@ -781,9 +766,7 @@
</span><span class="cx">     , m_imported(false)
</span><span class="cx">     , m_isImportedSet(false)
</span><span class="cx"> {
</span><del>-#if PLATFORM(DARWIN)
-    ASSERT(pthread_main_np());
-#endif
</del><ins>+    ASSERT(isMainThread());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IconDatabase::~IconDatabase()
</span><span class="lines">@@ -816,6 +799,12 @@
</span><span class="cx"> 
</span><span class="cx"> void IconDatabase::wakeSyncThread()
</span><span class="cx"> {
</span><ins>+    // The following is balanced by the call to enableSuddenTermination in the
+    // syncThreadMainLoop function.
+    // FIXME: It would be better to only disable sudden termination if we have
+    // something to write, not just if we have something to read.
+    disableSuddenTermination();
+
</ins><span class="cx">     MutexLocker locker(m_syncLock);
</span><span class="cx">     m_syncCondition.signal();
</span><span class="cx"> }
</span><span class="lines">@@ -823,16 +812,24 @@
</span><span class="cx"> void IconDatabase::scheduleOrDeferSyncTimer()
</span><span class="cx"> {
</span><span class="cx">     ASSERT_NOT_SYNC_THREAD();
</span><del>-    if (!m_syncTimer)
-        m_syncTimer.set(new Timer&lt;IconDatabase&gt;(this, &amp;IconDatabase::syncTimerFired));
</del><span class="cx"> 
</span><del>-    m_syncTimer-&gt;startOneShot(updateTimerDelay);
</del><ins>+    if (!m_syncTimer.isActive()) {
+        // The following is balanced by the call to enableSuddenTermination in the
+        // syncTimerFired function.
+        disableSuddenTermination();
+    }
+
+    m_syncTimer.startOneShot(updateTimerDelay);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void IconDatabase::syncTimerFired(Timer&lt;IconDatabase&gt;*)
</span><span class="cx"> {
</span><span class="cx">     ASSERT_NOT_SYNC_THREAD();
</span><span class="cx">     wakeSyncThread();
</span><ins>+
+    // The following is balanced by the call to disableSuddenTermination in the
+    // scheduleOrDeferSyncTimer function.
+    enableSuddenTermination();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // ******************
</span><span class="lines">@@ -1329,8 +1326,9 @@
</span><span class="cx"> void* IconDatabase::syncThreadMainLoop()
</span><span class="cx"> {
</span><span class="cx">     ASSERT_ICON_SYNC_THREAD();
</span><del>-    static bool prunedUnretainedIcons = false;
</del><span class="cx"> 
</span><ins>+    bool shouldReenableSuddenTermination = false;
+
</ins><span class="cx">     m_syncLock.lock();
</span><span class="cx"> 
</span><span class="cx">     // It's possible thread termination is requested before the main loop even starts - in that case, just skip straight to cleanup
</span><span class="lines">@@ -1368,6 +1366,7 @@
</span><span class="cx">             // or if private browsing is enabled
</span><span class="cx">             // We also don't want to prune if the m_databaseCleanupCounter count is non-zero - that means someone
</span><span class="cx">             // has asked to delay pruning
</span><ins>+            static bool prunedUnretainedIcons = false;
</ins><span class="cx">             if (didWrite &amp;&amp; !m_privateBrowsingEnabled &amp;&amp; !prunedUnretainedIcons &amp;&amp; !databaseCleanupCounter) {
</span><span class="cx"> #ifndef NDEBUG
</span><span class="cx">                 double time = currentTime();
</span><span class="lines">@@ -1400,13 +1399,32 @@
</span><span class="cx">         // We handle those at the top of this main loop so continue to jump back up there
</span><span class="cx">         if (shouldStopThreadActivity())
</span><span class="cx">             continue;
</span><del>-            
-        m_syncCondition.wait(m_syncLock); 
</del><ins>+
+        if (shouldReenableSuddenTermination) {
+            // The following is balanced by the call to disableSuddenTermination in the
+            // wakeSyncThread function. Any time we wait on the condition, we also have
+            // to enableSuddenTermation, after doing the next batch of work.
+            enableSuddenTermination();
+        }
+
+        m_syncCondition.wait(m_syncLock);
+
+        shouldReenableSuddenTermination = true;
</ins><span class="cx">     }
</span><ins>+
</ins><span class="cx">     m_syncLock.unlock();
</span><span class="cx">     
</span><span class="cx">     // Thread is terminating at this point
</span><del>-    return cleanupSyncThread();
</del><ins>+    cleanupSyncThread();
+
+    if (shouldReenableSuddenTermination) {
+        // The following is balanced by the call to disableSuddenTermination in the
+        // wakeSyncThread function. Any time we wait on the condition, we also have
+        // to enableSuddenTermation, after doing the next batch of work.
+        enableSuddenTermination();
+    }
+
+    return 0;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool IconDatabase::readFromDatabase()
</span><span class="lines">@@ -1693,23 +1711,23 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void IconDatabase::deleteAllPreparedStatements()
</span><del>-{        
</del><ins>+{
</ins><span class="cx">     ASSERT_ICON_SYNC_THREAD();
</span><span class="cx">     
</span><del>-    m_setIconIDForPageURLStatement.set(0);
-    m_removePageURLStatement.set(0);
-    m_getIconIDForIconURLStatement.set(0);
-    m_getImageDataForIconURLStatement.set(0);
-    m_addIconToIconInfoStatement.set(0);
-    m_addIconToIconDataStatement.set(0);
-    m_getImageDataStatement.set(0);
-    m_deletePageURLsForIconURLStatement.set(0);
-    m_deleteIconFromIconInfoStatement.set(0);
-    m_deleteIconFromIconDataStatement.set(0);
-    m_updateIconInfoStatement.set(0);
-    m_updateIconDataStatement.set(0);
-    m_setIconInfoStatement.set(0);
-    m_setIconDataStatement.set(0);
</del><ins>+    m_setIconIDForPageURLStatement.clear();
+    m_removePageURLStatement.clear();
+    m_getIconIDForIconURLStatement.clear();
+    m_getImageDataForIconURLStatement.clear();
+    m_addIconToIconInfoStatement.clear();
+    m_addIconToIconDataStatement.clear();
+    m_getImageDataStatement.clear();
+    m_deletePageURLsForIconURLStatement.clear();
+    m_deleteIconFromIconInfoStatement.clear();
+    m_deleteIconFromIconDataStatement.clear();
+    m_updateIconInfoStatement.clear();
+    m_updateIconDataStatement.clear();
+    m_setIconInfoStatement.clear();
+    m_setIconDataStatement.clear();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void* IconDatabase::cleanupSyncThread()
</span></span></pre></div>
<a id="trunkWebCoreloadericonIconDatabaseh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/loader/icon/IconDatabase.h (42659 => 42660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/loader/icon/IconDatabase.h        2009-04-19 22:26:00 UTC (rev 42659)
+++ trunk/WebCore/loader/icon/IconDatabase.h        2009-04-19 22:47:19 UTC (rev 42660)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -27,17 +27,15 @@
</span><span class="cx"> #ifndef IconDatabase_h
</span><span class="cx"> #define IconDatabase_h
</span><span class="cx"> 
</span><del>-#if ENABLE(ICONDATABASE)
-#include &quot;SQLiteDatabase.h&quot;
-#endif
-
</del><span class="cx"> #include &quot;StringHash.h&quot;
</span><span class="cx"> #include &quot;Timer.h&quot;
</span><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="cx"> #include &lt;wtf/Noncopyable.h&gt;
</span><span class="cx"> #include &lt;wtf/OwnPtr.h&gt;
</span><ins>+
</ins><span class="cx"> #if ENABLE(ICONDATABASE)
</span><ins>+#include &quot;SQLiteDatabase.h&quot;
</ins><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -116,9 +114,9 @@
</span><span class="cx"> 
</span><span class="cx">     void wakeSyncThread();
</span><span class="cx">     void scheduleOrDeferSyncTimer();
</span><del>-    OwnPtr&lt;Timer&lt;IconDatabase&gt; &gt; m_syncTimer;
</del><span class="cx">     void syncTimerFired(Timer&lt;IconDatabase&gt;*);
</span><span class="cx">     
</span><ins>+    Timer&lt;IconDatabase&gt; m_syncTimer;
</ins><span class="cx">     ThreadIdentifier m_syncThread;
</span><span class="cx">     bool m_syncThreadRunning;
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkWebCorestorageLocalStorageAreacpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/storage/LocalStorageArea.cpp (42659 => 42660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/storage/LocalStorageArea.cpp        2009-04-19 22:26:00 UTC (rev 42659)
+++ trunk/WebCore/storage/LocalStorageArea.cpp        2009-04-19 22:47:19 UTC (rev 42660)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -29,16 +29,12 @@
</span><span class="cx"> #include &quot;CString.h&quot;
</span><span class="cx"> #include &quot;EventNames.h&quot;
</span><span class="cx"> #include &quot;Frame.h&quot;
</span><del>-#include &quot;FrameTree.h&quot;
</del><span class="cx"> #include &quot;HTMLElement.h&quot;
</span><span class="cx"> #include &quot;LocalStorage.h&quot;
</span><del>-#include &quot;LocalStorageTask.h&quot;
-#include &quot;LocalStorageThread.h&quot;
</del><span class="cx"> #include &quot;Page.h&quot;
</span><span class="cx"> #include &quot;PageGroup.h&quot;
</span><del>-#include &quot;PlatformString.h&quot;
-#include &quot;SecurityOrigin.h&quot;
</del><span class="cx"> #include &quot;SQLiteStatement.h&quot;
</span><ins>+#include &quot;SuddenTermination.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -69,7 +65,13 @@
</span><span class="cx"> 
</span><span class="cx"> void LocalStorageArea::scheduleFinalSync()
</span><span class="cx"> {
</span><del>-    m_syncTimer.stop();
</del><ins>+    if (m_syncTimer.isActive())
+        m_syncTimer.stop();
+    else {
+        // The following is balanced by the call to enableSuddenTermination in the
+        // syncTimerFired function.
+        disableSuddenTermination();
+    }
</ins><span class="cx">     syncTimerFired(&amp;m_syncTimer);
</span><span class="cx">     m_finalSyncScheduled = true;
</span><span class="cx"> }
</span><span class="lines">@@ -237,8 +239,13 @@
</span><span class="cx">     ASSERT(!m_finalSyncScheduled);
</span><span class="cx"> 
</span><span class="cx">     m_changedItems.set(key, value);
</span><del>-    if (!m_syncTimer.isActive())
</del><ins>+    if (!m_syncTimer.isActive()) {
</ins><span class="cx">         m_syncTimer.startOneShot(LocalStorageSyncInterval);
</span><ins>+
+        // The following is balanced by the call to enableSuddenTermination in the
+        // syncTimerFired function.
+        disableSuddenTermination();
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void LocalStorageArea::scheduleClear()
</span><span class="lines">@@ -248,8 +255,13 @@
</span><span class="cx"> 
</span><span class="cx">     m_changedItems.clear();
</span><span class="cx">     m_itemsCleared = true;
</span><del>-    if (!m_syncTimer.isActive())
</del><ins>+    if (!m_syncTimer.isActive()) {
</ins><span class="cx">         m_syncTimer.startOneShot(LocalStorageSyncInterval);
</span><ins>+
+        // The following is balanced by the call to enableSuddenTermination in the
+        // syncTimerFired function.
+        disableSuddenTermination();
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void LocalStorageArea::syncTimerFired(Timer&lt;LocalStorageArea&gt;*)
</span><span class="lines">@@ -273,10 +285,19 @@
</span><span class="cx"> 
</span><span class="cx">         if (!m_syncScheduled) {
</span><span class="cx">             m_syncScheduled = true;
</span><ins>+
+            // The following is balanced by the call to enableSuddenTermination in the
+            // performSync function.
+            disableSuddenTermination();
+
</ins><span class="cx">             m_localStorage-&gt;scheduleSync(this);
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // The following is balanced by the calls to disableSuddenTermination in the
+    // scheduleItemForSync, scheduleClear, and scheduleFinalSync functions.
+    enableSuddenTermination();
+
</ins><span class="cx">     m_changedItems.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -347,25 +368,15 @@
</span><span class="cx">     m_importCondition.signal();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LocalStorageArea::performSync()
</del><ins>+void LocalStorageArea::sync(bool clearItems, const HashMap&lt;String, String&gt;&amp; items)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><span class="cx"> 
</span><span class="cx">     if (!m_database.isOpen())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    HashMap&lt;String, String&gt; items;
-    bool clearFirst = false;
-    {
-        MutexLocker locker(m_syncLock);
-        m_itemsPendingSync.swap(items);
-        clearFirst = m_clearItemsWhileSyncing;
-        m_clearItemsWhileSyncing = false;
-        m_syncScheduled = false;
-    }
-
-    // If the clear flag is marked, then we clear all items out before we write any new ones in
-    if (clearFirst) {
</del><ins>+    // If the clear flag is set, then we clear all items out before we write any new ones in.
+    if (clearItems) {
</ins><span class="cx">         SQLiteStatement clear(m_database, &quot;DELETE FROM ItemTable&quot;);
</span><span class="cx">         if (clear.prepare() != SQLResultOk) {
</span><span class="cx">             LOG_ERROR(&quot;Failed to prepare clear statement - cannot write to local storage database&quot;);
</span><span class="lines">@@ -391,10 +402,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    HashMap&lt;String, String&gt;::iterator end = items.end();
</del><ins>+    HashMap&lt;String, String&gt;::const_iterator end = items.end();
</ins><span class="cx"> 
</span><del>-    for (HashMap&lt;String, String&gt;::iterator it = items.begin(); it != end; ++it) {
-        // Based on the null-ness of the second argument, decide whether this is an insert or a delete
</del><ins>+    for (HashMap&lt;String, String&gt;::const_iterator it = items.begin(); it != end; ++it) {
+        // Based on the null-ness of the second argument, decide whether this is an insert or a delete.
</ins><span class="cx">         SQLiteStatement&amp; query = it-&gt;second.isNull() ? remove : insert;        
</span><span class="cx"> 
</span><span class="cx">         query.bindText(1, it-&gt;first);
</span><span class="lines">@@ -413,4 +424,29 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void LocalStorageArea::performSync()
+{
+    ASSERT(!isMainThread());
+
+    bool clearItems;
+    HashMap&lt;String, String&gt; items;
+    {
+        MutexLocker locker(m_syncLock);
+
+        ASSERT(m_syncScheduled);
+
+        clearItems = m_clearItemsWhileSyncing;
+        m_itemsPendingSync.swap(items);
+
+        m_clearItemsWhileSyncing = false;
+        m_syncScheduled = false;
+    }
+
+    sync(clearItems, items);
+
+    // The following is balanced by the call to disableSuddenTermination in the
+    // syncTimerFired function.
+    enableSuddenTermination();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkWebCorestorageLocalStorageAreah"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/storage/LocalStorageArea.h (42659 => 42660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/storage/LocalStorageArea.h        2009-04-19 22:26:00 UTC (rev 42659)
+++ trunk/WebCore/storage/LocalStorageArea.h        2009-04-19 22:47:19 UTC (rev 42660)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
</del><ins>+ * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,17 +26,11 @@
</span><span class="cx"> #ifndef LocalStorageArea_h
</span><span class="cx"> #define LocalStorageArea_h
</span><span class="cx"> 
</span><del>-#include &quot;LocalStorageTask.h&quot;
-#include &quot;LocalStorageThread.h&quot;
-
</del><span class="cx"> #include &quot;SQLiteDatabase.h&quot;
</span><span class="cx"> #include &quot;StorageArea.h&quot;
</span><span class="cx"> #include &quot;StringHash.h&quot;
</span><span class="cx"> #include &quot;Timer.h&quot;
</span><del>-
</del><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><del>-#include &lt;wtf/PassRefPtr.h&gt;
-#include &lt;wtf/Threading.h&gt;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx">     
</span><span class="lines">@@ -88,6 +82,7 @@
</span><span class="cx"> 
</span><span class="cx">     private:
</span><span class="cx">         void syncTimerFired(Timer&lt;LocalStorageArea&gt;*);
</span><ins>+        void sync(bool clearItems, const HashMap&lt;String, String&gt;&amp; items);
</ins><span class="cx"> 
</span><span class="cx">         Mutex m_syncLock;
</span><span class="cx">         HashMap&lt;String, String&gt; m_itemsPendingSync;
</span></span></pre>
</div>
</div>

</body>
</html>