blob: 3c305f39d057147c8a8feb12654a0f826404b09a [file] [log] [blame]
[email protected]da6bce0c2013-07-03 04:33:371// Copyright 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_CONNECTION_H_
6#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_
7
avib7348942015-12-25 20:57:108#include "base/macros.h"
[email protected]da6bce0c2013-07-03 04:33:379#include "base/memory/ref_counted.h"
cmumford5c0b3e02014-11-11 01:22:5110#include "base/memory/weak_ptr.h"
[email protected]da6bce0c2013-07-03 04:33:3711#include "content/browser/indexed_db/indexed_db_database.h"
12#include "content/browser/indexed_db/indexed_db_database_callbacks.h"
palakj05f35ea2016-07-08 00:59:2113#include "content/browser/indexed_db/indexed_db_observer.h"
[email protected]da6bce0c2013-07-03 04:33:3714
15namespace content {
[email protected]da6bce0c2013-07-03 04:33:3716class IndexedDBDatabaseError;
17
18class CONTENT_EXPORT IndexedDBConnection {
19 public:
20 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db,
21 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks);
22 virtual ~IndexedDBConnection();
23
[email protected]1c0f12272013-10-19 22:24:4624 // These methods are virtual to allow subclassing in unit tests.
[email protected]da6bce0c2013-07-03 04:33:3725 virtual void ForceClose();
26 virtual void Close();
[email protected]1c0f12272013-10-19 22:24:4627 virtual bool IsConnected();
[email protected]da6bce0c2013-07-03 04:33:3728
[email protected]75a854a2014-07-07 15:57:3629 void VersionChangeIgnored();
30
palakj05f35ea2016-07-08 00:59:2131 virtual void ActivatePendingObservers(
32 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers);
33 // Removes observer listed in |remove_observer_ids| from active_observer of
34 // connection or pending_observer of transactions associated with this
35 // connection.
36 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids);
37
jsbell1869ef42014-10-03 17:34:3838 IndexedDBDatabase* database() const { return database_.get(); }
39 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); }
palakj05f35ea2016-07-08 00:59:2140 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers()
41 const {
42 return active_observers_;
43 }
44 base::WeakPtr<IndexedDBConnection> GetWeakPtr() {
45 return weak_factory_.GetWeakPtr();
46 }
[email protected]da6bce0c2013-07-03 04:33:3747
48 private:
[email protected]1c0f12272013-10-19 22:24:4649 // NULL in some unit tests, and after the connection is closed.
[email protected]da6bce0c2013-07-03 04:33:3750 scoped_refptr<IndexedDBDatabase> database_;
51
52 // The callbacks_ member is cleared when the connection is closed.
53 // May be NULL in unit tests.
54 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
palakj05f35ea2016-07-08 00:59:2155 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_;
cmumford5c0b3e02014-11-11 01:22:5156 base::WeakPtrFactory<IndexedDBConnection> weak_factory_;
57
[email protected]e8ca0f52014-06-07 08:46:3458 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection);
[email protected]da6bce0c2013-07-03 04:33:3759};
60
61} // namespace content
62
63#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_