Changeset 254859 in webkit
- Timestamp:
- Jan 21, 2020 9:57:36 AM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r254858 r254859 1 2020-01-21 Chris Dumez <cdumez@apple.com> 2 3 Minor improvements to StorageAreaMap 4 https://bugs.webkit.org/show_bug.cgi?id=206433 5 6 Reviewed by Darin Adler. 7 8 Use inline initialization for some of StorageMap's data member. 9 Also specify uint8_t as underlying type of StorageType enum class for better packing. 10 11 * inspector/InspectorInstrumentation.h: 12 * storage/StorageArea.h: 13 * storage/StorageMap.cpp: 14 (WebCore::StorageMap::StorageMap): 15 * storage/StorageMap.h: 16 * storage/StorageType.h: 17 1 18 2020-01-21 Chris Dumez <cdumez@apple.com> 2 19 -
trunk/Source/WebCore/inspector/InspectorInstrumentation.h
r253226 r254859 109 109 #endif 110 110 111 enum class StorageType ;111 enum class StorageType : uint8_t; 112 112 113 113 struct ComputedEffectTiming; -
trunk/Source/WebCore/page/Page.h
r254739 r254859 717 717 #endif 718 718 719 void forEachDocument(const WTF::Function<void(Document&)>&) const;719 WEBCORE_EXPORT void forEachDocument(const WTF::Function<void(Document&)>&) const; 720 720 void forEachMediaElement(const WTF::Function<void(HTMLMediaElement&)>&); 721 721 -
trunk/Source/WebCore/storage/StorageArea.h
r248734 r254859 36 36 class StorageSyncManager; 37 37 38 enum class StorageType ;38 enum class StorageType : uint8_t; 39 39 40 40 struct SecurityOriginData; -
trunk/Source/WebCore/storage/StorageMap.cpp
r247486 r254859 38 38 StorageMap::StorageMap(unsigned quota) 39 39 : m_iterator(m_map.end()) 40 , m_iteratorIndex(UINT_MAX)41 40 , m_quotaSize(quota) // quota measured in bytes 42 , m_currentLength(0)43 41 { 44 42 } -
trunk/Source/WebCore/storage/StorageMap.h
r247486 r254859 63 63 HashMap<String, String> m_map; 64 64 HashMap<String, String>::iterator m_iterator; 65 unsigned m_iteratorIndex ;65 unsigned m_iteratorIndex { std::numeric_limits<unsigned>::max() }; 66 66 67 67 unsigned m_quotaSize; // Measured in bytes. 68 unsigned m_currentLength ; // Measured in UChars.68 unsigned m_currentLength { 0 }; // Measured in UChars. 69 69 }; 70 70 -
trunk/Source/WebCore/storage/StorageType.h
r248734 r254859 28 28 namespace WebCore { 29 29 30 enum class StorageType {30 enum class StorageType : uint8_t { 31 31 Session, 32 32 Local, -
trunk/Source/WebKit/ChangeLog
r254852 r254859 1 2020-01-21 Chris Dumez <cdumez@apple.com> 2 3 Minor improvements to StorageAreaMap 4 https://bugs.webkit.org/show_bug.cgi?id=206433 5 6 Reviewed by Darin Adler. 7 8 Minor improvements to StorageAreaMap: 9 1. The class does not need to be RefCounted, as it is solely owned by StorageNamespaceImpl. Having it 10 RefCounted was actually dangerous because StorageAreaMap had a raw pointer data member to its owner: 11 m_storageNamespace. This raw pointer could become stale if you extend the lifetime of the StorageAreaMap 12 object to outlive its StorageNamespaceImpl. 13 2. Make StorageAreaMap::connect() private as it is never called from outside the class 14 3. Reorder data members for better packing 15 4. Use modern loops in the implementation 16 5. Rename loadValuesIfNeeded() to ensureStorageMap() and have it return the StorageMap object. This makes 17 calls site more concise and it makes it clearer when this method needs to be called. 18 6. Mark class as final 19 7. Replace LOG_ERROR() with RELEASE_LOG_ERROR() so that we can see error logging in sysdiagnoses 20 8. Use more references instead of raw pointers to make it clear when null checks are not needed 21 22 * WebProcess/WebStorage/StorageAreaImpl.cpp: 23 (WebKit::StorageAreaImpl::create): 24 (WebKit::StorageAreaImpl::StorageAreaImpl): 25 * WebProcess/WebStorage/StorageAreaImpl.h: 26 * WebProcess/WebStorage/StorageAreaMap.cpp: 27 (WebKit::StorageAreaMap::StorageAreaMap): 28 (WebKit::StorageAreaMap::length): 29 (WebKit::StorageAreaMap::key): 30 (WebKit::StorageAreaMap::item): 31 (WebKit::StorageAreaMap::setItem): 32 (WebKit::StorageAreaMap::removeItem): 33 (WebKit::StorageAreaMap::clear): 34 (WebKit::StorageAreaMap::contains): 35 (WebKit::StorageAreaMap::resetValues): 36 (WebKit::StorageAreaMap::ensureStorageMap): 37 (WebKit::StorageAreaMap::applyChange): 38 (WebKit::StorageAreaMap::dispatchSessionStorageEvent): 39 (WebKit::StorageAreaMap::dispatchLocalStorageEvent): 40 (WebKit::StorageAreaMap::connect): 41 (WebKit::StorageAreaMap::disconnect): 42 * WebProcess/WebStorage/StorageAreaMap.h: 43 * WebProcess/WebStorage/StorageAreaMap.messages.in: 44 * WebProcess/WebStorage/StorageNamespaceImpl.cpp: 45 (WebKit::StorageNamespaceImpl::storageArea): 46 * WebProcess/WebStorage/StorageNamespaceImpl.h: 47 1 48 2020-01-21 Alejandro G. Castro <alex@igalia.com> 2 49 -
trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaImpl.cpp
r250738 r254859 38 38 using namespace WebCore; 39 39 40 Ref<StorageAreaImpl> StorageAreaImpl::create( Ref<StorageAreaMap>&& storageAreaMap)40 Ref<StorageAreaImpl> StorageAreaImpl::create(StorageAreaMap& storageAreaMap) 41 41 { 42 return adoptRef(*new StorageAreaImpl( WTFMove(storageAreaMap)));42 return adoptRef(*new StorageAreaImpl(storageAreaMap)); 43 43 } 44 44 45 StorageAreaImpl::StorageAreaImpl( Ref<StorageAreaMap>&& storageAreaMap)45 StorageAreaImpl::StorageAreaImpl(StorageAreaMap& storageAreaMap) 46 46 : m_identifier(Identifier::generate()) 47 , m_storageAreaMap(makeWeakPtr(storageAreaMap .get()))47 , m_storageAreaMap(makeWeakPtr(storageAreaMap)) 48 48 { 49 49 } … … 99 99 { 100 100 if (m_storageAreaMap) 101 return m_storageAreaMap-> storageType();101 return m_storageAreaMap->type(); 102 102 103 103 // We probably need an Invalid type. -
trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaImpl.h
r248817 r254859 44 44 using Identifier = StorageAreaImplIdentifier; 45 45 46 static Ref<StorageAreaImpl> create( Ref<StorageAreaMap>&&);46 static Ref<StorageAreaImpl> create(StorageAreaMap&); 47 47 virtual ~StorageAreaImpl(); 48 48 … … 50 50 51 51 private: 52 StorageAreaImpl( Ref<StorageAreaMap>&&);52 StorageAreaImpl(StorageAreaMap&); 53 53 54 54 // WebCore::StorageArea. -
trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaMap.cpp
r252757 r254859 1 1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2013-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #include "StorageAreaMap.h" 28 28 29 #include "Logging.h" 29 30 #include "NetworkProcessConnection.h" 30 31 #include "StorageAreaImpl.h" … … 49 50 using namespace WebCore; 50 51 51 Ref<StorageAreaMap> StorageAreaMap::create(StorageNamespaceImpl* storageNamespace, Ref<WebCore::SecurityOrigin>&& securityOrigin) 52 { 53 return adoptRef(*new StorageAreaMap(storageNamespace, WTFMove(securityOrigin))); 54 } 55 56 StorageAreaMap::StorageAreaMap(StorageNamespaceImpl* storageNamespace, Ref<WebCore::SecurityOrigin>&& securityOrigin) 57 : m_storageNamespace(storageNamespace) 58 , m_storageType(storageNamespace->storageType()) 59 , m_quotaInBytes(storageNamespace->quotaInBytes()) 52 StorageAreaMap::StorageAreaMap(StorageNamespaceImpl& storageNamespace, Ref<WebCore::SecurityOrigin>&& securityOrigin) 53 : m_namespace(storageNamespace) 60 54 , m_securityOrigin(WTFMove(securityOrigin)) 61 , m_ currentSeed(0)62 , m_ hasPendingClear(false)55 , m_quotaInBytes(storageNamespace.quotaInBytes()) 56 , m_type(storageNamespace.storageType()) 63 57 { 64 58 connect(); … … 72 66 unsigned StorageAreaMap::length() 73 67 { 74 loadValuesIfNeeded(); 75 76 return m_storageMap->length(); 68 return ensureMap().length(); 77 69 } 78 70 79 71 String StorageAreaMap::key(unsigned index) 80 72 { 81 loadValuesIfNeeded(); 82 83 return m_storageMap->key(index); 73 return ensureMap().key(index); 84 74 } 85 75 86 76 String StorageAreaMap::item(const String& key) 87 77 { 88 loadValuesIfNeeded(); 89 90 return m_storageMap->getItem(key); 78 return ensureMap().getItem(key); 91 79 } 92 80 93 81 void StorageAreaMap::setItem(Frame* sourceFrame, StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException) 94 82 { 95 loadValuesIfNeeded(); 96 97 ASSERT(m_storageMap->hasOneRef()); 83 auto& map = ensureMap(); 84 ASSERT(map.hasOneRef()); 98 85 99 86 String oldValue; 100 87 quotaException = false; 101 m _storageMap->setItem(key, value, oldValue, quotaException);88 map.setItem(key, value, oldValue, quotaException); 102 89 if (quotaException) 103 90 return; … … 108 95 m_pendingValueChanges.add(key); 109 96 110 if (m_ storageMapID)111 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::StorageManagerSet::SetItem(*m_ storageMapID, sourceArea->identifier(), m_currentSeed, key, value, sourceFrame->document()->url()), 0);97 if (m_mapID) 98 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::StorageManagerSet::SetItem(*m_mapID, sourceArea->identifier(), m_currentSeed, key, value, sourceFrame->document()->url()), 0); 112 99 else 113 LOG_ERROR("StorageAreaMap::setItem failsbecause storage map ID is invalid");100 RELEASE_LOG_ERROR(Storage, "StorageAreaMap::setItem failed because storage map ID is invalid"); 114 101 } 115 102 116 103 void StorageAreaMap::removeItem(WebCore::Frame* sourceFrame, StorageAreaImpl* sourceArea, const String& key) 117 104 { 118 loadValuesIfNeeded();119 ASSERT(m _storageMap->hasOneRef());105 auto& map = ensureMap(); 106 ASSERT(map.hasOneRef()); 120 107 121 108 String oldValue; 122 m _storageMap->removeItem(key, oldValue);109 map.removeItem(key, oldValue); 123 110 124 111 if (oldValue.isNull()) … … 127 114 m_pendingValueChanges.add(key); 128 115 129 if (m_ storageMapID)130 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::StorageManagerSet::RemoveItem(*m_ storageMapID, sourceArea->identifier(), m_currentSeed, key, sourceFrame->document()->url()), 0);116 if (m_mapID) 117 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::StorageManagerSet::RemoveItem(*m_mapID, sourceArea->identifier(), m_currentSeed, key, sourceFrame->document()->url()), 0); 131 118 else 132 LOG_ERROR("StorageAreaMap::removeItem failsbecause storage map ID is invalid");119 RELEASE_LOG_ERROR(Storage, "StorageAreaMap::removeItem failed because storage map ID is invalid"); 133 120 } 134 121 … … 140 127 141 128 m_hasPendingClear = true; 142 m_ storageMap = StorageMap::create(m_quotaInBytes);143 144 if (m_ storageMapID)145 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::StorageManagerSet::Clear(*m_ storageMapID, sourceArea->identifier(), m_currentSeed, sourceFrame->document()->url()), 0);129 m_map = StorageMap::create(m_quotaInBytes); 130 131 if (m_mapID) 132 WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::StorageManagerSet::Clear(*m_mapID, sourceArea->identifier(), m_currentSeed, sourceFrame->document()->url()), 0); 146 133 else 147 LOG_ERROR("StorageAreaMap::removeItem failsbecause storage map ID is invalid");134 RELEASE_LOG_ERROR(Storage, "StorageAreaMap::clear failed because storage map ID is invalid"); 148 135 } 149 136 150 137 bool StorageAreaMap::contains(const String& key) 151 138 { 152 loadValuesIfNeeded(); 153 154 return m_storageMap->contains(key); 139 return ensureMap().contains(key); 155 140 } 156 141 157 142 void StorageAreaMap::resetValues() 158 143 { 159 m_ storageMap = nullptr;144 m_map = nullptr; 160 145 161 146 m_pendingValueChanges.clear(); 162 147 m_hasPendingClear = false; 163 m_currentSeed++;164 } 165 166 void StorageAreaMap::loadValuesIfNeeded()148 ++m_currentSeed; 149 } 150 151 StorageMap& StorageAreaMap::ensureMap() 167 152 { 168 153 connect(); 169 154 170 if (m_storageMap) 171 return; 172 173 HashMap<String, String> values; 174 175 if (m_storageMapID) { 176 // The StorageManagerSet::GetValues() IPC may be very slow because it may need to fetch the values from disk and there may be a lot 177 // of data. 178 IPC::UnboundedSynchronousIPCScope unboundedSynchronousIPCScope; 179 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::GetValues(*m_storageMapID), Messages::StorageManagerSet::GetValues::Reply(values), 0); 180 } else 181 LOG_ERROR("StorageAreaMap::loadValuesIfNeeded fails to load from network process because storage map ID is invalid"); 182 183 m_storageMap = StorageMap::create(m_quotaInBytes); 184 m_storageMap->importItems(WTFMove(values)); 185 } 186 187 void StorageAreaMap::didSetItem(uint64_t storageMapSeed, const String& key, bool quotaError) 188 { 189 if (m_currentSeed != storageMapSeed) 155 if (!m_map) { 156 m_map = StorageMap::create(m_quotaInBytes); 157 158 if (m_mapID) { 159 // We need to use a IPC::UnboundedSynchronousIPCScope to prevent UIProcess hangs in case we receive a synchronous IPC from the UIProcess while we're waiting for a response 160 // from our StorageManagerSet::GetValues() IPC. This IPC may be very slow because it may need to fetch the values from disk and there may be a lot of data. 161 IPC::UnboundedSynchronousIPCScope unboundedSynchronousIPCScope; 162 HashMap<String, String> values; 163 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::GetValues(*m_mapID), Messages::StorageManagerSet::GetValues::Reply(values), 0); 164 m_map->importItems(WTFMove(values)); 165 } else 166 RELEASE_LOG_ERROR(Storage, "StorageAreaMap::ensureMap failed to load from network process because storage map ID is invalid"); 167 } 168 return *m_map; 169 } 170 171 void StorageAreaMap::didSetItem(uint64_t mapSeed, const String& key, bool quotaError) 172 { 173 if (m_currentSeed != mapSeed) 190 174 return; 191 175 … … 200 184 } 201 185 202 void StorageAreaMap::didRemoveItem(uint64_t storageMapSeed, const String& key)203 { 204 if (m_currentSeed != storageMapSeed)186 void StorageAreaMap::didRemoveItem(uint64_t mapSeed, const String& key) 187 { 188 if (m_currentSeed != mapSeed) 205 189 return; 206 190 … … 209 193 } 210 194 211 void StorageAreaMap::didClear(uint64_t storageMapSeed)212 { 213 if (m_currentSeed != storageMapSeed)195 void StorageAreaMap::didClear(uint64_t mapSeed) 196 { 197 if (m_currentSeed != mapSeed) 214 198 return; 215 199 … … 221 205 { 222 206 // We have not yet loaded anything from this storage map. 223 if (!m_ storageMap)207 if (!m_map) 224 208 return false; 225 209 … … 235 219 void StorageAreaMap::applyChange(const String& key, const String& newValue) 236 220 { 237 ASSERT(!m_ storageMap || m_storageMap->hasOneRef());221 ASSERT(!m_map || m_map->hasOneRef()); 238 222 239 223 // There is at least one clear pending we don't want to apply any changes until we get the corresponding DidClear messages. … … 243 227 if (!key) { 244 228 // A null key means clear. 245 auto new StorageMap = StorageMap::create(m_quotaInBytes);229 auto newMap = StorageMap::create(m_quotaInBytes); 246 230 247 231 // Any changes that were made locally after the clear must still be kept around in the new map. 248 for (auto it = m_pendingValueChanges.begin().keys(), end = m_pendingValueChanges.end().keys(); it != end; ++it) { 249 const String& key = *it; 250 251 String value = m_storageMap->getItem(key); 232 for (auto& change : m_pendingValueChanges) { 233 auto& key = change.key; 234 String value = m_map->getItem(key); 252 235 if (!value) { 253 236 // This change must have been a pending remove, ignore it. … … 256 239 257 240 String oldValue; 258 new StorageMap->setItemIgnoringQuota(key, oldValue);241 newMap->setItemIgnoringQuota(key, oldValue); 259 242 } 260 243 261 m_ storageMap = WTFMove(newStorageMap);244 m_map = WTFMove(newMap); 262 245 return; 263 246 } … … 269 252 // A null new value means that the item should be removed. 270 253 String oldValue; 271 m_ storageMap->removeItem(key, oldValue);272 return; 273 } 274 275 m_ storageMap->setItemIgnoringQuota(key, newValue);254 m_map->removeItem(key, oldValue); 255 return; 256 } 257 258 m_map->setItemIgnoringQuota(key, newValue); 276 259 } 277 260 … … 283 266 } 284 267 285 if ( storageType() == StorageType::Session)268 if (type() == StorageType::Session) 286 269 dispatchSessionStorageEvent(storageAreaImplID, key, oldValue, newValue, urlString); 287 270 else … … 294 277 } 295 278 279 static Vector<RefPtr<Frame>> framesForEventDispatching(Page& page, SecurityOrigin& origin, const Optional<StorageAreaImplIdentifier>& storageAreaImplID) 280 { 281 Vector<RefPtr<Frame>> frames; 282 page.forEachDocument([&](auto& document) { 283 if (!document.securityOrigin().equal(&origin)) 284 return; 285 286 auto* storage = document.domWindow() ? document.domWindow()->optionalSessionStorage() : nullptr; 287 if (!storage) 288 return; 289 290 auto& storageArea = static_cast<StorageAreaImpl&>(storage->area()); 291 if (storageArea.identifier() == storageAreaImplID) { 292 // This is the storage area that caused the event to be dispatched. 293 return; 294 } 295 296 if (auto* frame = document.frame()) 297 frames.append(frame); 298 }); 299 return frames; 300 } 301 296 302 void StorageAreaMap::dispatchSessionStorageEvent(const Optional<StorageAreaImplIdentifier>& storageAreaImplID, const String& key, const String& oldValue, const String& newValue, const String& urlString) 297 303 { 298 304 // Namespace IDs for session storage namespaces are equivalent to web page IDs 299 305 // so we can get the right page here. 300 WebPage* webPage = WebProcess::singleton().webPage(m_storageNamespace->sessionStoragePageID());306 auto* webPage = WebProcess::singleton().webPage(m_namespace.sessionStoragePageID()); 301 307 if (!webPage) 302 308 return; 303 309 310 auto* page = webPage->corePage(); 311 if (!page) 312 return; 313 314 auto frames = framesForEventDispatching(*page, m_securityOrigin, storageAreaImplID); 315 StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, m_securityOrigin->data()); 316 } 317 318 void StorageAreaMap::dispatchLocalStorageEvent(const Optional<StorageAreaImplIdentifier>& storageAreaImplID, const String& key, const String& oldValue, const String& newValue, const String& urlString) 319 { 320 ASSERT(isLocalStorage(type())); 321 304 322 Vector<RefPtr<Frame>> frames; 305 323 306 Page* page = webPage->corePage();307 for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {308 Document* document = frame->document();309 if (!document->securityOrigin().equal(m_securityOrigin.ptr()))310 continue;311 312 Storage* storage = document->domWindow()->optionalSessionStorage();313 if (!storage)314 continue;315 316 StorageAreaImpl& storageArea = static_cast<StorageAreaImpl&>(storage->area());317 if (storageArea.identifier() == storageAreaImplID) {318 // This is the storage area that caused the event to be dispatched.319 continue;320 }321 322 frames.append(frame);323 }324 325 StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, m_securityOrigin->data());326 }327 328 void StorageAreaMap::dispatchLocalStorageEvent(const Optional<StorageAreaImplIdentifier>& storageAreaImplID, const String& key, const String& oldValue, const String& newValue, const String& urlString)329 {330 ASSERT(isLocalStorage(storageType()));331 332 Vector<RefPtr<Frame>> frames;333 334 324 // Namespace IDs for local storage namespaces are equivalent to web page group IDs. 335 PageGroup& pageGroup = *WebProcess::singleton().webPageGroup(m_storageNamespace->pageGroupID())->corePageGroup(); 336 const HashSet<Page*>& pages = pageGroup.pages(); 337 for (HashSet<Page*>::const_iterator it = pages.begin(), end = pages.end(); it != end; ++it) { 338 for (Frame* frame = &(*it)->mainFrame(); frame; frame = frame->tree().traverseNext()) { 339 Document* document = frame->document(); 340 if (!document->securityOrigin().equal(m_securityOrigin.ptr())) 341 continue; 342 343 Storage* storage = document->domWindow()->optionalLocalStorage(); 344 if (!storage) 345 continue; 346 347 StorageAreaImpl& storageArea = static_cast<StorageAreaImpl&>(storage->area()); 348 if (storageArea.identifier() == storageAreaImplID) { 349 // This is the storage area that caused the event to be dispatched. 350 continue; 351 } 352 353 frames.append(frame); 354 } 355 } 325 auto& pageGroup = *WebProcess::singleton().webPageGroup(m_namespace.pageGroupID())->corePageGroup(); 326 for (auto* page : pageGroup.pages()) 327 frames.appendVector(framesForEventDispatching(*page, m_securityOrigin, storageAreaImplID)); 356 328 357 329 StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, m_securityOrigin->data()); … … 360 332 void StorageAreaMap::connect() 361 333 { 362 if (m_ storageMapID)363 return; 364 365 switch (m_ storageType) {334 if (m_mapID) 335 return; 336 337 switch (m_type) { 366 338 case StorageType::Local: 367 339 case StorageType::TransientLocal: 368 if (SecurityOrigin* topLevelOrigin = m_ storageNamespace->topLevelOrigin())369 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::ConnectToTransientLocalStorageArea(WebProcess::singleton().sessionID(), m_ storageNamespace->storageNamespaceID(), topLevelOrigin->data(), m_securityOrigin->data()), Messages::StorageManagerSet::ConnectToTransientLocalStorageArea::Reply(m_storageMapID), 0);340 if (SecurityOrigin* topLevelOrigin = m_namespace.topLevelOrigin()) 341 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::ConnectToTransientLocalStorageArea(WebProcess::singleton().sessionID(), m_namespace.storageNamespaceID(), topLevelOrigin->data(), m_securityOrigin->data()), Messages::StorageManagerSet::ConnectToTransientLocalStorageArea::Reply(m_mapID), 0); 370 342 else 371 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::ConnectToLocalStorageArea(WebProcess::singleton().sessionID(), m_ storageNamespace->storageNamespaceID(), m_securityOrigin->data()), Messages::StorageManagerSet::ConnectToLocalStorageArea::Reply(m_storageMapID), 0);343 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::ConnectToLocalStorageArea(WebProcess::singleton().sessionID(), m_namespace.storageNamespaceID(), m_securityOrigin->data()), Messages::StorageManagerSet::ConnectToLocalStorageArea::Reply(m_mapID), 0); 372 344 break; 373 345 case StorageType::Session: 374 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::ConnectToSessionStorageArea(WebProcess::singleton().sessionID(), m_ storageNamespace->storageNamespaceID(), m_securityOrigin->data()), Messages::StorageManagerSet::ConnectToSessionStorageArea::Reply(m_storageMapID), 0);375 } 376 377 if (m_ storageMapID)346 WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::StorageManagerSet::ConnectToSessionStorageArea(WebProcess::singleton().sessionID(), m_namespace.storageNamespaceID(), m_securityOrigin->data()), Messages::StorageManagerSet::ConnectToSessionStorageArea::Reply(m_mapID), 0); 347 } 348 349 if (m_mapID) 378 350 WebProcess::singleton().registerStorageAreaMap(*this); 379 351 } … … 381 353 void StorageAreaMap::disconnect() 382 354 { 383 if (!m_ storageMapID)355 if (!m_mapID) 384 356 return; 385 357 … … 387 359 WebProcess::singleton().unregisterStorageAreaMap(*this); 388 360 389 if (auto networkProcessConnection = WebProcess::singleton().existingNetworkProcessConnection())390 networkProcessConnection->connection().send(Messages::StorageManagerSet::DisconnectFromStorageArea(*m_ storageMapID), 0);391 392 m_ storageMapID = { };361 if (auto* networkProcessConnection = WebProcess::singleton().existingNetworkProcessConnection()) 362 networkProcessConnection->connection().send(Messages::StorageManagerSet::DisconnectFromStorageArea(*m_mapID), 0); 363 364 m_mapID = { }; 393 365 } 394 366 -
trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaMap.h
r248817 r254859 1 1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2013-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 47 47 class StorageNamespaceImpl; 48 48 49 class StorageAreaMap : public RefCounted<StorageAreaMap>, private IPC::MessageReceiver, public CanMakeWeakPtr<StorageAreaMap> { 49 class StorageAreaMap final : private IPC::MessageReceiver, public CanMakeWeakPtr<StorageAreaMap> { 50 WTF_MAKE_FAST_ALLOCATED; 50 51 public: 51 static Ref<StorageAreaMap> create(StorageNamespaceImpl*, Ref<WebCore::SecurityOrigin>&&);52 StorageAreaMap(StorageNamespaceImpl&, Ref<WebCore::SecurityOrigin>&&); 52 53 ~StorageAreaMap(); 53 54 54 WebCore::StorageType storageType() const { return m_storageType; }55 WebCore::StorageType type() const { return m_type; } 55 56 56 57 unsigned length(); … … 63 64 64 65 // IPC::MessageReceiver 65 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;66 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final; 66 67 67 68 const WebCore::SecurityOrigin& securityOrigin() const { return m_securityOrigin.get(); } 69 const Optional<StorageAreaIdentifier>& identifier() const { return m_mapID; } 68 70 69 void connect();70 71 void disconnect(); 71 const Optional<StorageAreaIdentifier>& identifier() const { return m_storageMapID; }72 72 73 73 private: 74 StorageAreaMap(StorageNamespaceImpl*, Ref<WebCore::SecurityOrigin>&&); 75 76 void didSetItem(uint64_t storageMapSeed, const String& key, bool quotaError); 77 void didRemoveItem(uint64_t storageMapSeed, const String& key); 78 void didClear(uint64_t storageMapSeed); 74 void didSetItem(uint64_t mapSeed, const String& key, bool quotaError); 75 void didRemoveItem(uint64_t mapSeed, const String& key); 76 void didClear(uint64_t mapSeed); 79 77 80 78 void dispatchStorageEvent(const Optional<StorageAreaImplIdentifier>& sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString); … … 82 80 83 81 void resetValues(); 84 void loadValuesIfNeeded();82 WebCore::StorageMap& ensureMap(); 85 83 86 84 bool shouldApplyChangeForKey(const String& key) const; … … 90 88 void dispatchLocalStorageEvent(const Optional<StorageAreaImplIdentifier>&, const String& key, const String& oldValue, const String& newValue, const String& urlString); 91 89 92 StorageNamespaceImpl* m_storageNamespace;90 void connect(); 93 91 94 Optional<StorageAreaIdentifier> m_storageMapID; 95 96 WebCore::StorageType m_storageType; 92 StorageNamespaceImpl& m_namespace; 93 Ref<WebCore::SecurityOrigin> m_securityOrigin; 94 RefPtr<WebCore::StorageMap> m_map; 95 Optional<StorageAreaIdentifier> m_mapID; 96 HashCountedSet<String> m_pendingValueChanges; 97 uint64_t m_currentSeed { 0 }; 97 98 unsigned m_quotaInBytes; 98 Ref<WebCore::SecurityOrigin> m_securityOrigin; 99 100 RefPtr<WebCore::StorageMap> m_storageMap; 101 102 uint64_t m_currentSeed; 103 bool m_hasPendingClear; 104 HashCountedSet<String> m_pendingValueChanges; 99 WebCore::StorageType m_type; 100 bool m_hasPendingClear { false }; 105 101 }; 106 102 -
trunk/Source/WebKit/WebProcess/WebStorage/StorageAreaMap.messages.in
r248817 r254859 21 21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 22 23 messages -> StorageAreaMap {23 messages -> StorageAreaMap NotRefCounted { 24 24 DidSetItem(uint64_t storageMapSeed, String key, bool quotaException) 25 25 DidRemoveItem(uint64_t storageMapSeed, String key) -
trunk/Source/WebKit/WebProcess/WebStorage/StorageNamespaceImpl.cpp
r250083 r254859 103 103 Ref<StorageArea> StorageNamespaceImpl::storageArea(const SecurityOriginData& securityOriginData) 104 104 { 105 RefPtr<StorageAreaMap> map; 106 107 auto securityOrigin = securityOriginData.securityOrigin(); 108 auto& slot = m_storageAreaMaps.add(securityOrigin->data(), nullptr).iterator->value; 109 if (!slot) { 110 map = StorageAreaMap::create(this, WTFMove(securityOrigin)); 111 slot = map.get(); 112 } else 113 map = slot; 114 115 return StorageAreaImpl::create(map.releaseNonNull()); 105 auto& map = m_storageAreaMaps.ensure(securityOriginData, [&] { 106 return makeUnique<StorageAreaMap>(*this, securityOriginData.securityOrigin()); 107 }).iterator->value; 108 return StorageAreaImpl::create(*map); 116 109 } 117 110 -
trunk/Source/WebKit/WebProcess/WebStorage/StorageNamespaceImpl.h
r250083 r254859 80 80 const unsigned m_quotaInBytes; 81 81 82 HashMap<WebCore::SecurityOriginData, RefPtr<StorageAreaMap>> m_storageAreaMaps;82 HashMap<WebCore::SecurityOriginData, std::unique_ptr<StorageAreaMap>> m_storageAreaMaps; 83 83 }; 84 84
Note: See TracChangeset
for help on using the changeset viewer.