Home | History | Annotate | Download | only in indexed_db
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_COORDINATOR_H_
      6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_COORDINATOR_H_
      7 
      8 #include <map>
      9 #include <set>
     10 #include <vector>
     11 
     12 #include "base/memory/ref_counted.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "content/browser/indexed_db/list_set.h"
     15 
     16 namespace content {
     17 
     18 class IndexedDBTransaction;
     19 
     20 // Transactions are executed in the order the were created.
     21 class IndexedDBTransactionCoordinator {
     22  public:
     23   IndexedDBTransactionCoordinator();
     24   ~IndexedDBTransactionCoordinator();
     25 
     26   // Called by transactions as they start and finish.
     27   void DidCreateTransaction(IndexedDBTransaction* transaction);
     28   void DidStartTransaction(IndexedDBTransaction* transaction);
     29   void DidFinishTransaction(IndexedDBTransaction* transaction);
     30 
     31 #ifndef NDEBUG
     32   bool IsActive(IndexedDBTransaction* transaction);
     33 #endif
     34 
     35   // Makes a snapshot of the transaction queue. For diagnostics only.
     36   std::vector<const IndexedDBTransaction*> GetTransactions() const;
     37 
     38  private:
     39   void ProcessStartedTransactions();
     40   bool CanRunTransaction(IndexedDBTransaction* transaction);
     41 
     42   // This is just an efficient way to keep references to all transactions.
     43   std::map<IndexedDBTransaction*, scoped_refptr<IndexedDBTransaction> >
     44       transactions_;
     45 
     46   // Transactions in different states are grouped below.
     47   // list_set is used to provide stable ordering; required by spec
     48   // for the queue, convenience for diagnostics for the rest.
     49   list_set<IndexedDBTransaction*> queued_transactions_;
     50   list_set<IndexedDBTransaction*> started_transactions_;
     51 };
     52 
     53 }  // namespace content
     54 
     55 #endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_TRANSACTION_COORDINATOR_H_
     56