[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 1 | // 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 | |||||
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
cmumford | 5c0b3e0 | 2014-11-11 01:22:51 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 11 | #include "content/browser/indexed_db/indexed_db_database.h" |
12 | #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | ||||
palakj | 05f35ea | 2016-07-08 00:59:21 | [diff] [blame^] | 13 | #include "content/browser/indexed_db/indexed_db_observer.h" |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 14 | |
15 | namespace content { | ||||
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 16 | class IndexedDBDatabaseError; |
17 | |||||
18 | class CONTENT_EXPORT IndexedDBConnection { | ||||
19 | public: | ||||
20 | IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, | ||||
21 | scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); | ||||
22 | virtual ~IndexedDBConnection(); | ||||
23 | |||||
[email protected] | 1c0f1227 | 2013-10-19 22:24:46 | [diff] [blame] | 24 | // These methods are virtual to allow subclassing in unit tests. |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 25 | virtual void ForceClose(); |
26 | virtual void Close(); | ||||
[email protected] | 1c0f1227 | 2013-10-19 22:24:46 | [diff] [blame] | 27 | virtual bool IsConnected(); |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 28 | |
[email protected] | 75a854a | 2014-07-07 15:57:36 | [diff] [blame] | 29 | void VersionChangeIgnored(); |
30 | |||||
palakj | 05f35ea | 2016-07-08 00:59:21 | [diff] [blame^] | 31 | 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 | |||||
jsbell | 1869ef4 | 2014-10-03 17:34:38 | [diff] [blame] | 38 | IndexedDBDatabase* database() const { return database_.get(); } |
39 | IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | ||||
palakj | 05f35ea | 2016-07-08 00:59:21 | [diff] [blame^] | 40 | 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] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 47 | |
48 | private: | ||||
[email protected] | 1c0f1227 | 2013-10-19 22:24:46 | [diff] [blame] | 49 | // NULL in some unit tests, and after the connection is closed. |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 50 | 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_; | ||||
palakj | 05f35ea | 2016-07-08 00:59:21 | [diff] [blame^] | 55 | std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; |
cmumford | 5c0b3e0 | 2014-11-11 01:22:51 | [diff] [blame] | 56 | base::WeakPtrFactory<IndexedDBConnection> weak_factory_; |
57 | |||||
[email protected] | e8ca0f5 | 2014-06-07 08:46:34 | [diff] [blame] | 58 | DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); |
[email protected] | da6bce0c | 2013-07-03 04:33:37 | [diff] [blame] | 59 | }; |
60 | |||||
61 | } // namespace content | ||||
62 | |||||
63 | #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |