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

Side by Side Diff: Source/modules/webdatabase/DatabaseTask.h

Issue 198673002: Rename DatabaseTaskSynchronizer to TaskSynchronizer and move it to platform/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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
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
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived 14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission. 15 * from this software without specific prior written permission.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28
28 #ifndef DatabaseTask_h 29 #ifndef DatabaseTask_h
29 #define DatabaseTask_h 30 #define DatabaseTask_h
30 31
31 #include "heap/Handle.h" 32 #include "heap/Handle.h"
32 #include "modules/webdatabase/DatabaseBackend.h" 33 #include "modules/webdatabase/DatabaseBackend.h"
33 #include "modules/webdatabase/DatabaseBasicTypes.h" 34 #include "modules/webdatabase/DatabaseBasicTypes.h"
34 #include "modules/webdatabase/DatabaseError.h" 35 #include "modules/webdatabase/DatabaseError.h"
35 #include "modules/webdatabase/SQLTransactionBackend.h" 36 #include "modules/webdatabase/SQLTransactionBackend.h"
36 #include "platform/Task.h" 37 #include "platform/Task.h"
38 #include "platform/TaskSynchronizer.h"
37 #include "wtf/OwnPtr.h" 39 #include "wtf/OwnPtr.h"
38 #include "wtf/PassOwnPtr.h" 40 #include "wtf/PassOwnPtr.h"
39 #include "wtf/PassRefPtr.h" 41 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
41 #include "wtf/Threading.h" 43 #include "wtf/Threading.h"
42 #include "wtf/Vector.h" 44 #include "wtf/Vector.h"
43 #include "wtf/text/WTFString.h" 45 #include "wtf/text/WTFString.h"
44 46
45 namespace WebCore { 47 namespace WebCore {
46 48
47 // Can be used to wait until DatabaseTask is completed.
48 // Has to be passed into DatabaseTask::create to be associated with the task.
49 class DatabaseTaskSynchronizer {
50 WTF_MAKE_NONCOPYABLE(DatabaseTaskSynchronizer);
51 public:
52 DatabaseTaskSynchronizer();
53
54 // Called from main thread to wait until task is completed.
55 void waitForTaskCompletion();
56
57 // Called by the task.
58 void taskCompleted();
59
60 #ifndef NDEBUG
61 bool hasCheckedForTermination() const { return m_hasCheckedForTermination; }
62 void setHasCheckedForTermination() { m_hasCheckedForTermination = true; }
63 #endif
64
65 private:
66 bool m_taskCompleted;
67 Mutex m_synchronousMutex;
68 ThreadCondition m_synchronousCondition;
69 #ifndef NDEBUG
70 bool m_hasCheckedForTermination;
71 #endif
72 };
73
74 class DatabaseTask : public blink::WebThread::Task { 49 class DatabaseTask : public blink::WebThread::Task {
75 WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED; 50 WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED;
76 public: 51 public:
77 virtual ~DatabaseTask(); 52 virtual ~DatabaseTask();
78 53
79 virtual void run() OVERRIDE FINAL; 54 virtual void run() OVERRIDE FINAL;
80 55
81 DatabaseBackend* database() const { return m_database.get(); } 56 DatabaseBackend* database() const { return m_database.get(); }
82 #ifndef NDEBUG 57 #ifndef NDEBUG
83 bool hasSynchronizer() const { return m_synchronizer; } 58 bool hasSynchronizer() const { return m_synchronizer; }
84 bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedFor Termination(); } 59 bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedFor Termination(); }
85 #endif 60 #endif
86 61
87 protected: 62 protected:
88 DatabaseTask(DatabaseBackend*, DatabaseTaskSynchronizer*); 63 DatabaseTask(DatabaseBackend*, TaskSynchronizer*);
89 64
90 private: 65 private:
91 virtual void doPerformTask() = 0; 66 virtual void doPerformTask() = 0;
92 virtual void taskCancelled() { } 67 virtual void taskCancelled() { }
93 68
94 RefPtrWillBeCrossThreadPersistent<DatabaseBackend> m_database; 69 RefPtrWillBeCrossThreadPersistent<DatabaseBackend> m_database;
95 DatabaseTaskSynchronizer* m_synchronizer; 70 TaskSynchronizer* m_synchronizer;
96 71
97 #if !LOG_DISABLED 72 #if !LOG_DISABLED
98 virtual const char* debugTaskName() const = 0; 73 virtual const char* debugTaskName() const = 0;
99 bool m_complete; 74 bool m_complete;
100 #endif 75 #endif
101 }; 76 };
102 77
103 class DatabaseBackend::DatabaseOpenTask FINAL : public DatabaseTask { 78 class DatabaseBackend::DatabaseOpenTask FINAL : public DatabaseTask {
104 public: 79 public:
105 static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVers ionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success) 80 static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVers ionInNewDatabase, TaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
106 { 81 {
107 return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchr onizer, error, errorMessage, success)); 82 return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchr onizer, error, errorMessage, success));
108 } 83 }
109 84
110 private: 85 private:
111 DatabaseOpenTask(DatabaseBackend*, bool setVersionInNewDatabase, DatabaseTas kSynchronizer*, DatabaseError&, String& errorMessage, bool& success); 86 DatabaseOpenTask(DatabaseBackend*, bool setVersionInNewDatabase, TaskSynchro nizer*, DatabaseError&, String& errorMessage, bool& success);
112 87
113 virtual void doPerformTask() OVERRIDE; 88 virtual void doPerformTask() OVERRIDE;
114 #if !LOG_DISABLED 89 #if !LOG_DISABLED
115 virtual const char* debugTaskName() const OVERRIDE; 90 virtual const char* debugTaskName() const OVERRIDE;
116 #endif 91 #endif
117 92
118 bool m_setVersionInNewDatabase; 93 bool m_setVersionInNewDatabase;
119 DatabaseError& m_error; 94 DatabaseError& m_error;
120 String& m_errorMessage; 95 String& m_errorMessage;
121 bool& m_success; 96 bool& m_success;
122 }; 97 };
123 98
124 class DatabaseBackend::DatabaseCloseTask FINAL : public DatabaseTask { 99 class DatabaseBackend::DatabaseCloseTask FINAL : public DatabaseTask {
125 public: 100 public:
126 static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, DatabaseTas kSynchronizer* synchronizer) 101 static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, TaskSynchro nizer* synchronizer)
127 { 102 {
128 return adoptPtr(new DatabaseCloseTask(db, synchronizer)); 103 return adoptPtr(new DatabaseCloseTask(db, synchronizer));
129 } 104 }
130 105
131 private: 106 private:
132 DatabaseCloseTask(DatabaseBackend*, DatabaseTaskSynchronizer*); 107 DatabaseCloseTask(DatabaseBackend*, TaskSynchronizer*);
133 108
134 virtual void doPerformTask() OVERRIDE; 109 virtual void doPerformTask() OVERRIDE;
135 #if !LOG_DISABLED 110 #if !LOG_DISABLED
136 virtual const char* debugTaskName() const OVERRIDE; 111 virtual const char* debugTaskName() const OVERRIDE;
137 #endif 112 #endif
138 }; 113 };
139 114
140 class DatabaseBackend::DatabaseTransactionTask FINAL : public DatabaseTask { 115 class DatabaseBackend::DatabaseTransactionTask FINAL : public DatabaseTask {
141 public: 116 public:
142 virtual ~DatabaseTransactionTask(); 117 virtual ~DatabaseTransactionTask();
(...skipping 13 matching lines...) Expand all
156 virtual void taskCancelled() OVERRIDE; 131 virtual void taskCancelled() OVERRIDE;
157 #if !LOG_DISABLED 132 #if !LOG_DISABLED
158 virtual const char* debugTaskName() const OVERRIDE; 133 virtual const char* debugTaskName() const OVERRIDE;
159 #endif 134 #endif
160 135
161 RefPtrWillBeCrossThreadPersistent<SQLTransactionBackend> m_transaction; 136 RefPtrWillBeCrossThreadPersistent<SQLTransactionBackend> m_transaction;
162 }; 137 };
163 138
164 class DatabaseBackend::DatabaseTableNamesTask FINAL : public DatabaseTask { 139 class DatabaseBackend::DatabaseTableNamesTask FINAL : public DatabaseTask {
165 public: 140 public:
166 static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, Databa seTaskSynchronizer* synchronizer, Vector<String>& names) 141 static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, TaskSy nchronizer* synchronizer, Vector<String>& names)
167 { 142 {
168 return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names)); 143 return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names));
169 } 144 }
170 145
171 private: 146 private:
172 DatabaseTableNamesTask(DatabaseBackend*, DatabaseTaskSynchronizer*, Vector<S tring>& names); 147 DatabaseTableNamesTask(DatabaseBackend*, TaskSynchronizer*, Vector<String>& names);
173 148
174 virtual void doPerformTask() OVERRIDE; 149 virtual void doPerformTask() OVERRIDE;
175 #if !LOG_DISABLED 150 #if !LOG_DISABLED
176 virtual const char* debugTaskName() const OVERRIDE; 151 virtual const char* debugTaskName() const OVERRIDE;
177 #endif 152 #endif
178 153
179 Vector<String>& m_tableNames; 154 Vector<String>& m_tableNames;
180 }; 155 };
181 156
182 } // namespace WebCore 157 } // namespace WebCore
183 158
184 #endif // DatabaseTask_h 159 #endif // DatabaseTask_h
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/DatabaseManager.h ('k') | Source/modules/webdatabase/DatabaseTask.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698