Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: content/browser/indexed_db/indexed_db_connection.h

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: rebased & working Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
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 IndexedDBConnection(int child_process_id,
27 scoped_refptr<IndexedDBDatabase> db,
23 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); 28 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks);
24 virtual ~IndexedDBConnection(); 29 virtual ~IndexedDBConnection();
25 30
26 // These methods are virtual to allow subclassing in unit tests. 31 // These methods are virtual to allow subclassing in unit tests.
27 virtual void ForceClose(); 32 virtual void ForceClose();
28 virtual void Close(); 33 virtual void Close();
29 virtual bool IsConnected(); 34 virtual bool IsConnected();
30 35
31 void VersionChangeIgnored(); 36 void VersionChangeIgnored();
32 37
33 virtual void ActivatePendingObservers( 38 virtual void ActivatePendingObservers(
34 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); 39 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers);
35 // Removes observer listed in |remove_observer_ids| from active_observer of 40 // Removes observer listed in |remove_observer_ids| from active_observer of
36 // connection or pending_observer of transactions associated with this 41 // connection or pending_observer of transactions associated with this
37 // connection. 42 // connection.
38 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); 43 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids);
39 44
40 int32_t id() const { return id_; } 45 int32_t id() const { return id_; }
46 int child_process_id() const { return child_process_id_; }
41 47
42 IndexedDBDatabase* database() const { return database_.get(); } 48 IndexedDBDatabase* database() const { return database_.get(); }
43 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } 49 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); }
44 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() 50 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers()
45 const { 51 const {
46 return active_observers_; 52 return active_observers_;
47 } 53 }
48 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { 54 base::WeakPtr<IndexedDBConnection> GetWeakPtr() {
49 return weak_factory_.GetWeakPtr(); 55 return weak_factory_.GetWeakPtr();
50 } 56 }
51 57
58 // Creates a transaction for this connection.
59 IndexedDBTransaction* CreateTransaction(
60 int64_t id,
61 const std::set<int64_t>& scope,
62 blink::WebIDBTransactionMode mode,
63 IndexedDBBackingStore::Transaction* backing_store_transaction);
64
65 void AbortTransaction(IndexedDBTransaction* transaction);
66 void AbortTransaction(IndexedDBTransaction* transaction,
67 const IndexedDBDatabaseError& error);
68
69 void AbortAllTransactions(const IndexedDBDatabaseError& error);
70
71 IndexedDBTransaction* GetTransaction(int64_t id);
72
73 base::WeakPtr<IndexedDBTransaction> StoreTransactionForTesting(
jsbell 2016/11/30 21:30:13 AddTransactionForTesting ?
dmurph 2016/11/30 23:13:07 Done.
74 std::unique_ptr<IndexedDBTransaction> transaction);
75
76 // We ignore calls where the id doesn't exist to facilitate our AbortAll call
77 // below.
78 // TODO(dmurph): Change the abort behavior so we don't have to ignore ids.
79 void EraseTransaction(int64_t id);
jsbell 2016/11/30 21:30:13 RemoveTransaction ?
dmurph 2016/11/30 23:13:07 Done.
80
81 const std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>>&
jsbell 2016/11/30 21:30:14 Since this complex type appears twice, add a using
82 transactions() const {
jsbell 2016/11/30 21:30:14 nit: single line? (but whatever clang format prefe
dmurph 2016/11/30 23:13:07 Done.
83 return transactions_;
84 }
85
52 private: 86 private:
53 const int32_t id_; 87 const int32_t id_;
54 88
89 // The process id of the child process this connection is associated with.
90 // Tracked for IndexedDBContextImpl::GetAllOriginsDetails and debugging.
91 const int child_process_id_;
92
55 // NULL in some unit tests, and after the connection is closed. 93 // NULL in some unit tests, and after the connection is closed.
56 scoped_refptr<IndexedDBDatabase> database_; 94 scoped_refptr<IndexedDBDatabase> database_;
95 // The connection owns transactions created on this connection.
jsbell 2016/11/30 21:30:14 nit: blank line before
dmurph 2016/11/30 23:13:07 Done.
96 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>>
97 transactions_;
57 98
58 // The callbacks_ member is cleared when the connection is closed. 99 // The callbacks_ member is cleared when the connection is closed.
59 // May be NULL in unit tests. 100 // May be NULL in unit tests.
60 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; 101 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
61 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; 102 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_;
62 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; 103 base::WeakPtrFactory<IndexedDBConnection> weak_factory_;
63 104
64 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); 105 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection);
65 }; 106 };
66 107
67 } // namespace content 108 } // namespace content
68 109
69 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ 110 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698