OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/indexed_db/database_impl.h" |
| 6 |
| 7 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/indexed_db_context.h" |
| 10 #include "content/public/browser/storage_partition.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 |
| 14 namespace indexed_db { |
| 15 |
| 16 using namespace indexed_db::mojom; |
| 17 |
| 18 DatabaseImpl::DatabaseImpl(content::BrowserContext* context, |
| 19 content::IndexedDBContext* indexed_db_context, |
| 20 mojom::DatabaseRequest request) |
| 21 : context_(context), |
| 22 indexed_db_context_(indexed_db_context), |
| 23 binding_(this, std::move(request)) { |
| 24 // TODO(cmumford): Eventually delete member if not needed. |
| 25 (void)context_; |
| 26 } |
| 27 |
| 28 DatabaseImpl::~DatabaseImpl() = default; |
| 29 |
| 30 void DatabaseImpl::Create(content::BrowserContext* context, |
| 31 mojom::DatabaseRequest request) { |
| 32 // TODO(cmumford): Is |Default| OK? |
| 33 content::StoragePartition* storage_partition = |
| 34 content::BrowserContext::GetDefaultStoragePartition(context); |
| 35 new DatabaseImpl(context, storage_partition->GetIndexedDBContext(), |
| 36 std::move(request)); |
| 37 } |
| 38 |
| 39 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, |
| 40 int64_t object_store_id, |
| 41 const mojo::String& name, |
| 42 const ::content::IndexedDBKeyPath& key_path
, |
| 43 bool auto_increment) {} |
| 44 |
| 45 void DatabaseImpl::DeleteObjectStore(int64_t transaction_id, |
| 46 int64_t object_store_id) {} |
| 47 |
| 48 void DatabaseImpl::CreateTransaction(int64_t id, |
| 49 mojo::Array<int64_t> scope, |
| 50 mojom::TransactionMode transaction_mode) {} |
| 51 |
| 52 void DatabaseImpl::DatabaseImpl::Close() {} |
| 53 |
| 54 void DatabaseImpl::VersionChangeIgnored() {} |
| 55 |
| 56 void DatabaseImpl::Abort(int64_t transaction_id) {} |
| 57 |
| 58 void DatabaseImpl::Commit(int64_t transaction_id) {} |
| 59 |
| 60 void DatabaseImpl::CreateIndex(int64_t transaction_id, |
| 61 int64_t object_store_id, |
| 62 int64_t index_id, |
| 63 const mojo::String& name, |
| 64 const ::content::IndexedDBKeyPath& key_path, |
| 65 bool unique, |
| 66 bool multi_entry) {} |
| 67 |
| 68 void DatabaseImpl::DeleteIndex(int64_t transaction_id, |
| 69 int64_t object_store_id, |
| 70 int64_t index_id) {} |
| 71 |
| 72 void DatabaseImpl::Get(int64_t database_id, |
| 73 int64_t transaction_id, |
| 74 int64_t object_store_id, |
| 75 int64_t index_id, |
| 76 mojom::KeyRangePtr key_range, |
| 77 bool key_only, |
| 78 const GetCallback& callback) { |
| 79 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 80 content::IndexedDBConnection* connection = |
| 81 GetOrTerminateProcess(&connection_map_, database_id); |
| 82 if (!connection || !connection->IsConnected()) |
| 83 return; |
| 84 |
| 85 #if 0 |
| 86 connection->database()->Get( |
| 87 HostTransactionId(transaction_id), object_store_id, |
| 88 index_id, |
| 89 base::WrapUnique(new IndexedDBKeyRange(key_range)), |
| 90 params.key_only, callbacks); |
| 91 #endif |
| 92 #if 0 |
| 93 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 94 IndexedDBConnection* connection = |
| 95 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 96 if (!connection || !connection->IsConnected()) |
| 97 return; |
| 98 |
| 99 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 100 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 101 connection->database()->Get( |
| 102 parent_->HostTransactionId(params.transaction_id), params.object_store_id, |
| 103 params.index_id, |
| 104 base::WrapUnique(new IndexedDBKeyRange(params.key_range)), |
| 105 params.key_only, callbacks); |
| 106 #endif |
| 107 |
| 108 GetResultPtr result = GetResult::New(); |
| 109 result->type = ResultType::Error; |
| 110 callback.Run(std::move(result)); |
| 111 } |
| 112 |
| 113 void DatabaseImpl::GetAll(int64_t transaction_id, |
| 114 int64_t object_store_id, |
| 115 int64_t index_id, |
| 116 mojom::KeyRangePtr key_range, |
| 117 int64_t max_count, |
| 118 bool key_only) {} |
| 119 |
| 120 void DatabaseImpl::Put(int64_t transaction_id, |
| 121 int64_t object_store_id, |
| 122 mojo::Array<int8_t> value, |
| 123 mojo::Array<mojom::BlobInfoPtr> blob_info, |
| 124 mojom::KeyPtr key, |
| 125 mojom::PutMode put_mode, |
| 126 mojo::Array<int64_t> index_ids, |
| 127 mojo::Array<mojo::Array<mojom::KeyPtr>> index_keys) {} |
| 128 |
| 129 void DatabaseImpl::DeleteRange(int64_t transaction_id, |
| 130 int64_t object_store_id, |
| 131 mojom::KeyRangePtr key_range) {} |
| 132 |
| 133 void DatabaseImpl::Clear(int64_t transaction_id, int64_t object_store_id) {} |
| 134 |
| 135 void DatabaseImpl::SetIndexKeys( |
| 136 int64_t transaction_id, |
| 137 int64_t object_store_id, |
| 138 mojom::KeyPtr primary_key, |
| 139 mojo::Array<int64_t> index_ids, |
| 140 mojo::Array<mojo::Array<mojom::KeyPtr>> index_keys) {} |
| 141 |
| 142 void DatabaseImpl::SetIndexesReady(int64_t transaction_id, |
| 143 int64_t object_store_id, |
| 144 mojo::Array<int64_t> index_ids) {} |
| 145 |
| 146 void DatabaseImpl::OpenCursor(int64_t transaction_id, |
| 147 int64_t object_store_id, |
| 148 int64_t index_id, |
| 149 mojom::KeyRangePtr key_range, |
| 150 mojom::CursorDirection direction, |
| 151 bool key_only, |
| 152 mojom::TaskType task_type) {} |
| 153 |
| 154 void DatabaseImpl::Count(int64_t transaction_id, |
| 155 int64_t object_store_id, |
| 156 int64_t index_id, |
| 157 mojom::KeyRangePtr key_range) {} |
| 158 |
| 159 void DatabaseImpl::AckReceivedBlobs(mojo::Array<mojo::String> uuids) {} |
| 160 |
| 161 void DatabaseImpl::CrashRendererAndClosePipe( |
| 162 content::bad_message::BadMessageReason reason) { |
| 163 // TODO(cmumford): Replace with preferred solution once implemented. |
| 164 // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-mojo/aPfAww
28ELo |
| 165 content::bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); |
| 166 |
| 167 // Looks like we need to use Binding instead of StrongBinding to get Close(). |
| 168 // binding_.Close(); |
| 169 } |
| 170 |
| 171 content::RenderProcessHost* DatabaseImpl::GetRenderProcessHost() { |
| 172 // TODO(cmumford): Need to implement this. |
| 173 NOTREACHED(); |
| 174 // return render_frame_host_->GetProcess(); |
| 175 return nullptr; |
| 176 } |
| 177 |
| 178 ////////////////////////////////////////////////////////////////////// |
| 179 // Helper templates. |
| 180 // |
| 181 |
| 182 template <typename ObjectType> |
| 183 ObjectType* DatabaseImpl::GetOrTerminateProcess( |
| 184 IDMap<ObjectType, IDMapOwnPointer>* map, |
| 185 int32_t ipc_return_object_id) { |
| 186 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 187 ObjectType* return_object = map->Lookup(ipc_return_object_id); |
| 188 if (!return_object) { |
| 189 NOTREACHED() << "Uh oh, couldn't find object with id " |
| 190 << ipc_return_object_id; |
| 191 CrashRendererAndClosePipe(content::bad_message::IDBDH_GET_OR_TERMINATE); |
| 192 } |
| 193 return return_object; |
| 194 } |
| 195 |
| 196 template <typename ObjectType> |
| 197 ObjectType* DatabaseImpl::GetOrTerminateProcess(RefIDMap<ObjectType>* map, |
| 198 int32_t ipc_return_object_id) { |
| 199 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 200 ObjectType* return_object = map->Lookup(ipc_return_object_id); |
| 201 if (!return_object) { |
| 202 NOTREACHED() << "Uh oh, couldn't find object with id " |
| 203 << ipc_return_object_id; |
| 204 CrashRendererAndClosePipe(content::bad_message::IDBDH_GET_OR_TERMINATE); |
| 205 } |
| 206 return return_object; |
| 207 } |
| 208 |
| 209 template <typename MapType> |
| 210 void DatabaseImpl::DestroyObject(MapType* map, int32_t ipc_object_id) { |
| 211 GetOrTerminateProcess(map, ipc_object_id); |
| 212 map->Remove(ipc_object_id); |
| 213 } |
| 214 |
| 215 #if 0 |
| 216 int64_t DatabaseImpl::HostTransactionId(int64_t transaction_id) { |
| 217 // Inject the renderer process id into the transaction id, to |
| 218 // uniquely identify this transaction, and effectively bind it to |
| 219 // the renderer that initiated it. The lower 32 bits of |
| 220 // transaction_id are guaranteed to be unique within that renderer. |
| 221 base::ProcessId pid = peer_pid(); |
| 222 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; |
| 223 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), |
| 224 "Process ID must fit in 32 bits"); |
| 225 |
| 226 return transaction_id | (static_cast<uint64_t>(pid) << 32); |
| 227 } |
| 228 |
| 229 int64_t DatabaseImpl::RendererTransactionId(int64_t host_transaction_id) { |
| 230 DCHECK(host_transaction_id >> 32 == peer_pid()) |
| 231 << "Invalid renderer target for transaction id"; |
| 232 return host_transaction_id & 0xffffffff; |
| 233 } |
| 234 #endif |
| 235 |
| 236 } // namespace indexed_db |
OLD | NEW |