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

Side by Side Diff: Source/modules/webdatabase/DatabaseSync.cpp

Issue 561093003: Remove worker support of Web SQL Database. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/webdatabase/DatabaseSync.h ('k') | Source/modules/webdatabase/DatabaseSync.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2010 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "modules/webdatabase/DatabaseSync.h"
33
34 #include "bindings/core/v8/ExceptionState.h"
35 #include "core/dom/ExceptionCode.h"
36 #include "core/dom/ExecutionContext.h"
37 #include "platform/Logging.h"
38 #include "modules/webdatabase/DatabaseCallback.h"
39 #include "modules/webdatabase/DatabaseContext.h"
40 #include "modules/webdatabase/DatabaseManager.h"
41 #include "modules/webdatabase/DatabaseTracker.h"
42 #include "modules/webdatabase/SQLError.h"
43 #include "modules/webdatabase/SQLTransactionSync.h"
44 #include "modules/webdatabase/SQLTransactionSyncCallback.h"
45 #include "wtf/PassRefPtr.h"
46 #include "wtf/RefPtr.h"
47 #include "wtf/text/CString.h"
48
49 namespace blink {
50
51 PassRefPtrWillBeRawPtr<DatabaseSync> DatabaseSync::create(ExecutionContext*, Pas sRefPtrWillBeRawPtr<DatabaseBackendBase> backend)
52 {
53 return static_cast<DatabaseSync*>(backend.get());
54 }
55
56 DatabaseSync::DatabaseSync(DatabaseContext* databaseContext,
57 const String& name, const String& expectedVersion, const String& displayName , unsigned long estimatedSize)
58 : DatabaseBackendSync(databaseContext, name, expectedVersion, displayName, e stimatedSize)
59 , DatabaseBase(databaseContext->executionContext())
60 {
61 setFrontend(this);
62 }
63
64 DatabaseSync::~DatabaseSync()
65 {
66 #if !ENABLE(OILPAN)
67 if (executionContext())
68 ASSERT(executionContext()->isContextThread());
69 #endif
70 }
71
72 void DatabaseSync::trace(Visitor* visitor)
73 {
74 DatabaseBackendSync::trace(visitor);
75 }
76
77 void DatabaseSync::changeVersion(const String& oldVersion, const String& newVers ion, PassOwnPtrWillBeRawPtr<SQLTransactionSyncCallback> changeVersionCallback, E xceptionState& exceptionState)
78 {
79 ASSERT(executionContext()->isContextThread());
80
81 if (sqliteDatabase().transactionInProgress()) {
82 reportChangeVersionResult(1, SQLError::DATABASE_ERR, 0);
83 setLastErrorMessage("unable to changeVersion from within a transaction") ;
84 exceptionState.throwDOMException(SQLDatabaseError, "Unable to change ver sion from within a transaction.");
85 return;
86 }
87
88 RefPtrWillBeRawPtr<SQLTransactionSync> transaction = SQLTransactionSync::cre ate(this, changeVersionCallback, false);
89 transaction->begin(exceptionState);
90 if (exceptionState.hadException()) {
91 ASSERT(!lastErrorMessage().isEmpty());
92 return;
93 }
94
95 String actualVersion;
96 if (!getVersionFromDatabase(actualVersion)) {
97 reportChangeVersionResult(2, SQLError::UNKNOWN_ERR, sqliteDatabase().las tError());
98 setLastErrorMessage("unable to read the current version", sqliteDatabase ().lastError(), sqliteDatabase().lastErrorMsg());
99 exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMes sage);
100 return;
101 }
102
103 if (actualVersion != oldVersion) {
104 reportChangeVersionResult(3, SQLError::VERSION_ERR, 0);
105 setLastErrorMessage("current version of the database and `oldVersion` ar gument do not match");
106 exceptionState.throwDOMException(VersionError, SQLError::versionErrorMes sage);
107 return;
108 }
109
110
111 transaction->execute(exceptionState);
112 if (exceptionState.hadException()) {
113 ASSERT(!lastErrorMessage().isEmpty());
114 return;
115 }
116
117 if (!setVersionInDatabase(newVersion)) {
118 reportChangeVersionResult(4, SQLError::UNKNOWN_ERR, sqliteDatabase().las tError());
119 setLastErrorMessage("unable to set the new version", sqliteDatabase().la stError(), sqliteDatabase().lastErrorMsg());
120 exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMes sage);
121 return;
122 }
123
124 transaction->commit(exceptionState);
125 if (exceptionState.hadException()) {
126 ASSERT(!lastErrorMessage().isEmpty());
127 setCachedVersion(oldVersion);
128 return;
129 }
130
131 reportChangeVersionResult(0, -1, 0); // OK
132
133 setExpectedVersion(newVersion);
134 setLastErrorMessage("");
135 }
136
137 void DatabaseSync::transaction(PassOwnPtrWillBeRawPtr<SQLTransactionSyncCallback > callback, ExceptionState& exceptionState)
138 {
139 runTransaction(callback, false, exceptionState);
140 }
141
142 void DatabaseSync::readTransaction(PassOwnPtrWillBeRawPtr<SQLTransactionSyncCall back> callback, ExceptionState& exceptionState)
143 {
144 runTransaction(callback, true, exceptionState);
145 }
146
147 void DatabaseSync::rollbackTransaction(SQLTransactionSync& transaction)
148 {
149 ASSERT(!lastErrorMessage().isEmpty());
150 transaction.rollback();
151 setLastErrorMessage("");
152 return;
153 }
154
155 void DatabaseSync::runTransaction(PassOwnPtrWillBeRawPtr<SQLTransactionSyncCallb ack> callback, bool readOnly, ExceptionState& exceptionState)
156 {
157 ASSERT(executionContext()->isContextThread());
158
159 if (sqliteDatabase().transactionInProgress()) {
160 setLastErrorMessage("unable to start a transaction from within a transac tion");
161 exceptionState.throwDOMException(SQLDatabaseError, "Unable to start a tr ansaction from within a transaction.");
162 return;
163 }
164
165 RefPtrWillBeRawPtr<SQLTransactionSync> transaction = SQLTransactionSync::cre ate(this, callback, readOnly);
166 transaction->begin(exceptionState);
167 if (exceptionState.hadException()) {
168 rollbackTransaction(*transaction);
169 return;
170 }
171
172 transaction->execute(exceptionState);
173 if (exceptionState.hadException()) {
174 rollbackTransaction(*transaction);
175 return;
176 }
177
178 transaction->commit(exceptionState);
179 if (exceptionState.hadException()) {
180 rollbackTransaction(*transaction);
181 return;
182 }
183
184 setLastErrorMessage("");
185 }
186
187 void DatabaseSync::closeImmediately()
188 {
189 ASSERT(executionContext()->isContextThread());
190
191 if (!opened())
192 return;
193
194 logErrorMessage("forcibly closing database");
195 closeDatabase();
196 }
197
198 void DatabaseSync::observeTransaction(SQLTransactionSync& transaction)
199 {
200 #if ENABLE(OILPAN)
201 m_observers.add(&transaction, adoptPtr(new TransactionObserver(transaction)) );
202 #endif
203 }
204
205 #if ENABLE(OILPAN)
206 DatabaseSync::TransactionObserver::~TransactionObserver()
207 {
208 m_transaction.rollbackIfInProgress();
209 }
210 #endif
211
212 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/DatabaseSync.h ('k') | Source/modules/webdatabase/DatabaseSync.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698