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

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

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: added comments and bug link Created 3 years, 11 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 28 matching lines...) Expand all
39 #include "modules/indexeddb/IDBKeyPath.h" 39 #include "modules/indexeddb/IDBKeyPath.h"
40 #include "modules/indexeddb/IDBObserver.h" 40 #include "modules/indexeddb/IDBObserver.h"
41 #include "modules/indexeddb/IDBObserverChanges.h" 41 #include "modules/indexeddb/IDBObserverChanges.h"
42 #include "modules/indexeddb/IDBTracing.h" 42 #include "modules/indexeddb/IDBTracing.h"
43 #include "modules/indexeddb/IDBVersionChangeEvent.h" 43 #include "modules/indexeddb/IDBVersionChangeEvent.h"
44 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" 44 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h"
45 #include "platform/Histogram.h" 45 #include "platform/Histogram.h"
46 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h" 46 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h"
47 #include "public/platform/modules/indexeddb/WebIDBTypes.h" 47 #include "public/platform/modules/indexeddb/WebIDBTypes.h"
48 #include "wtf/Atomics.h" 48 #include "wtf/Atomics.h"
49
49 #include <limits> 50 #include <limits>
50 #include <memory> 51 #include <memory>
51 52
52 using blink::WebIDBDatabase; 53 using blink::WebIDBDatabase;
53 54
54 namespace blink { 55 namespace blink {
55 56
57 const char IDBDatabase::cannotObserveVersionChangeTransaction[] =
58 "An observer cannot target a version change transaction.";
56 const char IDBDatabase::indexDeletedErrorMessage[] = 59 const char IDBDatabase::indexDeletedErrorMessage[] =
57 "The index or its object store has been deleted."; 60 "The index or its object store has been deleted.";
58 const char IDBDatabase::indexNameTakenErrorMessage[] = 61 const char IDBDatabase::indexNameTakenErrorMessage[] =
59 "An index with the specified name already exists."; 62 "An index with the specified name already exists.";
60 const char IDBDatabase::isKeyCursorErrorMessage[] = 63 const char IDBDatabase::isKeyCursorErrorMessage[] =
61 "The cursor is a key cursor."; 64 "The cursor is a key cursor.";
62 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] = 65 const char IDBDatabase::noKeyOrKeyRangeErrorMessage[] =
63 "No key or key range specified."; 66 "No key or key range specified.";
64 const char IDBDatabase::noSuchIndexErrorMessage[] = 67 const char IDBDatabase::noSuchIndexErrorMessage[] =
65 "The specified index was not found."; 68 "The specified index was not found.";
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 173 }
171 174
172 void IDBDatabase::onComplete(int64_t transactionId) { 175 void IDBDatabase::onComplete(int64_t transactionId) {
173 DCHECK(m_transactions.contains(transactionId)); 176 DCHECK(m_transactions.contains(transactionId));
174 m_transactions.get(transactionId)->onComplete(); 177 m_transactions.get(transactionId)->onComplete();
175 } 178 }
176 179
177 void IDBDatabase::onChanges( 180 void IDBDatabase::onChanges(
178 const std::unordered_map<int32_t, std::vector<int32_t>>& 181 const std::unordered_map<int32_t, std::vector<int32_t>>&
179 observation_index_map, 182 observation_index_map,
180 const WebVector<WebIDBObservation>& observations) { 183 const WebVector<WebIDBObservation>& observations,
184 const IDBDatabaseCallbacks::TransactionMap& transactions) {
181 for (const auto& map_entry : observation_index_map) { 185 for (const auto& map_entry : observation_index_map) {
182 auto it = m_observers.find(map_entry.first); 186 auto it = m_observers.find(map_entry.first);
183 if (it != m_observers.end()) { 187 if (it != m_observers.end()) {
184 IDBObserver* observer = it->value; 188 IDBObserver* observer = it->value;
189
190 IDBTransaction* transaction = nullptr;
191 auto it = transactions.find(map_entry.first);
192 if (it != transactions.end()) {
193 const std::pair<int64_t, std::vector<int64_t>>& obs_txn = it->second;
194 HashSet<String> stores;
195 for (int64_t store_id : obs_txn.second) {
196 stores.add(m_metadata.objectStores.get(store_id)->name);
197 }
198
199 transaction = IDBTransaction::createObserver(
200 getExecutionContext(), obs_txn.first, stores, this);
201 }
202
185 observer->callback()->call( 203 observer->callback()->call(
186 observer, 204 observer, IDBObserverChanges::create(this, transaction, observations,
187 IDBObserverChanges::create(this, observations, map_entry.second)); 205 map_entry.second));
206 if (transaction)
207 transaction->setActive(false);
188 } 208 }
189 } 209 }
190 } 210 }
191 211
192 DOMStringList* IDBDatabase::objectStoreNames() const { 212 DOMStringList* IDBDatabase::objectStoreNames() const {
193 DOMStringList* objectStoreNames = 213 DOMStringList* objectStoreNames =
194 DOMStringList::create(DOMStringList::IndexedDB); 214 DOMStringList::create(DOMStringList::IndexedDB);
195 for (const auto& it : m_metadata.objectStores) 215 for (const auto& it : m_metadata.objectStores)
196 objectStoreNames->append(it.value->name); 216 objectStoreNames->append(it.value->name);
197 objectStoreNames->sort(); 217 objectStoreNames->sort();
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 599
580 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) { 600 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) {
581 DEFINE_THREAD_SAFE_STATIC_LOCAL( 601 DEFINE_THREAD_SAFE_STATIC_LOCAL(
582 EnumerationHistogram, apiCallsHistogram, 602 EnumerationHistogram, apiCallsHistogram,
583 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", 603 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls",
584 IDBMethodsMax)); 604 IDBMethodsMax));
585 apiCallsHistogram.count(method); 605 apiCallsHistogram.count(method);
586 } 606 }
587 607
588 } // namespace blink 608 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698