OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 #include "modules/webdatabase/Database.h" | 36 #include "modules/webdatabase/Database.h" |
37 #include "modules/webdatabase/DatabaseClient.h" | 37 #include "modules/webdatabase/DatabaseClient.h" |
38 #include "modules/webdatabase/DatabaseContext.h" | 38 #include "modules/webdatabase/DatabaseContext.h" |
39 #include "modules/webdatabase/QuotaTracker.h" | 39 #include "modules/webdatabase/QuotaTracker.h" |
40 #include "modules/webdatabase/sqlite/SQLiteFileSystem.h" | 40 #include "modules/webdatabase/sqlite/SQLiteFileSystem.h" |
41 #include "platform/weborigin/DatabaseIdentifier.h" | 41 #include "platform/weborigin/DatabaseIdentifier.h" |
42 #include "platform/weborigin/SecurityOrigin.h" | 42 #include "platform/weborigin/SecurityOrigin.h" |
43 #include "platform/weborigin/SecurityOriginHash.h" | 43 #include "platform/weborigin/SecurityOriginHash.h" |
44 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
45 #include "public/platform/WebDatabaseObserver.h" | 45 #include "public/platform/WebDatabaseObserver.h" |
46 #include "public/platform/WebTraceLocation.h" | |
47 #include "wtf/Assertions.h" | 46 #include "wtf/Assertions.h" |
48 #include "wtf/StdLibExtras.h" | 47 #include "wtf/StdLibExtras.h" |
49 | 48 |
50 namespace blink { | 49 namespace blink { |
51 | 50 |
52 static void databaseClosed(Database* database) | 51 static void databaseClosed(Database* database) |
53 { | 52 { |
54 if (Platform::current()->databaseObserver()) { | 53 if (Platform::current()->databaseObserver()) { |
55 Platform::current()->databaseObserver()->databaseClosed( | 54 Platform::current()->databaseObserver()->databaseClosed( |
56 createDatabaseIdentifierFromSecurityOrigin(database->securityOrigin(
)), | 55 createDatabaseIdentifierFromSecurityOrigin(database->securityOrigin(
)), |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 nameMap->remove(name); | 154 nameMap->remove(name); |
156 delete databaseSet; | 155 delete databaseSet; |
157 if (nameMap->isEmpty()) { | 156 if (nameMap->isEmpty()) { |
158 m_openDatabaseMap->remove(originIdentifier); | 157 m_openDatabaseMap->remove(originIdentifier); |
159 delete nameMap; | 158 delete nameMap; |
160 } | 159 } |
161 } | 160 } |
162 | 161 |
163 ExecutionContext* executionContext = database->databaseContext()->executionC
ontext(); | 162 ExecutionContext* executionContext = database->databaseContext()->executionC
ontext(); |
164 if (!executionContext->isContextThread()) | 163 if (!executionContext->isContextThread()) |
165 executionContext->postTask(FROM_HERE, NotifyDatabaseObserverOnCloseTask:
:create(database)); | 164 executionContext->postTask(NotifyDatabaseObserverOnCloseTask::create(dat
abase)); |
166 else | 165 else |
167 databaseClosed(database); | 166 databaseClosed(database); |
168 } | 167 } |
169 | 168 |
170 void DatabaseTracker::prepareToOpenDatabase(Database* database) | 169 void DatabaseTracker::prepareToOpenDatabase(Database* database) |
171 { | 170 { |
172 ASSERT(database->databaseContext()->executionContext()->isContextThread()); | 171 ASSERT(database->databaseContext()->executionContext()->isContextThread()); |
173 if (Platform::current()->databaseObserver()) { | 172 if (Platform::current()->databaseObserver()) { |
174 Platform::current()->databaseObserver()->databaseOpened( | 173 Platform::current()->databaseObserver()->databaseOpened( |
175 createDatabaseIdentifierFromSecurityOrigin(database->securityOrigin(
)), | 174 createDatabaseIdentifierFromSecurityOrigin(database->securityOrigin(
)), |
176 database->stringIdentifier(), | 175 database->stringIdentifier(), |
177 database->displayName(), | 176 database->displayName(), |
178 database->estimatedSize()); | 177 database->estimatedSize()); |
179 } | 178 } |
180 } | 179 } |
181 | 180 |
182 void DatabaseTracker::failedToOpenDatabase(Database* database) | 181 void DatabaseTracker::failedToOpenDatabase(Database* database) |
183 { | 182 { |
184 ExecutionContext* executionContext = database->databaseContext()->executionC
ontext(); | 183 ExecutionContext* executionContext = database->databaseContext()->executionC
ontext(); |
185 if (!executionContext->isContextThread()) | 184 if (!executionContext->isContextThread()) |
186 executionContext->postTask(FROM_HERE, NotifyDatabaseObserverOnCloseTask:
:create(database)); | 185 executionContext->postTask(NotifyDatabaseObserverOnCloseTask::create(dat
abase)); |
187 else | 186 else |
188 databaseClosed(database); | 187 databaseClosed(database); |
189 } | 188 } |
190 | 189 |
191 unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* databa
se) | 190 unsigned long long DatabaseTracker::getMaxSizeForDatabase(const Database* databa
se) |
192 { | 191 { |
193 unsigned long long spaceAvailable = 0; | 192 unsigned long long spaceAvailable = 0; |
194 unsigned long long databaseSize = 0; | 193 unsigned long long databaseSize = 0; |
195 QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin( | 194 QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin( |
196 createDatabaseIdentifierFromSecurityOrigin(database->securityOrigin()), | 195 createDatabaseIdentifierFromSecurityOrigin(database->securityOrigin()), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); | 231 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); |
233 if (!nameMap) | 232 if (!nameMap) |
234 return; | 233 return; |
235 | 234 |
236 DatabaseSet* databaseSet = nameMap->get(name); | 235 DatabaseSet* databaseSet = nameMap->get(name); |
237 if (!databaseSet) | 236 if (!databaseSet) |
238 return; | 237 return; |
239 | 238 |
240 // We have to call closeImmediately() on the context thread. | 239 // We have to call closeImmediately() on the context thread. |
241 for (DatabaseSet::iterator it = databaseSet->begin(); it != databaseSet->end
(); ++it) | 240 for (DatabaseSet::iterator it = databaseSet->begin(); it != databaseSet->end
(); ++it) |
242 (*it)->databaseContext()->executionContext()->postTask(FROM_HERE, CloseO
neDatabaseImmediatelyTask::create(originIdentifier, name, *it)); | 241 (*it)->databaseContext()->executionContext()->postTask(CloseOneDatabaseI
mmediatelyTask::create(originIdentifier, name, *it)); |
243 } | 242 } |
244 | 243 |
245 void DatabaseTracker::closeOneDatabaseImmediately(const String& originIdentifier
, const String& name, Database* database) | 244 void DatabaseTracker::closeOneDatabaseImmediately(const String& originIdentifier
, const String& name, Database* database) |
246 { | 245 { |
247 // First we have to confirm the 'database' is still in our collection. | 246 // First we have to confirm the 'database' is still in our collection. |
248 { | 247 { |
249 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); | 248 MutexLocker openDatabaseMapLock(m_openDatabaseMapGuard); |
250 if (!m_openDatabaseMap) | 249 if (!m_openDatabaseMap) |
251 return; | 250 return; |
252 | 251 |
253 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); | 252 DatabaseNameMap* nameMap = m_openDatabaseMap->get(originIdentifier); |
254 if (!nameMap) | 253 if (!nameMap) |
255 return; | 254 return; |
256 | 255 |
257 DatabaseSet* databaseSet = nameMap->get(name); | 256 DatabaseSet* databaseSet = nameMap->get(name); |
258 if (!databaseSet) | 257 if (!databaseSet) |
259 return; | 258 return; |
260 | 259 |
261 DatabaseSet::iterator found = databaseSet->find(database); | 260 DatabaseSet::iterator found = databaseSet->find(database); |
262 if (found == databaseSet->end()) | 261 if (found == databaseSet->end()) |
263 return; | 262 return; |
264 } | 263 } |
265 | 264 |
266 // And we have to call closeImmediately() without our collection lock being
held. | 265 // And we have to call closeImmediately() without our collection lock being
held. |
267 database->closeImmediately(); | 266 database->closeImmediately(); |
268 } | 267 } |
269 | 268 |
270 } // namespace blink | 269 } // namespace blink |
OLD | NEW |