| 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 <set> |
| 10 #include <unordered_map> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 14 #include "content/browser/indexed_db/indexed_db_database.h" | 16 #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 | 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) const; |
| 72 |
| 73 base::WeakPtr<IndexedDBTransaction> AddTransactionForTesting( |
| 74 std::unique_ptr<IndexedDBTransaction> transaction); |
| 75 |
| 76 // We ignore calls where the id doesn't exist to facilitate the AbortAll call. |
| 77 // TODO(dmurph): Change that so this doesn't need to ignore unknown ids. |
| 78 void RemoveTransaction(int64_t id); |
| 79 |
| 52 private: | 80 private: |
| 53 const int32_t id_; | 81 const int32_t id_; |
| 54 | 82 |
| 83 // The process id of the child process this connection is associated with. |
| 84 // Tracked for IndexedDBContextImpl::GetAllOriginsDetails and debugging. |
| 85 const int child_process_id_; |
| 86 |
| 55 // NULL in some unit tests, and after the connection is closed. | 87 // NULL in some unit tests, and after the connection is closed. |
| 56 scoped_refptr<IndexedDBDatabase> database_; | 88 scoped_refptr<IndexedDBDatabase> database_; |
| 57 | 89 |
| 90 // The connection owns transactions created on this connection. |
| 91 std::unordered_map<int64_t, std::unique_ptr<IndexedDBTransaction>> |
| 92 transactions_; |
| 93 |
| 58 // The callbacks_ member is cleared when the connection is closed. | 94 // The callbacks_ member is cleared when the connection is closed. |
| 59 // May be NULL in unit tests. | 95 // May be NULL in unit tests. |
| 60 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 96 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
| 61 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; | 97 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; |
| 62 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; | 98 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; |
| 63 | 99 |
| 64 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); | 100 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); |
| 65 }; | 101 }; |
| 66 | 102 |
| 67 } // namespace content | 103 } // namespace content |
| 68 | 104 |
| 69 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 105 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
| OLD | NEW |