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 <map> |
| 9 #include <memory> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "Source/modules/indexeddb/indexed_db.mojom.h" |
8 #include "base/macros.h" | 14 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "content/browser/indexed_db/indexed_db_change_handler.h" |
11 #include "content/browser/indexed_db/indexed_db_database.h" | 18 #include "content/browser/indexed_db/indexed_db_database.h" |
12 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | |
13 #include "content/browser/indexed_db/indexed_db_observer.h" | 19 #include "content/browser/indexed_db/indexed_db_observer.h" |
| 20 #include "mojo/public/cpp/bindings/binding_set.h" |
| 21 #include "storage/common/quota/quota_status_code.h" |
14 | 22 |
15 namespace content { | 23 namespace content { |
16 class IndexedDBDatabaseError; | 24 class IndexedDBDatabaseError; |
17 | 25 |
18 class CONTENT_EXPORT IndexedDBConnection { | 26 class CONTENT_EXPORT IndexedDBConnection |
| 27 : public ::indexed_db::mojom::Database { |
19 public: | 28 public: |
20 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, | 29 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, |
21 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); | 30 scoped_refptr<IndexedDBChangeHandler> change_handler); |
22 virtual ~IndexedDBConnection(); | 31 ~IndexedDBConnection() override; |
23 | 32 |
24 // These methods are virtual to allow subclassing in unit tests. | 33 // These methods are virtual to allow subclassing in unit tests. |
25 virtual void ForceClose(); | 34 virtual void ForceClose(); |
26 virtual void Close(); | |
27 virtual bool IsConnected(); | 35 virtual bool IsConnected(); |
28 | 36 |
29 void VersionChangeIgnored(); | |
30 | |
31 virtual void ActivatePendingObservers( | 37 virtual void ActivatePendingObservers( |
32 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); | 38 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); |
33 // Removes observer listed in |remove_observer_ids| from active_observer of | 39 // Removes observer listed in |remove_observer_ids| from active_observer of |
34 // connection or pending_observer of transactions associated with this | 40 // connection or pending_observer of transactions associated with this |
35 // connection. | 41 // connection. |
36 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); | 42 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); |
37 | 43 |
38 void set_id(int32_t id); | 44 void set_id(int32_t id); |
39 int32_t id() const { return id_; } | 45 int32_t id() const { return id_; } |
40 | 46 |
41 IndexedDBDatabase* database() const { return database_.get(); } | 47 IndexedDBDatabase* database() const { return database_.get(); } |
42 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | 48 IndexedDBChangeHandler* change_handler() const { |
| 49 return change_handler_.get(); |
| 50 } |
43 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() | 51 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() |
44 const { | 52 const { |
45 return active_observers_; | 53 return active_observers_; |
46 } | 54 } |
47 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { | 55 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { |
48 return weak_factory_.GetWeakPtr(); | 56 return weak_factory_.GetWeakPtr(); |
49 } | 57 } |
50 | 58 |
| 59 // ::indexed_db::mojom::Database: |
| 60 void CreateObjectStore(int64_t transaction_id, |
| 61 int64_t object_store_id, |
| 62 const std::string& name, |
| 63 const IndexedDBKeyPath& key_path, |
| 64 bool auto_increment) override; |
| 65 |
| 66 void DeleteObjectStore(int64_t transaction_id, |
| 67 int64_t object_store_id) override; |
| 68 |
| 69 void CreateTransaction( |
| 70 int64_t transaction_id, |
| 71 const std::vector<int64_t>& scope, |
| 72 ::indexed_db::mojom::TransactionMode transaction_mode) override; |
| 73 |
| 74 void Close() override; |
| 75 |
| 76 void VersionChangeIgnored() override; |
| 77 |
| 78 void Abort(int64_t transaction_id) override; |
| 79 |
| 80 void Commit(int64_t transaction_id) override; |
| 81 |
| 82 void CreateIndex(int64_t transaction_id, |
| 83 int64_t object_store_id, |
| 84 int64_t index_id, |
| 85 const std::string& name, |
| 86 const IndexedDBKeyPath& key_path, |
| 87 bool unique, |
| 88 bool multi_entry) override; |
| 89 |
| 90 void DeleteIndex(int64_t transaction_id, |
| 91 int64_t object_store_id, |
| 92 int64_t index_id) override; |
| 93 |
| 94 void Get(int64_t transaction_id, |
| 95 int64_t object_store_id, |
| 96 int64_t index_id, |
| 97 ::indexed_db::mojom::KeyRangePtr key_range, |
| 98 bool key_only, |
| 99 const GetCallback& callback) override; |
| 100 |
| 101 void GetAll(int64_t transaction_id, |
| 102 int64_t object_store_id, |
| 103 int64_t index_id, |
| 104 ::indexed_db::mojom::KeyRangePtr key_range, |
| 105 int64_t max_count, |
| 106 bool key_only) override; |
| 107 |
| 108 void Put(int64_t transaction_id, |
| 109 int64_t object_store_id, |
| 110 const std::vector<int8_t>& value, |
| 111 std::vector<::indexed_db::mojom::BlobInfoPtr> blob_info, |
| 112 ::indexed_db::mojom::KeyPtr key, |
| 113 ::indexed_db::mojom::PutMode put_mode, |
| 114 const std::vector<int64_t>& index_ids, |
| 115 std::vector<std::vector<::indexed_db::mojom::KeyPtr>> index_keys) |
| 116 override; |
| 117 |
| 118 void DeleteRange(int64_t transaction_id, |
| 119 int64_t object_store_id, |
| 120 ::indexed_db::mojom::KeyRangePtr key_range) override; |
| 121 |
| 122 void Clear(int64_t transaction_id, int64_t object_store_id) override; |
| 123 |
| 124 void SetIndexKeys(int64_t transaction_id, |
| 125 int64_t object_store_id, |
| 126 ::indexed_db::mojom::KeyPtr primary_key, |
| 127 const std::vector<int64_t>& index_ids, |
| 128 std::vector<std::vector<::indexed_db::mojom::KeyPtr>> |
| 129 index_keys) override; |
| 130 |
| 131 void SetIndexesReady(int64_t transaction_id, |
| 132 int64_t object_store_id, |
| 133 const std::vector<int64_t>& index_ids) override; |
| 134 |
| 135 void OpenCursor(int64_t transaction_id, |
| 136 int64_t object_store_id, |
| 137 int64_t index_id, |
| 138 ::indexed_db::mojom::KeyRangePtr key_range, |
| 139 ::indexed_db::mojom::CursorDirection direction, |
| 140 bool key_only, |
| 141 ::indexed_db::mojom::TaskType task_type) override; |
| 142 |
| 143 void Count(int64_t transaction_id, |
| 144 int64_t object_store_id, |
| 145 int64_t index_id, |
| 146 ::indexed_db::mojom::KeyRangePtr key_range) override; |
| 147 |
| 148 void AckReceivedBlobs(const std::vector<std::string>& uuids) override; |
| 149 |
| 150 void Bind(::indexed_db::mojom::DatabaseRequest request); |
| 151 |
| 152 void RegisterTransactionId(int64_t transaction_id, const url::Origin& origin); |
| 153 |
| 154 // Misc: |
| 155 void FinishTransaction(int64_t transaction_id, bool committed); |
| 156 IndexedDBContext* context() const; |
| 157 |
51 private: | 158 private: |
52 enum { kInvalidId = -1 }; | 159 enum { kInvalidId = -1 }; |
| 160 |
| 161 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, |
| 162 storage::QuotaStatusCode status, |
| 163 int64_t usage, |
| 164 int64_t quota); |
53 // id_ is ipc_database_id | 165 // id_ is ipc_database_id |
54 int32_t id_ = kInvalidId; | 166 int32_t id_ = kInvalidId; |
55 | 167 |
56 // NULL in some unit tests, and after the connection is closed. | 168 // NULL in some unit tests, and after the connection is closed. |
57 scoped_refptr<IndexedDBDatabase> database_; | 169 scoped_refptr<IndexedDBDatabase> database_; |
| 170 std::map<int64_t, url::Origin> transaction_id_to_origin_; |
| 171 std::map<int64_t, uint64_t> transaction_id_to_size_; |
| 172 std::map<int64_t, int64_t> transaction_id_to_database_id_; |
58 | 173 |
59 // The callbacks_ member is cleared when the connection is closed. | 174 // The change_handler_ member is cleared when the connection is closed. |
60 // May be NULL in unit tests. | 175 // May be NULL in unit tests. |
61 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 176 scoped_refptr<IndexedDBChangeHandler> change_handler_; |
62 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; | 177 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; |
| 178 // TODO(cmumford): Is it possible to use StrongBinging? |
| 179 mojo::BindingSet<::indexed_db::mojom::Database> binding_; |
63 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; | 180 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; |
64 | 181 |
65 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); | 182 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); |
66 }; | 183 }; |
67 | 184 |
68 } // namespace content | 185 } // namespace content |
69 | 186 |
70 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 187 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
OLD | NEW |