| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 // An index's metadata will only get reverted if the index was in the | 109 // An index's metadata will only get reverted if the index was in the |
| 110 // database when the versionchange transaction started. | 110 // database when the versionchange transaction started. |
| 111 deleted_ = false; | 111 deleted_ = false; |
| 112 } | 112 } |
| 113 | 113 |
| 114 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, | 114 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, |
| 115 const ScriptValue& range, | 115 const ScriptValue& range, |
| 116 const String& direction_string, | 116 const String& direction_string, |
| 117 ExceptionState& exception_state) { | 117 ExceptionState& exception_state) { |
| 118 IDB_TRACE("IDBIndex::openCursor"); | 118 IDB_TRACE("IDBIndex::openCursorRequestSetup"); |
| 119 IDBRequest::AsyncTraceState metrics("IDBIndex::openCursor", this); |
| 119 if (IsDeleted()) { | 120 if (IsDeleted()) { |
| 120 exception_state.ThrowDOMException(kInvalidStateError, | 121 exception_state.ThrowDOMException(kInvalidStateError, |
| 121 IDBDatabase::kIndexDeletedErrorMessage); | 122 IDBDatabase::kIndexDeletedErrorMessage); |
| 122 return nullptr; | 123 return nullptr; |
| 123 } | 124 } |
| 124 if (!transaction_->IsActive()) { | 125 if (!transaction_->IsActive()) { |
| 125 exception_state.ThrowDOMException(kTransactionInactiveError, | 126 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 126 transaction_->InactiveErrorMessage()); | 127 transaction_->InactiveErrorMessage()); |
| 127 return nullptr; | 128 return nullptr; |
| 128 } | 129 } |
| 129 WebIDBCursorDirection direction = | 130 WebIDBCursorDirection direction = |
| 130 IDBCursor::StringToDirection(direction_string); | 131 IDBCursor::StringToDirection(direction_string); |
| 131 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( | 132 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( |
| 132 ExecutionContext::From(script_state), range, exception_state); | 133 ExecutionContext::From(script_state), range, exception_state); |
| 133 if (exception_state.HadException()) | 134 if (exception_state.HadException()) |
| 134 return nullptr; | 135 return nullptr; |
| 135 | 136 |
| 136 if (!BackendDB()) { | 137 if (!BackendDB()) { |
| 137 exception_state.ThrowDOMException(kInvalidStateError, | 138 exception_state.ThrowDOMException(kInvalidStateError, |
| 138 IDBDatabase::kDatabaseClosedErrorMessage); | 139 IDBDatabase::kDatabaseClosedErrorMessage); |
| 139 return nullptr; | 140 return nullptr; |
| 140 } | 141 } |
| 141 | 142 |
| 142 return openCursor(script_state, key_range, direction); | 143 return openCursor(script_state, key_range, direction, std::move(metrics)); |
| 143 } | 144 } |
| 144 | 145 |
| 145 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, | 146 IDBRequest* IDBIndex::openCursor(ScriptState* script_state, |
| 146 IDBKeyRange* key_range, | 147 IDBKeyRange* key_range, |
| 147 WebIDBCursorDirection direction) { | 148 WebIDBCursorDirection direction, |
| 148 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 149 IDBRequest::AsyncTraceState metrics) { |
| 149 transaction_.Get()); | 150 IDBRequest* request = |
| 151 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 152 std::move(metrics)); |
| 150 request->SetCursorDetails(IndexedDB::kCursorKeyAndValue, direction); | 153 request->SetCursorDetails(IndexedDB::kCursorKeyAndValue, direction); |
| 151 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(), | 154 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(), |
| 152 key_range, direction, false, kWebIDBTaskTypeNormal, | 155 key_range, direction, false, kWebIDBTaskTypeNormal, |
| 153 request->CreateWebCallbacks().release()); | 156 request->CreateWebCallbacks().release()); |
| 154 return request; | 157 return request; |
| 155 } | 158 } |
| 156 | 159 |
| 157 IDBRequest* IDBIndex::count(ScriptState* script_state, | 160 IDBRequest* IDBIndex::count(ScriptState* script_state, |
| 158 const ScriptValue& range, | 161 const ScriptValue& range, |
| 159 ExceptionState& exception_state) { | 162 ExceptionState& exception_state) { |
| 160 IDB_TRACE("IDBIndex::count"); | 163 IDB_TRACE("IDBIndex::countRequestSetup"); |
| 164 IDBRequest::AsyncTraceState metrics("IDBIndex::count", this); |
| 161 if (IsDeleted()) { | 165 if (IsDeleted()) { |
| 162 exception_state.ThrowDOMException(kInvalidStateError, | 166 exception_state.ThrowDOMException(kInvalidStateError, |
| 163 IDBDatabase::kIndexDeletedErrorMessage); | 167 IDBDatabase::kIndexDeletedErrorMessage); |
| 164 return nullptr; | 168 return nullptr; |
| 165 } | 169 } |
| 166 if (!transaction_->IsActive()) { | 170 if (!transaction_->IsActive()) { |
| 167 exception_state.ThrowDOMException(kTransactionInactiveError, | 171 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 168 transaction_->InactiveErrorMessage()); | 172 transaction_->InactiveErrorMessage()); |
| 169 return nullptr; | 173 return nullptr; |
| 170 } | 174 } |
| 171 | 175 |
| 172 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( | 176 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( |
| 173 ExecutionContext::From(script_state), range, exception_state); | 177 ExecutionContext::From(script_state), range, exception_state); |
| 174 if (exception_state.HadException()) | 178 if (exception_state.HadException()) |
| 175 return nullptr; | 179 return nullptr; |
| 176 | 180 |
| 177 if (!BackendDB()) { | 181 if (!BackendDB()) { |
| 178 exception_state.ThrowDOMException(kInvalidStateError, | 182 exception_state.ThrowDOMException(kInvalidStateError, |
| 179 IDBDatabase::kDatabaseClosedErrorMessage); | 183 IDBDatabase::kDatabaseClosedErrorMessage); |
| 180 return nullptr; | 184 return nullptr; |
| 181 } | 185 } |
| 182 | 186 |
| 183 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 187 IDBRequest* request = |
| 184 transaction_.Get()); | 188 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 189 std::move(metrics)); |
| 185 BackendDB()->Count(transaction_->Id(), object_store_->Id(), Id(), key_range, | 190 BackendDB()->Count(transaction_->Id(), object_store_->Id(), Id(), key_range, |
| 186 request->CreateWebCallbacks().release()); | 191 request->CreateWebCallbacks().release()); |
| 187 return request; | 192 return request; |
| 188 } | 193 } |
| 189 | 194 |
| 190 IDBRequest* IDBIndex::openKeyCursor(ScriptState* script_state, | 195 IDBRequest* IDBIndex::openKeyCursor(ScriptState* script_state, |
| 191 const ScriptValue& range, | 196 const ScriptValue& range, |
| 192 const String& direction_string, | 197 const String& direction_string, |
| 193 ExceptionState& exception_state) { | 198 ExceptionState& exception_state) { |
| 194 IDB_TRACE("IDBIndex::openKeyCursor"); | 199 IDB_TRACE("IDBIndex::openKeyCursorRequestSetup"); |
| 200 IDBRequest::AsyncTraceState metrics("IDBIndex::openKeyCursor", this); |
| 195 if (IsDeleted()) { | 201 if (IsDeleted()) { |
| 196 exception_state.ThrowDOMException(kInvalidStateError, | 202 exception_state.ThrowDOMException(kInvalidStateError, |
| 197 IDBDatabase::kIndexDeletedErrorMessage); | 203 IDBDatabase::kIndexDeletedErrorMessage); |
| 198 return nullptr; | 204 return nullptr; |
| 199 } | 205 } |
| 200 if (!transaction_->IsActive()) { | 206 if (!transaction_->IsActive()) { |
| 201 exception_state.ThrowDOMException(kTransactionInactiveError, | 207 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 202 transaction_->InactiveErrorMessage()); | 208 transaction_->InactiveErrorMessage()); |
| 203 return nullptr; | 209 return nullptr; |
| 204 } | 210 } |
| 205 WebIDBCursorDirection direction = | 211 WebIDBCursorDirection direction = |
| 206 IDBCursor::StringToDirection(direction_string); | 212 IDBCursor::StringToDirection(direction_string); |
| 207 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( | 213 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( |
| 208 ExecutionContext::From(script_state), range, exception_state); | 214 ExecutionContext::From(script_state), range, exception_state); |
| 209 if (exception_state.HadException()) | 215 if (exception_state.HadException()) |
| 210 return nullptr; | 216 return nullptr; |
| 211 if (!BackendDB()) { | 217 if (!BackendDB()) { |
| 212 exception_state.ThrowDOMException(kInvalidStateError, | 218 exception_state.ThrowDOMException(kInvalidStateError, |
| 213 IDBDatabase::kDatabaseClosedErrorMessage); | 219 IDBDatabase::kDatabaseClosedErrorMessage); |
| 214 return nullptr; | 220 return nullptr; |
| 215 } | 221 } |
| 216 | 222 |
| 217 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 223 IDBRequest* request = |
| 218 transaction_.Get()); | 224 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 225 std::move(metrics)); |
| 219 request->SetCursorDetails(IndexedDB::kCursorKeyOnly, direction); | 226 request->SetCursorDetails(IndexedDB::kCursorKeyOnly, direction); |
| 220 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(), | 227 BackendDB()->OpenCursor(transaction_->Id(), object_store_->Id(), Id(), |
| 221 key_range, direction, true, kWebIDBTaskTypeNormal, | 228 key_range, direction, true, kWebIDBTaskTypeNormal, |
| 222 request->CreateWebCallbacks().release()); | 229 request->CreateWebCallbacks().release()); |
| 223 return request; | 230 return request; |
| 224 } | 231 } |
| 225 | 232 |
| 226 IDBRequest* IDBIndex::get(ScriptState* script_state, | 233 IDBRequest* IDBIndex::get(ScriptState* script_state, |
| 227 const ScriptValue& key, | 234 const ScriptValue& key, |
| 228 ExceptionState& exception_state) { | 235 ExceptionState& exception_state) { |
| 229 IDB_TRACE("IDBIndex::get"); | 236 IDB_TRACE("IDBIndex::getRequestSetup"); |
| 230 return GetInternal(script_state, key, exception_state, false); | 237 return GetInternal(script_state, key, exception_state, false); |
| 231 } | 238 } |
| 232 | 239 |
| 233 IDBRequest* IDBIndex::getAll(ScriptState* script_state, | 240 IDBRequest* IDBIndex::getAll(ScriptState* script_state, |
| 234 const ScriptValue& range, | 241 const ScriptValue& range, |
| 235 ExceptionState& exception_state) { | 242 ExceptionState& exception_state) { |
| 236 return getAll(script_state, range, std::numeric_limits<uint32_t>::max(), | 243 return getAll(script_state, range, std::numeric_limits<uint32_t>::max(), |
| 237 exception_state); | 244 exception_state); |
| 238 } | 245 } |
| 239 | 246 |
| 240 IDBRequest* IDBIndex::getAll(ScriptState* script_state, | 247 IDBRequest* IDBIndex::getAll(ScriptState* script_state, |
| 241 const ScriptValue& range, | 248 const ScriptValue& range, |
| 242 unsigned long max_count, | 249 unsigned long max_count, |
| 243 ExceptionState& exception_state) { | 250 ExceptionState& exception_state) { |
| 244 IDB_TRACE("IDBIndex::getAll"); | 251 IDB_TRACE("IDBIndex::getAllRequestSetup"); |
| 245 return GetAllInternal(script_state, range, max_count, exception_state, false); | 252 return GetAllInternal(script_state, range, max_count, exception_state, false); |
| 246 } | 253 } |
| 247 | 254 |
| 248 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state, | 255 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state, |
| 249 const ScriptValue& range, | 256 const ScriptValue& range, |
| 250 ExceptionState& exception_state) { | 257 ExceptionState& exception_state) { |
| 251 return getAllKeys(script_state, range, std::numeric_limits<uint32_t>::max(), | 258 return getAllKeys(script_state, range, std::numeric_limits<uint32_t>::max(), |
| 252 exception_state); | 259 exception_state); |
| 253 } | 260 } |
| 254 | 261 |
| 255 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state, | 262 IDBRequest* IDBIndex::getAllKeys(ScriptState* script_state, |
| 256 const ScriptValue& range, | 263 const ScriptValue& range, |
| 257 uint32_t max_count, | 264 uint32_t max_count, |
| 258 ExceptionState& exception_state) { | 265 ExceptionState& exception_state) { |
| 259 IDB_TRACE("IDBIndex::getAllKeys"); | 266 IDB_TRACE("IDBIndex::getAllKeysRequestSetup"); |
| 260 return GetAllInternal(script_state, range, max_count, exception_state, | 267 return GetAllInternal(script_state, range, max_count, exception_state, |
| 261 /*key_only=*/true); | 268 /*key_only=*/true); |
| 262 } | 269 } |
| 263 | 270 |
| 264 IDBRequest* IDBIndex::getKey(ScriptState* script_state, | 271 IDBRequest* IDBIndex::getKey(ScriptState* script_state, |
| 265 const ScriptValue& key, | 272 const ScriptValue& key, |
| 266 ExceptionState& exception_state) { | 273 ExceptionState& exception_state) { |
| 267 IDB_TRACE("IDBIndex::getKey"); | 274 IDB_TRACE("IDBIndex::getKeyRequestSetup"); |
| 268 return GetInternal(script_state, key, exception_state, true); | 275 return GetInternal(script_state, key, exception_state, true); |
| 269 } | 276 } |
| 270 | 277 |
| 271 IDBRequest* IDBIndex::GetInternal(ScriptState* script_state, | 278 IDBRequest* IDBIndex::GetInternal(ScriptState* script_state, |
| 272 const ScriptValue& key, | 279 const ScriptValue& key, |
| 273 ExceptionState& exception_state, | 280 ExceptionState& exception_state, |
| 274 bool key_only) { | 281 bool key_only) { |
| 282 IDBRequest::AsyncTraceState metrics( |
| 283 key_only ? "IDBIndex::getKey" : "IDBIndex::get", this); |
| 275 if (IsDeleted()) { | 284 if (IsDeleted()) { |
| 276 exception_state.ThrowDOMException(kInvalidStateError, | 285 exception_state.ThrowDOMException(kInvalidStateError, |
| 277 IDBDatabase::kIndexDeletedErrorMessage); | 286 IDBDatabase::kIndexDeletedErrorMessage); |
| 278 return nullptr; | 287 return nullptr; |
| 279 } | 288 } |
| 280 if (!transaction_->IsActive()) { | 289 if (!transaction_->IsActive()) { |
| 281 exception_state.ThrowDOMException(kTransactionInactiveError, | 290 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 282 transaction_->InactiveErrorMessage()); | 291 transaction_->InactiveErrorMessage()); |
| 283 return nullptr; | 292 return nullptr; |
| 284 } | 293 } |
| 285 | 294 |
| 286 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( | 295 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( |
| 287 ExecutionContext::From(script_state), key, exception_state); | 296 ExecutionContext::From(script_state), key, exception_state); |
| 288 if (exception_state.HadException()) | 297 if (exception_state.HadException()) |
| 289 return nullptr; | 298 return nullptr; |
| 290 if (!key_range) { | 299 if (!key_range) { |
| 291 exception_state.ThrowDOMException( | 300 exception_state.ThrowDOMException( |
| 292 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); | 301 kDataError, IDBDatabase::kNoKeyOrKeyRangeErrorMessage); |
| 293 return nullptr; | 302 return nullptr; |
| 294 } | 303 } |
| 295 if (!BackendDB()) { | 304 if (!BackendDB()) { |
| 296 exception_state.ThrowDOMException(kInvalidStateError, | 305 exception_state.ThrowDOMException(kInvalidStateError, |
| 297 IDBDatabase::kDatabaseClosedErrorMessage); | 306 IDBDatabase::kDatabaseClosedErrorMessage); |
| 298 return nullptr; | 307 return nullptr; |
| 299 } | 308 } |
| 300 | 309 |
| 301 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 310 IDBRequest* request = |
| 302 transaction_.Get()); | 311 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 312 std::move(metrics)); |
| 303 BackendDB()->Get(transaction_->Id(), object_store_->Id(), Id(), key_range, | 313 BackendDB()->Get(transaction_->Id(), object_store_->Id(), Id(), key_range, |
| 304 key_only, request->CreateWebCallbacks().release()); | 314 key_only, request->CreateWebCallbacks().release()); |
| 305 return request; | 315 return request; |
| 306 } | 316 } |
| 307 | 317 |
| 308 IDBRequest* IDBIndex::GetAllInternal(ScriptState* script_state, | 318 IDBRequest* IDBIndex::GetAllInternal(ScriptState* script_state, |
| 309 const ScriptValue& range, | 319 const ScriptValue& range, |
| 310 unsigned long max_count, | 320 unsigned long max_count, |
| 311 ExceptionState& exception_state, | 321 ExceptionState& exception_state, |
| 312 bool key_only) { | 322 bool key_only) { |
| 323 IDBRequest::AsyncTraceState metrics( |
| 324 key_only ? "IDBIndex::getAllKeys" : "IDBIndex::getAll", this); |
| 313 if (!max_count) | 325 if (!max_count) |
| 314 max_count = std::numeric_limits<uint32_t>::max(); | 326 max_count = std::numeric_limits<uint32_t>::max(); |
| 315 | 327 |
| 316 if (IsDeleted()) { | 328 if (IsDeleted()) { |
| 317 exception_state.ThrowDOMException(kInvalidStateError, | 329 exception_state.ThrowDOMException(kInvalidStateError, |
| 318 IDBDatabase::kIndexDeletedErrorMessage); | 330 IDBDatabase::kIndexDeletedErrorMessage); |
| 319 return nullptr; | 331 return nullptr; |
| 320 } | 332 } |
| 321 if (!transaction_->IsActive()) { | 333 if (!transaction_->IsActive()) { |
| 322 exception_state.ThrowDOMException(kTransactionInactiveError, | 334 exception_state.ThrowDOMException(kTransactionInactiveError, |
| 323 transaction_->InactiveErrorMessage()); | 335 transaction_->InactiveErrorMessage()); |
| 324 return nullptr; | 336 return nullptr; |
| 325 } | 337 } |
| 326 | 338 |
| 327 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( | 339 IDBKeyRange* key_range = IDBKeyRange::FromScriptValue( |
| 328 ExecutionContext::From(script_state), range, exception_state); | 340 ExecutionContext::From(script_state), range, exception_state); |
| 329 if (exception_state.HadException()) | 341 if (exception_state.HadException()) |
| 330 return nullptr; | 342 return nullptr; |
| 331 if (!BackendDB()) { | 343 if (!BackendDB()) { |
| 332 exception_state.ThrowDOMException(kInvalidStateError, | 344 exception_state.ThrowDOMException(kInvalidStateError, |
| 333 IDBDatabase::kDatabaseClosedErrorMessage); | 345 IDBDatabase::kDatabaseClosedErrorMessage); |
| 334 return nullptr; | 346 return nullptr; |
| 335 } | 347 } |
| 336 | 348 |
| 337 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), | 349 IDBRequest* request = |
| 338 transaction_.Get()); | 350 IDBRequest::Create(script_state, IDBAny::Create(this), transaction_.Get(), |
| 351 std::move(metrics)); |
| 339 BackendDB()->GetAll(transaction_->Id(), object_store_->Id(), Id(), key_range, | 352 BackendDB()->GetAll(transaction_->Id(), object_store_->Id(), Id(), key_range, |
| 340 max_count, key_only, | 353 max_count, key_only, |
| 341 request->CreateWebCallbacks().release()); | 354 request->CreateWebCallbacks().release()); |
| 342 return request; | 355 return request; |
| 343 } | 356 } |
| 344 | 357 |
| 345 WebIDBDatabase* IDBIndex::BackendDB() const { | 358 WebIDBDatabase* IDBIndex::BackendDB() const { |
| 346 return transaction_->BackendDB(); | 359 return transaction_->BackendDB(); |
| 347 } | 360 } |
| 348 | 361 |
| 349 } // namespace blink | 362 } // namespace blink |
| OLD | NEW |