Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: Source/WebCore/storage/chromium/DatabaseTrackerChromium.cpp

Issue 9254017: Merge 103429 - Source/WebCore: [Chromium] DatabaseTrackerChromium: iterating DatabaseSet races wi... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/912/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebCore/storage/AbstractDatabase.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (!databaseSet) { 90 if (!databaseSet) {
91 databaseSet = new DatabaseSet(); 91 databaseSet = new DatabaseSet();
92 nameMap->set(name, databaseSet); 92 nameMap->set(name, databaseSet);
93 } 93 }
94 94
95 databaseSet->add(database); 95 databaseSet->add(database);
96 96
97 DatabaseObserver::databaseOpened(database); 97 DatabaseObserver::databaseOpened(database);
98 } 98 }
99 99
100 class TrackerRemoveOpenDatabaseTask : public ScriptExecutionContext::Task { 100 class NotifyDatabaseObserverOnCloseTask : public ScriptExecutionContext::Task {
101 public: 101 public:
102 static PassOwnPtr<TrackerRemoveOpenDatabaseTask> create(PassRefPtr<AbstractD atabase> database) 102 static PassOwnPtr<NotifyDatabaseObserverOnCloseTask> create(PassRefPtr<Abstr actDatabase> database)
103 { 103 {
104 return adoptPtr(new TrackerRemoveOpenDatabaseTask(database)); 104 return adoptPtr(new NotifyDatabaseObserverOnCloseTask(database));
105 } 105 }
106 106
107 virtual void performTask(ScriptExecutionContext* context) 107 virtual void performTask(ScriptExecutionContext* context)
108 { 108 {
109 DatabaseTracker::tracker().removeOpenDatabase(m_database.get()); 109 DatabaseObserver::databaseClosed(m_database.get());
110 }
111
112 virtual bool isCleanupTask() const
113 {
114 return true;
110 } 115 }
111 116
112 private: 117 private:
113 TrackerRemoveOpenDatabaseTask(PassRefPtr<AbstractDatabase> database) 118 NotifyDatabaseObserverOnCloseTask(PassRefPtr<AbstractDatabase> database)
114 : m_database(database) 119 : m_database(database)
115 { 120 {
116 } 121 }
117 122
118 RefPtr<AbstractDatabase> m_database; 123 RefPtr<AbstractDatabase> m_database;
119 }; 124 };
120 125
121 void DatabaseTracker::removeOpenDatabase(AbstractDatabase* database) 126 void DatabaseTracker::removeOpenDatabase(AbstractDatabase* database)
122 { 127 {
123 if (!database->scriptExecutionContext()->isContextThread()) {
124 database->scriptExecutionContext()->postTask(TrackerRemoveOpenDatabaseTa sk::create(database));
125 return;
126 }
127
128 String originIdentifier = database->securityOrigin()->databaseIdentifier(); 128 String originIdentifier = database->securityOrigin()->databaseIdentifier();
129 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 129 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
130 ASSERT(m_openDatabaseMap); 130 ASSERT(m_openDatabaseMap);
131 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); 131 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier);
132 if (!nameMap) 132 if (!nameMap)
133 return; 133 return;
134 134
135 String name(database->stringIdentifier()); 135 String name(database->stringIdentifier());
136 DatabaseSet* databaseSet = nameMap->get(name); 136 DatabaseSet* databaseSet = nameMap->get(name);
137 if (!databaseSet) 137 if (!databaseSet)
138 return; 138 return;
139 139
140 DatabaseSet::iterator found = databaseSet->find(database); 140 DatabaseSet::iterator found = databaseSet->find(database);
141 if (found == databaseSet->end()) 141 if (found == databaseSet->end())
142 return; 142 return;
143 143
144 databaseSet->remove(found); 144 databaseSet->remove(found);
145 if (databaseSet->isEmpty()) { 145 if (databaseSet->isEmpty()) {
146 nameMap->remove(name); 146 nameMap->remove(name);
147 delete databaseSet; 147 delete databaseSet;
148 if (nameMap->isEmpty()) { 148 if (nameMap->isEmpty()) {
149 m_openDatabaseMap->remove(originIdentifier); 149 m_openDatabaseMap->remove(originIdentifier);
150 delete nameMap; 150 delete nameMap;
151 } 151 }
152 } 152 }
153 153
154 DatabaseObserver::databaseClosed(database); 154 if (!database->scriptExecutionContext()->isContextThread())
155 database->scriptExecutionContext()->postTask(NotifyDatabaseObserverOnClo seTask::create(database));
156 else
157 DatabaseObserver::databaseClosed(database);
155 } 158 }
156 159
157 void DatabaseTracker::getOpenDatabases(SecurityOrigin* origin, const String& nam e, HashSet<RefPtr<AbstractDatabase> >* databases) 160 void DatabaseTracker::getOpenDatabases(SecurityOrigin* origin, const String& nam e, HashSet<RefPtr<AbstractDatabase> >* databases)
158 { 161 {
159 getOpenDatabases(origin->databaseIdentifier(), name, databases); 162 getOpenDatabases(origin->databaseIdentifier(), name, databases);
160 } 163 }
161 164
162 void DatabaseTracker::getOpenDatabases(const String& originIdentifier, const Str ing& name, HashSet<RefPtr<AbstractDatabase> >* databases) 165 void DatabaseTracker::getOpenDatabases(const String& originIdentifier, const Str ing& name, HashSet<RefPtr<AbstractDatabase> >* databases)
163 { 166 {
164 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); 167 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 for (DatabaseSet::const_iterator it = databaseSet->begin(); it != end; + +it) { 208 for (DatabaseSet::const_iterator it = databaseSet->begin(); it != end; + +it) {
206 if ((*it)->scriptExecutionContext() == context) 209 if ((*it)->scriptExecutionContext() == context)
207 (*it)->interrupt(); 210 (*it)->interrupt();
208 } 211 }
209 } 212 }
210 } 213 }
211 214
212 } 215 }
213 216
214 #endif // ENABLE(SQL_DATABASE) 217 #endif // ENABLE(SQL_DATABASE)
OLDNEW
« no previous file with comments | « Source/WebCore/storage/AbstractDatabase.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698