~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/Modules/webdatabase/DatabaseTask.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 *
 
8
 * 1.  Redistributions of source code must retain the above copyright
 
9
 *     notice, this list of conditions and the following disclaimer.
 
10
 * 2.  Redistributions in binary form must reproduce the above copyright
 
11
 *     notice, this list of conditions and the following disclaimer in the
 
12
 *     documentation and/or other materials provided with the distribution.
 
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
 
15
 *     from this software without specific prior written permission.
 
16
 *
 
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
 
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
 
21
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
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
 
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
 
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
#ifndef DatabaseTask_h
 
29
#define DatabaseTask_h
 
30
 
 
31
#if ENABLE(SQL_DATABASE)
 
32
 
 
33
#include "Database.h"
 
34
#include "SQLTransaction.h"
 
35
#include <wtf/OwnPtr.h>
 
36
#include <wtf/PassOwnPtr.h>
 
37
#include <wtf/PassRefPtr.h>
 
38
#include <wtf/Threading.h>
 
39
#include <wtf/Vector.h>
 
40
#include <wtf/text/WTFString.h>
 
41
 
 
42
namespace WebCore {
 
43
 
 
44
typedef int ExceptionCode;
 
45
 
 
46
// Can be used to wait until DatabaseTask is completed.
 
47
// Has to be passed into DatabaseTask::create to be associated with the task.
 
48
class DatabaseTaskSynchronizer {
 
49
    WTF_MAKE_NONCOPYABLE(DatabaseTaskSynchronizer);
 
50
public:
 
51
    DatabaseTaskSynchronizer();
 
52
 
 
53
    // Called from main thread to wait until task is completed.
 
54
    void waitForTaskCompletion();
 
55
 
 
56
    // Called by the task.
 
57
    void taskCompleted();
 
58
 
 
59
#ifndef NDEBUG
 
60
    bool hasCheckedForTermination() const { return m_hasCheckedForTermination; }
 
61
    void setHasCheckedForTermination() { m_hasCheckedForTermination = true; }
 
62
#endif
 
63
 
 
64
private:
 
65
    bool m_taskCompleted;
 
66
    Mutex m_synchronousMutex;
 
67
    ThreadCondition m_synchronousCondition;
 
68
#ifndef NDEBUG
 
69
    bool m_hasCheckedForTermination;
 
70
#endif
 
71
};
 
72
 
 
73
class DatabaseTask {
 
74
    WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED;
 
75
public:
 
76
    virtual ~DatabaseTask();
 
77
 
 
78
    void performTask();
 
79
 
 
80
    Database* database() const { return m_database; }
 
81
#ifndef NDEBUG
 
82
    bool hasSynchronizer() const { return m_synchronizer; }
 
83
    bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedForTermination(); }
 
84
#endif
 
85
 
 
86
protected:
 
87
    DatabaseTask(Database*, DatabaseTaskSynchronizer*);
 
88
 
 
89
private:
 
90
    virtual void doPerformTask() = 0;
 
91
 
 
92
    Database* m_database;
 
93
    DatabaseTaskSynchronizer* m_synchronizer;
 
94
 
 
95
#if !LOG_DISABLED
 
96
    virtual const char* debugTaskName() const = 0;
 
97
    bool m_complete;
 
98
#endif
 
99
};
 
100
 
 
101
class Database::DatabaseOpenTask : public DatabaseTask {
 
102
public:
 
103
    static PassOwnPtr<DatabaseOpenTask> create(Database* db, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, ExceptionCode& code, String& errorMessage, bool& success)
 
104
    {
 
105
        return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, code, errorMessage, success));
 
106
    }
 
107
 
 
108
private:
 
109
    DatabaseOpenTask(Database*, bool setVersionInNewDatabase, DatabaseTaskSynchronizer*, ExceptionCode&, String& errorMessage, bool& success);
 
110
 
 
111
    virtual void doPerformTask();
 
112
#if !LOG_DISABLED
 
113
    virtual const char* debugTaskName() const;
 
114
#endif
 
115
 
 
116
    bool m_setVersionInNewDatabase;
 
117
    ExceptionCode& m_code;
 
118
    String& m_errorMessage;
 
119
    bool& m_success;
 
120
};
 
121
 
 
122
class Database::DatabaseCloseTask : public DatabaseTask {
 
123
public:
 
124
    static PassOwnPtr<DatabaseCloseTask> create(Database* db, DatabaseTaskSynchronizer* synchronizer)
 
125
    {
 
126
        return adoptPtr(new DatabaseCloseTask(db, synchronizer));
 
127
    }
 
128
 
 
129
private:
 
130
    DatabaseCloseTask(Database*, DatabaseTaskSynchronizer*);
 
131
 
 
132
    virtual void doPerformTask();
 
133
#if !LOG_DISABLED
 
134
    virtual const char* debugTaskName() const;
 
135
#endif
 
136
};
 
137
 
 
138
class Database::DatabaseTransactionTask : public DatabaseTask {
 
139
public:
 
140
    // Transaction task is never synchronous, so no 'synchronizer' parameter.
 
141
    static PassOwnPtr<DatabaseTransactionTask> create(PassRefPtr<SQLTransaction> transaction)
 
142
    {
 
143
        return adoptPtr(new DatabaseTransactionTask(transaction));
 
144
    }
 
145
 
 
146
    SQLTransaction* transaction() const { return m_transaction.get(); }
 
147
 
 
148
private:
 
149
    explicit DatabaseTransactionTask(PassRefPtr<SQLTransaction>);
 
150
 
 
151
    virtual void doPerformTask();
 
152
#if !LOG_DISABLED
 
153
    virtual const char* debugTaskName() const;
 
154
#endif
 
155
 
 
156
    RefPtr<SQLTransaction> m_transaction;
 
157
};
 
158
 
 
159
class Database::DatabaseTableNamesTask : public DatabaseTask {
 
160
public:
 
161
    static PassOwnPtr<DatabaseTableNamesTask> create(Database* db, DatabaseTaskSynchronizer* synchronizer, Vector<String>& names)
 
162
    {
 
163
        return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names));
 
164
    }
 
165
 
 
166
private:
 
167
    DatabaseTableNamesTask(Database*, DatabaseTaskSynchronizer*, Vector<String>& names);
 
168
 
 
169
    virtual void doPerformTask();
 
170
#if !LOG_DISABLED
 
171
    virtual const char* debugTaskName() const;
 
172
#endif
 
173
 
 
174
    Vector<String>& m_tableNames;
 
175
};
 
176
 
 
177
} // namespace WebCore
 
178
 
 
179
#endif // ENABLE(SQL_DATABASE)
 
180
 
 
181
#endif // DatabaseTask_h