<!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>[182841] 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/182841">182841</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-04-15 04:19:19 -0700 (Wed, 15 Apr 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Network Cache: Add thread-safe accessors for storage paths
https://bugs.webkit.org/show_bug.cgi?id=143668
Reviewed by Darin Adler.
Less need to use StringCapture.
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::dumpFilePath):
(WebKit::NetworkCache::Cache::storagePath):
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::makeRecordsDirectoryPath):
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::basePath):
(WebKit::NetworkCache::Storage::versionPath):
(WebKit::NetworkCache::Storage::recordsPath):
(WebKit::NetworkCache::Storage::synchronize):
(WebKit::NetworkCache::Storage::remove):
(WebKit::NetworkCache::Storage::dispatchReadOperation):
(WebKit::NetworkCache::Storage::finishReadOperation):
(WebKit::NetworkCache::Storage::dispatchWriteOperation):
(WebKit::NetworkCache::Storage::traverse):
(WebKit::NetworkCache::Storage::clear):
(WebKit::NetworkCache::Storage::shrink):
(WebKit::NetworkCache::Storage::deleteOldVersions):
(WebKit::NetworkCache::makeRecordDirectoryPath): Deleted.
* NetworkProcess/cache/NetworkCacheStorage.h:
(WebKit::NetworkCache::Storage::baseDirectoryPath): Deleted.
(WebKit::NetworkCache::Storage::directoryPath): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182840 => 182841)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-04-15 09:52:32 UTC (rev 182840)
+++ trunk/Source/WebKit2/ChangeLog        2015-04-15 11:19:19 UTC (rev 182841)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-04-15 Antti Koivisto <antti@apple.com>
+
+ Network Cache: Add thread-safe accessors for storage paths
+ https://bugs.webkit.org/show_bug.cgi?id=143668
+
+ Reviewed by Darin Adler.
+
+ Less need to use StringCapture.
+
+ * NetworkProcess/cache/NetworkCache.cpp:
+ (WebKit::NetworkCache::Cache::dumpFilePath):
+ (WebKit::NetworkCache::Cache::storagePath):
+ * NetworkProcess/cache/NetworkCacheStorage.cpp:
+ (WebKit::NetworkCache::makeRecordsDirectoryPath):
+ (WebKit::NetworkCache::Storage::Storage):
+ (WebKit::NetworkCache::Storage::basePath):
+ (WebKit::NetworkCache::Storage::versionPath):
+ (WebKit::NetworkCache::Storage::recordsPath):
+ (WebKit::NetworkCache::Storage::synchronize):
+ (WebKit::NetworkCache::Storage::remove):
+ (WebKit::NetworkCache::Storage::dispatchReadOperation):
+ (WebKit::NetworkCache::Storage::finishReadOperation):
+ (WebKit::NetworkCache::Storage::dispatchWriteOperation):
+ (WebKit::NetworkCache::Storage::traverse):
+ (WebKit::NetworkCache::Storage::clear):
+ (WebKit::NetworkCache::Storage::shrink):
+ (WebKit::NetworkCache::Storage::deleteOldVersions):
+ (WebKit::NetworkCache::makeRecordDirectoryPath): Deleted.
+ * NetworkProcess/cache/NetworkCacheStorage.h:
+ (WebKit::NetworkCache::Storage::baseDirectoryPath): Deleted.
+ (WebKit::NetworkCache::Storage::directoryPath): Deleted.
+
</ins><span class="cx"> 2015-04-14 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> Update gesture swipe shadow style
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (182840 => 182841)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-04-15 09:52:32 UTC (rev 182840)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-04-15 11:19:19 UTC (rev 182841)
</span><span class="lines">@@ -426,7 +426,7 @@
</span><span class="cx">
</span><span class="cx"> String Cache::dumpFilePath() const
</span><span class="cx"> {
</span><del>- return WebCore::pathByAppendingComponent(m_storage->baseDirectoryPath(), "dump.json");
</del><ins>+ return WebCore::pathByAppendingComponent(m_storage->versionPath(), "dump.json");
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Cache::dumpContentsToFile()
</span><span class="lines">@@ -499,7 +499,7 @@
</span><span class="cx">
</span><span class="cx"> String Cache::storagePath() const
</span><span class="cx"> {
</span><del>- return m_storage ? m_storage->directoryPath() : String();
</del><ins>+ return m_storage ? m_storage->versionPath() : String();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (182840 => 182841)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2015-04-15 09:52:32 UTC (rev 182840)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2015-04-15 11:19:19 UTC (rev 182841)
</span><span class="lines">@@ -65,7 +65,7 @@
</span><span class="cx"> return WebCore::pathByAppendingComponent(baseDirectoryPath, versionSubdirectory);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static String makeRecordDirectoryPath(const String& baseDirectoryPath)
</del><ins>+static String makeRecordsDirectoryPath(const String& baseDirectoryPath)
</ins><span class="cx"> {
</span><span class="cx"> return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), recordsDirectoryName);
</span><span class="cx"> }
</span><span class="lines">@@ -76,8 +76,8 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> Storage::Storage(const String& baseDirectoryPath)
</span><del>- : m_baseDirectoryPath(baseDirectoryPath)
- , m_directoryPath(makeRecordDirectoryPath(baseDirectoryPath))
</del><ins>+ : m_basePath(baseDirectoryPath)
+ , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
</ins><span class="cx"> , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
</span><span class="cx"> , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
</span><span class="cx"> , m_serialBackgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background))
</span><span class="lines">@@ -87,6 +87,22 @@
</span><span class="cx"> synchronize();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
+String Storage::basePath() const
+{
+ return m_basePath.isolatedCopy();
+}
+
+String Storage::versionPath() const
+{
+ return makeVersionedDirectoryPath(basePath());
+}
+
+String Storage::recordsPath() const
+{
+ return m_recordsPath.isolatedCopy();
+}
+
</ins><span class="cx"> size_t Storage::approximateSize() const
</span><span class="cx"> {
</span><span class="cx"> return m_approximateSize + m_blobStorage.approximateSize();
</span><span class="lines">@@ -102,14 +118,11 @@
</span><span class="cx">
</span><span class="cx"> LOG(NetworkCacheStorage, "(NetworkProcess) synchronizing cache");
</span><span class="cx">
</span><del>- StringCapture cachePathCapture(m_directoryPath);
- backgroundIOQueue().dispatch([this, cachePathCapture] {
- String cachePath = cachePathCapture.string();
-
</del><ins>+ backgroundIOQueue().dispatch([this] {
</ins><span class="cx"> auto filter = std::make_unique<ContentsFilter>();
</span><span class="cx"> size_t size = 0;
</span><span class="cx"> unsigned count = 0;
</span><del>- traverseCacheFiles(cachePath, [&filter, &size, &count](const String& fileName, const String& partitionPath) {
</del><ins>+ traverseCacheFiles(recordsPath(), [&filter, &size, &count](const String& fileName, const String& partitionPath) {
</ins><span class="cx"> Key::HashType hash;
</span><span class="cx"> if (!Key::stringToHash(fileName, hash))
</span><span class="cx"> return;
</span><span class="lines">@@ -329,11 +342,10 @@
</span><span class="cx"> // For simplicity we also don't reduce m_approximateSize on removals.
</span><span class="cx"> // The next synchronization will update everything.
</span><span class="cx">
</span><del>- StringCapture recordPathCapture(recordPathForKey(key, m_directoryPath));
- StringCapture bodyPathCapture(bodyPathForKey(key, m_directoryPath));
- serialBackgroundIOQueue().dispatch([this, recordPathCapture, bodyPathCapture] {
- WebCore::deleteFile(recordPathCapture.string());
- m_blobStorage.remove(bodyPathCapture.string());
</del><ins>+ serialBackgroundIOQueue().dispatch([this, key] {
+ auto recordsPath = this->recordsPath();
+ WebCore::deleteFile(recordPathForKey(key, recordsPath));
+ m_blobStorage.remove(bodyPathForKey(key, recordsPath));
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -350,10 +362,10 @@
</span><span class="cx"> ASSERT(RunLoop::isMain());
</span><span class="cx"> ASSERT(m_activeReadOperations.contains(&read));
</span><span class="cx">
</span><del>- StringCapture cachePathCapture(m_directoryPath);
- ioQueue().dispatch([this, &read, cachePathCapture] {
- auto recordPath = recordPathForKey(read.key, cachePathCapture.string());
- auto bodyPath = bodyPathForKey(read.key, cachePathCapture.string());
</del><ins>+ ioQueue().dispatch([this, &read] {
+ auto recordsPath = this->recordsPath();
+ auto recordPath = recordPathForKey(read.key, recordsPath);
+ auto bodyPath = bodyPathForKey(read.key, recordsPath);
</ins><span class="cx"> // FIXME: Body and header retrieves can be done in parallel.
</span><span class="cx"> auto bodyBlob = m_blobStorage.get(bodyPath);
</span><span class="cx">
</span><span class="lines">@@ -371,7 +383,7 @@
</span><span class="cx">
</span><span class="cx"> bool success = read.completionHandler(WTF::move(record));
</span><span class="cx"> if (success)
</span><del>- updateFileModificationTime(recordPathForKey(read.key, m_directoryPath));
</del><ins>+ updateFileModificationTime(recordPathForKey(read.key, recordsPath()));
</ins><span class="cx"> else
</span><span class="cx"> remove(read.key);
</span><span class="cx"> ASSERT(m_activeReadOperations.contains(&read));
</span><span class="lines">@@ -444,11 +456,11 @@
</span><span class="cx"> // This was added already when starting the store but filter might have been wiped.
</span><span class="cx"> addToContentsFilter(write.record.key);
</span><span class="cx">
</span><del>- StringCapture cachePathCapture(m_directoryPath);
- backgroundIOQueue().dispatch([this, &write, cachePathCapture] {
- auto partitionPath = partitionPathForKey(write.record.key, cachePathCapture.string());
- auto recordPath = recordPathForKey(write.record.key, cachePathCapture.string());
- auto bodyPath = bodyPathForKey(write.record.key, cachePathCapture.string());
</del><ins>+ backgroundIOQueue().dispatch([this, &write] {
+ auto recordsPath = this->recordsPath();
+ auto partitionPath = partitionPathForKey(write.record.key, recordsPath);
+ auto recordPath = recordPathForKey(write.record.key, recordsPath);
+ auto bodyPath = bodyPathForKey(write.record.key, recordsPath);
</ins><span class="cx">
</span><span class="cx"> WebCore::makeAllDirectories(partitionPath);
</span><span class="cx">
</span><span class="lines">@@ -537,10 +549,8 @@
</span><span class="cx">
</span><span class="cx"> void Storage::traverse(TraverseFlags flags, std::function<void (const Record*, const RecordInfo&)>&& traverseHandler)
</span><span class="cx"> {
</span><del>- StringCapture cachePathCapture(m_directoryPath);
- ioQueue().dispatch([this, flags, cachePathCapture, traverseHandler] {
- String cachePath = cachePathCapture.string();
- traverseCacheFiles(cachePath, [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) {
</del><ins>+ ioQueue().dispatch([this, flags, traverseHandler] {
+ traverseCacheFiles(recordsPath(), [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) {
</ins><span class="cx"> auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
</span><span class="cx">
</span><span class="cx"> RecordInfo info;
</span><span class="lines">@@ -595,12 +605,10 @@
</span><span class="cx"> m_contentsFilter->clear();
</span><span class="cx"> m_approximateSize = 0;
</span><span class="cx">
</span><del>- StringCapture directoryPathCapture(m_directoryPath);
-
- ioQueue().dispatch([this, directoryPathCapture] {
- String directoryPath = directoryPathCapture.string();
- traverseDirectory(directoryPath, DT_DIR, [&directoryPath](const String& subdirName) {
- String subdirPath = WebCore::pathByAppendingComponent(directoryPath, subdirName);
</del><ins>+ ioQueue().dispatch([this] {
+ auto recordsPath = this->recordsPath();
+ traverseDirectory(recordsPath, DT_DIR, [&recordsPath](const String& subdirName) {
+ String subdirPath = WebCore::pathByAppendingComponent(recordsPath, subdirName);
</ins><span class="cx"> traverseDirectory(subdirPath, DT_REG, [&subdirPath](const String& fileName) {
</span><span class="cx"> WebCore::deleteFile(WebCore::pathByAppendingComponent(subdirPath, fileName));
</span><span class="cx"> });
</span><span class="lines">@@ -664,10 +672,9 @@
</span><span class="cx">
</span><span class="cx"> LOG(NetworkCacheStorage, "(NetworkProcess) shrinking cache approximateSize=%zu capacity=%zu", approximateSize(), m_capacity);
</span><span class="cx">
</span><del>- StringCapture cachePathCapture(m_directoryPath);
- backgroundIOQueue().dispatch([this, cachePathCapture] {
- String cachePath = cachePathCapture.string();
- traverseCacheFiles(cachePath, [this](const String& fileName, const String& partitionPath) {
</del><ins>+ backgroundIOQueue().dispatch([this] {
+ auto recordsPath = this->recordsPath();
+ traverseCacheFiles(recordsPath, [this](const String& fileName, const String& partitionPath) {
</ins><span class="cx"> auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
</span><span class="cx"> auto bodyPath = bodyPathForRecordPath(recordPath);
</span><span class="cx">
</span><span class="lines">@@ -686,8 +693,8 @@
</span><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> // Let system figure out if they are really empty.
</span><del>- traverseDirectory(cachePath, DT_DIR, [&cachePath](const String& subdirName) {
- auto partitionPath = WebCore::pathByAppendingComponent(cachePath, subdirName);
</del><ins>+ traverseDirectory(recordsPath, DT_DIR, [&recordsPath](const String& subdirName) {
+ auto partitionPath = WebCore::pathByAppendingComponent(recordsPath, subdirName);
</ins><span class="cx"> WebCore::deleteEmptyDirectory(partitionPath);
</span><span class="cx"> });
</span><span class="cx">
</span><span class="lines">@@ -704,9 +711,8 @@
</span><span class="cx"> void Storage::deleteOldVersions()
</span><span class="cx"> {
</span><span class="cx"> // Delete V1 cache.
</span><del>- StringCapture cachePathCapture(m_baseDirectoryPath);
- backgroundIOQueue().dispatch([cachePathCapture] {
- String cachePath = cachePathCapture.string();
</del><ins>+ backgroundIOQueue().dispatch([this] {
+ auto cachePath = basePath();
</ins><span class="cx"> traverseDirectory(cachePath, DT_DIR, [&cachePath](const String& subdirName) {
</span><span class="cx"> if (subdirName.startsWith(versionDirectoryPrefix))
</span><span class="cx"> return;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (182840 => 182841)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2015-04-15 09:52:32 UTC (rev 182840)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2015-04-15 11:19:19 UTC (rev 182841)
</span><span class="lines">@@ -83,8 +83,9 @@
</span><span class="cx">
</span><span class="cx"> static const unsigned version = 3;
</span><span class="cx">
</span><del>- const String& baseDirectoryPath() const { return m_baseDirectoryPath; }
- const String& directoryPath() const { return m_directoryPath; }
</del><ins>+ String basePath() const;
+ String versionPath() const;
+ String recordsPath() const;
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> Storage(const String& directoryPath);
</span><span class="lines">@@ -120,8 +121,8 @@
</span><span class="cx">
</span><span class="cx"> void addToContentsFilter(const Key&);
</span><span class="cx">
</span><del>- const String m_baseDirectoryPath;
- const String m_directoryPath;
</del><ins>+ const String m_basePath;
+ const String m_recordsPath;
</ins><span class="cx">
</span><span class="cx"> size_t m_capacity { std::numeric_limits<size_t>::max() };
</span><span class="cx"> size_t m_approximateSize { 0 };
</span></span></pre>
</div>
</div>
</body>
</html>