Chromium Code Reviews| 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" |
| 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 const url::Origin& origin, | |
| 28 scoped_refptr<IndexedDBDatabase> db, | |
| 23 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); | 29 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); |
| 24 virtual ~IndexedDBConnection(); | 30 virtual ~IndexedDBConnection(); |
| 25 | 31 |
| 26 // These methods are virtual to allow subclassing in unit tests. | 32 // These methods are virtual to allow subclassing in unit tests. |
| 27 virtual void ForceClose(); | 33 virtual void ForceClose(); |
| 28 virtual void Close(); | 34 virtual void Close(); |
| 29 virtual bool IsConnected(); | 35 virtual bool IsConnected(); |
| 30 | 36 |
| 31 void VersionChangeIgnored(); | 37 void VersionChangeIgnored(); |
| 32 | 38 |
| 33 virtual void ActivatePendingObservers( | 39 virtual void ActivatePendingObservers( |
| 34 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); | 40 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); |
| 35 // Removes observer listed in |remove_observer_ids| from active_observer of | 41 // Removes observer listed in |remove_observer_ids| from active_observer of |
| 36 // connection or pending_observer of transactions associated with this | 42 // connection or pending_observer of transactions associated with this |
| 37 // connection. | 43 // connection. |
| 38 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); | 44 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); |
| 39 | 45 |
| 40 int32_t id() const { return id_; } | 46 int32_t id() const { return id_; } |
| 47 int child_process_id() const { return child_process_id_; } | |
| 48 const url::Origin& origin() const { return origin_; } | |
| 41 | 49 |
| 42 IndexedDBDatabase* database() const { return database_.get(); } | 50 IndexedDBDatabase* database() const { return database_.get(); } |
| 43 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | 51 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } |
| 44 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() | 52 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() |
| 45 const { | 53 const { |
| 46 return active_observers_; | 54 return active_observers_; |
| 47 } | 55 } |
| 48 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { | 56 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { |
| 49 return weak_factory_.GetWeakPtr(); | 57 return weak_factory_.GetWeakPtr(); |
| 50 } | 58 } |
| 51 | 59 |
| 60 // Creates a transaction for this connection. | |
| 61 IndexedDBTransaction* CreateTransaction( | |
| 62 int64_t id, | |
| 63 const std::set<int64_t>& scope, | |
| 64 blink::WebIDBTransactionMode mode, | |
| 65 IndexedDBBackingStore::Transaction* backing_store_transaction); | |
| 66 | |
| 67 void AbortTransaction(IndexedDBTransaction* transaction); | |
| 68 void AbortTransaction(IndexedDBTransaction* transaction, | |
| 69 const IndexedDBDatabaseError& error); | |
| 70 | |
| 71 void AbortAllTransactions(const IndexedDBDatabaseError& error); | |
| 72 | |
| 73 IndexedDBTransaction* GetTransaction(int64_t id); | |
| 74 | |
| 75 IndexedDBTransaction* StoreTransactionForTesting( | |
| 76 std::unique_ptr<IndexedDBTransaction> transaction); | |
| 77 | |
| 78 // We ignore calls where the id doesn't exist to facilitate our AbortAll call | |
| 79 // below. | |
|
jsbell
2016/11/08 00:42:52
above?
dmurph
2016/11/09 00:27:32
Clarified.
| |
| 80 // TODO(dmurph): Change this to make aborting more robust. | |
| 81 void EraseTransaction(int64_t id); | |
| 82 | |
| 83 const std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>>& | |
| 84 transactions() const { | |
| 85 return transactions_; | |
| 86 } | |
| 87 | |
| 52 private: | 88 private: |
| 53 const int32_t id_; | 89 const int32_t id_; |
| 54 | 90 |
| 91 // The process id of the child process this connection is associated with. | |
| 92 // Tracked for IndexedDBContextImpl::GetAllOriginsDetails and debugging. | |
| 93 const int child_process_id_; | |
| 94 // The origin that this connection was created from. | |
|
jsbell
2016/11/08 00:42:52
Now that I think about it, this can be derived fro
dmurph
2016/11/09 00:27:32
Done.
| |
| 95 const url::Origin origin_; | |
| 96 | |
| 55 // NULL in some unit tests, and after the connection is closed. | 97 // NULL in some unit tests, and after the connection is closed. |
| 56 scoped_refptr<IndexedDBDatabase> database_; | 98 scoped_refptr<IndexedDBDatabase> database_; |
| 99 // The connection owns transactions created on this connection. | |
| 100 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>> | |
| 101 transactions_; | |
| 57 | 102 |
| 58 // The callbacks_ member is cleared when the connection is closed. | 103 // The callbacks_ member is cleared when the connection is closed. |
| 59 // May be NULL in unit tests. | 104 // May be NULL in unit tests. |
| 60 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 105 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
| 61 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; | 106 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; |
| 62 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; | 107 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; |
| 63 | 108 |
| 64 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); | 109 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); |
| 65 }; | 110 }; |
| 66 | 111 |
| 67 } // namespace content | 112 } // namespace content |
| 68 | 113 |
| 69 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 114 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
| OLD | NEW |