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 "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/browser/indexed_db/indexed_db_database.h" | 11 #include "content/browser/indexed_db/indexed_db_database.h" |
12 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 12 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
13 #include "content/browser/indexed_db/indexed_db_observer.h" | 13 #include "content/browser/indexed_db/indexed_db_observer.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "third_party/WebKit/public/platform/modules/indexeddb/indexed_db.mojom.
h" |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 class IndexedDBDatabaseError; | 18 class IndexedDBDatabaseError; |
17 | 19 |
18 class CONTENT_EXPORT IndexedDBConnection { | 20 class CONTENT_EXPORT IndexedDBConnection |
| 21 : public ::indexed_db::mojom::Database { |
19 public: | 22 public: |
20 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, | 23 IndexedDBConnection(scoped_refptr<IndexedDBDatabase> db, |
21 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); | 24 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks); |
22 virtual ~IndexedDBConnection(); | 25 ~IndexedDBConnection() override; |
23 | 26 |
24 // These methods are virtual to allow subclassing in unit tests. | 27 // These methods are virtual to allow subclassing in unit tests. |
25 virtual void ForceClose(); | 28 virtual void ForceClose(); |
26 virtual void Close(); | |
27 virtual bool IsConnected(); | 29 virtual bool IsConnected(); |
28 | 30 |
29 void VersionChangeIgnored(); | |
30 | |
31 virtual void ActivatePendingObservers( | 31 virtual void ActivatePendingObservers( |
32 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); | 32 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers); |
33 // Removes observer listed in |remove_observer_ids| from active_observer of | 33 // Removes observer listed in |remove_observer_ids| from active_observer of |
34 // connection or pending_observer of transactions associated with this | 34 // connection or pending_observer of transactions associated with this |
35 // connection. | 35 // connection. |
36 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); | 36 virtual void RemoveObservers(const std::vector<int32_t>& remove_observer_ids); |
37 | 37 |
38 IndexedDBDatabase* database() const { return database_.get(); } | 38 IndexedDBDatabase* database() const { return database_.get(); } |
39 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } | 39 IndexedDBDatabaseCallbacks* callbacks() const { return callbacks_.get(); } |
40 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() | 40 const std::vector<std::unique_ptr<IndexedDBObserver>>& active_observers() |
41 const { | 41 const { |
42 return active_observers_; | 42 return active_observers_; |
43 } | 43 } |
44 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { | 44 base::WeakPtr<IndexedDBConnection> GetWeakPtr() { |
45 return weak_factory_.GetWeakPtr(); | 45 return weak_factory_.GetWeakPtr(); |
46 } | 46 } |
47 | 47 |
| 48 // ::indexed_db::mojom::Database: |
| 49 void CreateObjectStore(int64_t transaction_id, |
| 50 int64_t object_store_id, |
| 51 const mojo::String& name, |
| 52 const IndexedDBKeyPath& key_path, |
| 53 bool auto_increment) override; |
| 54 |
| 55 void DeleteObjectStore(int64_t transaction_id, |
| 56 int64_t object_store_id) override; |
| 57 |
| 58 void CreateTransaction( |
| 59 int64_t id, |
| 60 mojo::Array<int64_t> scope, |
| 61 ::indexed_db::mojom::TransactionMode transaction_mode) override; |
| 62 |
| 63 void Close() override; |
| 64 |
| 65 void VersionChangeIgnored() override; |
| 66 |
| 67 void Abort(int64_t transaction_id) override; |
| 68 |
| 69 void Commit(int64_t transaction_id) override; |
| 70 |
| 71 void CreateIndex(int64_t transaction_id, |
| 72 int64_t object_store_id, |
| 73 int64_t index_id, |
| 74 const mojo::String& name, |
| 75 const IndexedDBKeyPath& key_path, |
| 76 bool unique, |
| 77 bool multi_entry) override; |
| 78 |
| 79 void DeleteIndex(int64_t transaction_id, |
| 80 int64_t object_store_id, |
| 81 int64_t index_id) override; |
| 82 |
| 83 void Get(int64_t database_id, |
| 84 int64_t transaction_id, |
| 85 int64_t object_store_id, |
| 86 int64_t index_id, |
| 87 ::indexed_db::mojom::KeyRangePtr key_range, |
| 88 bool key_only, |
| 89 const GetCallback& callback) override; |
| 90 |
| 91 void GetAll(int64_t transaction_id, |
| 92 int64_t object_store_id, |
| 93 int64_t index_id, |
| 94 ::indexed_db::mojom::KeyRangePtr key_range, |
| 95 int64_t max_count, |
| 96 bool key_only) override; |
| 97 |
| 98 void Put(int64_t transaction_id, |
| 99 int64_t object_store_id, |
| 100 mojo::Array<int8_t> value, |
| 101 mojo::Array<::indexed_db::mojom::BlobInfoPtr> blob_info, |
| 102 ::indexed_db::mojom::KeyPtr key, |
| 103 ::indexed_db::mojom::PutMode put_mode, |
| 104 mojo::Array<int64_t> index_ids, |
| 105 mojo::Array<mojo::Array<::indexed_db::mojom::KeyPtr>> index_keys) |
| 106 override; |
| 107 |
| 108 void DeleteRange(int64_t transaction_id, |
| 109 int64_t object_store_id, |
| 110 ::indexed_db::mojom::KeyRangePtr key_range) override; |
| 111 |
| 112 void Clear(int64_t transaction_id, int64_t object_store_id) override; |
| 113 |
| 114 void SetIndexKeys(int64_t transaction_id, |
| 115 int64_t object_store_id, |
| 116 ::indexed_db::mojom::KeyPtr primary_key, |
| 117 mojo::Array<int64_t> index_ids, |
| 118 mojo::Array<mojo::Array<::indexed_db::mojom::KeyPtr>> |
| 119 index_keys) override; |
| 120 |
| 121 void SetIndexesReady(int64_t transaction_id, |
| 122 int64_t object_store_id, |
| 123 mojo::Array<int64_t> index_ids) override; |
| 124 |
| 125 void OpenCursor(int64_t transaction_id, |
| 126 int64_t object_store_id, |
| 127 int64_t index_id, |
| 128 ::indexed_db::mojom::KeyRangePtr key_range, |
| 129 ::indexed_db::mojom::CursorDirection direction, |
| 130 bool key_only, |
| 131 ::indexed_db::mojom::TaskType task_type) override; |
| 132 |
| 133 void Count(int64_t transaction_id, |
| 134 int64_t object_store_id, |
| 135 int64_t index_id, |
| 136 ::indexed_db::mojom::KeyRangePtr key_range) override; |
| 137 |
| 138 void AckReceivedBlobs(mojo::Array<mojo::String> uuids) override; |
| 139 |
| 140 ::indexed_db::mojom::DatabasePtr CreateInterface(); |
| 141 |
48 private: | 142 private: |
49 // NULL in some unit tests, and after the connection is closed. | 143 // NULL in some unit tests, and after the connection is closed. |
50 scoped_refptr<IndexedDBDatabase> database_; | 144 scoped_refptr<IndexedDBDatabase> database_; |
51 | 145 |
52 // The callbacks_ member is cleared when the connection is closed. | 146 // The callbacks_ member is cleared when the connection is closed. |
53 // May be NULL in unit tests. | 147 // May be NULL in unit tests. |
54 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; | 148 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks_; |
55 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; | 149 std::vector<std::unique_ptr<IndexedDBObserver>> active_observers_; |
| 150 mojo::StrongBinding<::indexed_db::mojom::Database> binding_; |
56 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; | 151 base::WeakPtrFactory<IndexedDBConnection> weak_factory_; |
57 | 152 |
58 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); | 153 DISALLOW_COPY_AND_ASSIGN(IndexedDBConnection); |
59 }; | 154 }; |
60 | 155 |
61 } // namespace content | 156 } // namespace content |
62 | 157 |
63 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ | 158 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONNECTION_H_ |
OLD | NEW |