Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBObjectStore.cpp

Issue 2814253002: IndexedDB: Fix mocks/comments following the great blink rename (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 163 }
164 if (!BackendDB()) { 164 if (!BackendDB()) {
165 exception_state.ThrowDOMException(kInvalidStateError, 165 exception_state.ThrowDOMException(kInvalidStateError,
166 IDBDatabase::kDatabaseClosedErrorMessage); 166 IDBDatabase::kDatabaseClosedErrorMessage);
167 return nullptr; 167 return nullptr;
168 } 168 }
169 169
170 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 170 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this),
171 transaction_.Get()); 171 transaction_.Get());
172 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 172 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
173 key_range, false /* keyOnly */, 173 key_range, /*key_only=*/false,
174 request->CreateWebCallbacks().release()); 174 request->CreateWebCallbacks().release());
175 return request; 175 return request;
176 } 176 }
177 177
178 IDBRequest* IDBObjectStore::getKey(ScriptState* script_state, 178 IDBRequest* IDBObjectStore::getKey(ScriptState* script_state,
179 const ScriptValue& key, 179 const ScriptValue& key,
180 ExceptionState& exception_state) { 180 ExceptionState& exception_state) {
181 IDB_TRACE("IDBObjectStore::getKey"); 181 IDB_TRACE("IDBObjectStore::getKey");
182 if (IsDeleted()) { 182 if (IsDeleted()) {
183 exception_state.ThrowDOMException( 183 exception_state.ThrowDOMException(
(...skipping 23 matching lines...) Expand all
207 } 207 }
208 if (!BackendDB()) { 208 if (!BackendDB()) {
209 exception_state.ThrowDOMException(kInvalidStateError, 209 exception_state.ThrowDOMException(kInvalidStateError,
210 IDBDatabase::kDatabaseClosedErrorMessage); 210 IDBDatabase::kDatabaseClosedErrorMessage);
211 return nullptr; 211 return nullptr;
212 } 212 }
213 213
214 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 214 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this),
215 transaction_.Get()); 215 transaction_.Get());
216 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId, 216 BackendDB()->Get(transaction_->Id(), Id(), IDBIndexMetadata::kInvalidId,
217 key_range, true /* keyOnly */, 217 key_range, /*key_only=*/true,
218 request->CreateWebCallbacks().release()); 218 request->CreateWebCallbacks().release());
219 return request; 219 return request;
220 } 220 }
221 221
222 IDBRequest* IDBObjectStore::getAll(ScriptState* script_state, 222 IDBRequest* IDBObjectStore::getAll(ScriptState* script_state,
223 const ScriptValue& key_range, 223 const ScriptValue& key_range,
224 ExceptionState& exception_state) { 224 ExceptionState& exception_state) {
225 return getAll(script_state, key_range, std::numeric_limits<uint32_t>::max(), 225 return getAll(script_state, key_range, std::numeric_limits<uint32_t>::max(),
226 exception_state); 226 exception_state);
227 } 227 }
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this), 638 IDBRequest* request = IDBRequest::Create(script_state, IDBAny::Create(this),
639 transaction_.Get()); 639 transaction_.Get());
640 BackendDB()->Clear(transaction_->Id(), Id(), 640 BackendDB()->Clear(transaction_->Id(), Id(),
641 request->CreateWebCallbacks().release()); 641 request->CreateWebCallbacks().release());
642 return request; 642 return request;
643 } 643 }
644 644
645 namespace { 645 namespace {
646 // This class creates the index keys for a given index by extracting 646 // This class creates the index keys for a given index by extracting
647 // them from the SerializedScriptValue, for all the existing values in 647 // them from the SerializedScriptValue, for all the existing values in
648 // the objectStore. It only needs to be kept alive by virtue of being 648 // the object store. It only needs to be kept alive by virtue of being
649 // a listener on an IDBRequest object, in the same way that JavaScript 649 // a listener on an IDBRequest object, in the same way that JavaScript
650 // cursor success handlers are kept alive. 650 // cursor success handlers are kept alive.
651 class IndexPopulator final : public EventListener { 651 class IndexPopulator final : public EventListener {
652 public: 652 public:
653 static IndexPopulator* Create(ScriptState* script_state, 653 static IndexPopulator* Create(ScriptState* script_state,
654 IDBDatabase* database, 654 IDBDatabase* database,
655 int64_t transaction_id, 655 int64_t transaction_id,
656 int64_t object_store_id, 656 int64_t object_store_id,
657 RefPtr<const IDBIndexMetadata> index_metadata) { 657 RefPtr<const IDBIndexMetadata> index_metadata) {
658 return new IndexPopulator(script_state, database, transaction_id, 658 return new IndexPopulator(script_state, database, transaction_id,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 ScriptState::Scope scope(script_state_.Get()); 700 ScriptState::Scope scope(script_state_.Get());
701 701
702 IDBAny* cursor_any = request->ResultAsAny(); 702 IDBAny* cursor_any = request->ResultAsAny();
703 IDBCursorWithValue* cursor = nullptr; 703 IDBCursorWithValue* cursor = nullptr;
704 if (cursor_any->GetType() == IDBAny::kIDBCursorWithValueType) 704 if (cursor_any->GetType() == IDBAny::kIDBCursorWithValueType)
705 cursor = cursor_any->IdbCursorWithValue(); 705 cursor = cursor_any->IdbCursorWithValue();
706 706
707 Vector<int64_t> index_ids; 707 Vector<int64_t> index_ids;
708 index_ids.push_back(IndexMetadata().id); 708 index_ids.push_back(IndexMetadata().id);
709 if (cursor && !cursor->IsDeleted()) { 709 if (cursor && !cursor->IsDeleted()) {
710 cursor->continueFunction(nullptr, nullptr, ASSERT_NO_EXCEPTION); 710 cursor->Continue(nullptr, nullptr, ASSERT_NO_EXCEPTION);
711 711
712 IDBKey* primary_key = cursor->IdbPrimaryKey(); 712 IDBKey* primary_key = cursor->IdbPrimaryKey();
713 ScriptValue value = cursor->value(script_state_.Get()); 713 ScriptValue value = cursor->value(script_state_.Get());
714 714
715 IndexKeys index_keys; 715 IndexKeys index_keys;
716 GenerateIndexKeysForValue(script_state_->GetIsolate(), IndexMetadata(), 716 GenerateIndexKeysForValue(script_state_->GetIsolate(), IndexMetadata(),
717 value, &index_keys); 717 value, &index_keys);
718 718
719 HeapVector<IndexKeys> index_keys_list; 719 HeapVector<IndexKeys> index_keys_list;
720 index_keys_list.push_back(index_keys); 720 index_keys_list.push_back(index_keys);
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 1053
1054 for (auto& it : index_map_) { 1054 for (auto& it : index_map_) {
1055 IDBIndex* index = it.value; 1055 IDBIndex* index = it.value;
1056 index->MarkDeleted(); 1056 index->MarkDeleted();
1057 } 1057 }
1058 } 1058 }
1059 1059
1060 void IDBObjectStore::ClearIndexCache() { 1060 void IDBObjectStore::ClearIndexCache() {
1061 DCHECK(!transaction_->IsActive() || (IsDeleted() && IsNewlyCreated())); 1061 DCHECK(!transaction_->IsActive() || (IsDeleted() && IsNewlyCreated()));
1062 1062
1063 // There is no harm in having clearIndexCache() happen multiple times for
1064 // the same object. We assert that it is called once to uncover potential
1065 // object store accounting bugs.
1066 #if DCHECK_IS_ON() 1063 #if DCHECK_IS_ON()
1064 // There is no harm in having ClearIndexCache() happen multiple times for
1065 // the same object. We assert that it is called once to uncover potential
1066 // object store accounting bugs.
1067 DCHECK(!clear_index_cache_called_); 1067 DCHECK(!clear_index_cache_called_);
1068 clear_index_cache_called_ = true; 1068 clear_index_cache_called_ = true;
1069 #endif // DCHECK_IS_ON() 1069 #endif // DCHECK_IS_ON()
1070 1070
1071 index_map_.Clear(); 1071 index_map_.Clear();
1072 } 1072 }
1073 1073
1074 void IDBObjectStore::RevertMetadata( 1074 void IDBObjectStore::RevertMetadata(
1075 RefPtr<IDBObjectStoreMetadata> old_metadata) { 1075 RefPtr<IDBObjectStoreMetadata> old_metadata) {
1076 DCHECK(transaction_->IsVersionChange()); 1076 DCHECK(transaction_->IsVersionChange());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 deleted_index.RevertMetadata(std::move(old_index_metadata)); 1117 deleted_index.RevertMetadata(std::move(old_index_metadata));
1118 } 1118 }
1119 1119
1120 void IDBObjectStore::RenameIndex(int64_t index_id, const String& new_name) { 1120 void IDBObjectStore::RenameIndex(int64_t index_id, const String& new_name) {
1121 DCHECK(transaction_->IsVersionChange()); 1121 DCHECK(transaction_->IsVersionChange());
1122 DCHECK(transaction_->IsActive()); 1122 DCHECK(transaction_->IsActive());
1123 1123
1124 BackendDB()->RenameIndex(transaction_->Id(), Id(), index_id, new_name); 1124 BackendDB()->RenameIndex(transaction_->Id(), Id(), index_id, new_name);
1125 1125
1126 auto metadata_iterator = metadata_->indexes.Find(index_id); 1126 auto metadata_iterator = metadata_->indexes.Find(index_id);
1127 DCHECK_NE(metadata_iterator, metadata_->indexes.end()) << "Invalid indexId"; 1127 DCHECK_NE(metadata_iterator, metadata_->indexes.end()) << "Invalid index_id";
1128 const String& old_name = metadata_iterator->value->name; 1128 const String& old_name = metadata_iterator->value->name;
1129 1129
1130 DCHECK(index_map_.Contains(old_name)) 1130 DCHECK(index_map_.Contains(old_name))
1131 << "The index had to be accessed in order to be renamed."; 1131 << "The index had to be accessed in order to be renamed.";
1132 DCHECK(!index_map_.Contains(new_name)); 1132 DCHECK(!index_map_.Contains(new_name));
1133 index_map_.Set(new_name, index_map_.Take(old_name)); 1133 index_map_.Set(new_name, index_map_.Take(old_name));
1134 1134
1135 metadata_iterator->value->name = new_name; 1135 metadata_iterator->value->name = new_name;
1136 } 1136 }
1137 1137
1138 int64_t IDBObjectStore::FindIndexId(const String& name) const { 1138 int64_t IDBObjectStore::FindIndexId(const String& name) const {
1139 for (const auto& it : Metadata().indexes) { 1139 for (const auto& it : Metadata().indexes) {
1140 if (it.value->name == name) { 1140 if (it.value->name == name) {
1141 DCHECK_NE(it.key, IDBIndexMetadata::kInvalidId); 1141 DCHECK_NE(it.key, IDBIndexMetadata::kInvalidId);
1142 return it.key; 1142 return it.key;
1143 } 1143 }
1144 } 1144 }
1145 return IDBIndexMetadata::kInvalidId; 1145 return IDBIndexMetadata::kInvalidId;
1146 } 1146 }
1147 1147
1148 WebIDBDatabase* IDBObjectStore::BackendDB() const { 1148 WebIDBDatabase* IDBObjectStore::BackendDB() const {
1149 return transaction_->BackendDB(); 1149 return transaction_->BackendDB();
1150 } 1150 }
1151 1151
1152 } // namespace blink 1152 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698