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

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

Issue 214163004: Oilpan: Move database closing task in ~DatabaseBackendSync to a pre-finalization hook with HeapHash… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add a FIXME comment 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
« no previous file with comments | « Source/modules/webdatabase/DatabaseContext.h ('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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google, Inc. All Rights Reserved. 3 * Copyright (C) 2011 Google, 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 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 163 }
164 164
165 return m_databaseThread.get(); 165 return m_databaseThread.get();
166 } 166 }
167 167
168 void DatabaseContext::didOpenDatabase(DatabaseBackendBase& database) 168 void DatabaseContext::didOpenDatabase(DatabaseBackendBase& database)
169 { 169 {
170 if (!database.isSyncDatabase()) 170 if (!database.isSyncDatabase())
171 return; 171 return;
172 ASSERT(isContextThread()); 172 ASSERT(isContextThread());
173 #if ENABLE(OILPAN)
174 m_openSyncDatabases.add(&database, adoptPtr(new DatabaseCloser(database)));
175 #else
173 m_openSyncDatabases.add(&database); 176 m_openSyncDatabases.add(&database);
177 #endif
174 } 178 }
175 179
176 void DatabaseContext::didCloseDatabase(DatabaseBackendBase& database) 180 void DatabaseContext::didCloseDatabase(DatabaseBackendBase& database)
177 { 181 {
182 #if !ENABLE(OILPAN)
178 if (!database.isSyncDatabase()) 183 if (!database.isSyncDatabase())
179 return; 184 return;
180 ASSERT(isContextThread()); 185 ASSERT(isContextThread());
181 m_openSyncDatabases.remove(&database); 186 m_openSyncDatabases.remove(&database);
187 #endif
182 } 188 }
183 189
190 #if ENABLE(OILPAN)
191 DatabaseContext::DatabaseCloser::~DatabaseCloser()
192 {
193 m_database.closeImmediately();
194 }
195 #endif
196
184 void DatabaseContext::stopSyncDatabases() 197 void DatabaseContext::stopSyncDatabases()
185 { 198 {
186 // SQLite is "multi-thread safe", but each database handle can only be used 199 // SQLite is "multi-thread safe", but each database handle can only be used
187 // on a single thread at a time. 200 // on a single thread at a time.
188 // 201 //
189 // For DatabaseBackendSync, we open the SQLite database on the script 202 // For DatabaseBackendSync, we open the SQLite database on the script
190 // context thread. And hence we should also close it on that same 203 // context thread. And hence we should also close it on that same
191 // thread. This means that the SQLite database need to be closed here in the 204 // thread. This means that the SQLite database need to be closed here in the
192 // destructor. 205 // destructor.
193 ASSERT(isContextThread()); 206 ASSERT(isContextThread());
207 #if ENABLE(OILPAN)
208 // FIXME: We need to clear OwnPtr<> in the HeapHashMap explicitly.
209 // HeapHashMap::clear() doesn't destruct values
210 // immediately. crbug.com/357113.
211 for (PersistentHeapHashMap<WeakMember<DatabaseBackendBase>, OwnPtr<DatabaseC loser> >::iterator i = m_openSyncDatabases.begin(); i != m_openSyncDatabases.end (); ++i)
212 (*i).value.clear();
213 m_openSyncDatabases.clear();
214 #else
194 Vector<DatabaseBackendBase*> syncDatabases; 215 Vector<DatabaseBackendBase*> syncDatabases;
195 copyToVector(m_openSyncDatabases, syncDatabases); 216 copyToVector(m_openSyncDatabases, syncDatabases);
196 m_openSyncDatabases.clear(); 217 m_openSyncDatabases.clear();
197 for (size_t i = 0; i < syncDatabases.size(); ++i) 218 for (size_t i = 0; i < syncDatabases.size(); ++i)
198 syncDatabases[i]->closeImmediately(); 219 syncDatabases[i]->closeImmediately();
220 #endif
199 } 221 }
200 222
201 void DatabaseContext::stopDatabases() 223 void DatabaseContext::stopDatabases()
202 { 224 {
203 stopSyncDatabases(); 225 stopSyncDatabases();
204 226
205 // Though we initiate termination of the DatabaseThread here in 227 // Though we initiate termination of the DatabaseThread here in
206 // stopDatabases(), we can't clear the m_databaseThread ref till we get to 228 // stopDatabases(), we can't clear the m_databaseThread ref till we get to
207 // the destructor. This is because the Databases that are managed by 229 // the destructor. This is because the Databases that are managed by
208 // DatabaseThread still rely on this ref between the context and the thread 230 // DatabaseThread still rely on this ref between the context and the thread
(...skipping 24 matching lines...) Expand all
233 { 255 {
234 return executionContext()->securityOrigin(); 256 return executionContext()->securityOrigin();
235 } 257 }
236 258
237 bool DatabaseContext::isContextThread() const 259 bool DatabaseContext::isContextThread() const
238 { 260 {
239 return executionContext()->isContextThread(); 261 return executionContext()->isContextThread();
240 } 262 }
241 263
242 } // namespace WebCore 264 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/DatabaseContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698