Use OptionSet for NetworkCache::Storage::TraverseFlags
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2018 14:19:48 +0000 (14:19 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2018 14:19:48 +0000 (14:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188837

Reviewed by Anders Carlsson.

Type safe flags.

* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::Caches::initializeSize):
(WebKit::CacheStorage::Caches::readRecordsList):
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::traverse):
(WebKit::NetworkCache::Cache::dumpContentsToFile):
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::TraverseOperation::TraverseOperation):
(WebKit::NetworkCache::Storage::traverse):
* NetworkProcess/cache/NetworkCacheStorage.h:
* WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
(WebKit::UserMediaPermissionRequestManager::captureDevicesChanged):
(WebKit::UserMediaPermissionRequestManager::activityStateDidChange):

Also use OptionSet<>::containsAll() in a few places.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235169 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
Source/WebKit/NetworkProcess/cache/NetworkCache.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h
Source/WebKit/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp

index 759d36a..f17ee23 100644 (file)
@@ -1,3 +1,28 @@
+2018-08-22  Antti Koivisto  <antti@apple.com>
+
+        Use OptionSet for NetworkCache::Storage::TraverseFlags
+        https://bugs.webkit.org/show_bug.cgi?id=188837
+
+        Reviewed by Anders Carlsson.
+
+        Type safe flags.
+
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::Caches::initializeSize):
+        (WebKit::CacheStorage::Caches::readRecordsList):
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::traverse):
+        (WebKit::NetworkCache::Cache::dumpContentsToFile):
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::TraverseOperation::TraverseOperation):
+        (WebKit::NetworkCache::Storage::traverse):
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+        * WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
+        (WebKit::UserMediaPermissionRequestManager::captureDevicesChanged):
+        (WebKit::UserMediaPermissionRequestManager::activityStateDidChange):
+
+        Also use OptionSet<>::containsAll() in a few places.
+
 2018-08-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [WPE] pkg-config files should require libwpe
index 0349ff1..dae2012 100644 (file)
@@ -186,7 +186,7 @@ void Caches::initializeSize()
     }
 
     uint64_t size = 0;
-    m_storage->traverse({ }, 0, [protectedThis = makeRef(*this), this, protectedStorage = makeRef(*m_storage), size](const auto* storage, const auto& information) mutable {
+    m_storage->traverse({ }, { }, [protectedThis = makeRef(*this), this, protectedStorage = makeRef(*m_storage), size](const auto* storage, const auto& information) mutable {
         if (!storage) {
             if (m_pendingInitializationCallbacks.isEmpty()) {
                 // Caches was cleared so let's not get initialized.
@@ -460,7 +460,7 @@ void Caches::readRecordsList(Cache& cache, NetworkCache::Storage::TraverseHandle
         callback(nullptr, { });
         return;
     }
-    m_storage->traverse(cache.uniqueName(), 0, [protectedStorage = makeRef(*m_storage), callback = WTFMove(callback)](const auto* storage, const auto& information) {
+    m_storage->traverse(cache.uniqueName(), { }, [protectedStorage = makeRef(*m_storage), callback = WTFMove(callback)](const auto* storage, const auto& information) {
         callback(storage, information);
     });
 }
index 655b3ec..da07e82 100644 (file)
@@ -483,7 +483,7 @@ void Cache::traverse(Function<void (const TraversalEntry*)>&& traverseHandler)
 
     ++m_traverseCount;
 
-    m_storage->traverse(resourceType(), 0, [this, protectedThis = makeRef(*this), traverseHandler = WTFMove(traverseHandler)](const Storage::Record* record, const Storage::RecordInfo& recordInfo) {
+    m_storage->traverse(resourceType(), { }, [this, protectedThis = makeRef(*this), traverseHandler = WTFMove(traverseHandler)](const Storage::Record* record, const Storage::RecordInfo& recordInfo) {
         if (!record) {
             --m_traverseCount;
             traverseHandler(nullptr);
@@ -518,7 +518,7 @@ void Cache::dumpContentsToFile()
         size_t bodySize { 0 };
     };
     Totals totals;
-    auto flags = Storage::TraverseFlag::ComputeWorth | Storage::TraverseFlag::ShareCount;
+    auto flags = { Storage::TraverseFlag::ComputeWorth, Storage::TraverseFlag::ShareCount };
     size_t capacity = m_storage->capacity();
     m_storage->traverse(resourceType(), flags, [fd, totals, capacity](const Storage::Record* record, const Storage::RecordInfo& info) mutable {
         if (!record) {
index a3346e5..2781010 100644 (file)
@@ -123,7 +123,7 @@ public:
 struct Storage::TraverseOperation {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    TraverseOperation(Storage& storage, const String& type, TraverseFlags flags, TraverseHandler&& handler)
+    TraverseOperation(Storage& storage, const String& type, OptionSet<TraverseFlag> flags, TraverseHandler&& handler)
         : storage(storage)
         , type(type)
         , flags(flags)
@@ -132,7 +132,7 @@ public:
     Ref<Storage> storage;
 
     const String type;
-    const TraverseFlags flags;
+    const OptionSet<TraverseFlag> flags;
     const TraverseHandler handler;
 
     Lock activeMutex;
@@ -902,7 +902,7 @@ void Storage::store(const Record& record, MappedBodyHandler&& mappedBodyHandler,
     m_writeOperationDispatchTimer.startOneShot(m_initialWriteDelay);
 }
 
-void Storage::traverse(const String& type, TraverseFlags flags, TraverseHandler&& traverseHandler)
+void Storage::traverse(const String& type, OptionSet<TraverseFlag> flags, TraverseHandler&& traverseHandler)
 {
     ASSERT(RunLoop::isMain());
     ASSERT(traverseHandler);
index 626d42b..f152a66 100644 (file)
@@ -98,10 +98,9 @@ public:
         ComputeWorth = 1 << 0,
         ShareCount = 1 << 1,
     };
-    typedef unsigned TraverseFlags;
-    typedef Function<void (const Record*, const RecordInfo&)> TraverseHandler;
+    using TraverseHandler = Function<void (const Record*, const RecordInfo&)>;
     // Null record signals end.
-    void traverse(const String& type, TraverseFlags, TraverseHandler&&);
+    void traverse(const String& type, OptionSet<TraverseFlag>, TraverseHandler&&);
 
     void setCapacity(size_t);
     size_t capacity() const { return m_capacity; }
index 5fef60e..ff07ffa 100644 (file)
@@ -254,7 +254,7 @@ void UserMediaPermissionRequestManager::captureDevicesChanged(DeviceAccessState
     // * any of the input devices are attached to an active MediaStream in the browsing context, or
     // * the active document is fully active and has focus.
 
-    bool isActive = (m_page.corePage()->activityState() & focusedActiveWindow) == focusedActiveWindow;
+    bool isActive = m_page.corePage()->activityState().containsAll(focusedActiveWindow);
     if (!isActive && accessState == DeviceAccessState::NoAccess) {
         if (!isActive) {
             if (!m_monitoringActivityStateChange) {
@@ -277,7 +277,7 @@ void UserMediaPermissionRequestManager::captureDevicesChanged(DeviceAccessState
 
 void UserMediaPermissionRequestManager::activityStateDidChange(OptionSet<WebCore::ActivityState::Flag> oldActivityState, OptionSet<WebCore::ActivityState::Flag> newActivityState)
 {
-    if ((newActivityState & focusedActiveWindow) != focusedActiveWindow)
+    if (!newActivityState.containsAll(focusedActiveWindow))
         return;
 
     RunLoop::main().dispatch([this, weakThis = makeWeakPtr(*this)]() mutable {