Changeset 148161 in webkit
- Timestamp:
- Apr 10, 2013 6:22:52 PM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r148160 r148161 1 2013-04-10 Anders Carlsson <andersca@apple.com> 2 3 Make StorageAreaImpl a wrapper around StorageAreaMap 4 https://bugs.webkit.org/show_bug.cgi?id=114404 5 6 Reviewed by Oliver Hunt. 7 8 Prepare for moving all the code that deals with local storage values to StorageAreaMap, 9 and make StorageAreaImpl a dumb wrapper that simply calls through to the map. 10 11 * WebProcess/Storage/StorageAreaImpl.cpp: 12 (WebKit::StorageAreaImpl::create): 13 (WebKit::StorageAreaImpl::StorageAreaImpl): 14 (WebKit::StorageAreaImpl::~StorageAreaImpl): 15 (WebKit::StorageAreaImpl::storageType): 16 (WebKit::StorageAreaImpl::length): 17 (WebKit::StorageAreaImpl::key): 18 (WebKit::StorageAreaImpl::getItem): 19 (WebKit::StorageAreaImpl::setItem): 20 (WebKit::StorageAreaImpl::contains): 21 * WebProcess/Storage/StorageAreaImpl.h: 22 (WebKit::StorageAreaImpl::storageAreaID): 23 * WebProcess/Storage/StorageAreaMap.cpp: 24 (WebKit::generateStorageMapID): 25 (WebKit::StorageAreaMap::create): 26 (WebKit::StorageAreaMap::StorageAreaMap): 27 (WebKit::StorageAreaMap::storageType): 28 (WebKit::StorageAreaMap::length): 29 (WebKit::StorageAreaMap::key): 30 (WebKit::StorageAreaMap::item): 31 (WebKit::StorageAreaMap::setItem): 32 (WebKit::StorageAreaMap::contains): 33 (WebKit::StorageAreaMap::didSetItem): 34 (WebKit::StorageAreaMap::dispatchStorageEvent): 35 * WebProcess/Storage/StorageAreaMap.h: 36 * WebProcess/Storage/StorageNamespaceImpl.cpp: 37 (WebKit::StorageNamespaceImpl::storageArea): 38 * WebProcess/Storage/StorageNamespaceImpl.h: 39 (StorageNamespaceImpl): 40 1 41 2013-04-10 Anders Carlsson <andersca@apple.com> 2 42 -
trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.cpp
r148160 r148161 27 27 #include "StorageAreaImpl.h" 28 28 29 #include "SecurityOriginData.h" 30 #include "StorageAreaMapMessages.h" 31 #include "StorageManagerMessages.h" 32 #include "StorageNamespaceImpl.h" 33 #include "WebProcess.h" 29 #include "StorageAreaMap.h" 34 30 #include <WebCore/ExceptionCode.h> 35 31 #include <WebCore/Frame.h> 36 32 #include <WebCore/Page.h> 37 33 #include <WebCore/SchemeRegistry.h> 38 #include <WebCore/SecurityOrigin.h> 39 #include <WebCore/StorageMap.h> 34 #include <WebCore/Settings.h> 40 35 41 36 using namespace WebCore; … … 49 44 } 50 45 51 PassRefPtr<StorageAreaImpl> StorageAreaImpl::create( StorageNamespaceImpl* StorageNamespaceImpl, PassRefPtr<SecurityOrigin> securityOrigin)46 PassRefPtr<StorageAreaImpl> StorageAreaImpl::create(PassRefPtr<StorageAreaMap> storageAreaMap) 52 47 { 53 return adoptRef(new StorageAreaImpl( StorageNamespaceImpl, securityOrigin));48 return adoptRef(new StorageAreaImpl(storageAreaMap)); 54 49 } 55 50 56 StorageAreaImpl::StorageAreaImpl(StorageNamespaceImpl* StorageNamespaceImpl, PassRefPtr<SecurityOrigin> securityOrigin) 57 : m_storageNamespaceID(StorageNamespaceImpl->storageNamespaceID()) 58 , m_quotaInBytes(StorageNamespaceImpl->quotaInBytes()) 59 , m_storageAreaID(generateStorageAreaID()) 60 , m_securityOrigin(securityOrigin) 51 StorageAreaImpl::StorageAreaImpl(PassRefPtr<StorageAreaMap> storageAreaMap) 52 : m_storageAreaID(generateStorageAreaID()) 53 , m_storageAreaMap(storageAreaMap) 61 54 { 62 WebProcess::shared().connection()->send(Messages::StorageManager::CreateStorageMap(m_storageAreaID, StorageNamespaceImpl->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin.get())), 0);63 WebProcess::shared().addMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageAreaID, this);64 55 } 65 56 66 57 StorageAreaImpl::~StorageAreaImpl() 67 58 { 68 WebProcess::shared().connection()->send(Messages::StorageManager::DestroyStorageMap(m_storageAreaID), 0); 69 WebProcess::shared().removeMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageAreaID); 59 } 60 61 StorageType StorageAreaImpl::storageType() const 62 { 63 return m_storageAreaMap->storageType(); 70 64 } 71 65 … … 81 75 return 0; 82 76 83 loadValuesIfNeeded(); 84 return m_storageMap->length(); 77 return m_storageAreaMap->length(); 85 78 } 86 79 … … 92 85 return String(); 93 86 } 87 94 88 if (disabledByPrivateBrowsingInFrame(sourceFrame)) 95 89 return String(); 96 90 97 loadValuesIfNeeded(); 98 99 return m_storageMap->key(index); 91 return m_storageAreaMap->key(index); 100 92 } 101 93 … … 107 99 return String(); 108 100 } 101 109 102 if (disabledByPrivateBrowsingInFrame(sourceFrame)) 110 103 return String(); 111 104 112 loadValuesIfNeeded(); 113 return m_storageMap->getItem(key); 105 return m_storageAreaMap->item(key); 114 106 } 115 107 … … 129 121 } 130 122 131 loadValuesIfNeeded(); 123 bool quotaException; 124 m_storageAreaMap->setItem(this, key, value, quotaException); 132 125 133 ASSERT(m_storageMap->hasOneRef()); 134 String oldValue; 135 bool quotaException; 136 m_storageMap->setItem(key, value, oldValue, quotaException); 137 138 if (quotaException) { 126 if (quotaException) 139 127 ec = QUOTA_EXCEEDED_ERR; 140 return;141 }142 143 if (oldValue == value)144 return;145 146 m_pendingValueChanges.add(key);147 148 WebProcess::shared().connection()->send(Messages::StorageManager::SetItem(m_storageAreaID, key, value, sourceFrame->document()->url()), 0);149 128 } 150 129 … … 174 153 return false; 175 154 176 loadValuesIfNeeded(); 177 178 return m_storageMap->contains(key); 155 return m_storageAreaMap->contains(key); 179 156 } 180 157 … … 205 182 } 206 183 207 208 void StorageAreaImpl::didSetItem(const String& key, bool quotaError)209 {210 ASSERT(m_pendingValueChanges.contains(key));211 212 m_pendingValueChanges.remove(key);213 214 if (quotaError)215 resetValues();216 }217 218 void StorageAreaImpl::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)219 {220 if (!shouldApplyChangesForKey(key))221 return;222 223 ASSERT(!key.isNull());224 ASSERT(!newValue.isNull());225 226 ASSERT(m_storageMap->hasOneRef());227 m_storageMap->setItemIgnoringQuota(key, newValue);228 229 if (storageType() == SessionStorage)230 dispatchSessionStorageEvent(key, oldValue, newValue, urlString);231 else232 dispatchLocalStorageEvent(key, oldValue, newValue, urlString);233 }234 235 StorageType StorageAreaImpl::storageType() const236 {237 // A zero storage namespace ID is used for local storage.238 if (!m_storageNamespaceID)239 return LocalStorage;240 241 return SessionStorage;242 }243 244 184 bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* sourceFrame) const 245 185 { … … 253 193 } 254 194 255 bool StorageAreaImpl::shouldApplyChangesForKey(const String& key) const256 {257 // We have not yet loaded anything from this storage map.258 if (!m_storageMap)259 return false;260 261 // Check if this storage area is currently waiting for the storage manager to update the given key.262 // If that is the case, we don't want to apply any changes made by other storage areas, since263 // our change was made last.264 if (m_pendingValueChanges.contains(key))265 return false;266 267 return true;268 }269 270 void StorageAreaImpl::loadValuesIfNeeded()271 {272 if (m_storageMap)273 return;274 275 HashMap<String, String> values;276 // FIXME: This should use a special sendSync flag to indicate that we don't want to process incoming messages while waiting for a reply.277 // (This flag does not yet exist).278 WebProcess::shared().connection()->sendSync(Messages::StorageManager::GetValues(m_storageAreaID), Messages::StorageManager::GetValues::Reply(values), 0);279 280 m_storageMap = StorageMap::create(m_quotaInBytes);281 m_storageMap->importItems(values);282 }283 284 void StorageAreaImpl::resetValues()285 {286 m_storageMap = nullptr;287 m_pendingValueChanges.clear();288 }289 290 void StorageAreaImpl::dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)291 {292 ASSERT(storageType() == SessionStorage);293 294 // FIXME: Implement.295 UNUSED_PARAM(key);296 UNUSED_PARAM(oldValue);297 UNUSED_PARAM(newValue);298 UNUSED_PARAM(urlString);299 }300 301 void StorageAreaImpl::dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)302 {303 ASSERT(storageType() == LocalStorage);304 305 // FIXME: Implement.306 UNUSED_PARAM(key);307 UNUSED_PARAM(oldValue);308 UNUSED_PARAM(newValue);309 UNUSED_PARAM(urlString);310 }311 312 195 } // namespace WebKit -
trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.h
r148148 r148161 32 32 #include <wtf/HashMap.h> 33 33 34 namespace WebCore {35 class StorageMap;36 }37 38 34 namespace WebKit { 39 35 40 class Storage NamespaceImpl;36 class StorageAreaMap; 41 37 42 class StorageAreaImpl : public WebCore::StorageArea , private CoreIPC::MessageReceiver{38 class StorageAreaImpl : public WebCore::StorageArea { 43 39 public: 44 static PassRefPtr<StorageAreaImpl> create( StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>);40 static PassRefPtr<StorageAreaImpl> create(PassRefPtr<StorageAreaMap>); 45 41 virtual ~StorageAreaImpl(); 46 42 43 uint64_t storageAreaID() const { return m_storageAreaID; } 44 WebCore::StorageType storageType() const; 45 47 46 private: 48 StorageAreaImpl( StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>);47 StorageAreaImpl(PassRefPtr<StorageAreaMap>); 49 48 50 49 // WebCore::StorageArea. … … 62 61 virtual void closeDatabaseIfIdle() OVERRIDE; 63 62 64 // CoreIPC::MessageReceiver65 virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) OVERRIDE;66 67 void didSetItem(const String& key, bool quotaError);68 void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);69 70 WebCore::StorageType storageType() const;71 63 bool disabledByPrivateBrowsingInFrame(const WebCore::Frame* sourceFrame) const; 72 64 73 bool shouldApplyChangesForKey(const String& key) const;74 void loadValuesIfNeeded();75 void resetValues();76 77 void dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);78 void dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);79 80 uint64_t m_storageNamespaceID;81 unsigned m_quotaInBytes;82 65 uint64_t m_storageAreaID; 83 84 RefPtr<WebCore::SecurityOrigin> m_securityOrigin; 85 RefPtr<WebCore::StorageMap> m_storageMap; 86 87 HashCountedSet<String> m_pendingValueChanges; 66 RefPtr<StorageAreaMap> m_storageAreaMap; 88 67 }; 89 68 -
trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp
r148154 r148161 27 27 #include "StorageAreaMap.h" 28 28 29 #include "StorageNamespaceImpl.h" 30 #include <WebCore/StorageMap.h> 31 32 using namespace WebCore; 33 29 34 namespace WebKit { 30 35 31 PassRefPtr<StorageAreaMap> StorageAreaMap::create()36 static uint64_t generateStorageMapID() 32 37 { 33 return adoptRef(new StorageAreaMap); 38 static uint64_t storageMapID; 39 return ++storageMapID; 34 40 } 35 41 36 StorageAreaMap::StorageAreaMap() 42 PassRefPtr<StorageAreaMap> StorageAreaMap::create(StorageNamespaceImpl* storageNamespace, PassRefPtr<WebCore::SecurityOrigin> securityOrigin) 43 { 44 return adoptRef(new StorageAreaMap(storageNamespace, securityOrigin)); 45 } 46 47 StorageAreaMap::StorageAreaMap(StorageNamespaceImpl* storageNamespace, PassRefPtr<WebCore::SecurityOrigin> securityOrigin) 48 : m_storageMapID(generateStorageMapID()) 49 , m_storageNamespaceID(storageNamespace->storageNamespaceID()) 50 , m_quotaInBytes(storageNamespace->quotaInBytes()) 51 , m_securityOrigin(securityOrigin) 37 52 { 38 53 } … … 42 57 } 43 58 59 StorageType StorageAreaMap::storageType() const 60 { 61 // A zero storage namespace ID is used for local storage. 62 if (!m_storageNamespaceID) 63 return LocalStorage; 64 65 return SessionStorage; 66 } 67 68 unsigned StorageAreaMap::length() 69 { 70 // FIXME: Implement. 71 return 0; 72 } 73 74 String StorageAreaMap::key(unsigned index) 75 { 76 // FIXME: Implement. 77 return String(); 78 } 79 80 String StorageAreaMap::item(const String& key) 81 { 82 // FIXME: Implement. 83 return String(); 84 } 85 86 void StorageAreaMap::setItem(StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException) 87 { 88 // FIXME: Implement. 89 } 90 91 bool StorageAreaMap::contains(const String& key) 92 { 93 // FIXME: Implement. 94 return false; 95 } 96 44 97 void StorageAreaMap::didSetItem(const String& key, bool quotaError) 45 98 { 99 // FIXME: Implement. 46 100 } 47 101 48 102 void StorageAreaMap::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString) 49 103 { 104 // FIXME: Implement. 50 105 } 51 106 -
trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.h
r148154 r148161 28 28 29 29 #include "MessageReceiver.h" 30 #include <WebCore/SecurityOrigin.h> 31 #include <WebCore/StorageArea.h> 30 32 #include <wtf/Forward.h> 31 33 #include <wtf/PassRefPtr.h> 32 34 #include <wtf/RefCounted.h> 33 35 36 namespace WebCore { 37 class SecurityOrigin; 38 class StorageMap; 39 } 40 34 41 namespace WebKit { 42 43 class StorageAreaImpl; 44 class StorageNamespaceImpl; 35 45 36 46 class StorageAreaMap : public RefCounted<StorageAreaMap>, private CoreIPC::MessageReceiver { 37 47 public: 38 static PassRefPtr<StorageAreaMap> create( );48 static PassRefPtr<StorageAreaMap> create(StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>); 39 49 ~StorageAreaMap(); 40 50 51 WebCore::StorageType storageType() const; 52 53 unsigned length(); 54 String key(unsigned index); 55 String item(const String& key); 56 void setItem(StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException); 57 bool contains(const String& key); 58 41 59 private: 42 StorageAreaMap( );60 StorageAreaMap(StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>); 43 61 44 62 // CoreIPC::MessageReceiver … … 47 65 void didSetItem(const String& key, bool quotaError); 48 66 void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString); 67 68 void loadValuesIfNeeded(); 69 70 uint64_t m_storageMapID; 71 uint64_t m_storageNamespaceID; 72 unsigned m_quotaInBytes; 73 RefPtr<WebCore::SecurityOrigin> m_securityOrigin; 74 75 76 RefPtr<WebCore::StorageMap> m_storageMap; 49 77 }; 50 78 -
trunk/Source/WebKit2/WebProcess/Storage/StorageNamespaceImpl.cpp
r148148 r148161 28 28 29 29 #include "StorageAreaImpl.h" 30 #include "StorageAreaMap.h" 30 31 #include "WebPage.h" 31 32 #include <WebCore/SecurityOrigin.h> … … 53 54 PassRefPtr<StorageArea> StorageNamespaceImpl::storageArea(PassRefPtr<SecurityOrigin> securityOrigin) 54 55 { 55 HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageArea Impl> >::AddResult result = m_storageAreaMap.add(securityOrigin.get(), 0);56 HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaMap> >::AddResult result = m_storageAreaMaps.add(securityOrigin.get(), 0); 56 57 if (result.isNewEntry) 57 result.iterator->value = StorageArea Impl::create(this, securityOrigin);58 result.iterator->value = StorageAreaMap::create(this, securityOrigin); 58 59 59 return result.iterator->value;60 return StorageAreaImpl::create(result.iterator->value); 60 61 } 61 62 -
trunk/Source/WebKit2/WebProcess/Storage/StorageNamespaceImpl.h
r148148 r148161 34 34 namespace WebKit { 35 35 36 class StorageArea Impl;36 class StorageAreaMap; 37 37 class WebPage; 38 38 … … 59 59 unsigned m_quotaInBytes; 60 60 61 HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageArea Impl> > m_storageAreaMap;61 HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaMap> > m_storageAreaMaps; 62 62 }; 63 63
Note: See TracChangeset
for help on using the changeset viewer.