Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 11 matching lines...) Expand all Loading... | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/indexeddb/IDBRequest.h" | 29 #include "modules/indexeddb/IDBRequest.h" |
| 30 | 30 |
| 31 #include <memory> | 31 #include <memory> |
| 32 #include <utility> | |
| 33 | |
| 32 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "bindings/core/v8/ToV8ForCore.h" | 35 #include "bindings/core/v8/ToV8ForCore.h" |
| 34 #include "bindings/modules/v8/ToV8ForModules.h" | 36 #include "bindings/modules/v8/ToV8ForModules.h" |
| 35 #include "bindings/modules/v8/V8BindingForModules.h" | 37 #include "bindings/modules/v8/V8BindingForModules.h" |
| 36 #include "core/dom/DOMException.h" | 38 #include "core/dom/DOMException.h" |
| 37 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
| 38 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
| 39 #include "core/events/EventQueue.h" | 41 #include "core/events/EventQueue.h" |
| 40 #include "modules/IndexedDBNames.h" | 42 #include "modules/IndexedDBNames.h" |
| 41 #include "modules/indexeddb/IDBCursorWithValue.h" | 43 #include "modules/indexeddb/IDBCursorWithValue.h" |
| 42 #include "modules/indexeddb/IDBDatabase.h" | 44 #include "modules/indexeddb/IDBDatabase.h" |
| 43 #include "modules/indexeddb/IDBEventDispatcher.h" | 45 #include "modules/indexeddb/IDBEventDispatcher.h" |
| 46 #include "modules/indexeddb/IDBRequestQueueItem.h" | |
| 44 #include "modules/indexeddb/IDBTracing.h" | 47 #include "modules/indexeddb/IDBTracing.h" |
| 45 #include "modules/indexeddb/IDBValue.h" | 48 #include "modules/indexeddb/IDBValue.h" |
| 49 #include "modules/indexeddb/IDBValueWrapping.h" | |
| 46 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | 50 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
| 47 #include "platform/SharedBuffer.h" | 51 #include "platform/SharedBuffer.h" |
| 52 #include "platform/heap/Handle.h" | |
| 53 #include "platform/wtf/PtrUtil.h" | |
| 48 #include "public/platform/WebBlobInfo.h" | 54 #include "public/platform/WebBlobInfo.h" |
| 49 | 55 |
| 50 using blink::WebIDBCursor; | 56 using blink::WebIDBCursor; |
| 51 | 57 |
| 52 namespace blink { | 58 namespace blink { |
| 53 | 59 |
| 54 IDBRequest* IDBRequest::Create(ScriptState* script_state, | 60 IDBRequest* IDBRequest::Create(ScriptState* script_state, |
| 55 IDBAny* source, | 61 IDBAny* source, |
| 56 IDBTransaction* transaction) { | 62 IDBTransaction* transaction) { |
| 57 IDBRequest* request = new IDBRequest(script_state, source, transaction); | 63 IDBRequest* request = new IDBRequest(script_state, source, transaction); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 std::unique_ptr<WebIDBCallbacks> IDBRequest::CreateWebCallbacks() { | 142 std::unique_ptr<WebIDBCallbacks> IDBRequest::CreateWebCallbacks() { |
| 137 DCHECK(!web_callbacks_); | 143 DCHECK(!web_callbacks_); |
| 138 std::unique_ptr<WebIDBCallbacks> callbacks = | 144 std::unique_ptr<WebIDBCallbacks> callbacks = |
| 139 WebIDBCallbacksImpl::Create(this); | 145 WebIDBCallbacksImpl::Create(this); |
| 140 web_callbacks_ = callbacks.get(); | 146 web_callbacks_ = callbacks.get(); |
| 141 return callbacks; | 147 return callbacks; |
| 142 } | 148 } |
| 143 | 149 |
| 144 void IDBRequest::Abort() { | 150 void IDBRequest::Abort() { |
| 145 DCHECK(!request_aborted_); | 151 DCHECK(!request_aborted_); |
| 152 if (queue_item_) { | |
| 153 queue_item_->CancelLoading(); | |
| 154 | |
| 155 // A transaction's requests are aborted in order, so each aborted request | |
| 156 // should immediately get out of the result queue. | |
| 157 DCHECK(!queue_item_); | |
| 158 } | |
| 159 | |
| 146 if (!GetExecutionContext()) | 160 if (!GetExecutionContext()) |
| 147 return; | 161 return; |
| 148 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); | 162 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); |
| 149 if (ready_state_ == DONE) | 163 if (ready_state_ == DONE) |
| 150 return; | 164 return; |
| 151 | 165 |
| 152 EventQueue* event_queue = GetExecutionContext()->GetEventQueue(); | 166 EventQueue* event_queue = GetExecutionContext()->GetEventQueue(); |
| 153 for (size_t i = 0; i < enqueued_events_.size(); ++i) { | 167 for (size_t i = 0; i < enqueued_events_.size(); ++i) { |
| 154 bool removed = event_queue->CancelEvent(enqueued_events_[i].Get()); | 168 bool removed = event_queue->CancelEvent(enqueued_events_[i].Get()); |
| 155 DCHECK(removed); | 169 DCHECK(removed); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 if (result_->GetType() == IDBAny::kIDBCursorType) | 207 if (result_->GetType() == IDBAny::kIDBCursorType) |
| 194 return result_->IdbCursor(); | 208 return result_->IdbCursor(); |
| 195 if (result_->GetType() == IDBAny::kIDBCursorWithValueType) | 209 if (result_->GetType() == IDBAny::kIDBCursorWithValueType) |
| 196 return result_->IdbCursorWithValue(); | 210 return result_->IdbCursorWithValue(); |
| 197 return nullptr; | 211 return nullptr; |
| 198 } | 212 } |
| 199 | 213 |
| 200 void IDBRequest::SetResultCursor(IDBCursor* cursor, | 214 void IDBRequest::SetResultCursor(IDBCursor* cursor, |
| 201 IDBKey* key, | 215 IDBKey* key, |
| 202 IDBKey* primary_key, | 216 IDBKey* primary_key, |
| 203 PassRefPtr<IDBValue> value) { | 217 RefPtr<IDBValue>&& value) { |
| 204 DCHECK_EQ(ready_state_, PENDING); | 218 DCHECK_EQ(ready_state_, PENDING); |
| 205 cursor_key_ = key; | 219 cursor_key_ = key; |
| 206 cursor_primary_key_ = primary_key; | 220 cursor_primary_key_ = primary_key; |
| 207 cursor_value_ = std::move(value); | 221 cursor_value_ = std::move(value); |
| 208 AckReceivedBlobs(cursor_value_.Get()); | 222 AckReceivedBlobs(cursor_value_.Get()); |
| 209 | 223 |
| 210 EnqueueResultInternal(IDBAny::Create(cursor)); | 224 EnqueueResultInternal(IDBAny::Create(cursor)); |
| 211 } | 225 } |
| 212 | 226 |
| 213 void IDBRequest::AckReceivedBlobs(const IDBValue* value) { | 227 void IDBRequest::AckReceivedBlobs(const IDBValue* value) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 227 if (!GetExecutionContext()) | 241 if (!GetExecutionContext()) |
| 228 return false; | 242 return false; |
| 229 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); | 243 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); |
| 230 if (request_aborted_) | 244 if (request_aborted_) |
| 231 return false; | 245 return false; |
| 232 DCHECK_EQ(ready_state_, PENDING); | 246 DCHECK_EQ(ready_state_, PENDING); |
| 233 DCHECK(!error_ && !result_); | 247 DCHECK(!error_ && !result_); |
| 234 return true; | 248 return true; |
| 235 } | 249 } |
| 236 | 250 |
| 251 void IDBRequest::HandleResponse(DOMException* error) { | |
| 252 transit_blob_handles_.clear(); | |
| 253 if (!transaction_ || !transaction_->HasQueuedResults()) | |
| 254 return EnqueueResponse(error); | |
| 255 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 256 this, error, | |
| 257 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 258 WrapPersistent(transaction_.Get())))); | |
| 259 } | |
| 260 | |
| 261 void IDBRequest::HandleResponse(IDBKey* key) { | |
| 262 transit_blob_handles_.clear(); | |
| 263 DCHECK(transaction_); | |
| 264 if (!transaction_->HasQueuedResults()) | |
| 265 return EnqueueResponse(key); | |
| 266 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 267 this, key, | |
| 268 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 269 WrapPersistent(transaction_.Get())))); | |
| 270 } | |
| 271 | |
| 272 void IDBRequest::HandleResponse(int64_t value_or_old_version) { | |
| 273 DCHECK(transit_blob_handles_.IsEmpty()); | |
| 274 if (!transaction_ || !transaction_->HasQueuedResults()) | |
| 275 return EnqueueResponse(value_or_old_version); | |
| 276 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 277 this, value_or_old_version, | |
| 278 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 279 WrapPersistent(transaction_.Get())))); | |
| 280 } | |
| 281 | |
| 282 void IDBRequest::HandleResponse() { | |
| 283 DCHECK(transit_blob_handles_.IsEmpty()); | |
| 284 if (!transaction_ || !transaction_->HasQueuedResults()) | |
| 285 return EnqueueResponse(); | |
| 286 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 287 this, WTF::Bind(&IDBTransaction::OnResultReady, | |
| 288 WrapPersistent(transaction_.Get())))); | |
| 289 } | |
| 290 | |
| 291 void IDBRequest::HandleResponse(std::unique_ptr<WebIDBCursor> backend, | |
| 292 IDBKey* key, | |
| 293 IDBKey* primary_key, | |
| 294 RefPtr<IDBValue>&& value) { | |
| 295 DCHECK(transit_blob_handles_.IsEmpty()); | |
| 296 DCHECK(transaction_); | |
| 297 bool is_wrapped = IDBValueUnwrapper::IsWrapped(value.Get()); | |
| 298 if (!transaction_->HasQueuedResults() && !is_wrapped) { | |
| 299 return EnqueueResponse(std::move(backend), key, primary_key, | |
| 300 std::move(value)); | |
| 301 } | |
| 302 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 303 this, std::move(backend), key, primary_key, std::move(value), is_wrapped, | |
| 304 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 305 WrapPersistent(transaction_.Get())))); | |
| 306 } | |
| 307 | |
| 308 void IDBRequest::HandleResponse(RefPtr<IDBValue>&& value) { | |
| 309 DCHECK(transit_blob_handles_.IsEmpty()); | |
| 310 DCHECK(transaction_); | |
| 311 bool is_wrapped = IDBValueUnwrapper::IsWrapped(value.Get()); | |
| 312 if (!transaction_->HasQueuedResults() && !is_wrapped) | |
| 313 return EnqueueResponse(std::move(value)); | |
| 314 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 315 this, std::move(value), is_wrapped, | |
| 316 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 317 WrapPersistent(transaction_.Get())))); | |
| 318 } | |
| 319 | |
| 320 void IDBRequest::HandleResponse(const Vector<RefPtr<IDBValue>>& values) { | |
| 321 DCHECK(transit_blob_handles_.IsEmpty()); | |
| 322 DCHECK(transaction_); | |
| 323 bool is_wrapped = IDBValueUnwrapper::IsWrapped(values); | |
| 324 if (!transaction_->HasQueuedResults() && !is_wrapped) | |
| 325 return EnqueueResponse(values); | |
| 326 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 327 this, values, is_wrapped, | |
| 328 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 329 WrapPersistent(transaction_.Get())))); | |
|
dmurph
2017/05/25 17:28:06
nit: I'm not super sure how oilpan works, I want t
dcheng
2017/05/25 18:34:04
It might be good to document how we guarantee this
pwnall
2017/05/25 20:01:10
Done.
I added a comment in this CL.
pwnall
2017/05/25 20:01:10
dmurph: You seem to understand how OilPan works pe
| |
| 330 } | |
| 331 | |
| 332 void IDBRequest::HandleResponse(IDBKey* key, | |
| 333 IDBKey* primary_key, | |
| 334 RefPtr<IDBValue>&& value) { | |
| 335 DCHECK(transit_blob_handles_.IsEmpty()); | |
| 336 DCHECK(transaction_); | |
| 337 bool is_wrapped = IDBValueUnwrapper::IsWrapped(value.Get()); | |
| 338 if (!transaction_->HasQueuedResults() && !is_wrapped) | |
| 339 return EnqueueResponse(key, primary_key, std::move(value)); | |
| 340 | |
| 341 transaction_->EnqueueResult(WTF::MakeUnique<IDBRequestQueueItem>( | |
| 342 this, key, primary_key, std::move(value), is_wrapped, | |
| 343 WTF::Bind(&IDBTransaction::OnResultReady, | |
| 344 WrapPersistent(transaction_.Get())))); | |
| 345 } | |
| 346 | |
| 237 void IDBRequest::EnqueueResponse(DOMException* error) { | 347 void IDBRequest::EnqueueResponse(DOMException* error) { |
| 238 IDB_TRACE("IDBRequest::onError()"); | 348 IDB_TRACE("IDBRequest::EnqueueResponse(DOMException)"); |
| 239 ClearPutOperationBlobs(); | |
| 240 if (!ShouldEnqueueEvent()) | 349 if (!ShouldEnqueueEvent()) |
| 241 return; | 350 return; |
| 242 | 351 |
| 243 error_ = error; | 352 error_ = error; |
| 244 SetResult(IDBAny::CreateUndefined()); | 353 SetResult(IDBAny::CreateUndefined()); |
| 245 pending_cursor_.Clear(); | 354 pending_cursor_.Clear(); |
| 246 EnqueueEvent(Event::CreateCancelableBubble(EventTypeNames::error)); | 355 EnqueueEvent(Event::CreateCancelableBubble(EventTypeNames::error)); |
| 247 } | 356 } |
| 248 | 357 |
| 249 void IDBRequest::EnqueueResponse(const Vector<String>& string_list) { | 358 void IDBRequest::EnqueueResponse(const Vector<String>& string_list) { |
| 250 IDB_TRACE("IDBRequest::onSuccess(StringList)"); | 359 IDB_TRACE("IDBRequest::onSuccess(StringList)"); |
| 251 if (!ShouldEnqueueEvent()) | 360 if (!ShouldEnqueueEvent()) |
| 252 return; | 361 return; |
| 253 | 362 |
| 254 DOMStringList* dom_string_list = DOMStringList::Create(); | 363 DOMStringList* dom_string_list = DOMStringList::Create(); |
| 255 for (size_t i = 0; i < string_list.size(); ++i) | 364 for (size_t i = 0; i < string_list.size(); ++i) |
| 256 dom_string_list->Append(string_list[i]); | 365 dom_string_list->Append(string_list[i]); |
| 257 EnqueueResultInternal(IDBAny::Create(dom_string_list)); | 366 EnqueueResultInternal(IDBAny::Create(dom_string_list)); |
| 258 } | 367 } |
| 259 | 368 |
| 260 void IDBRequest::EnqueueResponse(std::unique_ptr<WebIDBCursor> backend, | 369 void IDBRequest::EnqueueResponse(std::unique_ptr<WebIDBCursor> backend, |
| 261 IDBKey* key, | 370 IDBKey* key, |
| 262 IDBKey* primary_key, | 371 IDBKey* primary_key, |
| 263 PassRefPtr<IDBValue> value) { | 372 RefPtr<IDBValue>&& value) { |
| 264 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); | 373 IDB_TRACE("IDBRequest::EnqueueResponse(IDBCursor)"); |
| 265 if (!ShouldEnqueueEvent()) | 374 if (!ShouldEnqueueEvent()) |
| 266 return; | 375 return; |
| 267 | 376 |
| 268 DCHECK(!pending_cursor_); | 377 DCHECK(!pending_cursor_); |
| 269 IDBCursor* cursor = nullptr; | 378 IDBCursor* cursor = nullptr; |
| 270 switch (cursor_type_) { | 379 switch (cursor_type_) { |
| 271 case IndexedDB::kCursorKeyOnly: | 380 case IndexedDB::kCursorKeyOnly: |
| 272 cursor = IDBCursor::Create(std::move(backend), cursor_direction_, this, | 381 cursor = IDBCursor::Create(std::move(backend), cursor_direction_, this, |
| 273 source_.Get(), transaction_.Get()); | 382 source_.Get(), transaction_.Get()); |
| 274 break; | 383 break; |
| 275 case IndexedDB::kCursorKeyAndValue: | 384 case IndexedDB::kCursorKeyAndValue: |
| 276 cursor = | 385 cursor = |
| 277 IDBCursorWithValue::Create(std::move(backend), cursor_direction_, | 386 IDBCursorWithValue::Create(std::move(backend), cursor_direction_, |
| 278 this, source_.Get(), transaction_.Get()); | 387 this, source_.Get(), transaction_.Get()); |
| 279 break; | 388 break; |
| 280 default: | 389 default: |
| 281 NOTREACHED(); | 390 NOTREACHED(); |
| 282 } | 391 } |
| 283 SetResultCursor(cursor, key, primary_key, std::move(value)); | 392 SetResultCursor(cursor, key, primary_key, std::move(value)); |
| 284 } | 393 } |
| 285 | 394 |
| 286 void IDBRequest::EnqueueResponse(IDBKey* idb_key) { | 395 void IDBRequest::EnqueueResponse(IDBKey* idb_key) { |
| 287 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); | 396 IDB_TRACE("IDBRequest::EnqueueResponse(IDBKey)"); |
| 288 ClearPutOperationBlobs(); | |
| 289 if (!ShouldEnqueueEvent()) | 397 if (!ShouldEnqueueEvent()) |
| 290 return; | 398 return; |
| 291 | 399 |
| 292 if (idb_key && idb_key->IsValid()) | 400 if (idb_key && idb_key->IsValid()) |
| 293 EnqueueResultInternal(IDBAny::Create(idb_key)); | 401 EnqueueResultInternal(IDBAny::Create(idb_key)); |
| 294 else | 402 else |
| 295 EnqueueResultInternal(IDBAny::CreateUndefined()); | 403 EnqueueResultInternal(IDBAny::CreateUndefined()); |
| 296 } | 404 } |
| 297 | 405 |
| 298 void IDBRequest::EnqueueResponse(const Vector<RefPtr<IDBValue>>& values) { | 406 void IDBRequest::EnqueueResponse(const Vector<RefPtr<IDBValue>>& values) { |
| 299 IDB_TRACE("IDBRequest::onSuccess([IDBValue])"); | 407 IDB_TRACE("IDBRequest::EnqueueResponse([IDBValue])"); |
| 300 if (!ShouldEnqueueEvent()) | 408 if (!ShouldEnqueueEvent()) |
| 301 return; | 409 return; |
| 302 | 410 |
| 303 AckReceivedBlobs(values); | 411 AckReceivedBlobs(values); |
| 304 EnqueueResultInternal(IDBAny::Create(values)); | 412 EnqueueResultInternal(IDBAny::Create(values)); |
| 305 } | 413 } |
| 306 | 414 |
| 307 #if DCHECK_IS_ON() | 415 #if DCHECK_IS_ON() |
| 308 static IDBObjectStore* EffectiveObjectStore(IDBAny* source) { | 416 static IDBObjectStore* EffectiveObjectStore(IDBAny* source) { |
| 309 if (source->GetType() == IDBAny::kIDBObjectStoreType) | 417 if (source->GetType() == IDBAny::kIDBObjectStoreType) |
| 310 return source->IdbObjectStore(); | 418 return source->IdbObjectStore(); |
| 311 if (source->GetType() == IDBAny::kIDBIndexType) | 419 if (source->GetType() == IDBAny::kIDBIndexType) |
| 312 return source->IdbIndex()->objectStore(); | 420 return source->IdbIndex()->objectStore(); |
| 313 | 421 |
| 314 NOTREACHED(); | 422 NOTREACHED(); |
| 315 return nullptr; | 423 return nullptr; |
| 316 } | 424 } |
| 317 #endif // DCHECK_IS_ON() | 425 #endif // DCHECK_IS_ON() |
| 318 | 426 |
| 319 void IDBRequest::EnqueueResponse(PassRefPtr<IDBValue> prp_value) { | 427 void IDBRequest::EnqueueResponse(RefPtr<IDBValue>&& value) { |
| 320 IDB_TRACE("IDBRequest::onSuccess(IDBValue)"); | 428 IDB_TRACE("IDBRequest::EnqueueResponse(IDBValue)"); |
| 321 if (!ShouldEnqueueEvent()) | 429 if (!ShouldEnqueueEvent()) |
| 322 return; | 430 return; |
| 323 | 431 |
| 324 RefPtr<IDBValue> value(std::move(prp_value)); | |
| 325 AckReceivedBlobs(value.Get()); | 432 AckReceivedBlobs(value.Get()); |
| 326 | 433 |
| 327 if (pending_cursor_) { | 434 if (pending_cursor_) { |
| 328 // Value should be null, signifying the end of the cursor's range. | 435 // Value should be null, signifying the end of the cursor's range. |
| 329 DCHECK(value->IsNull()); | 436 DCHECK(value->IsNull()); |
| 330 DCHECK(!value->BlobInfo()->size()); | 437 DCHECK(!value->BlobInfo()->size()); |
| 331 pending_cursor_->Close(); | 438 pending_cursor_->Close(); |
| 332 pending_cursor_.Clear(); | 439 pending_cursor_.Clear(); |
| 333 } | 440 } |
| 334 | 441 |
| 335 #if DCHECK_IS_ON() | 442 #if DCHECK_IS_ON() |
| 336 DCHECK(!value->PrimaryKey() || | 443 DCHECK(!value->PrimaryKey() || |
| 337 value->KeyPath() == EffectiveObjectStore(source_)->IdbKeyPath()); | 444 value->KeyPath() == EffectiveObjectStore(source_)->IdbKeyPath()); |
| 338 #endif | 445 #endif |
| 339 | 446 |
| 340 EnqueueResultInternal(IDBAny::Create(value.Release())); | 447 EnqueueResultInternal(IDBAny::Create(std::move(value))); |
| 341 } | 448 } |
| 342 | 449 |
| 343 void IDBRequest::EnqueueResponse(int64_t value) { | 450 void IDBRequest::EnqueueResponse(int64_t value) { |
| 344 IDB_TRACE("IDBRequest::onSuccess(int64_t)"); | 451 IDB_TRACE("IDBRequest::EnqueueResponse(int64_t)"); |
| 345 if (!ShouldEnqueueEvent()) | 452 if (!ShouldEnqueueEvent()) |
| 346 return; | 453 return; |
| 347 EnqueueResultInternal(IDBAny::Create(value)); | 454 EnqueueResultInternal(IDBAny::Create(value)); |
| 348 } | 455 } |
| 349 | 456 |
| 350 void IDBRequest::EnqueueResponse() { | 457 void IDBRequest::EnqueueResponse() { |
| 351 IDB_TRACE("IDBRequest::onSuccess()"); | 458 IDB_TRACE("IDBRequest::EnqueueResponse()"); |
| 352 if (!ShouldEnqueueEvent()) | 459 if (!ShouldEnqueueEvent()) |
| 353 return; | 460 return; |
| 354 EnqueueResultInternal(IDBAny::CreateUndefined()); | 461 EnqueueResultInternal(IDBAny::CreateUndefined()); |
| 355 } | 462 } |
| 356 | 463 |
| 357 void IDBRequest::EnqueueResultInternal(IDBAny* result) { | 464 void IDBRequest::EnqueueResultInternal(IDBAny* result) { |
| 358 DCHECK(GetExecutionContext()); | 465 DCHECK(GetExecutionContext()); |
| 359 DCHECK(!pending_cursor_); | 466 DCHECK(!pending_cursor_); |
| 360 DCHECK(transit_blob_handles_.IsEmpty()); | 467 DCHECK(transit_blob_handles_.IsEmpty()); |
| 361 SetResult(result); | 468 SetResult(result); |
| 362 EnqueueEvent(Event::Create(EventTypeNames::success)); | 469 EnqueueEvent(Event::Create(EventTypeNames::success)); |
| 363 } | 470 } |
| 364 | 471 |
| 365 void IDBRequest::SetResult(IDBAny* result) { | 472 void IDBRequest::SetResult(IDBAny* result) { |
| 366 result_ = result; | 473 result_ = result; |
| 367 result_dirty_ = true; | 474 result_dirty_ = true; |
| 368 } | 475 } |
| 369 | 476 |
| 370 void IDBRequest::EnqueueResponse(IDBKey* key, | 477 void IDBRequest::EnqueueResponse(IDBKey* key, |
| 371 IDBKey* primary_key, | 478 IDBKey* primary_key, |
| 372 PassRefPtr<IDBValue> value) { | 479 RefPtr<IDBValue>&& value) { |
| 373 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); | 480 IDB_TRACE("IDBRequest::EnqueueResponse(IDBKey, IDBKey primaryKey, IDBValue)"); |
| 374 if (!ShouldEnqueueEvent()) | 481 if (!ShouldEnqueueEvent()) |
| 375 return; | 482 return; |
| 376 | 483 |
| 377 DCHECK(pending_cursor_); | 484 DCHECK(pending_cursor_); |
| 378 SetResultCursor(pending_cursor_.Release(), key, primary_key, | 485 SetResultCursor(pending_cursor_.Release(), key, primary_key, |
| 379 std::move(value)); | 486 std::move(value)); |
| 380 } | 487 } |
| 381 | 488 |
| 382 bool IDBRequest::HasPendingActivity() const { | 489 bool IDBRequest::HasPendingActivity() const { |
| 383 // FIXME: In an ideal world, we should return true as long as anyone has a or | 490 // FIXME: In an ideal world, we should return true as long as anyone has a or |
| 384 // can get a handle to us and we have event listeners. This is order to | 491 // can get a handle to us and we have event listeners. This is order to |
| 385 // handle user generated events properly. | 492 // handle user generated events properly. |
| 386 return has_pending_activity_ && GetExecutionContext(); | 493 return has_pending_activity_ && GetExecutionContext(); |
| 387 } | 494 } |
| 388 | 495 |
| 389 void IDBRequest::ContextDestroyed(ExecutionContext*) { | 496 void IDBRequest::ContextDestroyed(ExecutionContext*) { |
| 390 if (ready_state_ == PENDING) { | 497 if (ready_state_ == PENDING) { |
| 391 ready_state_ = kEarlyDeath; | 498 ready_state_ = kEarlyDeath; |
| 499 if (queue_item_) | |
| 500 queue_item_->CancelLoading(); | |
| 392 if (transaction_) | 501 if (transaction_) |
| 393 transaction_->UnregisterRequest(this); | 502 transaction_->UnregisterRequest(this); |
| 394 } | 503 } |
| 395 | 504 |
| 396 enqueued_events_.clear(); | 505 enqueued_events_.clear(); |
| 397 if (source_) | 506 if (source_) |
| 398 source_->ContextWillBeDestroyed(); | 507 source_->ContextWillBeDestroyed(); |
| 399 if (result_) | 508 if (result_) |
| 400 result_->ContextWillBeDestroyed(); | 509 result_->ContextWillBeDestroyed(); |
| 401 if (pending_cursor_) | 510 if (pending_cursor_) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 } | 662 } |
| 554 | 663 |
| 555 void IDBRequest::DequeueEvent(Event* event) { | 664 void IDBRequest::DequeueEvent(Event* event) { |
| 556 for (size_t i = 0; i < enqueued_events_.size(); ++i) { | 665 for (size_t i = 0; i < enqueued_events_.size(); ++i) { |
| 557 if (enqueued_events_[i].Get() == event) | 666 if (enqueued_events_[i].Get() == event) |
| 558 enqueued_events_.erase(i); | 667 enqueued_events_.erase(i); |
| 559 } | 668 } |
| 560 } | 669 } |
| 561 | 670 |
| 562 } // namespace blink | 671 } // namespace blink |
| OLD | NEW |