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

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: updated unittests Created 4 years, 1 month 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 "content/browser/indexed_db/indexed_db_observer.h"
17 16
18 namespace content { 17 namespace content {
18 class IndexedDBDatabaseCallbacks;
19 class IndexedDBDatabaseError; 19 class IndexedDBDatabaseError;
20 class IndexedDBObserver;
21 class IndexedDBTransaction;
20 22
21 class CONTENT_EXPORT IndexedDBConnection { 23 class CONTENT_EXPORT IndexedDBConnection {
22 public: 24 public:
23 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, 25 IndexedDBConnection(int child_process_id,
26 scoped_refptr<IndexedDBDatabase> db,
24 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); 27 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks);
25 virtual ~IndexedDBConnection(); 28 virtual ~IndexedDBConnection();
26 29
27 // These methods are virtual to allow subclassing in unit tests. 30 // These methods are virtual to allow subclassing in unit tests.
28 virtual void ForceClose(); 31 virtual void ForceClose();
29 virtual void Close(); 32 virtual void Close();
30 virtual bool IsConnected(); 33 virtual bool IsConnected();
31 34
32 void VersionChangeIgnored(); 35 void VersionChangeIgnored();
33 36
34 virtual void ActivatePendingObservers( 37 virtual void ActivatePendingObservers(
35 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); 38 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers);
36 // Removes observer listed in |remove_observer_ids| from active_observer of 39 // Removes observer listed in |remove_observer_ids| from active_observer of
37 // connection or pending_observer of transactions associated with this 40 // connection or pending_observer of transactions associated with this
38 // connection. 41 // connection.
39 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); 42 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids);
40 43
41 int32_t id() const { return id_; } 44 int32_t id() const { return id_; }
45 int child_process_id() const { return child_process_id_; }
42 46
43 IndexedDBDatabase* database() const { return database_.get(); } 47 IndexedDBDatabase* database() const { return database_.get(); }
44 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } 48 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); }
45 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() 49 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers()
46 const { 50 const {
47 return active_observers_; 51 return active_observers_;
48 } 52 }
49 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { 53 base::WeakPtr<IndexedDBConnection> GetWeakPtr() {
50 return weak_factory_.GetWeakPtr(); 54 return weak_factory_.GetWeakPtr();
51 } 55 }
52 56
57 // Creates a transaction for this connection.
58 IndexedDBTransaction* CreateTransaction(
59 int64_t id,
60 const std::set<int64_t>& scope,
61 blink::WebIDBTransactionMode mode,
62 IndexedDBBackingStore::Transaction* backing_store_transaction);
63
64 IndexedDBTransaction* GetTransaction(int64_t id);
65
66 IndexedDBTransaction* StoreTransactionForTesting(
67 std::unique_ptr<IndexedDBTransaction> transaction);
68
69 // We ignore calls where the id doesn't exist to facilitate our AbortAll call
70 // below.
71 // TODO(dmurph): Change this to make aborting more robust.
72 void EraseTransaction(int64_t id);
73
74 void AbortAllTransactions(const IndexedDBDatabaseError& error);
75
76 const std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>>&
77 transactions() {
cmumford 2016/11/04 23:33:12 make method const.
dmurph 2016/11/07 20:05:22 Done.
78 return transactions_;
79 }
80
53 private: 81 private:
54 const int32_t id_; 82 const int32_t id_;
83 const int child_process_id_;
jsbell 2016/11/04 17:48:19 Can this be base::ProcessId rather than int?
jsbell 2016/11/04 17:48:19 Can you add a comment about why we track the proce
dmurph 2016/11/04 22:52:24 Well, we're given an 'int' down the whole stack, s
dmurph 2016/11/04 22:52:24 Done.
jsbell 2016/11/05 00:01:48 If it's given to us as an `int` that's fine (I did
55 84
56 // NULL in some unit tests, and after the connection is closed. 85 // NULL in some unit tests, and after the connection is closed.
57 scoped_refptr<IndexedDBDatabase> database_; 86 scoped_refptr<IndexedDBDatabase> database_;
87 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>>
jsbell 2016/11/04 17:48:19 Is there a good reason to use unordered_map vs. ma
jsbell 2016/11/04 17:48:19 Can you add comments to members as you touch them?
dmurph 2016/11/04 22:52:24 Done.
dmurph 2016/11/04 22:52:24 Huh. I don't know. I don't think so.
88 transactions_;
58 89
59 // The callbacks_ member is cleared when the connection is closed. 90 // The callbacks_ member is cleared when the connection is closed.
60 // May be NULL in unit tests. 91 // May be NULL in unit tests.
61 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; 92 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_;
62 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; 93 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_;
63 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; 94 base::WeakPtrFactory<IndexedDBConnection> weak_factory_;
64 95
65 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); 96 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection);
66 }; 97 };
67 98
68 } // namespace content 99 } // namespace content
69 100
70 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ 101 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698