1e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block/*
2e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * Copyright (C) 2010 Google Inc. All rights reserved.
3e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block *
4e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * Redistribution and use in source and binary forms, with or without
5e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * modification, are permitted provided that the following conditions
6e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * are met:
7e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block *
8e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * 1.  Redistributions of source code must retain the above copyright
9e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block *     notice, this list of conditions and the following disclaimer.
10e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * 2.  Redistributions in binary form must reproduce the above copyright
11e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block *     notice, this list of conditions and the following disclaimer in the
12e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block *     documentation and/or other materials provided with the distribution.
13e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block *
14e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block */
25e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
26e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block#include "config.h"
27e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block#include "IDBPendingTransactionMonitor.h"
28bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "IDBTransactionBackendInterface.h"
29e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
30e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block#if ENABLE(INDEXED_DATABASE)
31e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
32e8b154fd68f9b33be40a3590e58347f353835f5cSteve Blocknamespace WebCore {
33e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
34bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian MonsenVector<IDBTransactionBackendInterface*>* IDBPendingTransactionMonitor::m_transactions = 0;
35e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
36bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenvoid IDBPendingTransactionMonitor::addPendingTransaction(IDBTransactionBackendInterface* transaction)
37e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block{
38bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    if (!m_transactions)
39bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        m_transactions = new Vector<IDBTransactionBackendInterface*>();
40bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    m_transactions->append(transaction);
41e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block}
42e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
43bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenvoid IDBPendingTransactionMonitor::removePendingTransaction(IDBTransactionBackendInterface* transaction)
44e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block{
45bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    if (!m_transactions)
46bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        return;
47e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
48bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    size_t pos = m_transactions->find(transaction);
49bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    if (pos == notFound)
50bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        return;
51bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
52bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    m_transactions->remove(pos);
53bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
54bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    if (!m_transactions->size()) {
55bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        delete m_transactions;
56bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        m_transactions = 0;
57e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    }
58e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block}
59e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
60bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenvoid IDBPendingTransactionMonitor::abortPendingTransactions()
61e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block{
62bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    if (!m_transactions)
63e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block        return;
64e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
65bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    for (size_t i = 0; i < m_transactions->size(); ++i)
66bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        m_transactions->at(i)->abort();
67e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
68bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    delete m_transactions;
69bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    m_transactions = 0;
70e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block}
71e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block
72e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block};
73e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block#endif // ENABLE(INDEXED_DATABASE)
74