OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "content/browser/indexed_db/indexed_db_database.h" | 15 #include "content/browser/indexed_db/indexed_db_database.h" |
15 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 16 #include "url/origin.h" |
cmumford
2016/12/01 19:14:51
origin.h is unused, but you can include <set>.
dmurph
2016/12/01 21:12:23
Done.
| |
16 #include "content/browser/indexed_db/indexed_db_observer.h" | |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class IndexedDBDatabaseCallbacks; | |
20 class IndexedDBDatabaseError; | |
21 class IndexedDBObserver; | |
22 class IndexedDBTransaction; | |
19 | 23 |
20 class CONTENT_EXPORT IndexedDBConnection { | 24 class CONTENT_EXPORT IndexedDBConnection { |
21 public: | 25 public: |
22 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, | 26 using TransactionMap = |
27 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>>; | |
28 | |
29 IndexedDBConnection(int child_process_id, | |
30 scoped_refptr<IndexedDBDatabase> db, | |
23 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); | 31 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); |
24 virtual ~IndexedDBConnection(); | 32 virtual ~IndexedDBConnection(); |
25 | 33 |
26 // These methods are virtual to allow subclassing in unit tests. | 34 // These methods are virtual to allow subclassing in unit tests. |
27 virtual void ForceClose(); | 35 virtual void ForceClose(); |
28 virtual void Close(); | 36 virtual void Close(); |
29 virtual bool IsConnected(); | 37 virtual bool IsConnected(); |
30 | 38 |
31 void VersionChangeIgnored(); | 39 void VersionChangeIgnored(); |
32 | 40 |
33 virtual void ActivatePendingObservers( | 41 virtual void ActivatePendingObservers( |
34 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); | 42 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); |
35 // Removes observer listed in |remove_observer_ids| from active_observer of | 43 // Removes observer listed in |remove_observer_ids| from active_observer of |
36 // connection or pending_observer of transactions associated with this | 44 // connection or pending_observer of transactions associated with this |
37 // connection. | 45 // connection. |
38 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); | 46 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); |
39 | 47 |
40 int32_t id() const { return id_; } | 48 int32_t id() const { return id_; } |
49 int child_process_id() const { return child_process_id_; } | |
41 | 50 |
42 IndexedDBDatabase* database() const { return database_.get(); } | 51 IndexedDBDatabase* database() const { return database_.get(); } |
43 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | 52 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } |
44 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() | 53 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() |
45 const { | 54 const { |
46 return active_observers_; | 55 return active_observers_; |
47 } | 56 } |
48 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { | 57 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { |
49 return weak_factory_.GetWeakPtr(); | 58 return weak_factory_.GetWeakPtr(); |
50 } | 59 } |
51 | 60 |
61 // Creates a transaction for this connection. | |
62 IndexedDBTransaction* CreateTransaction( | |
63 int64_t id, | |
64 const std::set<int64_t>& scope, | |
65 blink::WebIDBTransactionMode mode, | |
66 IndexedDBBackingStore::Transaction* backing_store_transaction); | |
67 | |
68 void AbortTransaction(IndexedDBTransaction* transaction); | |
69 void AbortTransaction(IndexedDBTransaction* transaction, | |
70 const IndexedDBDatabaseError& error); | |
71 | |
72 void AbortAllTransactions(const IndexedDBDatabaseError& error); | |
73 | |
74 IndexedDBTransaction* GetTransaction(int64_t id); | |
cmumford
2016/12/01 19:14:51
Function should be const.
dmurph
2016/12/01 21:12:23
Done.
| |
75 | |
76 base::WeakPtr<IndexedDBTransaction> AddTransactionForTesting( | |
77 std::unique_ptr<IndexedDBTransaction> transaction); | |
78 | |
79 // We ignore calls where the id doesn't exist to facilitate the AbortAll call. | |
80 // TODO(dmurph): Change that so this doesn't need to ignore unknown ids. | |
81 void RemoveTransaction(int64_t id); | |
82 | |
83 const TransactionMap& transactions() const { return transactions_; } | |
cmumford
2016/12/01 19:14:51
transactions() is unused.
Also, now that there is
dmurph
2016/12/01 21:12:23
haha ok done ;)
| |
84 | |
52 private: | 85 private: |
53 const int32_t id_; | 86 const int32_t id_; |
54 | 87 |
88 // The process id of the child process this connection is associated with. | |
89 // Tracked for IndexedDBContextImpl::GetAllOriginsDetails and debugging. | |
90 const int child_process_id_; | |
91 | |
55 // NULL in some unit tests, and after the connection is closed. | 92 // NULL in some unit tests, and after the connection is closed. |
56 scoped_refptr<IndexedDBDatabase> database_; | 93 scoped_refptr<IndexedDBDatabase> database_; |
57 | 94 |
95 // The connection owns transactions created on this connection. | |
96 TransactionMap transactions_; | |
97 | |
58 // The callbacks_ member is cleared when the connection is closed. | 98 // The callbacks_ member is cleared when the connection is closed. |
59 // May be NULL in unit tests. | 99 // May be NULL in unit tests. |
60 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 100 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
61 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; | 101 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; |
62 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; | 102 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; |
63 | 103 |
64 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); | 104 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); |
65 }; | 105 }; |
66 | 106 |
67 } // namespace content | 107 } // namespace content |
68 | 108 |
69 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 109 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
OLD | NEW |