| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); | 74 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); |
| 75 if (!shouldEnqueueEvent()) | 75 if (!shouldEnqueueEvent()) |
| 76 return; | 76 return; |
| 77 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); | 77 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); |
| 78 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); | 78 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassOwnPtr<WebIDBData
base> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss, Str
ing dataLossMessage) | 81 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassOwnPtr<WebIDBData
base> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss, Str
ing dataLossMessage) |
| 82 { | 82 { |
| 83 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); | 83 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); |
| 84 if (m_contextStopped || !executionContext()) { | 84 if (m_contextStopped || !getExecutionContext()) { |
| 85 OwnPtr<WebIDBDatabase> db = backend; | 85 OwnPtr<WebIDBDatabase> db = backend; |
| 86 db->abort(m_transactionId); | 86 db->abort(m_transactionId); |
| 87 db->close(); | 87 db->close(); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 if (!shouldEnqueueEvent()) | 90 if (!shouldEnqueueEvent()) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 ASSERT(m_databaseCallbacks); | 93 ASSERT(m_databaseCallbacks); |
| 94 | 94 |
| 95 IDBDatabase* idbDatabase = IDBDatabase::create(executionContext(), backend,
m_databaseCallbacks.release()); | 95 IDBDatabase* idbDatabase = IDBDatabase::create(getExecutionContext(), backen
d, m_databaseCallbacks.release()); |
| 96 idbDatabase->setMetadata(metadata); | 96 idbDatabase->setMetadata(metadata); |
| 97 | 97 |
| 98 if (oldVersion == IDBDatabaseMetadata::NoVersion) { | 98 if (oldVersion == IDBDatabaseMetadata::NoVersion) { |
| 99 // This database hasn't had a version before. | 99 // This database hasn't had a version before. |
| 100 oldVersion = IDBDatabaseMetadata::DefaultVersion; | 100 oldVersion = IDBDatabaseMetadata::DefaultVersion; |
| 101 } | 101 } |
| 102 IDBDatabaseMetadata oldMetadata(metadata); | 102 IDBDatabaseMetadata oldMetadata(metadata); |
| 103 oldMetadata.version = oldVersion; | 103 oldMetadata.version = oldVersion; |
| 104 | 104 |
| 105 m_transaction = IDBTransaction::create(scriptState(), m_transactionId, idbDa
tabase, this, oldMetadata); | 105 m_transaction = IDBTransaction::create(getScriptState(), m_transactionId, id
bDatabase, this, oldMetadata); |
| 106 setResult(IDBAny::create(idbDatabase)); | 106 setResult(IDBAny::create(idbDatabase)); |
| 107 | 107 |
| 108 if (m_version == IDBDatabaseMetadata::NoVersion) | 108 if (m_version == IDBDatabaseMetadata::NoVersion) |
| 109 m_version = 1; | 109 m_version = 1; |
| 110 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol
dVersion, m_version, dataLoss, dataLossMessage)); | 110 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol
dVersion, m_version, dataLoss, dataLossMessage)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void IDBOpenDBRequest::onSuccess(PassOwnPtr<WebIDBDatabase> backend, const IDBDa
tabaseMetadata& metadata) | 113 void IDBOpenDBRequest::onSuccess(PassOwnPtr<WebIDBDatabase> backend, const IDBDa
tabaseMetadata& metadata) |
| 114 { | 114 { |
| 115 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); | 115 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); |
| 116 if (m_contextStopped || !executionContext()) { | 116 if (m_contextStopped || !getExecutionContext()) { |
| 117 OwnPtr<WebIDBDatabase> db = backend; | 117 OwnPtr<WebIDBDatabase> db = backend; |
| 118 if (db) | 118 if (db) |
| 119 db->close(); | 119 db->close(); |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 if (!shouldEnqueueEvent()) | 122 if (!shouldEnqueueEvent()) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 IDBDatabase* idbDatabase = nullptr; | 125 IDBDatabase* idbDatabase = nullptr; |
| 126 if (resultAsAny()) { | 126 if (resultAsAny()) { |
| 127 // Previous onUpgradeNeeded call delivered the backend. | 127 // Previous onUpgradeNeeded call delivered the backend. |
| 128 ASSERT(!backend.get()); | 128 ASSERT(!backend.get()); |
| 129 idbDatabase = resultAsAny()->idbDatabase(); | 129 idbDatabase = resultAsAny()->idbDatabase(); |
| 130 ASSERT(idbDatabase); | 130 ASSERT(idbDatabase); |
| 131 ASSERT(!m_databaseCallbacks); | 131 ASSERT(!m_databaseCallbacks); |
| 132 } else { | 132 } else { |
| 133 ASSERT(backend.get()); | 133 ASSERT(backend.get()); |
| 134 ASSERT(m_databaseCallbacks); | 134 ASSERT(m_databaseCallbacks); |
| 135 idbDatabase = IDBDatabase::create(executionContext(), backend, m_databas
eCallbacks.release()); | 135 idbDatabase = IDBDatabase::create(getExecutionContext(), backend, m_data
baseCallbacks.release()); |
| 136 setResult(IDBAny::create(idbDatabase)); | 136 setResult(IDBAny::create(idbDatabase)); |
| 137 } | 137 } |
| 138 idbDatabase->setMetadata(metadata); | 138 idbDatabase->setMetadata(metadata); |
| 139 enqueueEvent(Event::create(EventTypeNames::success)); | 139 enqueueEvent(Event::create(EventTypeNames::success)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void IDBOpenDBRequest::onSuccess(int64_t oldVersion) | 142 void IDBOpenDBRequest::onSuccess(int64_t oldVersion) |
| 143 { | 143 { |
| 144 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); | 144 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); |
| 145 if (!shouldEnqueueEvent()) | 145 if (!shouldEnqueueEvent()) |
| 146 return; | 146 return; |
| 147 if (oldVersion == IDBDatabaseMetadata::NoVersion) { | 147 if (oldVersion == IDBDatabaseMetadata::NoVersion) { |
| 148 // This database hasn't had an integer version before. | 148 // This database hasn't had an integer version before. |
| 149 oldVersion = IDBDatabaseMetadata::DefaultVersion; | 149 oldVersion = IDBDatabaseMetadata::DefaultVersion; |
| 150 } | 150 } |
| 151 setResult(IDBAny::createUndefined()); | 151 setResult(IDBAny::createUndefined()); |
| 152 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi
on, Nullable<unsigned long long>())); | 152 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi
on, Nullable<unsigned long long>())); |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool IDBOpenDBRequest::shouldEnqueueEvent() const | 155 bool IDBOpenDBRequest::shouldEnqueueEvent() const |
| 156 { | 156 { |
| 157 if (m_contextStopped || !executionContext()) | 157 if (m_contextStopped || !getExecutionContext()) |
| 158 return false; | 158 return false; |
| 159 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 159 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
| 160 if (m_requestAborted) | 160 if (m_requestAborted) |
| 161 return false; | 161 return false; |
| 162 return true; | 162 return true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(PassRefPtrWillBeRawP
tr<Event> event) | 165 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(PassRefPtrWillBeRawP
tr<Event> event) |
| 166 { | 166 { |
| 167 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, | 167 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, |
| 168 // an "error" event should be fired instead. | 168 // an "error" event should be fired instead. |
| 169 if (event->type() == EventTypeNames::success && resultAsAny()->getType() ==
IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { | 169 if (event->type() == EventTypeNames::success && resultAsAny()->getType() ==
IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { |
| 170 dequeueEvent(event.get()); | 170 dequeueEvent(event.get()); |
| 171 setResult(nullptr); | 171 setResult(nullptr); |
| 172 onError(DOMException::create(AbortError, "The connection was closed.")); | 172 onError(DOMException::create(AbortError, "The connection was closed.")); |
| 173 return DispatchEventResult::CanceledBeforeDispatch; | 173 return DispatchEventResult::CanceledBeforeDispatch; |
| 174 } | 174 } |
| 175 | 175 |
| 176 return IDBRequest::dispatchEventInternal(event); | 176 return IDBRequest::dispatchEventInternal(event); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |