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

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

Issue 2288973002: Merge TaskSynchronizer into WaitableEvent. (Closed)
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 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 * 7 *
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 17 matching lines...) Expand all
28 28
29 #include "modules/webdatabase/DatabaseTask.h" 29 #include "modules/webdatabase/DatabaseTask.h"
30 30
31 #include "modules/webdatabase/Database.h" 31 #include "modules/webdatabase/Database.h"
32 #include "modules/webdatabase/DatabaseContext.h" 32 #include "modules/webdatabase/DatabaseContext.h"
33 #include "modules/webdatabase/DatabaseThread.h" 33 #include "modules/webdatabase/DatabaseThread.h"
34 #include "modules/webdatabase/StorageLog.h" 34 #include "modules/webdatabase/StorageLog.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 DatabaseTask::DatabaseTask(Database* database, TaskSynchronizer* synchronizer) 38 DatabaseTask::DatabaseTask(Database* database, WaitableEvent* completeEvent)
39 : m_database(database) 39 : m_database(database)
40 , m_synchronizer(synchronizer) 40 , m_completeEvent(completeEvent)
41 #if DCHECK_IS_ON() 41 #if DCHECK_IS_ON()
42 , m_complete(false) 42 , m_complete(false)
43 #endif 43 #endif
44 { 44 {
45 } 45 }
46 46
47 DatabaseTask::~DatabaseTask() 47 DatabaseTask::~DatabaseTask()
48 { 48 {
49 #if DCHECK_IS_ON() 49 #if DCHECK_IS_ON()
50 ASSERT(m_complete || !m_synchronizer); 50 DCHECK(m_complete || !m_completeEvent);
51 #endif 51 #endif
52 } 52 }
53 53
54 void DatabaseTask::run() 54 void DatabaseTask::run()
55 { 55 {
56 // Database tasks are meant to be used only once, so make sure this one hasn 't been performed before. 56 // Database tasks are meant to be used only once, so make sure this one hasn 't been performed before.
57 #if DCHECK_IS_ON() 57 #if DCHECK_IS_ON()
58 ASSERT(!m_complete); 58 ASSERT(!m_complete);
59 #endif 59 #endif
60 60
61 if (!m_synchronizer && !m_database->getDatabaseContext()->databaseThread()-> isDatabaseOpen(m_database.get())) { 61 if (!m_completeEvent && !m_database->getDatabaseContext()->databaseThread()- >isDatabaseOpen(m_database.get())) {
62 taskCancelled(); 62 taskCancelled();
63 #if DCHECK_IS_ON() 63 #if DCHECK_IS_ON()
64 m_complete = true; 64 m_complete = true;
65 #endif 65 #endif
66 return; 66 return;
67 } 67 }
68 #if DCHECK_IS_ON() 68 #if DCHECK_IS_ON()
69 STORAGE_DVLOG(1) << "Performing " << debugTaskName() << " " << this; 69 STORAGE_DVLOG(1) << "Performing " << debugTaskName() << " " << this;
70 #endif 70 #endif
71 m_database->resetAuthorizer(); 71 m_database->resetAuthorizer();
72 doPerformTask(); 72 doPerformTask();
73 73
74 if (m_synchronizer) 74 if (m_completeEvent)
75 m_synchronizer->taskCompleted(); 75 m_completeEvent->signal();
76 76
77 #if DCHECK_IS_ON() 77 #if DCHECK_IS_ON()
78 m_complete = true; 78 m_complete = true;
79 #endif 79 #endif
80 } 80 }
81 81
82 // *** DatabaseOpenTask *** 82 // *** DatabaseOpenTask ***
83 // Opens the database file and verifies the version matches the expected version . 83 // Opens the database file and verifies the version matches the expected version .
84 84
85 Database::DatabaseOpenTask::DatabaseOpenTask(Database* database, bool setVersion InNewDatabase, TaskSynchronizer* synchronizer, DatabaseError& error, String& err orMessage, bool& success) 85 Database::DatabaseOpenTask::DatabaseOpenTask(Database* database, bool setVersion InNewDatabase, WaitableEvent* completeEvent, DatabaseError& error, String& error Message, bool& success)
86 : DatabaseTask(database, synchronizer) 86 : DatabaseTask(database, completeEvent)
87 , m_setVersionInNewDatabase(setVersionInNewDatabase) 87 , m_setVersionInNewDatabase(setVersionInNewDatabase)
88 , m_error(error) 88 , m_error(error)
89 , m_errorMessage(errorMessage) 89 , m_errorMessage(errorMessage)
90 , m_success(success) 90 , m_success(success)
91 { 91 {
92 ASSERT(synchronizer); // A task with output parameters is supposed to be syn chronous. 92 DCHECK(completeEvent); // A task with output parameters is supposed to be sy nchronous.
93 } 93 }
94 94
95 void Database::DatabaseOpenTask::doPerformTask() 95 void Database::DatabaseOpenTask::doPerformTask()
96 { 96 {
97 String errorMessage; 97 String errorMessage;
98 m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_er ror, errorMessage); 98 m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_er ror, errorMessage);
99 if (!m_success) 99 if (!m_success)
100 m_errorMessage = errorMessage.isolatedCopy(); 100 m_errorMessage = errorMessage.isolatedCopy();
101 } 101 }
102 102
103 #if DCHECK_IS_ON() 103 #if DCHECK_IS_ON()
104 const char* Database::DatabaseOpenTask::debugTaskName() const 104 const char* Database::DatabaseOpenTask::debugTaskName() const
105 { 105 {
106 return "DatabaseOpenTask"; 106 return "DatabaseOpenTask";
107 } 107 }
108 #endif 108 #endif
109 109
110 // *** DatabaseCloseTask *** 110 // *** DatabaseCloseTask ***
111 // Closes the database. 111 // Closes the database.
112 112
113 Database::DatabaseCloseTask::DatabaseCloseTask(Database* database, TaskSynchroni zer* synchronizer) 113 Database::DatabaseCloseTask::DatabaseCloseTask(Database* database, WaitableEvent * completeEvent)
114 : DatabaseTask(database, synchronizer) 114 : DatabaseTask(database, completeEvent)
115 { 115 {
116 } 116 }
117 117
118 void Database::DatabaseCloseTask::doPerformTask() 118 void Database::DatabaseCloseTask::doPerformTask()
119 { 119 {
120 database()->close(); 120 database()->close();
121 } 121 }
122 122
123 #if DCHECK_IS_ON() 123 #if DCHECK_IS_ON()
124 const char* Database::DatabaseCloseTask::debugTaskName() const 124 const char* Database::DatabaseCloseTask::debugTaskName() const
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 #if DCHECK_IS_ON() 161 #if DCHECK_IS_ON()
162 const char* Database::DatabaseTransactionTask::debugTaskName() const 162 const char* Database::DatabaseTransactionTask::debugTaskName() const
163 { 163 {
164 return "DatabaseTransactionTask"; 164 return "DatabaseTransactionTask";
165 } 165 }
166 #endif 166 #endif
167 167
168 // *** DatabaseTableNamesTask *** 168 // *** DatabaseTableNamesTask ***
169 // Retrieves a list of all tables in the database - for WebInspector support. 169 // Retrieves a list of all tables in the database - for WebInspector support.
170 170
171 Database::DatabaseTableNamesTask::DatabaseTableNamesTask(Database* database, Tas kSynchronizer* synchronizer, Vector<String>& names) 171 Database::DatabaseTableNamesTask::DatabaseTableNamesTask(Database* database, Wai tableEvent* completeEvent, Vector<String>& names)
172 : DatabaseTask(database, synchronizer) 172 : DatabaseTask(database, completeEvent)
173 , m_tableNames(names) 173 , m_tableNames(names)
174 { 174 {
175 ASSERT(synchronizer); // A task with output parameters is supposed to be syn chronous. 175 DCHECK(completeEvent); // A task with output parameters is supposed to be sy nchronous.
176 } 176 }
177 177
178 void Database::DatabaseTableNamesTask::doPerformTask() 178 void Database::DatabaseTableNamesTask::doPerformTask()
179 { 179 {
180 m_tableNames = database()->performGetTableNames(); 180 m_tableNames = database()->performGetTableNames();
181 } 181 }
182 182
183 #if DCHECK_IS_ON() 183 #if DCHECK_IS_ON()
184 const char* Database::DatabaseTableNamesTask::debugTaskName() const 184 const char* Database::DatabaseTableNamesTask::debugTaskName() const
185 { 185 {
186 return "DatabaseTableNamesTask"; 186 return "DatabaseTableNamesTask";
187 } 187 }
188 #endif 188 #endif
189 189
190 } // namespace blink 190 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698