Bug 39041

Summary: Move the code that should be shared by sync and async DBs to a separate class
Product: WebKit Reporter: Dumitru Daniliuc <dumi>
Component: New BugsAssignee: Dumitru Daniliuc <dumi>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, beidson, dglazkov, ericu, eric, michaeln, webkit-ews, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 34990    
Attachments:
Description Flags
patch #1: Add a base class for Database and DatabaseSync
abarth: review+, dumi: commit-queue-
patch #2: clean up
abarth: review+, dumi: commit-queue-
patch #3: Move the reusable code from Database to AbstractDatabase
dumi: commit-queue-
patch #3: Move the reusable code from Database to AbstractDatabase
dumi: commit-queue-
patch #3: Move the reusable code from Database to AbstractDatabase
dumi: commit-queue-
patch #3: Get DatabaseTracker ready for sync DBs
dumi: commit-queue-
patch #3: Get DatabaseTracker ready for sync DBs
abarth: review+, dumi: commit-queue-
patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag
dumi: commit-queue-
patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag
dumi: commit-queue-
patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag abarth: review+, dumi: commit-queue-

Dumitru Daniliuc
Reported 2010-05-12 20:41:49 PDT
Some code in Database.cpp can be reused by DatabaseSync.cpp. We should move it to a common parent class. A parent class is probably better than a member variable, because then DatabaseTracker could handle both types of DBs in the same way.
Attachments
patch #1: Add a base class for Database and DatabaseSync (11.26 KB, patch)
2010-05-12 21:20 PDT, Dumitru Daniliuc
abarth: review+
dumi: commit-queue-
patch #2: clean up (24.42 KB, patch)
2010-05-13 16:26 PDT, Dumitru Daniliuc
abarth: review+
dumi: commit-queue-
patch #3: Move the reusable code from Database to AbstractDatabase (74.06 KB, patch)
2010-06-02 04:23 PDT, Dumitru Daniliuc
dumi: commit-queue-
patch #3: Move the reusable code from Database to AbstractDatabase (74.03 KB, patch)
2010-06-02 04:31 PDT, Dumitru Daniliuc
dumi: commit-queue-
patch #3: Move the reusable code from Database to AbstractDatabase (82.02 KB, patch)
2010-06-02 16:05 PDT, Dumitru Daniliuc
dumi: commit-queue-
patch #3: Get DatabaseTracker ready for sync DBs (20.87 KB, patch)
2010-06-10 19:44 PDT, Dumitru Daniliuc
dumi: commit-queue-
patch #3: Get DatabaseTracker ready for sync DBs (21.10 KB, patch)
2010-06-10 19:59 PDT, Dumitru Daniliuc
abarth: review+
dumi: commit-queue-
patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag (19.27 KB, patch)
2010-06-15 04:11 PDT, Dumitru Daniliuc
dumi: commit-queue-
patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag (19.69 KB, patch)
2010-06-15 04:28 PDT, Dumitru Daniliuc
dumi: commit-queue-
patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag (20.68 KB, patch)
2010-06-15 04:38 PDT, Dumitru Daniliuc
abarth: review+
dumi: commit-queue-
Dumitru Daniliuc
Comment 1 2010-05-12 21:20:12 PDT
Created attachment 55936 [details] patch #1: Add a base class for Database and DatabaseSync
Adam Barth
Comment 2 2010-05-12 22:22:56 PDT
Comment on attachment 55936 [details] patch #1: Add a base class for Database and DatabaseSync Ok. I think you're over reacting to bradee-oh, but whatever.
Dumitru Daniliuc
Comment 3 2010-05-12 23:49:41 PDT
patch #1 landed as r59349.
Brady Eidson
Comment 4 2010-05-13 09:39:28 PDT
(In reply to comment #2) > (From update of attachment 55936 [details]) > Ok. I think you're over reacting to bradee-oh, but whatever. Lol.
Dumitru Daniliuc
Comment 5 2010-05-13 16:26:02 PDT
Created attachment 56032 [details] patch #2: clean up Cleaning up the DB classes to make it easier to move code out of them into new classes: removing unused #includes, replacing #includes in header files with forward class declarations as much as possible, removing 'friend' declarations, and adding getters for private fields where necessary.
WebKit Review Bot
Comment 6 2010-05-13 16:28:35 PDT
Attachment 56032 [details] did not pass style-queue: Failed to run "['WebKitTools/Scripts/check-webkit-style', '--no-squash']" exit_code: 1 WebCore/storage/Database.cpp:50: Alphabetical sorting problem. [build/include_order] [4] Total errors found: 1 in 11 files If any of these errors are false positives, please file a bug against check-webkit-style.
Adam Barth
Comment 7 2010-05-13 17:00:33 PDT
Comment on attachment 56032 [details] patch #2: clean up Looks reasonable overall. I need to look at it more carefully later.
Dumitru Daniliuc
Comment 8 2010-05-13 17:07:06 PDT
> WebCore/storage/Database.cpp:50: Alphabetical sorting problem. [build/include_order] [4] Will take care of this when landing/re-uploading.
Dumitru Daniliuc
Comment 9 2010-05-25 13:33:54 PDT
Ping.
Adam Barth
Comment 10 2010-06-01 11:47:38 PDT
Comment on attachment 56032 [details] patch #2: clean up Looks great! Nice work. WebCore/storage/Database.h:55 + class SecurityOrigin; I don't think we need the NDEBUG conditional here. It's not a terrible thing to forward declare this class. WebCore/storage/DatabaseTask.cpp:  + MutexLocker locker(m_transaction->database()->m_transactionInProgressMutex); Not 100% sure why we lost this mutex here, but ok. WebCore/storage/Database.cpp:660 + MutexLocker locker(m_transactionInProgressMutex); Oh, I see. It went here.
Dumitru Daniliuc
Comment 11 2010-06-01 12:56:15 PDT
> WebCore/storage/Database.h:55 > + class SecurityOrigin; > I don't think we need the NDEBUG conditional here. It's not a terrible thing to forward declare this class. done. > WebCore/storage/DatabaseTask.cpp:  > + MutexLocker locker(m_transaction->database()->m_transactionInProgressMutex); > Not 100% sure why we lost this mutex here, but ok. > > WebCore/storage/Database.cpp:660 > + MutexLocker locker(m_transactionInProgressMutex); > Oh, I see. It went here. i made this change to keep m_transactionInProgressMutex private to the Database class.
Dumitru Daniliuc
Comment 12 2010-06-01 14:40:59 PDT
patch #2 landed as r60508.
Dumitru Daniliuc
Comment 13 2010-06-02 04:23:23 PDT
Created attachment 57643 [details] patch #3: Move the reusable code from Database to AbstractDatabase patch #3 has mostly mechanical changes, with a couple of exceptions: 1. guidToDatabaseMap() was removed from Database.cpp; it wasn't used by anybody. 2. Database::close() was changed to be callable from any thread by moving the logic from WebKit/chromium/src/WebDatabase.cpp there. All storage/ and fast/workers/storage/ layout tests passed.
WebKit Review Bot
Comment 14 2010-06-02 04:27:29 PDT
Attachment 57643 [details] did not pass style-queue: Failed to run "['WebKitTools/Scripts/check-webkit-style', '--no-squash']" exit_code: 1 WARNING: File exempt from style guide. Skipping: "WebKit/qt/Api/qwebsettings.cpp" WebCore/storage/AbstractDatabase.cpp:41: Alphabetical sorting problem. [build/include_order] [4] WebCore/storage/AbstractDatabase.cpp:122: An else if statement should be written as an if statement when the prior "if" concludes with a return, break, continue or goto statement. [readability/control_flow] [4] WebCore/storage/AbstractDatabase.h:36: Alphabetical sorting problem. [build/include_order] [4] WebKit/gtk/webkit/webkitwebview.cpp:43: Alphabetical sorting problem. [build/include_order] [4] Total errors found: 4 in 31 files If any of these errors are false positives, please file a bug against check-webkit-style.
Dumitru Daniliuc
Comment 15 2010-06-02 04:31:50 PDT
Created attachment 57644 [details] patch #3: Move the reusable code from Database to AbstractDatabase Same patch, fixed the style errors.
WebKit Review Bot
Comment 16 2010-06-02 05:36:08 PDT
WebKit Review Bot
Comment 17 2010-06-02 06:29:26 PDT
Dumitru Daniliuc
Comment 18 2010-06-02 16:05:23 PDT
Created attachment 57711 [details] patch #3: Move the reusable code from Database to AbstractDatabase The patch should build on all platforms now.
Adam Barth
Comment 19 2010-06-09 12:12:27 PDT
Comment on attachment 57711 [details] patch #3: Move the reusable code from Database to AbstractDatabase WebCore/storage/AbstractDatabase.cpp:51 + if (origin.endsWith("/")) This shouldn't ever happen. Origins don't end in "/". WebCore/storage/AbstractDatabase.cpp:48 + static int guidForOriginAndName(const String& origin, const String& name) You should use an anonymous namespace instead of "static". It doesn't matter much, but it's the C++ way. Oh, I guess this is all just moving code around. I thought I was supposed to review the correctness of the code (which is quite complicated). Let me try this again.
Adam Barth
Comment 20 2010-06-09 12:16:58 PDT
Comment on attachment 57711 [details] patch #3: Move the reusable code from Database to AbstractDatabase This is too complicated for me to review. The general approach seems reasonable. The perform* methods don't seem quite ideal... I've also never seen this code before, so it's all new to me. Is there someone more familiar with this stuff who can review?
Dumitru Daniliuc
Comment 21 2010-06-10 14:46:28 PDT
Let's postpone patch #3, since we don't have a sync implementation yet and don't know what parts will be reused and which ones won't. We can do a refactoring (merge code from Database and DatabaseSync into AbstractDatabase) after DatabaseSync is implemented.
Michael Nordman
Comment 22 2010-06-10 15:05:48 PDT
Yup... getting further along in the sync impl may help inform this refactoring effort. I'm not sure having promoted so much to the public interface is an improvement. The set of classes that make up the database system are a tightly couple bunch. The public interface being determined what that set of classes needs really makes it difficult for an innocent consumer of the Database class to know what methods they should be calling from the oustide looking in. ***** DatabaseThread.h Since this class only works with async Database instances, I don't think the unscheduleDatabaseTasks() method should accept an AbstractDatabase* as a parameter. ***** DatabaseThread.cpp It looks like you've renamed the existing non-virtual close(ClosePolicy) method to performClose(ClosePolicy)... and added a new virtual method for close(). I think this callsite can continue to call the renamed non-virtual performClose(ClosePolicy) method. If the class interface is not modified, the changes to SameDatabasePredicate class are not needed. Also, it might be nice to put the SameDatabasePredicate in an anon namespace. ***** ScriptExecutionContext.cpp Since the DBThread only works with async Databases, it seems like the call to unscheduleTasks for AbstactDatabases is out of place in stopDatabases. Hmmm... does the script execution context even need to keep SyncDatabases in its collection of open databases. It looks like the only reason it has the collection is to 'stop' anyhing in async process when the time comes to do so... but with SyncDatabases... there never is anything going on in the background to 'stop'. ***** WebKit\chromium\src\WebDatabase.cpp I'm still getting a handle on what has been virtualized and why so can't comment on this quite yet. ***** AbstractDatabse vs Database virtual void performCreationCallback(); Why virtualize this method, its only called for concrete Databases? virtual void notifyDatabaseThreadDatabaseOpen(); This method feels very out of place in this class. Maybe this is something the 'openTask' could do after having called performOpenAndVerify()? virtual void close(); virtual void stop(); I think you've virtualized this pair of methods to support the following callsites. - ScriptExcecutionContext::stopDatabases() - WebDatabase::closeDatabaseImmediately() The virtual stop() method on the abstract class feels a little out of place. What does 'stop' mean for a sync database class. I'm trying to track down the callsites for close(), it looks like WebDatabase::closeDatabaseImmediately the only usage of that method. Maybe we could use a virtualized method for that? virtual void closeImmediately();
Dumitru Daniliuc
Comment 23 2010-06-10 19:44:08 PDT
Created attachment 58437 [details] patch #3: Get DatabaseTracker ready for sync DBs
WebKit Review Bot
Comment 24 2010-06-10 19:56:49 PDT
Dumitru Daniliuc
Comment 25 2010-06-10 19:59:38 PDT
Created attachment 58438 [details] patch #3: Get DatabaseTracker ready for sync DBs
Michael Nordman
Comment 26 2010-06-11 12:30:01 PDT
Comment on attachment 58438 [details] patch #3: Get DatabaseTracker ready for sync DBs This change is so much easier to grok! Fwiw... LGTM WebKit/chromium/src/WebDatabase.cpp:114 + PassRefPtr<SecurityOrigin> originPrp(WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); Maybe use SecurityOrigin::createFromDatabaseIdentifier() directly instead of the awkward local PassRefPtr variable?
Dumitru Daniliuc
Comment 27 2010-06-11 12:50:41 PDT
> WebKit/chromium/src/WebDatabase.cpp:114 > + PassRefPtr<SecurityOrigin> originPrp(WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); > Maybe use SecurityOrigin::createFromDatabaseIdentifier() directly instead of the awkward local PassRefPtr variable? let's leave it as it is for now, since it's not directly related to this patch. i'll bring this up with darin (fisher) and if he agrees, i'll change this in a separate patch.
Dumitru Daniliuc
Comment 28 2010-06-11 13:12:33 PDT
(In reply to comment #27) > > WebKit/chromium/src/WebDatabase.cpp:114 > > + PassRefPtr<SecurityOrigin> originPrp(WebSecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); > > Maybe use SecurityOrigin::createFromDatabaseIdentifier() directly instead of the awkward local PassRefPtr variable? > > let's leave it as it is for now, since it's not directly related to this patch. i'll bring this up with darin (fisher) and if he agrees, i'll change this in a separate patch. fixed, after our discussion.
Adam Barth
Comment 29 2010-06-14 13:38:17 PDT
Comment on attachment 58438 [details] patch #3: Get DatabaseTracker ready for sync DBs LGTM. Thanks for making this easy to review.
Dumitru Daniliuc
Comment 30 2010-06-14 15:09:37 PDT
patch #3 landed as r61154. This bug should stay open until we have a fully working sync implementation of WebSQLDatabases in workers. Then we can move the common code to AbstractDatabase and close this bug.
WebKit Review Bot
Comment 31 2010-06-14 15:23:52 PDT
Dumitru Daniliuc
Comment 32 2010-06-15 04:11:30 PDT
Created attachment 58767 [details] patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag Moved isAvailable() and setIsAvailable() from Database and DatabaseSync to AbstractDatabase. Also, made a cosmetic change to WorkerContext::openDatabaseSync() to make it match the style of WorkerContext::openDatabase().
WebKit Review Bot
Comment 33 2010-06-15 04:16:49 PDT
Attachment 58767 [details] did not pass style-queue: Failed to run "['WebKitTools/Scripts/check-webkit-style', '--no-squash']" exit_code: 1 WARNING: File exempt from style guide. Skipping: "WebKit/qt/Api/qwebsettings.cpp" WebKit/gtk/webkit/webkitwebview.cpp:43: Alphabetical sorting problem. [build/include_order] [4] Total errors found: 1 in 19 files If any of these errors are false positives, please file a bug against check-webkit-style.
Eric Seidel (no email)
Comment 34 2010-06-15 04:19:47 PDT
Early Warning System Bot
Comment 35 2010-06-15 04:23:05 PDT
Dumitru Daniliuc
Comment 36 2010-06-15 04:28:38 PDT
Created attachment 58768 [details] patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag Same patch, should fix the style and build problems.
Eric Seidel (no email)
Comment 37 2010-06-15 04:33:45 PDT
Dumitru Daniliuc
Comment 38 2010-06-15 04:38:10 PDT
Created attachment 58769 [details] patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag Forgot to patch WebCore.base.exp.
Adam Barth
Comment 39 2010-06-17 17:02:39 PDT
Comment on attachment 58769 [details] patch #4: sync and async DB APIs should be enabled/disabled at runtime by the same flag Great! A couple minor comments. WebCore/storage/AbstractDatabase.cpp:36 + static bool isDatabaseAvailable = true; I forget how the webkit-dev thread turned out. g_isDatabaseAvailable? Not sure. WebCore/workers/WorkerContext.cpp:297 + ec = SECURITY_ERR; Security Error?
Dumitru Daniliuc
Comment 40 2010-06-17 17:16:08 PDT
> WebCore/storage/AbstractDatabase.cpp:36 > + static bool isDatabaseAvailable = true; > I forget how the webkit-dev thread turned out. g_isDatabaseAvailable? Not sure. Took a look at that thread. Looks like Jeremy + Jon Mason proposed using the "g_" prefix for file-level static variables, Maciej objected, and that was the end of it. > WebCore/workers/WorkerContext.cpp:297 > + ec = SECURITY_ERR; > Security Error? From the DB spec: "The user agent may raise a SECURITY_ERR exception instead of returning a Database object if the request violates a policy decision (e.g. if the user agent is configured to not allow the page to open databases)."
Dumitru Daniliuc
Comment 41 2010-06-18 02:16:53 PDT
patch #4 landed as r61388.
Dumitru Daniliuc
Comment 42 2010-06-30 04:46:57 PDT
All common code was moved to AbstractDatabase. There's still some clean up to do in AbstractDatabase; I'll open separate bugs for that as I get to it.
Note You need to log in before you can comment on or make changes to this bug.