OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google 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 Loading... |
28 | 28 |
29 #include "core/dom/ScriptExecutionContext.h" | 29 #include "core/dom/ScriptExecutionContext.h" |
30 #include "modules/indexeddb/IDBDatabase.h" | 30 #include "modules/indexeddb/IDBDatabase.h" |
31 #include "modules/indexeddb/IDBDatabaseCallbacksImpl.h" | 31 #include "modules/indexeddb/IDBDatabaseCallbacksImpl.h" |
32 #include "modules/indexeddb/IDBPendingTransactionMonitor.h" | 32 #include "modules/indexeddb/IDBPendingTransactionMonitor.h" |
33 #include "modules/indexeddb/IDBTracing.h" | 33 #include "modules/indexeddb/IDBTracing.h" |
34 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 34 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 PassRefPtr<IDBOpenDBRequest> IDBOpenDBRequest::create(ScriptExecutionContext* co
ntext, PassRefPtr<IDBDatabaseCallbacksImpl> callbacks, int64_t transactionId, in
t64_t version) | 38 PassRefPtr<IDBOpenDBRequest> IDBOpenDBRequest::create(ScriptExecutionContext* co
ntext, IDBDatabaseCallbacksImpl* callbacks, int64_t transactionId, int64_t versi
on) |
39 { | 39 { |
40 RefPtr<IDBOpenDBRequest> request(adoptRef(new IDBOpenDBRequest(context, call
backs, transactionId, version))); | 40 RefPtr<IDBOpenDBRequest> request(adoptRef(new IDBOpenDBRequest(context, call
backs, transactionId, version))); |
41 request->suspendIfNeeded(); | 41 request->suspendIfNeeded(); |
42 return request.release(); | 42 return request.release(); |
43 } | 43 } |
44 | 44 |
45 IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext* context, PassRefPtr<I
DBDatabaseCallbacksImpl> callbacks, int64_t transactionId, int64_t version) | 45 IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext* context, IDBDatabaseC
allbacksImpl* callbacks, int64_t transactionId, int64_t version) |
46 : IDBRequest(context, IDBAny::createNull(), IDBDatabaseBackendInterface::Nor
malTask, 0) | 46 : IDBRequest(context, IDBAny::createNull(), IDBDatabaseBackendInterface::Nor
malTask, 0) |
47 , m_databaseCallbacks(callbacks) | 47 , m_databaseCallbacks(callbacks) |
48 , m_transactionId(transactionId) | 48 , m_transactionId(transactionId) |
49 , m_version(version) | 49 , m_version(version) |
50 { | 50 { |
51 ASSERT(!m_result); | 51 ASSERT(!m_result); |
52 ScriptWrappable::init(this); | 52 ScriptWrappable::init(this); |
53 } | 53 } |
54 | 54 |
55 IDBOpenDBRequest::~IDBOpenDBRequest() | 55 IDBOpenDBRequest::~IDBOpenDBRequest() |
56 { | 56 { |
57 } | 57 } |
58 | 58 |
59 const AtomicString& IDBOpenDBRequest::interfaceName() const | 59 const AtomicString& IDBOpenDBRequest::interfaceName() const |
60 { | 60 { |
61 return eventNames().interfaceForIDBOpenDBRequest; | 61 return eventNames().interfaceForIDBOpenDBRequest; |
62 } | 62 } |
63 | 63 |
64 void IDBOpenDBRequest::onBlocked(int64_t oldVersion) | 64 void IDBOpenDBRequest::onBlocked(int64_t oldVersion) |
65 { | 65 { |
66 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); | 66 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); |
67 if (!shouldEnqueueEvent()) | 67 if (!shouldEnqueueEvent()) |
68 return; | 68 return; |
69 RefPtr<IDBAny> newVersionAny = (m_version == IDBDatabaseMetadata::DefaultInt
Version) ? IDBAny::createNull() : IDBAny::create(m_version); | 69 RefPtr<IDBAny> newVersionAny = (m_version == IDBDatabaseMetadata::DefaultInt
Version) ? IDBAny::createNull() : IDBAny::create(m_version); |
70 enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), newVe
rsionAny.release(), eventNames().blockedEvent)); | 70 enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), newVe
rsionAny.release(), eventNames().blockedEvent)); |
71 } | 71 } |
72 | 72 |
73 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassRefPtr<IDBDatabas
eBackendInterface> prpDatabaseBackend, const IDBDatabaseMetadata& metadata) | 73 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, IDBDatabaseBackendInt
erface* databaseBackend, const IDBDatabaseMetadata& metadata) |
74 { | 74 { |
75 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); | 75 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); |
76 if (m_contextStopped || !scriptExecutionContext()) { | 76 if (m_contextStopped || !scriptExecutionContext()) { |
77 RefPtr<IDBDatabaseBackendInterface> db = prpDatabaseBackend; | 77 databaseBackend->abort(m_transactionId); |
78 db->abort(m_transactionId); | 78 databaseBackend->close(m_databaseCallbacks); |
79 db->close(m_databaseCallbacks); | |
80 return; | 79 return; |
81 } | 80 } |
82 if (!shouldEnqueueEvent()) | 81 if (!shouldEnqueueEvent()) |
83 return; | 82 return; |
84 | 83 |
85 ASSERT(m_databaseCallbacks); | 84 ASSERT(m_databaseCallbacks); |
86 | 85 |
87 RefPtr<IDBDatabaseBackendInterface> databaseBackend = prpDatabaseBackend; | 86 IDBDatabase* idbDatabase = IDBDatabase::create(scriptExecutionContext(), dat
abaseBackend, m_databaseCallbacks); |
88 | |
89 RefPtr<IDBDatabase> idbDatabase = IDBDatabase::create(scriptExecutionContext
(), databaseBackend, m_databaseCallbacks); | |
90 idbDatabase->setMetadata(metadata); | 87 idbDatabase->setMetadata(metadata); |
91 m_databaseCallbacks->connect(idbDatabase.get()); | 88 m_databaseCallbacks->connect(idbDatabase); |
92 m_databaseCallbacks = 0; | 89 m_databaseCallbacks = 0; |
93 | 90 |
94 if (oldVersion == IDBDatabaseMetadata::NoIntVersion) { | 91 if (oldVersion == IDBDatabaseMetadata::NoIntVersion) { |
95 // This database hasn't had an integer version before. | 92 // This database hasn't had an integer version before. |
96 oldVersion = IDBDatabaseMetadata::DefaultIntVersion; | 93 oldVersion = IDBDatabaseMetadata::DefaultIntVersion; |
97 } | 94 } |
98 IDBDatabaseMetadata oldMetadata(metadata); | 95 IDBDatabaseMetadata oldMetadata(metadata); |
99 oldMetadata.intVersion = oldVersion; | 96 oldMetadata.intVersion = oldVersion; |
100 | 97 |
101 m_transaction = IDBTransaction::create(scriptExecutionContext(), m_transacti
onId, idbDatabase.get(), this, oldMetadata); | 98 m_transaction = IDBTransaction::create(scriptExecutionContext(), m_transacti
onId, idbDatabase, this, oldMetadata); |
102 m_result = IDBAny::create(idbDatabase.release()); | 99 m_result = IDBAny::create(idbDatabase); |
103 | 100 |
104 if (m_version == IDBDatabaseMetadata::NoIntVersion) | 101 if (m_version == IDBDatabaseMetadata::NoIntVersion) |
105 m_version = 1; | 102 m_version = 1; |
106 enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), IDBAn
y::create(m_version), eventNames().upgradeneededEvent)); | 103 enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), IDBAn
y::create(m_version), eventNames().upgradeneededEvent)); |
107 } | 104 } |
108 | 105 |
109 void IDBOpenDBRequest::onSuccess(PassRefPtr<IDBDatabaseBackendInterface> prpBack
end, const IDBDatabaseMetadata& metadata) | 106 void IDBOpenDBRequest::onSuccess(IDBDatabaseBackendInterface* backend, const IDB
DatabaseMetadata& metadata) |
110 { | 107 { |
111 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); | 108 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); |
112 if (m_contextStopped || !scriptExecutionContext()) { | 109 if (m_contextStopped || !scriptExecutionContext()) { |
113 RefPtr<IDBDatabaseBackendInterface> db = prpBackend; | 110 backend->close(m_databaseCallbacks); |
114 db->close(m_databaseCallbacks); | |
115 return; | 111 return; |
116 } | 112 } |
117 if (!shouldEnqueueEvent()) | 113 if (!shouldEnqueueEvent()) |
118 return; | 114 return; |
119 | 115 |
120 RefPtr<IDBDatabaseBackendInterface> backend = prpBackend; | 116 IDBDatabase* idbDatabase; |
121 RefPtr<IDBDatabase> idbDatabase; | |
122 if (m_result) { | 117 if (m_result) { |
123 idbDatabase = m_result->idbDatabase(); | 118 idbDatabase = m_result->idbDatabase(); |
124 ASSERT(idbDatabase); | 119 ASSERT(idbDatabase); |
125 ASSERT(!m_databaseCallbacks); | 120 ASSERT(!m_databaseCallbacks); |
126 } else { | 121 } else { |
127 ASSERT(m_databaseCallbacks); | 122 ASSERT(m_databaseCallbacks); |
128 idbDatabase = IDBDatabase::create(scriptExecutionContext(), backend.rele
ase(), m_databaseCallbacks); | 123 idbDatabase = IDBDatabase::create(scriptExecutionContext(), backend, m_d
atabaseCallbacks); |
129 m_databaseCallbacks->connect(idbDatabase.get()); | 124 m_databaseCallbacks->connect(idbDatabase); |
130 m_databaseCallbacks = 0; | 125 m_databaseCallbacks = 0; |
131 m_result = IDBAny::create(idbDatabase.get()); | 126 m_result = IDBAny::create(idbDatabase); |
132 } | 127 } |
133 idbDatabase->setMetadata(metadata); | 128 idbDatabase->setMetadata(metadata); |
134 enqueueEvent(Event::create(eventNames().successEvent, false, false)); | 129 enqueueEvent(Event::create(eventNames().successEvent, false, false)); |
135 } | 130 } |
136 | 131 |
137 bool IDBOpenDBRequest::shouldEnqueueEvent() const | 132 bool IDBOpenDBRequest::shouldEnqueueEvent() const |
138 { | 133 { |
139 if (m_contextStopped || !scriptExecutionContext()) | 134 if (m_contextStopped || !scriptExecutionContext()) |
140 return false; | 135 return false; |
141 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 136 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
142 if (m_requestAborted) | 137 if (m_requestAborted) |
143 return false; | 138 return false; |
144 return true; | 139 return true; |
145 } | 140 } |
146 | 141 |
147 bool IDBOpenDBRequest::dispatchEvent(PassRefPtr<Event> event) | 142 bool IDBOpenDBRequest::dispatchEvent(PassRefPtr<Event> event) |
148 { | 143 { |
149 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, | 144 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, |
150 // an "error" event should be fired instead. | 145 // an "error" event should be fired instead. |
151 if (event->type() == eventNames().successEvent && m_result->type() == IDBAny
::IDBDatabaseType && m_result->idbDatabase()->isClosePending()) { | 146 if (event->type() == eventNames().successEvent && m_result->type() == IDBAny
::IDBDatabaseType && m_result->idbDatabase()->isClosePending()) { |
152 m_result.clear(); | 147 m_result.clear(); |
153 onError(IDBDatabaseError::create(IDBDatabaseException::AbortError, "The
connection was closed.")); | 148 onError(IDBDatabaseError::create(IDBDatabaseException::AbortError, "The
connection was closed.")); |
154 return false; | 149 return false; |
155 } | 150 } |
156 | 151 |
157 return IDBRequest::dispatchEvent(event); | 152 return IDBRequest::dispatchEvent(event); |
158 } | 153 } |
159 | 154 |
160 } // namespace WebCore | 155 } // namespace WebCore |
OLD | NEW |