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

Side by Side Diff: Source/modules/webdatabase/SQLTransactionCoordinator.cpp

Issue 198213005: Oilpan: Prepare to move AbstractSQLTransactionBackend, SQLTransactionBackend, and SQLTransactionCoo… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Back to inline allocation Created 6 years, 9 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 SQLTransactionCoordinator::SQLTransactionCoordinator() 47 SQLTransactionCoordinator::SQLTransactionCoordinator()
48 : m_isShuttingDown(false) 48 : m_isShuttingDown(false)
49 { 49 {
50 } 50 }
51 51
52 void SQLTransactionCoordinator::processPendingTransactions(CoordinationInfo& inf o) 52 void SQLTransactionCoordinator::processPendingTransactions(CoordinationInfo& inf o)
53 { 53 {
54 if (info.activeWriteTransaction || info.pendingTransactions.isEmpty()) 54 if (info.activeWriteTransaction || info.pendingTransactions.isEmpty())
55 return; 55 return;
56 56
57 RefPtr<SQLTransactionBackend> firstPendingTransaction = info.pendingTransact ions.first(); 57 RefPtrWillBeRawPtr<SQLTransactionBackend> firstPendingTransaction = info.pen dingTransactions.first();
58 if (firstPendingTransaction->isReadOnly()) { 58 if (firstPendingTransaction->isReadOnly()) {
59 do { 59 do {
60 firstPendingTransaction = info.pendingTransactions.takeFirst(); 60 firstPendingTransaction = info.pendingTransactions.takeFirst();
61 info.activeReadTransactions.add(firstPendingTransaction); 61 info.activeReadTransactions.add(firstPendingTransaction);
62 firstPendingTransaction->lockAcquired(); 62 firstPendingTransaction->lockAcquired();
63 } while (!info.pendingTransactions.isEmpty() && info.pendingTransactions .first()->isReadOnly()); 63 } while (!info.pendingTransactions.isEmpty() && info.pendingTransactions .first()->isReadOnly());
64 } else if (info.activeReadTransactions.isEmpty()) { 64 } else if (info.activeReadTransactions.isEmpty()) {
65 info.pendingTransactions.removeFirst(); 65 info.pendingTransactions.removeFirst();
66 info.activeWriteTransaction = firstPendingTransaction; 66 info.activeWriteTransaction = firstPendingTransaction;
67 firstPendingTransaction->lockAcquired(); 67 firstPendingTransaction->lockAcquired();
68 } 68 }
69 } 69 }
70 70
71 void SQLTransactionCoordinator::acquireLock(SQLTransactionBackend* transaction) 71 void SQLTransactionCoordinator::acquireLock(SQLTransactionBackend* transaction)
72 { 72 {
73 ASSERT(!m_isShuttingDown); 73 ASSERT(!m_isShuttingDown);
74 74
75 String dbIdentifier = getDatabaseIdentifier(transaction); 75 String dbIdentifier = getDatabaseIdentifier(transaction);
76 76
77 CoordinationInfoMap::iterator coordinationInfoIterator = m_coordinationInfoM ap.find(dbIdentifier); 77 CoordinationInfoHeapMap::iterator coordinationInfoIterator = m_coordinationI nfoMap.find(dbIdentifier);
78 if (coordinationInfoIterator == m_coordinationInfoMap.end()) { 78 if (coordinationInfoIterator == m_coordinationInfoMap.end()) {
79 // No pending transactions for this DB 79 // No pending transactions for this DB
80 CoordinationInfo& info = m_coordinationInfoMap.add(dbIdentifier, Coordin ationInfo()).storedValue->value; 80 CoordinationInfo& info = m_coordinationInfoMap.add(dbIdentifier, Coordin ationInfo()).storedValue->value;
81 info.pendingTransactions.append(transaction); 81 info.pendingTransactions.append(transaction);
82 processPendingTransactions(info); 82 processPendingTransactions(info);
83 } else { 83 } else {
84 CoordinationInfo& info = coordinationInfoIterator->value; 84 CoordinationInfo& info = coordinationInfoIterator->value;
85 info.pendingTransactions.append(transaction); 85 info.pendingTransactions.append(transaction);
86 processPendingTransactions(info); 86 processPendingTransactions(info);
87 } 87 }
88 88
89 } 89 }
90 90
91 void SQLTransactionCoordinator::releaseLock(SQLTransactionBackend* transaction) 91 void SQLTransactionCoordinator::releaseLock(SQLTransactionBackend* transaction)
92 { 92 {
93 if (m_isShuttingDown) 93 if (m_isShuttingDown)
94 return; 94 return;
95 95
96 String dbIdentifier = getDatabaseIdentifier(transaction); 96 String dbIdentifier = getDatabaseIdentifier(transaction);
97 97
98 CoordinationInfoMap::iterator coordinationInfoIterator = m_coordinationInfoM ap.find(dbIdentifier); 98 CoordinationInfoHeapMap::iterator coordinationInfoIterator = m_coordinationI nfoMap.find(dbIdentifier);
99 ASSERT_WITH_SECURITY_IMPLICATION(coordinationInfoIterator != m_coordinationI nfoMap.end()); 99 ASSERT_WITH_SECURITY_IMPLICATION(coordinationInfoIterator != m_coordinationI nfoMap.end());
100 CoordinationInfo& info = coordinationInfoIterator->value; 100 CoordinationInfo& info = coordinationInfoIterator->value;
101 101
102 if (transaction->isReadOnly()) { 102 if (transaction->isReadOnly()) {
103 ASSERT(info.activeReadTransactions.contains(transaction)); 103 ASSERT(info.activeReadTransactions.contains(transaction));
104 info.activeReadTransactions.remove(transaction); 104 info.activeReadTransactions.remove(transaction);
105 } else { 105 } else {
106 ASSERT(info.activeWriteTransaction == transaction); 106 ASSERT(info.activeWriteTransaction == transaction);
107 info.activeWriteTransaction = nullptr; 107 info.activeWriteTransaction = nullptr;
108 } 108 }
109 109
110 processPendingTransactions(info); 110 processPendingTransactions(info);
111 } 111 }
112 112
113 void SQLTransactionCoordinator::shutdown() 113 void SQLTransactionCoordinator::shutdown()
114 { 114 {
115 // Prevent releaseLock() from accessing / changing the coordinationInfo 115 // Prevent releaseLock() from accessing / changing the coordinationInfo
116 // while we're shutting down. 116 // while we're shutting down.
117 m_isShuttingDown = true; 117 m_isShuttingDown = true;
118 118
119 // Notify all transactions in progress that the database thread is shutting down 119 // Notify all transactions in progress that the database thread is shutting down
120 for (CoordinationInfoMap::iterator coordinationInfoIterator = m_coordination InfoMap.begin(); 120 for (CoordinationInfoHeapMap::iterator coordinationInfoIterator = m_coordina tionInfoMap.begin();
121 coordinationInfoIterator != m_coordinationInfoMap.end(); ++coordination InfoIterator) { 121 coordinationInfoIterator != m_coordinationInfoMap.end(); ++coordination InfoIterator) {
122 CoordinationInfo& info = coordinationInfoIterator->value; 122 CoordinationInfo& info = coordinationInfoIterator->value;
123 123
124 // Clean up transactions that have reached "lockAcquired": 124 // Clean up transactions that have reached "lockAcquired":
125 // Transaction phase 4 cleanup. See comment on "What happens if a 125 // Transaction phase 4 cleanup. See comment on "What happens if a
126 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. 126 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp.
127 if (info.activeWriteTransaction) 127 if (info.activeWriteTransaction)
128 info.activeWriteTransaction->notifyDatabaseThreadIsShuttingDown(); 128 info.activeWriteTransaction->notifyDatabaseThreadIsShuttingDown();
129 for (HashSet<RefPtr<SQLTransactionBackend> >::iterator activeReadTransac tionsIterator = 129 for (WillBeHeapHashSet<RefPtrWillBeMember<SQLTransactionBackend> >::iter ator activeReadTransactionsIterator =
130 info.activeReadTransactions.begin(); 130 info.activeReadTransactions.begin();
131 activeReadTransactionsIterator != info.activeReadTransactions.end() ; 131 activeReadTransactionsIterator != info.activeReadTransactions.end() ;
132 ++activeReadTransactionsIterator) { 132 ++activeReadTransactionsIterator) {
133 (*activeReadTransactionsIterator)->notifyDatabaseThreadIsShuttingDow n(); 133 (*activeReadTransactionsIterator)->notifyDatabaseThreadIsShuttingDow n();
134 } 134 }
135 135
136 // Clean up transactions that have NOT reached "lockAcquired": 136 // Clean up transactions that have NOT reached "lockAcquired":
137 // Transaction phase 3 cleanup. See comment on "What happens if a 137 // Transaction phase 3 cleanup. See comment on "What happens if a
138 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. 138 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp.
139 while (!info.pendingTransactions.isEmpty()) { 139 while (!info.pendingTransactions.isEmpty()) {
140 RefPtr<SQLTransactionBackend> transaction = info.pendingTransactions .first(); 140 RefPtrWillBeRawPtr<SQLTransactionBackend> transaction = info.pending Transactions.first();
141 transaction->notifyDatabaseThreadIsShuttingDown(); 141 transaction->notifyDatabaseThreadIsShuttingDown();
142 } 142 }
143 } 143 }
144 144
145 // Clean up all pending transactions for all databases 145 // Clean up all pending transactions for all databases
146 m_coordinationInfoMap.clear(); 146 m_coordinationInfoMap.clear();
147 } 147 }
148 148
149 } // namespace WebCore 149 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698