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 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"); |
|
pwnall
2017/05/25 23:04:25
The Call suffixes don't seem very informative to m
dmurph
2017/05/31 19:26:25
Done.
| |
| 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 IDBRequest::AsyncTraceState metrics("IDBCursor::advance", this); | |
| 142 if (!count) { | 142 if (!count) { |
| 143 exception_state.ThrowTypeError( | 143 exception_state.ThrowTypeError( |
| 144 "A count argument with value 0 (zero) was supplied, must be greater " | 144 "A count argument with value 0 (zero) was supplied, must be greater " |
| 145 "than 0."); | 145 "than 0."); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 if (!transaction_->IsActive()) { | 148 if (!transaction_->IsActive()) { |
| 149 exception_state.ThrowDOMException(kTransactionInactiveError, | 149 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 150 transaction_->InactiveErrorMessage()); | 150 transaction_->InactiveErrorMessage()); |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 if (IsDeleted()) { | 153 if (IsDeleted()) { |
| 154 exception_state.ThrowDOMException(kInvalidStateError, | 154 exception_state.ThrowDOMException(kInvalidStateError, |
| 155 IDBDatabase::kSourceDeletedErrorMessage); | 155 IDBDatabase::kSourceDeletedErrorMessage); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 if (!got_value_) { | 158 if (!got_value_) { |
| 159 exception_state.ThrowDOMException(kInvalidStateError, | 159 exception_state.ThrowDOMException(kInvalidStateError, |
| 160 IDBDatabase::kNoValueErrorMessage); | 160 IDBDatabase::kNoValueErrorMessage); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 request_->SetPendingCursor(this); | 164 request_->SetPendingCursor(this); |
| 165 request_->AssignNewMetrics(std::move(metrics)); | |
| 165 got_value_ = false; | 166 got_value_ = false; |
| 166 backend_->Advance(count, request_->CreateWebCallbacks().release()); | 167 backend_->Advance(count, request_->CreateWebCallbacks().release()); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void IDBCursor::continueFunction(ScriptState* script_state, | 170 void IDBCursor::continueFunction(ScriptState* script_state, |
| 170 const ScriptValue& key_value, | 171 const ScriptValue& key_value, |
| 171 ExceptionState& exception_state) { | 172 ExceptionState& exception_state) { |
| 172 IDB_TRACE("IDBCursor::continue"); | 173 IDB_TRACE("IDBCursor::continueCall"); |
| 174 IDBRequest::AsyncTraceState metrics("IDBCursor::continue", this); | |
| 173 | 175 |
| 174 if (!transaction_->IsActive()) { | 176 if (!transaction_->IsActive()) { |
| 175 exception_state.ThrowDOMException(kTransactionInactiveError, | 177 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 176 transaction_->InactiveErrorMessage()); | 178 transaction_->InactiveErrorMessage()); |
| 177 return; | 179 return; |
| 178 } | 180 } |
| 179 if (!got_value_) { | 181 if (!got_value_) { |
| 180 exception_state.ThrowDOMException(kInvalidStateError, | 182 exception_state.ThrowDOMException(kInvalidStateError, |
| 181 IDBDatabase::kNoValueErrorMessage); | 183 IDBDatabase::kNoValueErrorMessage); |
| 182 return; | 184 return; |
| 183 } | 185 } |
| 184 if (IsDeleted()) { | 186 if (IsDeleted()) { |
| 185 exception_state.ThrowDOMException(kInvalidStateError, | 187 exception_state.ThrowDOMException(kInvalidStateError, |
| 186 IDBDatabase::kSourceDeletedErrorMessage); | 188 IDBDatabase::kSourceDeletedErrorMessage); |
| 187 return; | 189 return; |
| 188 } | 190 } |
| 189 | 191 |
| 190 IDBKey* key = key_value.IsUndefined() || key_value.IsNull() | 192 IDBKey* key = key_value.IsUndefined() || key_value.IsNull() |
| 191 ? nullptr | 193 ? nullptr |
| 192 : ScriptValue::To<IDBKey*>(script_state->GetIsolate(), | 194 : ScriptValue::To<IDBKey*>(script_state->GetIsolate(), |
| 193 key_value, exception_state); | 195 key_value, exception_state); |
| 194 if (exception_state.HadException()) | 196 if (exception_state.HadException()) |
| 195 return; | 197 return; |
| 196 if (key && !key->IsValid()) { | 198 if (key && !key->IsValid()) { |
| 197 exception_state.ThrowDOMException(kDataError, | 199 exception_state.ThrowDOMException(kDataError, |
| 198 IDBDatabase::kNotValidKeyErrorMessage); | 200 IDBDatabase::kNotValidKeyErrorMessage); |
| 199 return; | 201 return; |
| 200 } | 202 } |
| 201 Continue(key, nullptr, exception_state); | 203 Continue(key, nullptr, exception_state, std::move(metrics)); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void IDBCursor::continuePrimaryKey(ScriptState* script_state, | 206 void IDBCursor::continuePrimaryKey(ScriptState* script_state, |
| 205 const ScriptValue& key_value, | 207 const ScriptValue& key_value, |
| 206 const ScriptValue& primary_key_value, | 208 const ScriptValue& primary_key_value, |
| 207 ExceptionState& exception_state) { | 209 ExceptionState& exception_state) { |
| 208 IDB_TRACE("IDBCursor::continuePrimaryKey"); | 210 IDB_TRACE("IDBCursor::continuePrimaryKeyCall"); |
| 211 IDBRequest::AsyncTraceState metrics("IDBCursor::continuePrimaryKey", this); | |
| 209 | 212 |
| 210 if (!transaction_->IsActive()) { | 213 if (!transaction_->IsActive()) { |
| 211 exception_state.ThrowDOMException(kTransactionInactiveError, | 214 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 212 transaction_->InactiveErrorMessage()); | 215 transaction_->InactiveErrorMessage()); |
| 213 return; | 216 return; |
| 214 } | 217 } |
| 215 | 218 |
| 216 if (IsDeleted()) { | 219 if (IsDeleted()) { |
| 217 exception_state.ThrowDOMException(kInvalidStateError, | 220 exception_state.ThrowDOMException(kInvalidStateError, |
| 218 IDBDatabase::kSourceDeletedErrorMessage); | 221 IDBDatabase::kSourceDeletedErrorMessage); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 IDBKey* primary_key = ScriptValue::To<IDBKey*>( | 254 IDBKey* primary_key = ScriptValue::To<IDBKey*>( |
| 252 script_state->GetIsolate(), primary_key_value, exception_state); | 255 script_state->GetIsolate(), primary_key_value, exception_state); |
| 253 if (exception_state.HadException()) | 256 if (exception_state.HadException()) |
| 254 return; | 257 return; |
| 255 if (!primary_key->IsValid()) { | 258 if (!primary_key->IsValid()) { |
| 256 exception_state.ThrowDOMException(kDataError, | 259 exception_state.ThrowDOMException(kDataError, |
| 257 IDBDatabase::kNotValidKeyErrorMessage); | 260 IDBDatabase::kNotValidKeyErrorMessage); |
| 258 return; | 261 return; |
| 259 } | 262 } |
| 260 | 263 |
| 261 Continue(key, primary_key, exception_state); | 264 Continue(key, primary_key, exception_state, std::move(metrics)); |
| 262 } | 265 } |
| 263 | 266 |
| 264 void IDBCursor::Continue(IDBKey* key, | 267 void IDBCursor::Continue(IDBKey* key, |
| 265 IDBKey* primary_key, | 268 IDBKey* primary_key, |
| 266 ExceptionState& exception_state) { | 269 ExceptionState& exception_state, |
| 270 IDBRequest::AsyncTraceState metrics) { | |
| 267 DCHECK(transaction_->IsActive()); | 271 DCHECK(transaction_->IsActive()); |
| 268 DCHECK(got_value_); | 272 DCHECK(got_value_); |
| 269 DCHECK(!IsDeleted()); | 273 DCHECK(!IsDeleted()); |
| 270 DCHECK(!primary_key || (key && primary_key)); | 274 DCHECK(!primary_key || (key && primary_key)); |
| 271 | 275 |
| 272 if (key) { | 276 if (key) { |
| 273 DCHECK(key_); | 277 DCHECK(key_); |
| 274 if (direction_ == kWebIDBCursorDirectionNext || | 278 if (direction_ == kWebIDBCursorDirectionNext || |
| 275 direction_ == kWebIDBCursorDirectionNextNoDuplicate) { | 279 direction_ == kWebIDBCursorDirectionNextNoDuplicate) { |
| 276 const bool ok = | 280 const bool ok = |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 293 "equal to this cursor's position."); | 297 "equal to this cursor's position."); |
| 294 return; | 298 return; |
| 295 } | 299 } |
| 296 } | 300 } |
| 297 } | 301 } |
| 298 | 302 |
| 299 // FIXME: We're not using the context from when continue was called, which | 303 // FIXME: We're not using the context from when continue was called, which |
| 300 // means the callback will be on the original context openCursor was called | 304 // means the callback will be on the original context openCursor was called |
| 301 // on. Is this right? | 305 // on. Is this right? |
| 302 request_->SetPendingCursor(this); | 306 request_->SetPendingCursor(this); |
| 307 request_->AssignNewMetrics(std::move(metrics)); | |
| 303 got_value_ = false; | 308 got_value_ = false; |
| 304 backend_->ContinueFunction(key, primary_key, | 309 backend_->ContinueFunction(key, primary_key, |
| 305 request_->CreateWebCallbacks().release()); | 310 request_->CreateWebCallbacks().release()); |
| 306 } | 311 } |
| 307 | 312 |
| 308 IDBRequest* IDBCursor::deleteFunction(ScriptState* script_state, | 313 IDBRequest* IDBCursor::deleteFunction(ScriptState* script_state, |
| 309 ExceptionState& exception_state) { | 314 ExceptionState& exception_state) { |
| 310 IDB_TRACE("IDBCursor::delete"); | 315 IDB_TRACE("IDBCursor::deleteCall"); |
| 316 IDBRequest::AsyncTraceState metrics("IDBCursor::delete", this); | |
| 311 if (!transaction_->IsActive()) { | 317 if (!transaction_->IsActive()) { |
| 312 exception_state.ThrowDOMException(kTransactionInactiveError, | 318 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 313 transaction_->InactiveErrorMessage()); | 319 transaction_->InactiveErrorMessage()); |
| 314 return nullptr; | 320 return nullptr; |
| 315 } | 321 } |
| 316 if (transaction_->IsReadOnly()) { | 322 if (transaction_->IsReadOnly()) { |
| 317 exception_state.ThrowDOMException( | 323 exception_state.ThrowDOMException( |
| 318 kReadOnlyError, | 324 kReadOnlyError, |
| 319 "The record may not be deleted inside a read-only transaction."); | 325 "The record may not be deleted inside a read-only transaction."); |
| 320 return nullptr; | 326 return nullptr; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 336 } | 342 } |
| 337 if (!transaction_->BackendDB()) { | 343 if (!transaction_->BackendDB()) { |
| 338 exception_state.ThrowDOMException(kInvalidStateError, | 344 exception_state.ThrowDOMException(kInvalidStateError, |
| 339 IDBDatabase::kDatabaseClosedErrorMessage); | 345 IDBDatabase::kDatabaseClosedErrorMessage); |
| 340 return nullptr; | 346 return nullptr; |
| 341 } | 347 } |
| 342 | 348 |
| 343 IDBKeyRange* key_range = IDBKeyRange::only(primary_key_, exception_state); | 349 IDBKeyRange* key_range = IDBKeyRange::only(primary_key_, exception_state); |
| 344 DCHECK(!exception_state.HadException()); | 350 DCHECK(!exception_state.HadException()); |
| 345 | 351 |
| 346 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 352 IDBRequest* request = |
| 347 transaction_.Get()); | 353 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 354 std::move(metrics)); | |
| 348 transaction_->BackendDB()->DeleteRange( | 355 transaction_->BackendDB()->DeleteRange( |
| 349 transaction_->Id(), EffectiveObjectStore()->Id(), key_range, | 356 transaction_->Id(), EffectiveObjectStore()->Id(), key_range, |
| 350 request->CreateWebCallbacks().release()); | 357 request->CreateWebCallbacks().release()); |
| 351 return request; | 358 return request; |
| 352 } | 359 } |
| 353 | 360 |
| 354 void IDBCursor::PostSuccessHandlerCallback() { | 361 void IDBCursor::PostSuccessHandlerCallback() { |
| 355 if (backend_) | 362 if (backend_) |
| 356 backend_->PostSuccessHandlerCallback(); | 363 backend_->PostSuccessHandlerCallback(); |
| 357 } | 364 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 case kWebIDBCursorDirectionPrevNoDuplicate: | 465 case kWebIDBCursorDirectionPrevNoDuplicate: |
| 459 return IndexedDBNames::prevunique; | 466 return IndexedDBNames::prevunique; |
| 460 | 467 |
| 461 default: | 468 default: |
| 462 NOTREACHED(); | 469 NOTREACHED(); |
| 463 return IndexedDBNames::next; | 470 return IndexedDBNames::next; |
| 464 } | 471 } |
| 465 } | 472 } |
| 466 | 473 |
| 467 } // namespace blink | 474 } // namespace blink |
| OLD | NEW |