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 #include "content/browser/indexed_db/indexed_db_connection.h" | 5 #include "content/browser/indexed_db/indexed_db_connection.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 | 9 |
| 10 using ::indexed_db::mojom::BlobInfoPtr; |
| 11 using ::indexed_db::mojom::CursorDirection; |
| 12 using ::indexed_db::mojom::KeyPtr; |
| 13 using ::indexed_db::mojom::KeyRangePtr; |
| 14 using ::indexed_db::mojom::PutMode; |
| 15 using ::indexed_db::mojom::TaskType; |
| 16 using ::indexed_db::mojom::TransactionMode; |
| 17 |
10 namespace content { | 18 namespace content { |
11 | 19 |
12 IndexedDBConnection::IndexedDBConnection( | 20 IndexedDBConnection::IndexedDBConnection( |
13 scoped_refptr<IndexedDBDatabase> database, | 21 scoped_refptr<IndexedDBDatabase> database, |
14 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) | 22 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks) |
15 : database_(database), callbacks_(callbacks), weak_factory_(this) {} | 23 : database_(database), |
| 24 callbacks_(callbacks), |
| 25 binding_(this), |
| 26 weak_factory_(this) {} |
16 | 27 |
17 IndexedDBConnection::~IndexedDBConnection() {} | 28 IndexedDBConnection::~IndexedDBConnection() {} |
18 | 29 |
19 void IndexedDBConnection::Close() { | |
20 if (!callbacks_.get()) | |
21 return; | |
22 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); | |
23 database_->Close(this, false /* forced */); | |
24 if (this_obj) { | |
25 database_ = nullptr; | |
26 callbacks_ = nullptr; | |
27 active_observers_.clear(); | |
28 } | |
29 } | |
30 | |
31 void IndexedDBConnection::ForceClose() { | 30 void IndexedDBConnection::ForceClose() { |
32 if (!callbacks_.get()) | 31 if (!callbacks_.get()) |
33 return; | 32 return; |
34 | 33 |
35 // IndexedDBDatabase::Close() can delete this instance. | 34 // IndexedDBDatabase::Close() can delete this instance. |
36 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); | 35 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); |
37 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks(callbacks_); | 36 scoped_refptr<IndexedDBDatabaseCallbacks> callbacks(callbacks_); |
38 database_->Close(this, true /* forced */); | 37 database_->Close(this, true /* forced */); |
39 if (this_obj) { | 38 if (this_obj) { |
40 database_ = nullptr; | 39 database_ = nullptr; |
41 callbacks_ = nullptr; | 40 callbacks_ = nullptr; |
42 active_observers_.clear(); | 41 active_observers_.clear(); |
43 } | 42 } |
44 callbacks->OnForcedClose(); | 43 callbacks->OnForcedClose(); |
45 } | 44 } |
46 | 45 |
| 46 bool IndexedDBConnection::IsConnected() { |
| 47 return database_.get() != NULL; |
| 48 } |
| 49 |
| 50 void IndexedDBConnection::CreateObjectStore(int64_t transaction_id, |
| 51 int64_t object_store_id, |
| 52 const mojo::String& name, |
| 53 const IndexedDBKeyPath& key_path, |
| 54 bool auto_increment) {} |
| 55 |
| 56 void IndexedDBConnection::DeleteObjectStore(int64_t transaction_id, |
| 57 int64_t object_store_id) {} |
| 58 |
| 59 void IndexedDBConnection::CreateTransaction(int64_t id, |
| 60 mojo::Array<int64_t> scope, |
| 61 TransactionMode transaction_mode) {} |
| 62 |
| 63 void IndexedDBConnection::Close() { |
| 64 if (!callbacks_.get()) |
| 65 return; |
| 66 base::WeakPtr<IndexedDBConnection> this_obj = weak_factory_.GetWeakPtr(); |
| 67 database_->Close(this, false /* forced */); |
| 68 if (this_obj) { |
| 69 database_ = nullptr; |
| 70 callbacks_ = nullptr; |
| 71 active_observers_.clear(); |
| 72 } |
| 73 } |
| 74 |
47 void IndexedDBConnection::VersionChangeIgnored() { | 75 void IndexedDBConnection::VersionChangeIgnored() { |
48 if (!database_.get()) | 76 if (!database_.get()) |
49 return; | 77 return; |
50 database_->VersionChangeIgnored(); | 78 database_->VersionChangeIgnored(); |
51 } | 79 } |
52 | 80 |
53 bool IndexedDBConnection::IsConnected() { | 81 void IndexedDBConnection::Abort(int64_t transaction_id) {} |
54 return database_.get() != NULL; | 82 |
| 83 void IndexedDBConnection::Commit(int64_t transaction_id) {} |
| 84 |
| 85 void IndexedDBConnection::CreateIndex(int64_t transaction_id, |
| 86 int64_t object_store_id, |
| 87 int64_t index_id, |
| 88 const mojo::String& name, |
| 89 const IndexedDBKeyPath& key_path, |
| 90 bool unique, |
| 91 bool multi_entry) {} |
| 92 |
| 93 void IndexedDBConnection::DeleteIndex(int64_t transaction_id, |
| 94 int64_t object_store_id, |
| 95 int64_t index_id) {} |
| 96 |
| 97 void IndexedDBConnection::Get(int64_t database_id, |
| 98 int64_t transaction_id, |
| 99 int64_t object_store_id, |
| 100 int64_t index_id, |
| 101 KeyRangePtr key_range, |
| 102 bool key_only, |
| 103 const GetCallback& callback) { |
| 104 if (!IsConnected()) |
| 105 return; |
| 106 |
| 107 #if 0 |
| 108 connection->database()->Get( |
| 109 HostTransactionId(transaction_id), object_store_id, |
| 110 index_id, |
| 111 base::WrapUnique(new IndexedDBKeyRange(key_range)), |
| 112 params.key_only, callbacks); |
| 113 #endif |
| 114 #if 0 |
| 115 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 116 IndexedDBConnection* connection = |
| 117 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 118 if (!connection || !connection->IsConnected()) |
| 119 return; |
| 120 |
| 121 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 122 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 123 connection->database()->Get( |
| 124 parent_->HostTransactionId(params.transaction_id), params.object_store_id, |
| 125 params.index_id, |
| 126 base::WrapUnique(new IndexedDBKeyRange(params.key_range)), |
| 127 params.key_only, callbacks); |
| 128 #endif |
| 129 |
| 130 ::indexed_db::mojom::GetResultPtr result = |
| 131 ::indexed_db::mojom::GetResult::New(); |
| 132 result->type = ::indexed_db::mojom::ResultType::Error; |
| 133 callback.Run(std::move(result)); |
| 134 } |
| 135 |
| 136 void IndexedDBConnection::GetAll(int64_t transaction_id, |
| 137 int64_t object_store_id, |
| 138 int64_t index_id, |
| 139 KeyRangePtr key_range, |
| 140 int64_t max_count, |
| 141 bool key_only) {} |
| 142 |
| 143 void IndexedDBConnection::Put(int64_t transaction_id, |
| 144 int64_t object_store_id, |
| 145 mojo::Array<int8_t> value, |
| 146 mojo::Array<BlobInfoPtr> blob_info, |
| 147 KeyPtr key, |
| 148 PutMode put_mode, |
| 149 mojo::Array<int64_t> index_ids, |
| 150 mojo::Array<mojo::Array<KeyPtr>> index_keys) {} |
| 151 |
| 152 void IndexedDBConnection::DeleteRange(int64_t transaction_id, |
| 153 int64_t object_store_id, |
| 154 KeyRangePtr key_range) {} |
| 155 |
| 156 void IndexedDBConnection::Clear(int64_t transaction_id, |
| 157 int64_t object_store_id) {} |
| 158 |
| 159 void IndexedDBConnection::SetIndexKeys( |
| 160 int64_t transaction_id, |
| 161 int64_t object_store_id, |
| 162 KeyPtr primary_key, |
| 163 mojo::Array<int64_t> index_ids, |
| 164 mojo::Array<mojo::Array<KeyPtr>> index_keys) {} |
| 165 |
| 166 void IndexedDBConnection::SetIndexesReady(int64_t transaction_id, |
| 167 int64_t object_store_id, |
| 168 mojo::Array<int64_t> index_ids) {} |
| 169 |
| 170 void IndexedDBConnection::OpenCursor(int64_t transaction_id, |
| 171 int64_t object_store_id, |
| 172 int64_t index_id, |
| 173 KeyRangePtr key_range, |
| 174 CursorDirection direction, |
| 175 bool key_only, |
| 176 TaskType task_type) {} |
| 177 |
| 178 void IndexedDBConnection::Count(int64_t transaction_id, |
| 179 int64_t object_store_id, |
| 180 int64_t index_id, |
| 181 KeyRangePtr key_range) {} |
| 182 |
| 183 void IndexedDBConnection::AckReceivedBlobs(mojo::Array<mojo::String> uuids) {} |
| 184 |
| 185 ::indexed_db::mojom::DatabasePtr IndexedDBConnection::CreateInterface() { |
| 186 ::indexed_db::mojom::DatabasePtr interface; |
| 187 binding_.Bind(&interface); |
| 188 return interface; |
55 } | 189 } |
56 | 190 |
57 // The observers begin listening to changes only once they are activated. | 191 // The observers begin listening to changes only once they are activated. |
58 void IndexedDBConnection::ActivatePendingObservers( | 192 void IndexedDBConnection::ActivatePendingObservers( |
59 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers) { | 193 std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers) { |
60 for (auto& observer : pending_observers) { | 194 for (auto& observer : pending_observers) { |
61 active_observers_.push_back(std::move(observer)); | 195 active_observers_.push_back(std::move(observer)); |
62 } | 196 } |
63 pending_observers.clear(); | 197 pending_observers.clear(); |
64 } | 198 } |
(...skipping 10 matching lines...) Expand all Loading... |
75 if (it != active_observers_.end()) | 209 if (it != active_observers_.end()) |
76 active_observers_.erase(it); | 210 active_observers_.erase(it); |
77 else | 211 else |
78 pending_observer_ids.push_back(id_to_remove); | 212 pending_observer_ids.push_back(id_to_remove); |
79 } | 213 } |
80 if (!pending_observer_ids.empty()) | 214 if (!pending_observer_ids.empty()) |
81 database_->RemovePendingObservers(this, pending_observer_ids); | 215 database_->RemovePendingObservers(this, pending_observer_ids); |
82 } | 216 } |
83 | 217 |
84 } // namespace content | 218 } // namespace content |
OLD | NEW |