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

Side by Side Diff: Source/modules/indexeddb/IDBTransaction.cpp

Issue 23653024: IndexedDB: Have IDBCursor and IDBRequest explicitly break ref cycles (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 RefPtr<IDBRequest> request = *m_requestList.begin(); 215 RefPtr<IDBRequest> request = *m_requestList.begin();
216 m_requestList.remove(request); 216 m_requestList.remove(request);
217 request->abort(); 217 request->abort();
218 } 218 }
219 } 219 }
220 220
221 RefPtr<IDBTransaction> selfRef = this; 221 RefPtr<IDBTransaction> selfRef = this;
222 backendDB()->abort(m_id); 222 backendDB()->abort(m_id);
223 } 223 }
224 224
225 IDBTransaction::OpenCursorNotifier::OpenCursorNotifier(PassRefPtr<IDBTransaction > transaction, IDBCursor* cursor)
226 : m_transaction(transaction),
227 m_cursor(cursor)
228 {
229 m_transaction->registerOpenCursor(m_cursor);
230 }
231
232 IDBTransaction::OpenCursorNotifier::~OpenCursorNotifier()
233 {
234 if (m_cursor)
235 m_transaction->unregisterOpenCursor(m_cursor);
236 }
237
238 void IDBTransaction::OpenCursorNotifier::cursorFinished()
239 {
240 if (m_cursor) {
241 m_transaction->unregisterOpenCursor(m_cursor);
242 m_cursor = 0;
243 m_transaction.clear();
244 }
245 }
246
247 void IDBTransaction::registerOpenCursor(IDBCursor* cursor)
248 {
249 m_openCursors.add(cursor);
250 }
251
252 void IDBTransaction::unregisterOpenCursor(IDBCursor* cursor)
253 {
254 m_openCursors.remove(cursor);
255 }
256
257 void IDBTransaction::closeOpenCursors()
258 {
259 HashSet<IDBCursor*> cursors;
260 cursors.swap(m_openCursors);
261 for (HashSet<IDBCursor*>::iterator i = cursors.begin(); i != cursors.end(); ++i)
262 (*i)->close();
263 }
264
265 void IDBTransaction::registerRequest(IDBRequest* request) 225 void IDBTransaction::registerRequest(IDBRequest* request)
266 { 226 {
267 ASSERT(request); 227 ASSERT(request);
268 ASSERT(m_state == Active); 228 ASSERT(m_state == Active);
269 m_requestList.add(request); 229 m_requestList.add(request);
270 } 230 }
271 231
272 void IDBTransaction::unregisterRequest(IDBRequest* request) 232 void IDBTransaction::unregisterRequest(IDBRequest* request)
273 { 233 {
274 ASSERT(request); 234 ASSERT(request);
(...skipping 21 matching lines...) Expand all
296 m_state = Finishing; 256 m_state = Finishing;
297 } 257 }
298 258
299 if (isVersionChange()) { 259 if (isVersionChange()) {
300 for (IDBObjectStoreMetadataMap::iterator it = m_objectStoreCleanupMap.be gin(); it != m_objectStoreCleanupMap.end(); ++it) 260 for (IDBObjectStoreMetadataMap::iterator it = m_objectStoreCleanupMap.be gin(); it != m_objectStoreCleanupMap.end(); ++it)
301 it->key->setMetadata(it->value); 261 it->key->setMetadata(it->value);
302 m_database->setMetadata(m_previousMetadata); 262 m_database->setMetadata(m_previousMetadata);
303 m_database->close(); 263 m_database->close();
304 } 264 }
305 m_objectStoreCleanupMap.clear(); 265 m_objectStoreCleanupMap.clear();
306 closeOpenCursors();
307 266
308 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters. 267 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters.
309 enqueueEvent(Event::createBubble(eventNames().abortEvent)); 268 enqueueEvent(Event::createBubble(eventNames().abortEvent));
310 m_database->transactionFinished(this); 269 m_database->transactionFinished(this);
311 } 270 }
312 271
313 void IDBTransaction::onComplete() 272 void IDBTransaction::onComplete()
314 { 273 {
315 IDB_TRACE("IDBTransaction::onComplete"); 274 IDB_TRACE("IDBTransaction::onComplete");
316 ASSERT(m_state != Finished); 275 ASSERT(m_state != Finished);
317 m_state = Finishing; 276 m_state = Finishing;
318 m_objectStoreCleanupMap.clear(); 277 m_objectStoreCleanupMap.clear();
319 closeOpenCursors();
320 278
321 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters. 279 // Enqueue events before notifying database, as database may close which enq ueues more events and order matters.
322 enqueueEvent(Event::create(eventNames().completeEvent)); 280 enqueueEvent(Event::create(eventNames().completeEvent));
323 m_database->transactionFinished(this); 281 m_database->transactionFinished(this);
324 } 282 }
325 283
326 bool IDBTransaction::hasPendingActivity() const 284 bool IDBTransaction::hasPendingActivity() const
327 { 285 {
328 // FIXME: In an ideal world, we should return true as long as anyone has a o r can 286 // FIXME: In an ideal world, we should return true as long as anyone has a o r can
329 // get a handle to us or any child request object and any of those ha ve 287 // get a handle to us or any child request object and any of those ha ve
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 { 402 {
445 return &m_eventTargetData; 403 return &m_eventTargetData;
446 } 404 }
447 405
448 IDBDatabaseBackendInterface* IDBTransaction::backendDB() const 406 IDBDatabaseBackendInterface* IDBTransaction::backendDB() const
449 { 407 {
450 return db()->backend(); 408 return db()->backend();
451 } 409 }
452 410
453 } // namespace WebCore 411 } // namespace WebCore
OLDNEW
« Source/modules/indexeddb/IDBRequest.cpp ('K') | « Source/modules/indexeddb/IDBTransaction.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698