Changeset 149631 in webkit
- Timestamp:
- May 6, 2013, 1:13:08 PM (12 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r149620 r149631 1 2013-05-06 Anders Carlsson <andersca@apple.com> 2 3 Handle closing the local storage database 4 https://bugs.webkit.org/show_bug.cgi?id=115669 5 6 Reviewed by Beth Dakin. 7 8 * UIProcess/Storage/LocalStorageDatabase.cpp: 9 (WebKit::LocalStorageDatabase::LocalStorageDatabase): 10 Initialize m_isClosed. 11 12 (WebKit::LocalStorageDatabase::~LocalStorageDatabase): 13 Assert that m_isClosed is false. 14 15 (WebKit::LocalStorageDatabase::close): 16 Set m_isClosed to true and write any pending changes to disk. 17 18 (WebKit::LocalStorageDatabase::updateDatabase): 19 Compute the changed items and pass them to updateDatabaseWithChangedItems. 20 21 (WebKit::LocalStorageDatabase::updateDatabaseWithChangedItems): 22 Split out the code that actually writes to the database from updateDatabase and into this function. 23 24 * UIProcess/Storage/LocalStorageDatabase.h: 25 * UIProcess/Storage/StorageManager.cpp: 26 (WebKit::StorageManager::StorageArea::~StorageArea): 27 Call close(). 28 1 29 2013-05-06 Zan Dobersek <zdobersek@igalia.com> 2 30 -
trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp
r149618 r149631 54 54 , m_failedToOpenDatabase(false) 55 55 , m_didImportItems(false) 56 , m_isClosed(false) 56 57 , m_didScheduleDatabaseUpdate(false) 57 58 , m_shouldClearItems(false) … … 61 62 LocalStorageDatabase::~LocalStorageDatabase() 62 63 { 64 ASSERT(m_isClosed); 63 65 } 64 66 … … 204 206 } 205 207 208 void LocalStorageDatabase::close() 209 { 210 ASSERT(!m_isClosed); 211 m_isClosed = true; 212 213 if (m_didScheduleDatabaseUpdate) { 214 updateDatabaseWithChangedItems(m_changedItems); 215 m_changedItems.clear(); 216 } 217 218 // FIXME: Delete the database if it's empty. 219 } 220 206 221 void LocalStorageDatabase::itemDidChange(const String& key, const String& value) 207 222 { … … 221 236 void LocalStorageDatabase::updateDatabase() 222 237 { 238 if (m_isClosed) 239 return; 240 223 241 ASSERT(m_didScheduleDatabaseUpdate); 224 225 242 m_didScheduleDatabaseUpdate = false; 226 243 244 HashMap<String, String> changedItems; 245 if (m_changedItems.size() <= maximumItemsToUpdate) { 246 // There are few enough changed items that we can just always write all of them. 247 m_changedItems.swap(changedItems); 248 } else { 249 for (int i = 0; i < maximumItemsToUpdate; ++i) { 250 auto it = m_changedItems.begin(); 251 changedItems.add(it->key, it->value); 252 253 m_changedItems.remove(it); 254 } 255 256 ASSERT(changedItems.size() <= maximumItemsToUpdate); 257 258 // Reschedule the update for the remaining items. 259 scheduleDatabaseUpdate(); 260 } 261 262 updateDatabaseWithChangedItems(changedItems); 263 } 264 265 void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems) 266 { 227 267 if (m_shouldClearItems) { 228 268 m_shouldClearItems = false; … … 241 281 } 242 282 243 HashMap<String, String> changedItems;244 if (m_changedItems.size() > maximumItemsToUpdate) {245 for (int i = 0; i < maximumItemsToUpdate; ++i) {246 auto it = m_changedItems.begin();247 changedItems.add(it->key, it->value);248 249 m_changedItems.remove(it);250 }251 252 // Reschedule the update for the remaining items.253 scheduleDatabaseUpdate();254 } else {255 // There are few enough changed items that we can just always write all of them.256 m_changedItems.swap(changedItems);257 }258 259 ASSERT(changedItems.size() <= maximumItemsToUpdate);260 261 283 SQLiteStatement insertStatement(m_database, "INSERT INTO ItemTable VALUES (?, ?)"); 262 284 if (insertStatement.prepare() != SQLResultOk) { -
trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h
r149618 r149631 53 53 void clear(); 54 54 55 // Will block until all pending changes have been written to disk. 56 void close(); 57 55 58 private: 56 59 LocalStorageDatabase(const String& databaseFilename, PassRefPtr<WorkQueue>); … … 69 72 void scheduleDatabaseUpdate(); 70 73 void updateDatabase(); 74 void updateDatabaseWithChangedItems(const HashMap<String, String>&); 71 75 72 76 String m_databaseFilename; … … 76 80 bool m_failedToOpenDatabase; 77 81 bool m_didImportItems; 82 bool m_isClosed; 78 83 79 84 bool m_didScheduleDatabaseUpdate; -
trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp
r149618 r149631 118 118 ASSERT(m_eventListeners.isEmpty()); 119 119 120 if (m_localStorageDatabase) 121 m_localStorageDatabase->close(); 122 120 123 if (m_localStorageNamespace) 121 124 m_localStorageNamespace->didDestroyStorageArea(this);
Note:
See TracChangeset
for help on using the changeset viewer.