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

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/Database.cpp

Issue 1694893002: Avoid data race on Database::m_opened. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: avoid casts Created 4 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/modules/webdatabase/Database.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) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "modules/webdatabase/SQLTransactionClient.h" 46 #include "modules/webdatabase/SQLTransactionClient.h"
47 #include "modules/webdatabase/SQLTransactionCoordinator.h" 47 #include "modules/webdatabase/SQLTransactionCoordinator.h"
48 #include "modules/webdatabase/SQLTransactionErrorCallback.h" 48 #include "modules/webdatabase/SQLTransactionErrorCallback.h"
49 #include "modules/webdatabase/sqlite/SQLiteStatement.h" 49 #include "modules/webdatabase/sqlite/SQLiteStatement.h"
50 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" 50 #include "modules/webdatabase/sqlite/SQLiteTransaction.h"
51 #include "platform/Logging.h" 51 #include "platform/Logging.h"
52 #include "platform/heap/SafePoint.h" 52 #include "platform/heap/SafePoint.h"
53 #include "platform/weborigin/DatabaseIdentifier.h" 53 #include "platform/weborigin/DatabaseIdentifier.h"
54 #include "public/platform/Platform.h" 54 #include "public/platform/Platform.h"
55 #include "public/platform/WebDatabaseObserver.h" 55 #include "public/platform/WebDatabaseObserver.h"
56 #include "wtf/Atomics.h"
56 57
57 // Registering "opened" databases with the DatabaseTracker 58 // Registering "opened" databases with the DatabaseTracker
58 // ======================================================= 59 // =======================================================
59 // The DatabaseTracker maintains a list of databases that have been 60 // The DatabaseTracker maintains a list of databases that have been
60 // "opened" so that the client can call interrupt or delete on every database 61 // "opened" so that the client can call interrupt or delete on every database
61 // associated with a DatabaseContext. 62 // associated with a DatabaseContext.
62 // 63 //
63 // We will only call DatabaseTracker::addOpenDatabase() to add the database 64 // We will only call DatabaseTracker::addOpenDatabase() to add the database
64 // to the tracker as opened when we've succeeded in opening the database, 65 // to the tracker as opened when we've succeeded in opening the database,
65 // and will set m_opened to true. Similarly, we only call 66 // and will set m_opened to true. Similarly, we only call
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return guid; 202 return guid;
202 } 203 }
203 204
204 Database::Database(DatabaseContext* databaseContext, const String& name, const S tring& expectedVersion, const String& displayName, unsigned long estimatedSize) 205 Database::Database(DatabaseContext* databaseContext, const String& name, const S tring& expectedVersion, const String& displayName, unsigned long estimatedSize)
205 : m_databaseContext(databaseContext) 206 : m_databaseContext(databaseContext)
206 , m_name(name.isolatedCopy()) 207 , m_name(name.isolatedCopy())
207 , m_expectedVersion(expectedVersion.isolatedCopy()) 208 , m_expectedVersion(expectedVersion.isolatedCopy())
208 , m_displayName(displayName.isolatedCopy()) 209 , m_displayName(displayName.isolatedCopy())
209 , m_estimatedSize(estimatedSize) 210 , m_estimatedSize(estimatedSize)
210 , m_guid(0) 211 , m_guid(0)
211 , m_opened(false) 212 , m_opened(0)
212 , m_new(false) 213 , m_new(false)
213 , m_transactionInProgress(false) 214 , m_transactionInProgress(false)
214 , m_isTransactionQueueEnabled(true) 215 , m_isTransactionQueueEnabled(true)
215 { 216 {
216 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate dCopy(); 217 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate dCopy();
217 218
218 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); 219 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName);
219 220
220 if (m_name.isNull()) 221 if (m_name.isNull())
221 m_name = ""; 222 m_name = "";
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 const char* Database::databaseInfoTableName() 363 const char* Database::databaseInfoTableName()
363 { 364 {
364 return infoTableName; 365 return infoTableName;
365 } 366 }
366 367
367 void Database::closeDatabase() 368 void Database::closeDatabase()
368 { 369 {
369 if (!m_opened) 370 if (!m_opened)
370 return; 371 return;
371 372
373 releaseStore(&m_opened, 0);
372 m_sqliteDatabase.close(); 374 m_sqliteDatabase.close();
373 m_opened = false;
374 // See comment at the top this file regarding calling removeOpenDatabase(). 375 // See comment at the top this file regarding calling removeOpenDatabase().
375 DatabaseTracker::tracker().removeOpenDatabase(this); 376 DatabaseTracker::tracker().removeOpenDatabase(this);
376 { 377 {
377 SafePointAwareMutexLocker locker(guidMutex()); 378 SafePointAwareMutexLocker locker(guidMutex());
378 379
379 ASSERT(guidCount().contains(m_guid)); 380 ASSERT(guidCount().contains(m_guid));
380 if (guidCount().remove(m_guid)) { 381 if (guidCount().remove(m_guid)) {
381 guidToVersionMap().remove(m_guid); 382 guidToVersionMap().remove(m_guid);
382 } 383 }
383 } 384 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 errorMessage = "unable to open database, version mismatch, '" + m_expect edVersion + "' does not match the currentVersion of '" + currentVersion + "'"; 524 errorMessage = "unable to open database, version mismatch, '" + m_expect edVersion + "' does not match the currentVersion of '" + currentVersion + "'";
524 m_sqliteDatabase.close(); 525 m_sqliteDatabase.close();
525 return false; 526 return false;
526 } 527 }
527 528
528 ASSERT(m_databaseAuthorizer); 529 ASSERT(m_databaseAuthorizer);
529 m_sqliteDatabase.setAuthorizer(m_databaseAuthorizer.get()); 530 m_sqliteDatabase.setAuthorizer(m_databaseAuthorizer.get());
530 531
531 // See comment at the top this file regarding calling addOpenDatabase(). 532 // See comment at the top this file regarding calling addOpenDatabase().
532 DatabaseTracker::tracker().addOpenDatabase(this); 533 DatabaseTracker::tracker().addOpenDatabase(this);
533 m_opened = true; 534 m_opened = 1;
534 535
535 // Declare success: 536 // Declare success:
536 error = DatabaseError::None; // Clear the presumed error from above. 537 error = DatabaseError::None; // Clear the presumed error from above.
537 onExitCaller.setOpenSucceeded(); 538 onExitCaller.setOpenSucceeded();
538 539
539 if (m_new && !shouldSetVersionInNewDatabase) { 540 if (m_new && !shouldSetVersionInNewDatabase) {
540 // The caller provided a creationCallback which will set the expected 541 // The caller provided a creationCallback which will set the expected
541 // version. 542 // version.
542 m_expectedVersion = ""; 543 m_expectedVersion = "";
543 } 544 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 895
895 SecurityOrigin* Database::securityOrigin() const 896 SecurityOrigin* Database::securityOrigin() const
896 { 897 {
897 if (executionContext()->isContextThread()) 898 if (executionContext()->isContextThread())
898 return m_contextThreadSecurityOrigin.get(); 899 return m_contextThreadSecurityOrigin.get();
899 if (databaseContext()->databaseThread()->isDatabaseThread()) 900 if (databaseContext()->databaseThread()->isDatabaseThread())
900 return m_databaseThreadSecurityOrigin.get(); 901 return m_databaseThreadSecurityOrigin.get();
901 return 0; 902 return 0;
902 } 903 }
903 904
905 bool Database::opened()
906 {
907 return static_cast<bool>(acquireLoad(&m_opened));
908 }
909
904 } // namespace blink 910 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webdatabase/Database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698