1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_COORDINATOR_H_ 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_COORDINATOR_H_ 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <map> 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <set> 10ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include <vector> 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/ref_counted.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/browser/indexed_db/list_set.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content { 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexedDBTransaction; 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Transactions are executed in the order the were created. 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class IndexedDBTransactionCoordinator { 22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public: 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) IndexedDBTransactionCoordinator(); 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ~IndexedDBTransactionCoordinator(); 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Called by transactions as they start and finish. 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void DidCreateTransaction(scoped_refptr<IndexedDBTransaction> transaction); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void DidFinishTransaction(IndexedDBTransaction* transaction); 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool IsRunningVersionChangeTransaction() const; 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef NDEBUG 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool IsActive(IndexedDBTransaction* transaction); 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 36ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Makes a snapshot of the transaction queue. For diagnostics only. 37ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch std::vector<const IndexedDBTransaction*> GetTransactions() const; 38ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private: 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef list_set<scoped_refptr<IndexedDBTransaction> > TransactionSet; 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void ProcessQueuedTransactions(); 43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool CanStartTransaction(IndexedDBTransaction* const transaction, 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const std::set<int64>& locked_scope) const; 45ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Transactions in different states are grouped below. 47ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // list_set is used to provide stable ordering; required by spec 48ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // for the queue, convenience for diagnostics for the rest. 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TransactionSet queued_transactions_; 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TransactionSet started_transactions_; 51f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 52f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(IndexedDBTransactionCoordinator); 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace content 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_COORDINATOR_H_ 58