| 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 22 matching lines...) Expand all Loading... |
| 33 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | 33 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
| 34 #include "modules/indexeddb/IDBTracing.h" | 34 #include "modules/indexeddb/IDBTracing.h" |
| 35 #include "modules/indexeddb/IDBVersionChangeEvent.h" | 35 #include "modules/indexeddb/IDBVersionChangeEvent.h" |
| 36 | 36 |
| 37 using blink::WebIDBDatabase; | 37 using blink::WebIDBDatabase; |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 IDBOpenDBRequest* IDBOpenDBRequest::create(ScriptState* scriptState, IDBDatabase
Callbacks* callbacks, int64_t transactionId, int64_t version) | 41 IDBOpenDBRequest* IDBOpenDBRequest::create(ScriptState* scriptState, IDBDatabase
Callbacks* callbacks, int64_t transactionId, int64_t version) |
| 42 { | 42 { |
| 43 IDBOpenDBRequest* request = new IDBOpenDBRequest(scriptState, callbacks, tra
nsactionId, version); | 43 return new IDBOpenDBRequest(scriptState, callbacks, transactionId, version); |
| 44 request->suspendIfNeeded(); | |
| 45 return request; | |
| 46 } | 44 } |
| 47 | 45 |
| 48 IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* scriptState, IDBDatabaseCallback
s* callbacks, int64_t transactionId, int64_t version) | 46 IDBOpenDBRequest::IDBOpenDBRequest(ScriptState* scriptState, IDBDatabaseCallback
s* callbacks, int64_t transactionId, int64_t version) |
| 49 : IDBRequest(scriptState, IDBAny::createNull(), nullptr) | 47 : IDBRequest(scriptState, IDBAny::createNull(), nullptr) |
| 50 , m_databaseCallbacks(callbacks) | 48 , m_databaseCallbacks(callbacks) |
| 51 , m_transactionId(transactionId) | 49 , m_transactionId(transactionId) |
| 52 , m_version(version) | 50 , m_version(version) |
| 53 { | 51 { |
| 54 ASSERT(!resultAsAny()); | 52 ASSERT(!resultAsAny()); |
| 55 } | 53 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); | 72 IDB_TRACE("IDBOpenDBRequest::onBlocked()"); |
| 75 if (!shouldEnqueueEvent()) | 73 if (!shouldEnqueueEvent()) |
| 76 return; | 74 return; |
| 77 Nullable<unsigned long long> newVersionNullable = (m_version == IDBDatabaseM
etadata::DefaultVersion) ? Nullable<unsigned long long>() : Nullable<unsigned lo
ng long>(m_version); | 75 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)); | 76 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::blocked, oldVersi
on, newVersionNullable)); |
| 79 } | 77 } |
| 80 | 78 |
| 81 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassOwnPtr<WebIDBData
base> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss, Str
ing dataLossMessage) | 79 void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassOwnPtr<WebIDBData
base> backend, const IDBDatabaseMetadata& metadata, WebIDBDataLoss dataLoss, Str
ing dataLossMessage) |
| 82 { | 80 { |
| 83 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); | 81 IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()"); |
| 84 if (m_contextStopped || !executionContext()) { | 82 if (!executionContext()) { |
| 85 OwnPtr<WebIDBDatabase> db = backend; | 83 OwnPtr<WebIDBDatabase> db = backend; |
| 86 db->abort(m_transactionId); | 84 db->abort(m_transactionId); |
| 87 db->close(); | 85 db->close(); |
| 88 return; | 86 return; |
| 89 } | 87 } |
| 90 if (!shouldEnqueueEvent()) | 88 if (!shouldEnqueueEvent()) |
| 91 return; | 89 return; |
| 92 | 90 |
| 93 ASSERT(m_databaseCallbacks); | 91 ASSERT(m_databaseCallbacks); |
| 94 | 92 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 setResult(IDBAny::create(idbDatabase)); | 104 setResult(IDBAny::create(idbDatabase)); |
| 107 | 105 |
| 108 if (m_version == IDBDatabaseMetadata::NoVersion) | 106 if (m_version == IDBDatabaseMetadata::NoVersion) |
| 109 m_version = 1; | 107 m_version = 1; |
| 110 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol
dVersion, m_version, dataLoss, dataLossMessage)); | 108 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::upgradeneeded, ol
dVersion, m_version, dataLoss, dataLossMessage)); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void IDBOpenDBRequest::onSuccess(PassOwnPtr<WebIDBDatabase> backend, const IDBDa
tabaseMetadata& metadata) | 111 void IDBOpenDBRequest::onSuccess(PassOwnPtr<WebIDBDatabase> backend, const IDBDa
tabaseMetadata& metadata) |
| 114 { | 112 { |
| 115 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); | 113 IDB_TRACE("IDBOpenDBRequest::onSuccess()"); |
| 116 if (m_contextStopped || !executionContext()) { | 114 if (!executionContext()) { |
| 117 OwnPtr<WebIDBDatabase> db = backend; | 115 OwnPtr<WebIDBDatabase> db = backend; |
| 118 if (db) | 116 if (db) |
| 119 db->close(); | 117 db->close(); |
| 120 return; | 118 return; |
| 121 } | 119 } |
| 122 if (!shouldEnqueueEvent()) | 120 if (!shouldEnqueueEvent()) |
| 123 return; | 121 return; |
| 124 | 122 |
| 125 IDBDatabase* idbDatabase = nullptr; | 123 IDBDatabase* idbDatabase = nullptr; |
| 126 if (resultAsAny()) { | 124 if (resultAsAny()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 147 if (oldVersion == IDBDatabaseMetadata::NoVersion) { | 145 if (oldVersion == IDBDatabaseMetadata::NoVersion) { |
| 148 // This database hasn't had an integer version before. | 146 // This database hasn't had an integer version before. |
| 149 oldVersion = IDBDatabaseMetadata::DefaultVersion; | 147 oldVersion = IDBDatabaseMetadata::DefaultVersion; |
| 150 } | 148 } |
| 151 setResult(IDBAny::createUndefined()); | 149 setResult(IDBAny::createUndefined()); |
| 152 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi
on, Nullable<unsigned long long>())); | 150 enqueueEvent(IDBVersionChangeEvent::create(EventTypeNames::success, oldVersi
on, Nullable<unsigned long long>())); |
| 153 } | 151 } |
| 154 | 152 |
| 155 bool IDBOpenDBRequest::shouldEnqueueEvent() const | 153 bool IDBOpenDBRequest::shouldEnqueueEvent() const |
| 156 { | 154 { |
| 157 if (m_contextStopped || !executionContext()) | 155 if (!executionContext()) |
| 158 return false; | 156 return false; |
| 159 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 157 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
| 160 if (m_requestAborted) | 158 if (m_requestAborted) |
| 161 return false; | 159 return false; |
| 162 return true; | 160 return true; |
| 163 } | 161 } |
| 164 | 162 |
| 165 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(PassRefPtrWillBeRawP
tr<Event> event) | 163 DispatchEventResult IDBOpenDBRequest::dispatchEventInternal(PassRefPtrWillBeRawP
tr<Event> event) |
| 166 { | 164 { |
| 167 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, | 165 // If the connection closed between onUpgradeNeeded and the delivery of the
"success" event, |
| 168 // an "error" event should be fired instead. | 166 // an "error" event should be fired instead. |
| 169 if (event->type() == EventTypeNames::success && resultAsAny()->type() == IDB
Any::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { | 167 if (event->type() == EventTypeNames::success && resultAsAny()->type() == IDB
Any::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { |
| 170 dequeueEvent(event.get()); | 168 dequeueEvent(event.get()); |
| 171 setResult(nullptr); | 169 setResult(nullptr); |
| 172 onError(DOMException::create(AbortError, "The connection was closed.")); | 170 onError(DOMException::create(AbortError, "The connection was closed.")); |
| 173 return DispatchEventResult::CanceledBeforeDispatch; | 171 return DispatchEventResult::CanceledBeforeDispatch; |
| 174 } | 172 } |
| 175 | 173 |
| 176 return IDBRequest::dispatchEventInternal(event); | 174 return IDBRequest::dispatchEventInternal(event); |
| 177 } | 175 } |
| 178 | 176 |
| 179 } // namespace blink | 177 } // namespace blink |
| OLD | NEW |