| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 if (!wrapper.IsEmpty()) { | 95 if (!wrapper.IsEmpty()) { |
| 96 V8PrivateProperty::GetIDBCursorRequest(isolate).Set( | 96 V8PrivateProperty::GetIDBCursorRequest(isolate).Set( |
| 97 wrapper, ToV8(request_.Get(), wrapper, isolate)); | 97 wrapper, ToV8(request_.Get(), wrapper, isolate)); |
| 98 } | 98 } |
| 99 return wrapper; | 99 return wrapper; |
| 100 } | 100 } |
| 101 | 101 |
| 102 IDBRequest* IDBCursor::update(ScriptState* script_state, | 102 IDBRequest* IDBCursor::update(ScriptState* script_state, |
| 103 const ScriptValue& value, | 103 const ScriptValue& value, |
| 104 ExceptionState& exception_state) { | 104 ExceptionState& exception_state) { |
| 105 IDB_TRACE("IDBCursor::update"); | 105 IDB_TRACE("IDBCursor::updateCall"); |
| 106 | |
| 107 if (!transaction_->IsActive()) { | 106 if (!transaction_->IsActive()) { |
| 108 exception_state.ThrowDOMException(kTransactionInactiveError, | 107 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 109 transaction_->InactiveErrorMessage()); | 108 transaction_->InactiveErrorMessage()); |
| 110 return nullptr; | 109 return nullptr; |
| 111 } | 110 } |
| 112 if (transaction_->IsReadOnly()) { | 111 if (transaction_->IsReadOnly()) { |
| 113 exception_state.ThrowDOMException( | 112 exception_state.ThrowDOMException( |
| 114 kReadOnlyError, | 113 kReadOnlyError, |
| 115 "The record may not be updated inside a read-only transaction."); | 114 "The record may not be updated inside a read-only transaction."); |
| 116 return nullptr; | 115 return nullptr; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 131 return nullptr; | 130 return nullptr; |
| 132 } | 131 } |
| 133 | 132 |
| 134 IDBObjectStore* object_store = EffectiveObjectStore(); | 133 IDBObjectStore* object_store = EffectiveObjectStore(); |
| 135 return object_store->put(script_state, kWebIDBPutModeCursorUpdate, | 134 return object_store->put(script_state, kWebIDBPutModeCursorUpdate, |
| 136 IDBAny::Create(this), value, primary_key_, | 135 IDBAny::Create(this), value, primary_key_, |
| 137 exception_state); | 136 exception_state); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void IDBCursor::advance(unsigned count, ExceptionState& exception_state) { | 139 void IDBCursor::advance(unsigned count, ExceptionState& exception_state) { |
| 141 IDB_TRACE("IDBCursor::advance"); | 140 IDB_TRACE("IDBCursor::advanceCall"); |
| 141 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>( |
| 142 nullptr, "IDBCursor::advance", this); |
| 142 if (!count) { | 143 if (!count) { |
| 143 exception_state.ThrowTypeError( | 144 exception_state.ThrowTypeError( |
| 144 "A count argument with value 0 (zero) was supplied, must be greater " | 145 "A count argument with value 0 (zero) was supplied, must be greater " |
| 145 "than 0."); | 146 "than 0."); |
| 146 return; | 147 return; |
| 147 } | 148 } |
| 148 if (!transaction_->IsActive()) { | 149 if (!transaction_->IsActive()) { |
| 149 exception_state.ThrowDOMException(kTransactionInactiveError, | 150 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 150 transaction_->InactiveErrorMessage()); | 151 transaction_->InactiveErrorMessage()); |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 if (IsDeleted()) { | 154 if (IsDeleted()) { |
| 154 exception_state.ThrowDOMException(kInvalidStateError, | 155 exception_state.ThrowDOMException(kInvalidStateError, |
| 155 IDBDatabase::kSourceDeletedErrorMessage); | 156 IDBDatabase::kSourceDeletedErrorMessage); |
| 156 return; | 157 return; |
| 157 } | 158 } |
| 158 if (!got_value_) { | 159 if (!got_value_) { |
| 159 exception_state.ThrowDOMException(kInvalidStateError, | 160 exception_state.ThrowDOMException(kInvalidStateError, |
| 160 IDBDatabase::kNoValueErrorMessage); | 161 IDBDatabase::kNoValueErrorMessage); |
| 161 return; | 162 return; |
| 162 } | 163 } |
| 163 | 164 |
| 164 request_->SetPendingCursor(this); | 165 request_->SetPendingCursor(this); |
| 166 request_->AssignNewMetrics(std::move(metrics)); |
| 165 got_value_ = false; | 167 got_value_ = false; |
| 166 backend_->Advance(count, request_->CreateWebCallbacks().release()); | 168 backend_->Advance(count, request_->CreateWebCallbacks().release()); |
| 167 } | 169 } |
| 168 | 170 |
| 169 void IDBCursor::continueFunction(ScriptState* script_state, | 171 void IDBCursor::continueFunction(ScriptState* script_state, |
| 170 const ScriptValue& key_value, | 172 const ScriptValue& key_value, |
| 171 ExceptionState& exception_state) { | 173 ExceptionState& exception_state) { |
| 172 IDB_TRACE("IDBCursor::continue"); | 174 IDB_TRACE("IDBCursor::continueCall"); |
| 175 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>( |
| 176 nullptr, "IDBCursor::continue", this); |
| 173 | 177 |
| 174 if (!transaction_->IsActive()) { | 178 if (!transaction_->IsActive()) { |
| 175 exception_state.ThrowDOMException(kTransactionInactiveError, | 179 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 176 transaction_->InactiveErrorMessage()); | 180 transaction_->InactiveErrorMessage()); |
| 177 return; | 181 return; |
| 178 } | 182 } |
| 179 if (!got_value_) { | 183 if (!got_value_) { |
| 180 exception_state.ThrowDOMException(kInvalidStateError, | 184 exception_state.ThrowDOMException(kInvalidStateError, |
| 181 IDBDatabase::kNoValueErrorMessage); | 185 IDBDatabase::kNoValueErrorMessage); |
| 182 return; | 186 return; |
| 183 } | 187 } |
| 184 if (IsDeleted()) { | 188 if (IsDeleted()) { |
| 185 exception_state.ThrowDOMException(kInvalidStateError, | 189 exception_state.ThrowDOMException(kInvalidStateError, |
| 186 IDBDatabase::kSourceDeletedErrorMessage); | 190 IDBDatabase::kSourceDeletedErrorMessage); |
| 187 return; | 191 return; |
| 188 } | 192 } |
| 189 | 193 |
| 190 IDBKey* key = key_value.IsUndefined() || key_value.IsNull() | 194 IDBKey* key = key_value.IsUndefined() || key_value.IsNull() |
| 191 ? nullptr | 195 ? nullptr |
| 192 : ScriptValue::To<IDBKey*>(script_state->GetIsolate(), | 196 : ScriptValue::To<IDBKey*>(script_state->GetIsolate(), |
| 193 key_value, exception_state); | 197 key_value, exception_state); |
| 194 if (exception_state.HadException()) | 198 if (exception_state.HadException()) |
| 195 return; | 199 return; |
| 196 if (key && !key->IsValid()) { | 200 if (key && !key->IsValid()) { |
| 197 exception_state.ThrowDOMException(kDataError, | 201 exception_state.ThrowDOMException(kDataError, |
| 198 IDBDatabase::kNotValidKeyErrorMessage); | 202 IDBDatabase::kNotValidKeyErrorMessage); |
| 199 return; | 203 return; |
| 200 } | 204 } |
| 205 request_->AssignNewMetrics(std::move(metrics)); |
| 201 Continue(key, nullptr, exception_state); | 206 Continue(key, nullptr, exception_state); |
| 202 } | 207 } |
| 203 | 208 |
| 204 void IDBCursor::continuePrimaryKey(ScriptState* script_state, | 209 void IDBCursor::continuePrimaryKey(ScriptState* script_state, |
| 205 const ScriptValue& key_value, | 210 const ScriptValue& key_value, |
| 206 const ScriptValue& primary_key_value, | 211 const ScriptValue& primary_key_value, |
| 207 ExceptionState& exception_state) { | 212 ExceptionState& exception_state) { |
| 208 IDB_TRACE("IDBCursor::continuePrimaryKey"); | 213 IDB_TRACE("IDBCursor::continuePrimaryKeyCall"); |
| 214 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>( |
| 215 nullptr, "IDBCursor::continuePrimaryKey", this); |
| 209 | 216 |
| 210 if (!transaction_->IsActive()) { | 217 if (!transaction_->IsActive()) { |
| 211 exception_state.ThrowDOMException(kTransactionInactiveError, | 218 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 212 transaction_->InactiveErrorMessage()); | 219 transaction_->InactiveErrorMessage()); |
| 213 return; | 220 return; |
| 214 } | 221 } |
| 215 | 222 |
| 216 if (IsDeleted()) { | 223 if (IsDeleted()) { |
| 217 exception_state.ThrowDOMException(kInvalidStateError, | 224 exception_state.ThrowDOMException(kInvalidStateError, |
| 218 IDBDatabase::kSourceDeletedErrorMessage); | 225 IDBDatabase::kSourceDeletedErrorMessage); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 IDBKey* primary_key = ScriptValue::To<IDBKey*>( | 258 IDBKey* primary_key = ScriptValue::To<IDBKey*>( |
| 252 script_state->GetIsolate(), primary_key_value, exception_state); | 259 script_state->GetIsolate(), primary_key_value, exception_state); |
| 253 if (exception_state.HadException()) | 260 if (exception_state.HadException()) |
| 254 return; | 261 return; |
| 255 if (!primary_key->IsValid()) { | 262 if (!primary_key->IsValid()) { |
| 256 exception_state.ThrowDOMException(kDataError, | 263 exception_state.ThrowDOMException(kDataError, |
| 257 IDBDatabase::kNotValidKeyErrorMessage); | 264 IDBDatabase::kNotValidKeyErrorMessage); |
| 258 return; | 265 return; |
| 259 } | 266 } |
| 260 | 267 |
| 268 request_->AssignNewMetrics(std::move(metrics)); |
| 261 Continue(key, primary_key, exception_state); | 269 Continue(key, primary_key, exception_state); |
| 262 } | 270 } |
| 263 | 271 |
| 264 void IDBCursor::Continue(IDBKey* key, | 272 void IDBCursor::Continue(IDBKey* key, |
| 265 IDBKey* primary_key, | 273 IDBKey* primary_key, |
| 266 ExceptionState& exception_state) { | 274 ExceptionState& exception_state) { |
| 267 DCHECK(transaction_->IsActive()); | 275 DCHECK(transaction_->IsActive()); |
| 268 DCHECK(got_value_); | 276 DCHECK(got_value_); |
| 269 DCHECK(!IsDeleted()); | 277 DCHECK(!IsDeleted()); |
| 270 DCHECK(!primary_key || (key && primary_key)); | 278 DCHECK(!primary_key || (key && primary_key)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 300 // means the callback will be on the original context openCursor was called | 308 // means the callback will be on the original context openCursor was called |
| 301 // on. Is this right? | 309 // on. Is this right? |
| 302 request_->SetPendingCursor(this); | 310 request_->SetPendingCursor(this); |
| 303 got_value_ = false; | 311 got_value_ = false; |
| 304 backend_->ContinueFunction(key, primary_key, | 312 backend_->ContinueFunction(key, primary_key, |
| 305 request_->CreateWebCallbacks().release()); | 313 request_->CreateWebCallbacks().release()); |
| 306 } | 314 } |
| 307 | 315 |
| 308 IDBRequest* IDBCursor::deleteFunction(ScriptState* script_state, | 316 IDBRequest* IDBCursor::deleteFunction(ScriptState* script_state, |
| 309 ExceptionState& exception_state) { | 317 ExceptionState& exception_state) { |
| 310 IDB_TRACE("IDBCursor::delete"); | 318 IDB_TRACE("IDBCursor::deleteCall"); |
| 319 auto metrics = WTF::MakeUnique<IDBRequest::ScopedMetricsTracker>( |
| 320 nullptr, "IDBCursor::delete", this); |
| 311 if (!transaction_->IsActive()) { | 321 if (!transaction_->IsActive()) { |
| 312 exception_state.ThrowDOMException(kTransactionInactiveError, | 322 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 313 transaction_->InactiveErrorMessage()); | 323 transaction_->InactiveErrorMessage()); |
| 314 return nullptr; | 324 return nullptr; |
| 315 } | 325 } |
| 316 if (transaction_->IsReadOnly()) { | 326 if (transaction_->IsReadOnly()) { |
| 317 exception_state.ThrowDOMException( | 327 exception_state.ThrowDOMException( |
| 318 kReadOnlyError, | 328 kReadOnlyError, |
| 319 "The record may not be deleted inside a read-only transaction."); | 329 "The record may not be deleted inside a read-only transaction."); |
| 320 return nullptr; | 330 return nullptr; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 336 } | 346 } |
| 337 if (!transaction_->BackendDB()) { | 347 if (!transaction_->BackendDB()) { |
| 338 exception_state.ThrowDOMException(kInvalidStateError, | 348 exception_state.ThrowDOMException(kInvalidStateError, |
| 339 IDBDatabase::kDatabaseClosedErrorMessage); | 349 IDBDatabase::kDatabaseClosedErrorMessage); |
| 340 return nullptr; | 350 return nullptr; |
| 341 } | 351 } |
| 342 | 352 |
| 343 IDBKeyRange* key_range = IDBKeyRange::only(primary_key_, exception_state); | 353 IDBKeyRange* key_range = IDBKeyRange::only(primary_key_, exception_state); |
| 344 DCHECK(!exception_state.HadException()); | 354 DCHECK(!exception_state.HadException()); |
| 345 | 355 |
| 346 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 356 IDBRequest* request = |
| 347 transaction_.Get()); | 357 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 358 std::move(metrics)); |
| 348 transaction_->BackendDB()->DeleteRange( | 359 transaction_->BackendDB()->DeleteRange( |
| 349 transaction_->Id(), EffectiveObjectStore()->Id(), key_range, | 360 transaction_->Id(), EffectiveObjectStore()->Id(), key_range, |
| 350 request->CreateWebCallbacks().release()); | 361 request->CreateWebCallbacks().release()); |
| 351 return request; | 362 return request; |
| 352 } | 363 } |
| 353 | 364 |
| 354 void IDBCursor::PostSuccessHandlerCallback() { | 365 void IDBCursor::PostSuccessHandlerCallback() { |
| 355 if (backend_) | 366 if (backend_) |
| 356 backend_->PostSuccessHandlerCallback(); | 367 backend_->PostSuccessHandlerCallback(); |
| 357 } | 368 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 case kWebIDBCursorDirectionPrevNoDuplicate: | 469 case kWebIDBCursorDirectionPrevNoDuplicate: |
| 459 return IndexedDBNames::prevunique; | 470 return IndexedDBNames::prevunique; |
| 460 | 471 |
| 461 default: | 472 default: |
| 462 NOTREACHED(); | 473 NOTREACHED(); |
| 463 return IndexedDBNames::next; | 474 return IndexedDBNames::next; |
| 464 } | 475 } |
| 465 } | 476 } |
| 466 | 477 |
| 467 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |