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

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

Issue 593423002: Revert of DatabaseBackend should not post a task to an already terminated database thread (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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
« no previous file with comments | « Source/modules/webdatabase/DatabaseContext.h ('k') | Source/modules/webdatabase/DatabaseTask.h » ('j') | 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 // Create the database thread on first request - but not if at least one database was already opened, 159 // Create the database thread on first request - but not if at least one database was already opened,
160 // because in that case we already had a database thread and terminated it and should not create another. 160 // because in that case we already had a database thread and terminated it and should not create another.
161 m_databaseThread = DatabaseThread::create(); 161 m_databaseThread = DatabaseThread::create();
162 m_databaseThread->start(); 162 m_databaseThread->start();
163 } 163 }
164 164
165 return m_databaseThread.get(); 165 return m_databaseThread.get();
166 } 166 }
167 167
168 bool DatabaseContext::databaseThreadAvailable()
169 {
170 return m_databaseThread && !m_hasRequestedTermination;
171 }
172
173 void DatabaseContext::stopDatabases() 168 void DatabaseContext::stopDatabases()
174 { 169 {
175 // Though we initiate termination of the DatabaseThread here in 170 // Though we initiate termination of the DatabaseThread here in
176 // stopDatabases(), we can't clear the m_databaseThread ref till we get to 171 // stopDatabases(), we can't clear the m_databaseThread ref till we get to
177 // the destructor. This is because the Databases that are managed by 172 // the destructor. This is because the Databases that are managed by
178 // DatabaseThread still rely on this ref between the context and the thread 173 // DatabaseThread still rely on this ref between the context and the thread
179 // to execute the task for closing the database. By the time we get to the 174 // to execute the task for closing the database. By the time we get to the
180 // destructor, we're guaranteed that the databases are destructed (which is 175 // destructor, we're guaranteed that the databases are destructed (which is
181 // why our ref count is 0 then and we're destructing). Then, the 176 // why our ref count is 0 then and we're destructing). Then, the
182 // m_databaseThread RefPtr destructor will deref and delete the 177 // m_databaseThread RefPtr destructor will deref and delete the
183 // DatabaseThread. 178 // DatabaseThread.
184 179
185 if (databaseThreadAvailable()) { 180 if (m_databaseThread && !m_hasRequestedTermination) {
186 TaskSynchronizer sync; 181 TaskSynchronizer sync;
187 m_databaseThread->requestTermination(&sync); 182 m_databaseThread->requestTermination(&sync);
188 m_hasRequestedTermination = true; 183 m_hasRequestedTermination = true;
189 sync.waitForTaskCompletion(); 184 sync.waitForTaskCompletion();
190 } 185 }
191 } 186 }
192 187
193 bool DatabaseContext::allowDatabaseAccess() const 188 bool DatabaseContext::allowDatabaseAccess() const
194 { 189 {
195 return toDocument(executionContext())->isActive(); 190 return toDocument(executionContext())->isActive();
196 } 191 }
197 192
198 SecurityOrigin* DatabaseContext::securityOrigin() const 193 SecurityOrigin* DatabaseContext::securityOrigin() const
199 { 194 {
200 return executionContext()->securityOrigin(); 195 return executionContext()->securityOrigin();
201 } 196 }
202 197
203 bool DatabaseContext::isContextThread() const 198 bool DatabaseContext::isContextThread() const
204 { 199 {
205 return executionContext()->isContextThread(); 200 return executionContext()->isContextThread();
206 } 201 }
207 202
208 } // namespace blink 203 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/DatabaseContext.h ('k') | Source/modules/webdatabase/DatabaseTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698