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

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: Transactions working 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 29 matching lines...) Expand all
40 #include "modules/indexeddb/IDBKeyPath.h" 40 #include "modules/indexeddb/IDBKeyPath.h"
41 #include "modules/indexeddb/IDBObserver.h" 41 #include "modules/indexeddb/IDBObserver.h"
42 #include "modules/indexeddb/IDBObserverChanges.h" 42 #include "modules/indexeddb/IDBObserverChanges.h"
43 #include "modules/indexeddb/IDBTracing.h" 43 #include "modules/indexeddb/IDBTracing.h"
44 #include "modules/indexeddb/IDBVersionChangeEvent.h" 44 #include "modules/indexeddb/IDBVersionChangeEvent.h"
45 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h" 45 #include "modules/indexeddb/WebIDBDatabaseCallbacksImpl.h"
46 #include "platform/Histogram.h" 46 #include "platform/Histogram.h"
47 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h" 47 #include "public/platform/modules/indexeddb/WebIDBKeyPath.h"
48 #include "public/platform/modules/indexeddb/WebIDBTypes.h" 48 #include "public/platform/modules/indexeddb/WebIDBTypes.h"
49 #include "wtf/Atomics.h" 49 #include "wtf/Atomics.h"
50
50 #include <limits> 51 #include <limits>
51 #include <memory> 52 #include <memory>
52 53
53 using blink::WebIDBDatabase; 54 using blink::WebIDBDatabase;
54 55
55 namespace blink { 56 namespace blink {
56 57
57 const char IDBDatabase::indexDeletedErrorMessage[] = 58 const char IDBDatabase::indexDeletedErrorMessage[] =
58 "The index or its object store has been deleted."; 59 "The index or its object store has been deleted.";
59 const char IDBDatabase::indexNameTakenErrorMessage[] = 60 const char IDBDatabase::indexNameTakenErrorMessage[] =
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 172 }
172 173
173 void IDBDatabase::onComplete(int64_t transactionId) { 174 void IDBDatabase::onComplete(int64_t transactionId) {
174 DCHECK(m_transactions.contains(transactionId)); 175 DCHECK(m_transactions.contains(transactionId));
175 m_transactions.get(transactionId)->onComplete(); 176 m_transactions.get(transactionId)->onComplete();
176 } 177 }
177 178
178 void IDBDatabase::onChanges( 179 void IDBDatabase::onChanges(
179 const std::unordered_map<int32_t, std::vector<int32_t>>& 180 const std::unordered_map<int32_t, std::vector<int32_t>>&
180 observation_index_map, 181 observation_index_map,
181 const WebVector<WebIDBObservation>& observations) { 182 const WebVector<WebIDBObservation>& observations,
183 const std::unordered_map<int32_t, std::pair<int64_t, std::vector<int64_t>>>&
184 transactions) {
182 for (const auto& map_entry : observation_index_map) { 185 for (const auto& map_entry : observation_index_map) {
183 auto it = m_observers.find(map_entry.first); 186 auto it = m_observers.find(map_entry.first);
184 if (it != m_observers.end()) { 187 if (it != m_observers.end()) {
185 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
186 observer->callback()->call( 203 observer->callback()->call(
187 observer, 204 observer, IDBObserverChanges::create(this, transaction, observations,
188 IDBObserverChanges::create(this, observations, map_entry.second)); 205 map_entry.second));
206 if (transaction)
207 transaction->setActive(false);
189 } 208 }
190 } 209 }
191 } 210 }
192 211
193 DOMStringList* IDBDatabase::objectStoreNames() const { 212 DOMStringList* IDBDatabase::objectStoreNames() const {
194 DOMStringList* objectStoreNames = 213 DOMStringList* objectStoreNames =
195 DOMStringList::create(DOMStringList::IndexedDB); 214 DOMStringList::create(DOMStringList::IndexedDB);
196 for (const auto& it : m_metadata.objectStores) 215 for (const auto& it : m_metadata.objectStores)
197 objectStoreNames->append(it.value->name); 216 objectStoreNames->append(it.value->name);
198 objectStoreNames->sort(); 217 objectStoreNames->sort();
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 599
581 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) { 600 void IDBDatabase::recordApiCallsHistogram(IndexedDatabaseMethods method) {
582 DEFINE_THREAD_SAFE_STATIC_LOCAL( 601 DEFINE_THREAD_SAFE_STATIC_LOCAL(
583 EnumerationHistogram, apiCallsHistogram, 602 EnumerationHistogram, apiCallsHistogram,
584 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls", 603 new EnumerationHistogram("WebCore.IndexedDB.FrontEndAPICalls",
585 IDBMethodsMax)); 604 IDBMethodsMax));
586 apiCallsHistogram.count(method); 605 apiCallsHistogram.count(method);
587 } 606 }
588 607
589 } // namespace blink 608 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698