| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 EventQueue* event_queue = GetExecutionContext()->GetEventQueue(); | 157 EventQueue* event_queue = GetExecutionContext()->GetEventQueue(); |
| 158 for (size_t i = 0; i < enqueued_events_.size(); ++i) { | 158 for (size_t i = 0; i < enqueued_events_.size(); ++i) { |
| 159 bool removed = event_queue->CancelEvent(enqueued_events_[i].Get()); | 159 bool removed = event_queue->CancelEvent(enqueued_events_[i].Get()); |
| 160 DCHECK(removed); | 160 DCHECK(removed); |
| 161 } | 161 } |
| 162 enqueued_events_.clear(); | 162 enqueued_events_.clear(); |
| 163 | 163 |
| 164 error_.Clear(); | 164 error_.Clear(); |
| 165 result_.Clear(); | 165 result_.Clear(); |
| 166 OnError(DOMException::Create( | 166 EnqueueResponse(DOMException::Create( |
| 167 kAbortError, | 167 kAbortError, |
| 168 "The transaction was aborted, so the request cannot be fulfilled.")); | 168 "The transaction was aborted, so the request cannot be fulfilled.")); |
| 169 request_aborted_ = true; | 169 request_aborted_ = true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void IDBRequest::SetCursorDetails(IndexedDB::CursorType cursor_type, | 172 void IDBRequest::SetCursorDetails(IndexedDB::CursorType cursor_type, |
| 173 WebIDBCursorDirection direction) { | 173 WebIDBCursorDirection direction) { |
| 174 DCHECK_EQ(ready_state_, PENDING); | 174 DCHECK_EQ(ready_state_, PENDING); |
| 175 DCHECK(!pending_cursor_); | 175 DCHECK(!pending_cursor_); |
| 176 cursor_type_ = cursor_type; | 176 cursor_type_ = cursor_type; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 205 void IDBRequest::SetResultCursor(IDBCursor* cursor, | 205 void IDBRequest::SetResultCursor(IDBCursor* cursor, |
| 206 IDBKey* key, | 206 IDBKey* key, |
| 207 IDBKey* primary_key, | 207 IDBKey* primary_key, |
| 208 PassRefPtr<IDBValue> value) { | 208 PassRefPtr<IDBValue> value) { |
| 209 DCHECK_EQ(ready_state_, PENDING); | 209 DCHECK_EQ(ready_state_, PENDING); |
| 210 cursor_key_ = key; | 210 cursor_key_ = key; |
| 211 cursor_primary_key_ = primary_key; | 211 cursor_primary_key_ = primary_key; |
| 212 cursor_value_ = std::move(value); | 212 cursor_value_ = std::move(value); |
| 213 AckReceivedBlobs(cursor_value_.Get()); | 213 AckReceivedBlobs(cursor_value_.Get()); |
| 214 | 214 |
| 215 OnSuccessInternal(IDBAny::Create(cursor)); | 215 EnqueueResultInternal(IDBAny::Create(cursor)); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void IDBRequest::AckReceivedBlobs(const IDBValue* value) { | 218 void IDBRequest::AckReceivedBlobs(const IDBValue* value) { |
| 219 if (!transaction_ || !transaction_->BackendDB()) | 219 if (!transaction_ || !transaction_->BackendDB()) |
| 220 return; | 220 return; |
| 221 Vector<String> uuids = value->GetUUIDs(); | 221 Vector<String> uuids = value->GetUUIDs(); |
| 222 if (!uuids.IsEmpty()) | 222 if (!uuids.IsEmpty()) |
| 223 transaction_->BackendDB()->AckReceivedBlobs(uuids); | 223 transaction_->BackendDB()->AckReceivedBlobs(uuids); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void IDBRequest::AckReceivedBlobs(const Vector<RefPtr<IDBValue>>& values) { | 226 void IDBRequest::AckReceivedBlobs(const Vector<RefPtr<IDBValue>>& values) { |
| 227 for (size_t i = 0; i < values.size(); ++i) | 227 for (size_t i = 0; i < values.size(); ++i) |
| 228 AckReceivedBlobs(values[i].Get()); | 228 AckReceivedBlobs(values[i].Get()); |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool IDBRequest::ShouldEnqueueEvent() const { | 231 bool IDBRequest::ShouldEnqueueEvent() const { |
| 232 if (!GetExecutionContext()) | 232 if (!GetExecutionContext()) |
| 233 return false; | 233 return false; |
| 234 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); | 234 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); |
| 235 if (request_aborted_) | 235 if (request_aborted_) |
| 236 return false; | 236 return false; |
| 237 DCHECK_EQ(ready_state_, PENDING); | 237 DCHECK_EQ(ready_state_, PENDING); |
| 238 DCHECK(!error_ && !result_); | 238 DCHECK(!error_ && !result_); |
| 239 return true; | 239 return true; |
| 240 } | 240 } |
| 241 | 241 |
| 242 void IDBRequest::OnError(DOMException* error) { | 242 void IDBRequest::EnqueueResponse(DOMException* error) { |
| 243 IDB_TRACE("IDBRequest::onError()"); | 243 IDB_TRACE("IDBRequest::onError()"); |
| 244 ClearPutOperationBlobs(); | 244 ClearPutOperationBlobs(); |
| 245 if (!ShouldEnqueueEvent()) | 245 if (!ShouldEnqueueEvent()) |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 error_ = error; | 248 error_ = error; |
| 249 SetResult(IDBAny::CreateUndefined()); | 249 SetResult(IDBAny::CreateUndefined()); |
| 250 pending_cursor_.Clear(); | 250 pending_cursor_.Clear(); |
| 251 EnqueueEvent(Event::CreateCancelableBubble(EventTypeNames::error)); | 251 EnqueueEvent(Event::CreateCancelableBubble(EventTypeNames::error)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void IDBRequest::OnSuccess(const Vector<String>& string_list) { | 254 void IDBRequest::EnqueueResponse(const Vector<String>& string_list) { |
| 255 IDB_TRACE("IDBRequest::onSuccess(StringList)"); | 255 IDB_TRACE("IDBRequest::onSuccess(StringList)"); |
| 256 if (!ShouldEnqueueEvent()) | 256 if (!ShouldEnqueueEvent()) |
| 257 return; | 257 return; |
| 258 | 258 |
| 259 DOMStringList* dom_string_list = DOMStringList::Create(); | 259 DOMStringList* dom_string_list = DOMStringList::Create(); |
| 260 for (size_t i = 0; i < string_list.size(); ++i) | 260 for (size_t i = 0; i < string_list.size(); ++i) |
| 261 dom_string_list->Append(string_list[i]); | 261 dom_string_list->Append(string_list[i]); |
| 262 OnSuccessInternal(IDBAny::Create(dom_string_list)); | 262 EnqueueResultInternal(IDBAny::Create(dom_string_list)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void IDBRequest::OnSuccess(std::unique_ptr<WebIDBCursor> backend, | 265 void IDBRequest::EnqueueResponse(std::unique_ptr<WebIDBCursor> backend, |
| 266 IDBKey* key, | 266 IDBKey* key, |
| 267 IDBKey* primary_key, | 267 IDBKey* primary_key, |
| 268 PassRefPtr<IDBValue> value) { | 268 PassRefPtr<IDBValue> value) { |
| 269 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); | 269 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); |
| 270 if (!ShouldEnqueueEvent()) | 270 if (!ShouldEnqueueEvent()) |
| 271 return; | 271 return; |
| 272 | 272 |
| 273 DCHECK(!pending_cursor_); | 273 DCHECK(!pending_cursor_); |
| 274 IDBCursor* cursor = nullptr; | 274 IDBCursor* cursor = nullptr; |
| 275 switch (cursor_type_) { | 275 switch (cursor_type_) { |
| 276 case IndexedDB::kCursorKeyOnly: | 276 case IndexedDB::kCursorKeyOnly: |
| 277 cursor = IDBCursor::Create(std::move(backend), cursor_direction_, this, | 277 cursor = IDBCursor::Create(std::move(backend), cursor_direction_, this, |
| 278 source_.Get(), transaction_.Get()); | 278 source_.Get(), transaction_.Get()); |
| 279 break; | 279 break; |
| 280 case IndexedDB::kCursorKeyAndValue: | 280 case IndexedDB::kCursorKeyAndValue: |
| 281 cursor = | 281 cursor = |
| 282 IDBCursorWithValue::Create(std::move(backend), cursor_direction_, | 282 IDBCursorWithValue::Create(std::move(backend), cursor_direction_, |
| 283 this, source_.Get(), transaction_.Get()); | 283 this, source_.Get(), transaction_.Get()); |
| 284 break; | 284 break; |
| 285 default: | 285 default: |
| 286 NOTREACHED(); | 286 NOTREACHED(); |
| 287 } | 287 } |
| 288 SetResultCursor(cursor, key, primary_key, std::move(value)); | 288 SetResultCursor(cursor, key, primary_key, std::move(value)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void IDBRequest::OnSuccess(IDBKey* idb_key) { | 291 void IDBRequest::EnqueueResponse(IDBKey* idb_key) { |
| 292 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); | 292 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); |
| 293 ClearPutOperationBlobs(); | 293 ClearPutOperationBlobs(); |
| 294 if (!ShouldEnqueueEvent()) | 294 if (!ShouldEnqueueEvent()) |
| 295 return; | 295 return; |
| 296 | 296 |
| 297 if (idb_key && idb_key->IsValid()) | 297 if (idb_key && idb_key->IsValid()) |
| 298 OnSuccessInternal(IDBAny::Create(idb_key)); | 298 EnqueueResultInternal(IDBAny::Create(idb_key)); |
| 299 else | 299 else |
| 300 OnSuccessInternal(IDBAny::CreateUndefined()); | 300 EnqueueResultInternal(IDBAny::CreateUndefined()); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void IDBRequest::OnSuccess(const Vector<RefPtr<IDBValue>>& values) { | 303 void IDBRequest::EnqueueResponse(const Vector<RefPtr<IDBValue>>& values) { |
| 304 IDB_TRACE("IDBRequest::onSuccess([IDBValue])"); | 304 IDB_TRACE("IDBRequest::onSuccess([IDBValue])"); |
| 305 if (!ShouldEnqueueEvent()) | 305 if (!ShouldEnqueueEvent()) |
| 306 return; | 306 return; |
| 307 | 307 |
| 308 AckReceivedBlobs(values); | 308 AckReceivedBlobs(values); |
| 309 OnSuccessInternal(IDBAny::Create(values)); | 309 EnqueueResultInternal(IDBAny::Create(values)); |
| 310 } | 310 } |
| 311 | 311 |
| 312 #if DCHECK_IS_ON() | 312 #if DCHECK_IS_ON() |
| 313 static IDBObjectStore* EffectiveObjectStore(IDBAny* source) { | 313 static IDBObjectStore* EffectiveObjectStore(IDBAny* source) { |
| 314 if (source->GetType() == IDBAny::kIDBObjectStoreType) | 314 if (source->GetType() == IDBAny::kIDBObjectStoreType) |
| 315 return source->IdbObjectStore(); | 315 return source->IdbObjectStore(); |
| 316 if (source->GetType() == IDBAny::kIDBIndexType) | 316 if (source->GetType() == IDBAny::kIDBIndexType) |
| 317 return source->IdbIndex()->objectStore(); | 317 return source->IdbIndex()->objectStore(); |
| 318 | 318 |
| 319 NOTREACHED(); | 319 NOTREACHED(); |
| 320 return nullptr; | 320 return nullptr; |
| 321 } | 321 } |
| 322 #endif // DCHECK_IS_ON() | 322 #endif // DCHECK_IS_ON() |
| 323 | 323 |
| 324 void IDBRequest::OnSuccess(PassRefPtr<IDBValue> prp_value) { | 324 void IDBRequest::EnqueueResponse(PassRefPtr<IDBValue> prp_value) { |
| 325 IDB_TRACE("IDBRequest::onSuccess(IDBValue)"); | 325 IDB_TRACE("IDBRequest::onSuccess(IDBValue)"); |
| 326 if (!ShouldEnqueueEvent()) | 326 if (!ShouldEnqueueEvent()) |
| 327 return; | 327 return; |
| 328 | 328 |
| 329 RefPtr<IDBValue> value(std::move(prp_value)); | 329 RefPtr<IDBValue> value(std::move(prp_value)); |
| 330 AckReceivedBlobs(value.Get()); | 330 AckReceivedBlobs(value.Get()); |
| 331 | 331 |
| 332 if (pending_cursor_) { | 332 if (pending_cursor_) { |
| 333 // Value should be null, signifying the end of the cursor's range. | 333 // Value should be null, signifying the end of the cursor's range. |
| 334 DCHECK(value->IsNull()); | 334 DCHECK(value->IsNull()); |
| 335 DCHECK(!value->BlobInfo()->size()); | 335 DCHECK(!value->BlobInfo()->size()); |
| 336 pending_cursor_->Close(); | 336 pending_cursor_->Close(); |
| 337 pending_cursor_.Clear(); | 337 pending_cursor_.Clear(); |
| 338 } | 338 } |
| 339 | 339 |
| 340 #if DCHECK_IS_ON() | 340 #if DCHECK_IS_ON() |
| 341 DCHECK(!value->PrimaryKey() || | 341 DCHECK(!value->PrimaryKey() || |
| 342 value->KeyPath() == EffectiveObjectStore(source_)->IdbKeyPath()); | 342 value->KeyPath() == EffectiveObjectStore(source_)->IdbKeyPath()); |
| 343 #endif | 343 #endif |
| 344 | 344 |
| 345 OnSuccessInternal(IDBAny::Create(value.Release())); | 345 EnqueueResultInternal(IDBAny::Create(value.Release())); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void IDBRequest::OnSuccess(int64_t value) { | 348 void IDBRequest::EnqueueResponse(int64_t value) { |
| 349 IDB_TRACE("IDBRequest::onSuccess(int64_t)"); | 349 IDB_TRACE("IDBRequest::onSuccess(int64_t)"); |
| 350 if (!ShouldEnqueueEvent()) | 350 if (!ShouldEnqueueEvent()) |
| 351 return; | 351 return; |
| 352 OnSuccessInternal(IDBAny::Create(value)); | 352 EnqueueResultInternal(IDBAny::Create(value)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void IDBRequest::OnSuccess() { | 355 void IDBRequest::EnqueueResponse() { |
| 356 IDB_TRACE("IDBRequest::onSuccess()"); | 356 IDB_TRACE("IDBRequest::onSuccess()"); |
| 357 if (!ShouldEnqueueEvent()) | 357 if (!ShouldEnqueueEvent()) |
| 358 return; | 358 return; |
| 359 OnSuccessInternal(IDBAny::CreateUndefined()); | 359 EnqueueResultInternal(IDBAny::CreateUndefined()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void IDBRequest::OnSuccessInternal(IDBAny* result) { | 362 void IDBRequest::EnqueueResultInternal(IDBAny* result) { |
| 363 DCHECK(GetExecutionContext()); | 363 DCHECK(GetExecutionContext()); |
| 364 DCHECK(!pending_cursor_); | 364 DCHECK(!pending_cursor_); |
| 365 DCHECK(transit_blob_handles_.IsEmpty()); | 365 DCHECK(transit_blob_handles_.IsEmpty()); |
| 366 SetResult(result); | 366 SetResult(result); |
| 367 EnqueueEvent(Event::Create(EventTypeNames::success)); | 367 EnqueueEvent(Event::Create(EventTypeNames::success)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void IDBRequest::SetResult(IDBAny* result) { | 370 void IDBRequest::SetResult(IDBAny* result) { |
| 371 result_ = result; | 371 result_ = result; |
| 372 result_dirty_ = true; | 372 result_dirty_ = true; |
| 373 } | 373 } |
| 374 | 374 |
| 375 void IDBRequest::OnSuccess(IDBKey* key, | 375 void IDBRequest::EnqueueResponse(IDBKey* key, |
| 376 IDBKey* primary_key, | 376 IDBKey* primary_key, |
| 377 PassRefPtr<IDBValue> value) { | 377 PassRefPtr<IDBValue> value) { |
| 378 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); | 378 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); |
| 379 if (!ShouldEnqueueEvent()) | 379 if (!ShouldEnqueueEvent()) |
| 380 return; | 380 return; |
| 381 | 381 |
| 382 DCHECK(pending_cursor_); | 382 DCHECK(pending_cursor_); |
| 383 SetResultCursor(pending_cursor_.Release(), key, primary_key, | 383 SetResultCursor(pending_cursor_.Release(), key, primary_key, |
| 384 std::move(value)); | 384 std::move(value)); |
| 385 } | 385 } |
| 386 | 386 |
| 387 bool IDBRequest::HasPendingActivity() const { | 387 bool IDBRequest::HasPendingActivity() const { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 556 } |
| 557 | 557 |
| 558 void IDBRequest::DequeueEvent(Event* event) { | 558 void IDBRequest::DequeueEvent(Event* event) { |
| 559 for (size_t i = 0; i < enqueued_events_.size(); ++i) { | 559 for (size_t i = 0; i < enqueued_events_.size(); ++i) { |
| 560 if (enqueued_events_[i].Get() == event) | 560 if (enqueued_events_[i].Get() == event) |
| 561 enqueued_events_.erase(i); | 561 enqueued_events_.erase(i); |
| 562 } | 562 } |
| 563 } | 563 } |
| 564 | 564 |
| 565 } // namespace blink | 565 } // namespace blink |
| OLD | NEW |