Chromium Code Reviews| 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/bad_message.h" | |
| 8 #include "content/browser/child_process_security_policy_impl.h" | |
| 9 #include "content/browser/indexed_db/indexed_db_connection.h" | |
| 10 #include "content/browser/indexed_db/indexed_db_context_impl.h" | |
| 11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | |
| 12 #include "content/browser/indexed_db/indexed_db_value.h" | |
| 13 #include "content/common/indexed_db/indexed_db_messages.h" | |
| 14 #include "storage/browser/blob/blob_storage_context.h" | |
| 15 #include "storage/browser/quota/quota_manager_proxy.h" | |
| 16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class DatabaseImpl::IDBThreadHelper { | |
| 21 public: | |
| 22 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection, | |
| 23 const url::Origin& origin, | |
| 24 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host); | |
| 25 ~IDBThreadHelper(); | |
| 26 | |
| 27 void CreateObjectStore(int64_t transaction_id, | |
| 28 int64_t object_store_id, | |
| 29 const base::string16& name, | |
| 30 const IndexedDBKeyPath& key_path, | |
| 31 bool auto_increment); | |
| 32 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); | |
| 33 void RenameObjectStore(int64_t transaction_id, | |
| 34 int64_t object_store_id, | |
| 35 const base::string16& new_name); | |
| 36 void CreateTransaction(int64_t transaction_id, | |
| 37 const std::vector<int64_t>& object_store_ids, | |
| 38 blink::WebIDBTransactionMode mode); | |
| 39 void Close(); | |
| 40 void VersionChangeIgnored(); | |
| 41 void AddObserver(int64_t transaction_id, | |
| 42 int32_t observer_id, | |
| 43 bool include_transaction, | |
| 44 bool no_records, | |
| 45 bool values, | |
| 46 uint16_t operation_types); | |
| 47 void RemoveObservers(const std::vector<int32_t>& observers); | |
| 48 void Get(int64_t transaction_id, | |
| 49 int64_t object_store_id, | |
| 50 int64_t index_id, | |
| 51 const IndexedDBKeyRange& key_range, | |
| 52 bool key_only, | |
| 53 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 54 void GetAll(int64_t transaction_id, | |
| 55 int64_t object_store_id, | |
| 56 int64_t index_id, | |
| 57 const IndexedDBKeyRange& key_range, | |
| 58 bool key_only, | |
| 59 int64_t max_count, | |
| 60 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 61 void Put(int64_t transaction_id, | |
| 62 int64_t object_store_id, | |
| 63 ::indexed_db::mojom::ValuePtr value, | |
| 64 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, | |
| 65 const IndexedDBKey& key, | |
| 66 blink::WebIDBPutMode mode, | |
| 67 const std::vector<IndexedDBIndexKeys>& index_keys, | |
| 68 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 69 void SetIndexKeys(int64_t transaction_id, | |
| 70 int64_t object_store_id, | |
| 71 const IndexedDBKey& primary_key, | |
| 72 const std::vector<IndexedDBIndexKeys>& index_keys); | |
| 73 void SetIndexesReady(int64_t transaction_id, | |
| 74 int64_t object_store_id, | |
| 75 const std::vector<int64_t>& index_ids); | |
| 76 void OpenCursor(int64_t transaction_id, | |
| 77 int64_t object_store_id, | |
| 78 int64_t index_id, | |
| 79 const IndexedDBKeyRange& key_range, | |
| 80 blink::WebIDBCursorDirection direction, | |
| 81 bool key_only, | |
| 82 blink::WebIDBTaskType task_type, | |
| 83 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 84 void Count(int64_t transaction_id, | |
| 85 int64_t object_store_id, | |
| 86 int64_t index_id, | |
| 87 const IndexedDBKeyRange& key_range, | |
| 88 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 89 void DeleteRange(int64_t transaction_id, | |
| 90 int64_t object_store_id, | |
| 91 const IndexedDBKeyRange& key_range, | |
| 92 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 93 void Clear(int64_t transaction_id, | |
| 94 int64_t object_store_id, | |
| 95 scoped_refptr<IndexedDBCallbacks> callbacks); | |
| 96 void CreateIndex(int64_t transaction_id, | |
| 97 int64_t object_store_id, | |
| 98 int64_t index_id, | |
| 99 const base::string16& name, | |
| 100 const IndexedDBKeyPath& key_path, | |
| 101 bool unique, | |
| 102 bool multi_entry); | |
| 103 void DeleteIndex(int64_t transaction_id, | |
| 104 int64_t object_store_id, | |
| 105 int64_t index_id); | |
| 106 void RenameIndex(int64_t transaction_id, | |
| 107 int64_t object_store_id, | |
| 108 int64_t index_id, | |
| 109 const base::string16& new_name); | |
| 110 void Abort(int64_t transaction_id); | |
| 111 void Commit(int64_t transaction_id); | |
| 112 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, | |
| 113 storage::QuotaStatusCode status, | |
| 114 int64_t usage, | |
| 115 int64_t quota); | |
| 116 void AckReceivedBlobs(const std::vector<std::string>& uuids); | |
| 117 | |
| 118 private: | |
| 119 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | |
| 120 std::unique_ptr<IndexedDBConnection> connection_; | |
| 121 const url::Origin origin_; | |
| 122 base::WeakPtrFactory<IDBThreadHelper> weak_factory_; | |
| 123 }; | |
| 124 | |
| 125 DatabaseImpl::DatabaseImpl( | |
| 126 std::unique_ptr<IndexedDBConnection> connection, | |
| 127 const url::Origin& origin, | |
| 128 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | |
| 129 : dispatcher_host_(dispatcher_host), | |
| 130 origin_(origin), | |
| 131 idb_runner_(base::ThreadTaskRunnerHandle::Get()) { | |
| 132 helper_ = new IDBThreadHelper(std::move(connection), origin, | |
| 133 std::move(dispatcher_host)); | |
| 134 } | |
| 135 | |
| 136 DatabaseImpl::~DatabaseImpl() { | |
| 137 idb_runner_->DeleteSoon(FROM_HERE, helper_); | |
| 138 } | |
| 139 | |
| 140 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, | |
| 141 int64_t object_store_id, | |
| 142 const base::string16& name, | |
| 143 const IndexedDBKeyPath& key_path, | |
| 144 bool auto_increment) { | |
| 145 idb_runner_->PostTask( | |
| 146 FROM_HERE, base::Bind(&IDBThreadHelper::CreateObjectStore, | |
| 147 base::Unretained(helper_), transaction_id, | |
| 148 object_store_id, name, key_path, auto_increment)); | |
| 149 } | |
| 150 | |
| 151 void DatabaseImpl::DeleteObjectStore(int64_t transaction_id, | |
| 152 int64_t object_store_id) { | |
| 153 idb_runner_->PostTask( | |
| 154 FROM_HERE, | |
| 155 base::Bind(&IDBThreadHelper::DeleteObjectStore, base::Unretained(helper_), | |
| 156 transaction_id, object_store_id)); | |
| 157 } | |
| 158 | |
| 159 void DatabaseImpl::RenameObjectStore(int64_t transaction_id, | |
| 160 int64_t object_store_id, | |
| 161 const base::string16& new_name) { | |
| 162 idb_runner_->PostTask( | |
| 163 FROM_HERE, | |
| 164 base::Bind(&IDBThreadHelper::RenameObjectStore, base::Unretained(helper_), | |
| 165 transaction_id, object_store_id, new_name)); | |
| 166 } | |
| 167 | |
| 168 void DatabaseImpl::CreateTransaction( | |
| 169 int64_t transaction_id, | |
| 170 const std::vector<int64_t>& object_store_ids, | |
| 171 blink::WebIDBTransactionMode mode) { | |
| 172 idb_runner_->PostTask( | |
| 173 FROM_HERE, | |
| 174 base::Bind(&IDBThreadHelper::CreateTransaction, base::Unretained(helper_), | |
| 175 transaction_id, object_store_ids, mode)); | |
| 176 } | |
| 177 | |
| 178 void DatabaseImpl::Close() { | |
| 179 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Close, | |
| 180 base::Unretained(helper_))); | |
| 181 } | |
| 182 | |
| 183 void DatabaseImpl::VersionChangeIgnored() { | |
| 184 idb_runner_->PostTask(FROM_HERE, | |
| 185 base::Bind(&IDBThreadHelper::VersionChangeIgnored, | |
| 186 base::Unretained(helper_))); | |
| 187 } | |
| 188 | |
| 189 void DatabaseImpl::AddObserver(int64_t transaction_id, | |
| 190 int32_t observer_id, | |
| 191 bool include_transaction, | |
| 192 bool no_records, | |
| 193 bool values, | |
| 194 uint16_t operation_types) { | |
| 195 idb_runner_->PostTask( | |
| 196 FROM_HERE, | |
| 197 base::Bind(&IDBThreadHelper::AddObserver, base::Unretained(helper_), | |
| 198 transaction_id, observer_id, include_transaction, no_records, | |
| 199 values, operation_types)); | |
| 200 } | |
| 201 | |
| 202 void DatabaseImpl::RemoveObservers(const std::vector<int32_t>& observers) { | |
| 203 idb_runner_->PostTask(FROM_HERE, | |
| 204 base::Bind(&IDBThreadHelper::RemoveObservers, | |
| 205 base::Unretained(helper_), observers)); | |
| 206 } | |
| 207 | |
| 208 void DatabaseImpl::Get( | |
| 209 int64_t transaction_id, | |
| 210 int64_t object_store_id, | |
| 211 int64_t index_id, | |
| 212 const IndexedDBKeyRange& key_range, | |
| 213 bool key_only, | |
| 214 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 215 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 216 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 217 idb_runner_->PostTask( | |
| 218 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_), | |
| 219 transaction_id, object_store_id, index_id, | |
| 220 key_range, key_only, base::Passed(&callbacks))); | |
| 221 } | |
| 222 | |
| 223 void DatabaseImpl::GetAll( | |
| 224 int64_t transaction_id, | |
| 225 int64_t object_store_id, | |
| 226 int64_t index_id, | |
| 227 const IndexedDBKeyRange& key_range, | |
| 228 bool key_only, | |
| 229 int64_t max_count, | |
| 230 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 231 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 232 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 233 idb_runner_->PostTask( | |
| 234 FROM_HERE, | |
| 235 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_), | |
| 236 transaction_id, object_store_id, index_id, key_range, key_only, | |
| 237 max_count, base::Passed(&callbacks))); | |
| 238 } | |
| 239 | |
| 240 void DatabaseImpl::Put( | |
| 241 int64_t transaction_id, | |
| 242 int64_t object_store_id, | |
| 243 ::indexed_db::mojom::ValuePtr value, | |
| 244 const IndexedDBKey& key, | |
| 245 blink::WebIDBPutMode mode, | |
| 246 const std::vector<IndexedDBIndexKeys>& index_keys, | |
| 247 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 248 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; | |
| 249 for (const auto& info : value->blob_or_file_info) { | |
| 250 handles.push_back( | |
| 251 dispatcher_host_->blob_storage_context()->GetBlobDataFromUUID( | |
| 252 info->uuid)); | |
| 253 } | |
| 254 | |
| 255 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 256 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 257 | |
| 258 idb_runner_->PostTask( | |
| 259 FROM_HERE, base::Bind(&IDBThreadHelper::Put, base::Unretained(helper_), | |
| 260 transaction_id, object_store_id, | |
| 261 base::Passed(&value), base::Passed(&handles), key, | |
| 262 mode, index_keys, base::Passed(&callbacks))); | |
| 263 } | |
| 264 | |
| 265 void DatabaseImpl::SetIndexKeys( | |
| 266 int64_t transaction_id, | |
| 267 int64_t object_store_id, | |
| 268 const IndexedDBKey& primary_key, | |
| 269 const std::vector<IndexedDBIndexKeys>& index_keys) { | |
| 270 idb_runner_->PostTask( | |
| 271 FROM_HERE, | |
| 272 base::Bind(&IDBThreadHelper::SetIndexKeys, base::Unretained(helper_), | |
| 273 transaction_id, object_store_id, primary_key, index_keys)); | |
| 274 } | |
| 275 | |
| 276 void DatabaseImpl::SetIndexesReady(int64_t transaction_id, | |
| 277 int64_t object_store_id, | |
| 278 const std::vector<int64_t>& index_ids) { | |
| 279 idb_runner_->PostTask( | |
| 280 FROM_HERE, | |
| 281 base::Bind(&IDBThreadHelper::SetIndexesReady, base::Unretained(helper_), | |
| 282 transaction_id, object_store_id, index_ids)); | |
| 283 } | |
| 284 | |
| 285 void DatabaseImpl::OpenCursor( | |
| 286 int64_t transaction_id, | |
| 287 int64_t object_store_id, | |
| 288 int64_t index_id, | |
| 289 const IndexedDBKeyRange& key_range, | |
| 290 blink::WebIDBCursorDirection direction, | |
| 291 bool key_only, | |
| 292 blink::WebIDBTaskType task_type, | |
| 293 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 294 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 295 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 296 idb_runner_->PostTask( | |
| 297 FROM_HERE, | |
| 298 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_), | |
| 299 transaction_id, object_store_id, index_id, key_range, | |
| 300 direction, key_only, task_type, base::Passed(&callbacks))); | |
| 301 } | |
| 302 | |
| 303 void DatabaseImpl::Count( | |
| 304 int64_t transaction_id, | |
| 305 int64_t object_store_id, | |
| 306 int64_t index_id, | |
| 307 const IndexedDBKeyRange& key_range, | |
| 308 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 309 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 310 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 311 idb_runner_->PostTask( | |
| 312 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_), | |
| 313 transaction_id, object_store_id, index_id, | |
| 314 key_range, base::Passed(&callbacks))); | |
| 315 } | |
| 316 | |
| 317 void DatabaseImpl::DeleteRange( | |
| 318 int64_t transaction_id, | |
| 319 int64_t object_store_id, | |
| 320 const IndexedDBKeyRange& key_range, | |
| 321 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 322 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 323 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 324 idb_runner_->PostTask( | |
| 325 FROM_HERE, | |
| 326 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_), | |
| 327 transaction_id, object_store_id, key_range, | |
| 328 base::Passed(&callbacks))); | |
| 329 } | |
| 330 | |
| 331 void DatabaseImpl::Clear( | |
| 332 int64_t transaction_id, | |
| 333 int64_t object_store_id, | |
| 334 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | |
| 335 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | |
| 336 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | |
| 337 idb_runner_->PostTask( | |
| 338 FROM_HERE, | |
| 339 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_), | |
| 340 transaction_id, object_store_id, base::Passed(&callbacks))); | |
| 341 } | |
| 342 | |
| 343 void DatabaseImpl::CreateIndex(int64_t transaction_id, | |
| 344 int64_t object_store_id, | |
| 345 int64_t index_id, | |
| 346 const base::string16& name, | |
| 347 const IndexedDBKeyPath& key_path, | |
| 348 bool unique, | |
| 349 bool multi_entry) { | |
| 350 idb_runner_->PostTask( | |
| 351 FROM_HERE, | |
| 352 base::Bind(&IDBThreadHelper::CreateIndex, base::Unretained(helper_), | |
| 353 transaction_id, object_store_id, index_id, name, key_path, | |
| 354 unique, multi_entry)); | |
| 355 } | |
| 356 | |
| 357 void DatabaseImpl::DeleteIndex(int64_t transaction_id, | |
| 358 int64_t object_store_id, | |
| 359 int64_t index_id) { | |
| 360 idb_runner_->PostTask( | |
| 361 FROM_HERE, | |
| 362 base::Bind(&IDBThreadHelper::DeleteIndex, base::Unretained(helper_), | |
| 363 transaction_id, object_store_id, index_id)); | |
| 364 } | |
| 365 | |
| 366 void DatabaseImpl::RenameIndex(int64_t transaction_id, | |
| 367 int64_t object_store_id, | |
| 368 int64_t index_id, | |
| 369 const base::string16& new_name) { | |
| 370 idb_runner_->PostTask( | |
| 371 FROM_HERE, | |
| 372 base::Bind(&IDBThreadHelper::RenameIndex, base::Unretained(helper_), | |
| 373 transaction_id, object_store_id, index_id, new_name)); | |
| 374 } | |
| 375 | |
| 376 void DatabaseImpl::Abort(int64_t transaction_id) { | |
| 377 idb_runner_->PostTask( | |
| 378 FROM_HERE, base::Bind(&IDBThreadHelper::Abort, base::Unretained(helper_), | |
| 379 transaction_id)); | |
| 380 } | |
| 381 | |
| 382 void DatabaseImpl::Commit(int64_t transaction_id) { | |
| 383 idb_runner_->PostTask( | |
| 384 FROM_HERE, base::Bind(&IDBThreadHelper::Commit, base::Unretained(helper_), | |
| 385 transaction_id)); | |
| 386 } | |
| 387 | |
| 388 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { | |
| 389 for (const auto& uuid : uuids) | |
| 390 dispatcher_host_->DropBlobData(uuid); | |
| 391 } | |
| 392 | |
| 393 DatabaseImpl::IDBThreadHelper::IDBThreadHelper( | |
| 394 std::unique_ptr<IndexedDBConnection> connection, | |
| 395 const url::Origin& origin, | |
| 396 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | |
| 397 : dispatcher_host_(std::move(dispatcher_host)), | |
| 398 connection_(std::move(connection)), | |
| 399 origin_(origin), | |
| 400 weak_factory_(this) { | |
| 401 dispatcher_host_->context()->ConnectionOpened(origin_, connection.get()); | |
| 402 } | |
| 403 | |
| 404 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() { | |
| 405 if (connection_->IsConnected()) | |
| 406 connection_->Close(); | |
| 407 dispatcher_host_->context()->ConnectionClosed(origin_, connection_.get()); | |
| 408 } | |
| 409 | |
| 410 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( | |
| 411 int64_t transaction_id, | |
| 412 int64_t object_store_id, | |
| 413 const base::string16& name, | |
| 414 const IndexedDBKeyPath& key_path, | |
| 415 bool auto_increment) { | |
| 416 if (!connection_->IsConnected()) | |
|
dcheng
2016/11/03 04:27:04
I don't know if it's easily possible, but it would
Reilly Grant (use Gerrit)
2016/11/03 21:32:22
Once the Database pipe is no longer associated and
| |
| 417 return; | |
| 418 | |
| 419 connection_->database()->CreateObjectStore( | |
| 420 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 421 name, key_path, auto_increment); | |
| 422 } | |
| 423 | |
| 424 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id, | |
| 425 int64_t object_store_id) { | |
| 426 if (!connection_->IsConnected()) | |
| 427 return; | |
| 428 | |
| 429 connection_->database()->DeleteObjectStore( | |
| 430 dispatcher_host_->HostTransactionId(transaction_id), object_store_id); | |
| 431 } | |
| 432 | |
| 433 void DatabaseImpl::IDBThreadHelper::RenameObjectStore( | |
| 434 int64_t transaction_id, | |
| 435 int64_t object_store_id, | |
| 436 const base::string16& new_name) { | |
| 437 if (!connection_->IsConnected()) | |
| 438 return; | |
| 439 | |
| 440 connection_->database()->RenameObjectStore( | |
| 441 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 442 new_name); | |
| 443 } | |
| 444 | |
| 445 void DatabaseImpl::IDBThreadHelper::CreateTransaction( | |
| 446 int64_t transaction_id, | |
| 447 const std::vector<int64_t>& object_store_ids, | |
| 448 blink::WebIDBTransactionMode mode) { | |
| 449 if (!connection_->IsConnected()) | |
| 450 return; | |
| 451 | |
| 452 int64_t host_transaction_id = | |
| 453 dispatcher_host_->HostTransactionId(transaction_id); | |
| 454 if (!dispatcher_host_->RegisterTransactionId(host_transaction_id, origin_)) { | |
| 455 DLOG(ERROR) << "Duplicate host_transaction_id."; | |
| 456 return; | |
| 457 } | |
| 458 | |
| 459 connection_->database()->CreateTransaction( | |
| 460 host_transaction_id, connection_.get(), object_store_ids, mode); | |
| 461 } | |
| 462 | |
| 463 void DatabaseImpl::IDBThreadHelper::Close() { | |
| 464 if (!connection_->IsConnected()) | |
| 465 return; | |
| 466 | |
| 467 connection_->Close(); | |
| 468 } | |
| 469 | |
| 470 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() { | |
| 471 if (!connection_->IsConnected()) | |
| 472 return; | |
| 473 | |
| 474 connection_->VersionChangeIgnored(); | |
| 475 } | |
| 476 | |
| 477 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id, | |
| 478 int32_t observer_id, | |
| 479 bool include_transaction, | |
| 480 bool no_records, | |
| 481 bool values, | |
| 482 uint16_t operation_types) { | |
| 483 if (!connection_->IsConnected()) | |
| 484 return; | |
| 485 | |
| 486 IndexedDBObserver::Options options(include_transaction, no_records, values, | |
| 487 operation_types); | |
| 488 connection_->database()->AddPendingObserver( | |
| 489 dispatcher_host_->HostTransactionId(transaction_id), observer_id, | |
| 490 options); | |
| 491 } | |
| 492 | |
| 493 void DatabaseImpl::IDBThreadHelper::RemoveObservers( | |
| 494 const std::vector<int32_t>& observers) { | |
| 495 if (!connection_->IsConnected()) | |
| 496 return; | |
| 497 | |
| 498 connection_->RemoveObservers(observers); | |
| 499 } | |
| 500 | |
| 501 void DatabaseImpl::IDBThreadHelper::Get( | |
| 502 int64_t transaction_id, | |
| 503 int64_t object_store_id, | |
| 504 int64_t index_id, | |
| 505 const IndexedDBKeyRange& key_range, | |
| 506 bool key_only, | |
| 507 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 508 if (!connection_->IsConnected()) | |
| 509 return; | |
| 510 | |
| 511 connection_->database()->Get( | |
| 512 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 513 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, | |
| 514 callbacks); | |
| 515 } | |
| 516 | |
| 517 void DatabaseImpl::IDBThreadHelper::GetAll( | |
| 518 int64_t transaction_id, | |
| 519 int64_t object_store_id, | |
| 520 int64_t index_id, | |
| 521 const IndexedDBKeyRange& key_range, | |
| 522 bool key_only, | |
| 523 int64_t max_count, | |
| 524 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 525 if (!connection_->IsConnected()) | |
| 526 return; | |
| 527 | |
| 528 connection_->database()->GetAll( | |
| 529 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 530 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, | |
| 531 max_count, callbacks); | |
| 532 } | |
| 533 | |
| 534 void DatabaseImpl::IDBThreadHelper::Put( | |
| 535 int64_t transaction_id, | |
| 536 int64_t object_store_id, | |
| 537 ::indexed_db::mojom::ValuePtr mojo_value, | |
| 538 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, | |
| 539 const IndexedDBKey& key, | |
| 540 blink::WebIDBPutMode mode, | |
| 541 const std::vector<IndexedDBIndexKeys>& index_keys, | |
| 542 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 543 if (!connection_->IsConnected()) | |
| 544 return; | |
| 545 | |
| 546 int64_t host_transaction_id = | |
| 547 dispatcher_host_->HostTransactionId(transaction_id); | |
| 548 | |
| 549 ChildProcessSecurityPolicyImpl* policy = | |
| 550 ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 551 std::vector<IndexedDBBlobInfo> blob_info( | |
| 552 mojo_value->blob_or_file_info.size()); | |
| 553 for (size_t i = 0; i < mojo_value->blob_or_file_info.size(); ++i) { | |
| 554 const auto& info = mojo_value->blob_or_file_info[i]; | |
| 555 if (info->is_file) { | |
| 556 base::FilePath path; | |
| 557 if (!info->file_path.empty()) { | |
| 558 path = base::FilePath::FromUTF16Unsafe(info->file_path); | |
| 559 if (!policy->CanReadFile(dispatcher_host_->ipc_process_id(), path)) { | |
| 560 bad_message::ReceivedBadMessage(dispatcher_host_.get(), | |
| 561 bad_message::IDBDH_CAN_READ_FILE); | |
| 562 return; | |
| 563 } | |
| 564 } | |
| 565 blob_info[i] = | |
| 566 IndexedDBBlobInfo(info->uuid, path, info->file_name, info->mime_type); | |
|
dcheng
2016/11/03 04:27:04
Is UUID actually non-empty in this case?
Reilly Grant (use Gerrit)
2016/11/03 21:32:22
UUID gets populated whether or not the blob is a f
| |
| 567 if (info->size != static_cast<uint64_t>(-1)) { | |
| 568 blob_info[i].set_last_modified( | |
| 569 base::Time::FromDoubleT(info->last_modified)); | |
| 570 blob_info[i].set_size(info->size); | |
| 571 } | |
| 572 } else { | |
| 573 blob_info[i] = IndexedDBBlobInfo(info->uuid, info->mime_type, info->size); | |
|
dcheng
2016/11/03 04:27:04
Also, is it important to validate that this UUID i
Reilly Grant (use Gerrit)
2016/11/03 21:32:21
The UUID is looked up in DatabaseImpl::Put when we
| |
| 574 } | |
| 575 } | |
| 576 | |
| 577 int64_t commit_size = mojo_value->bits.size(); | |
| 578 IndexedDBValue value; | |
| 579 value.bits = std::move(mojo_value->bits); | |
| 580 value.blob_info.swap(blob_info); | |
| 581 connection_->database()->Put(host_transaction_id, object_store_id, &value, | |
| 582 &handles, base::MakeUnique<IndexedDBKey>(key), | |
| 583 mode, callbacks, index_keys); | |
| 584 | |
| 585 // Size can't be big enough to overflow because it represents the | |
| 586 // actual bytes passed through IPC. | |
| 587 dispatcher_host_->AddToTransaction(host_transaction_id, commit_size); | |
| 588 } | |
| 589 | |
| 590 void DatabaseImpl::IDBThreadHelper::SetIndexKeys( | |
| 591 int64_t transaction_id, | |
| 592 int64_t object_store_id, | |
| 593 const IndexedDBKey& primary_key, | |
| 594 const std::vector<IndexedDBIndexKeys>& index_keys) { | |
| 595 if (!connection_->IsConnected()) | |
| 596 return; | |
| 597 | |
| 598 connection_->database()->SetIndexKeys( | |
| 599 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 600 base::MakeUnique<IndexedDBKey>(primary_key), index_keys); | |
| 601 } | |
| 602 | |
| 603 void DatabaseImpl::IDBThreadHelper::SetIndexesReady( | |
| 604 int64_t transaction_id, | |
| 605 int64_t object_store_id, | |
| 606 const std::vector<int64_t>& index_ids) { | |
| 607 if (!connection_->IsConnected()) | |
| 608 return; | |
| 609 | |
| 610 connection_->database()->SetIndexesReady( | |
| 611 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 612 index_ids); | |
| 613 } | |
| 614 | |
| 615 void DatabaseImpl::IDBThreadHelper::OpenCursor( | |
| 616 int64_t transaction_id, | |
| 617 int64_t object_store_id, | |
| 618 int64_t index_id, | |
| 619 const IndexedDBKeyRange& key_range, | |
| 620 blink::WebIDBCursorDirection direction, | |
| 621 bool key_only, | |
| 622 blink::WebIDBTaskType task_type, | |
| 623 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 624 if (!connection_->IsConnected()) | |
| 625 return; | |
| 626 | |
| 627 connection_->database()->OpenCursor( | |
| 628 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 629 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), direction, | |
| 630 key_only, task_type, callbacks); | |
| 631 } | |
| 632 | |
| 633 void DatabaseImpl::IDBThreadHelper::Count( | |
| 634 int64_t transaction_id, | |
| 635 int64_t object_store_id, | |
| 636 int64_t index_id, | |
| 637 const IndexedDBKeyRange& key_range, | |
| 638 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 639 if (!connection_->IsConnected()) | |
| 640 return; | |
| 641 | |
| 642 connection_->database()->Count( | |
| 643 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 644 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), callbacks); | |
| 645 } | |
| 646 | |
| 647 void DatabaseImpl::IDBThreadHelper::DeleteRange( | |
| 648 int64_t transaction_id, | |
| 649 int64_t object_store_id, | |
| 650 const IndexedDBKeyRange& key_range, | |
| 651 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 652 if (!connection_->IsConnected()) | |
| 653 return; | |
| 654 | |
| 655 connection_->database()->DeleteRange( | |
| 656 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 657 base::MakeUnique<IndexedDBKeyRange>(key_range), callbacks); | |
| 658 } | |
| 659 | |
| 660 void DatabaseImpl::IDBThreadHelper::Clear( | |
| 661 int64_t transaction_id, | |
| 662 int64_t object_store_id, | |
| 663 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
| 664 if (!connection_->IsConnected()) | |
| 665 return; | |
| 666 | |
| 667 connection_->database()->Clear( | |
| 668 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 669 callbacks); | |
| 670 } | |
| 671 | |
| 672 void DatabaseImpl::IDBThreadHelper::CreateIndex( | |
| 673 int64_t transaction_id, | |
| 674 int64_t object_store_id, | |
| 675 int64_t index_id, | |
| 676 const base::string16& name, | |
| 677 const IndexedDBKeyPath& key_path, | |
| 678 bool unique, | |
| 679 bool multi_entry) { | |
| 680 if (!connection_->IsConnected()) | |
| 681 return; | |
| 682 | |
| 683 connection_->database()->CreateIndex( | |
| 684 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 685 index_id, name, key_path, unique, multi_entry); | |
| 686 } | |
| 687 | |
| 688 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id, | |
| 689 int64_t object_store_id, | |
| 690 int64_t index_id) { | |
| 691 if (!connection_->IsConnected()) | |
| 692 return; | |
| 693 | |
| 694 connection_->database()->DeleteIndex( | |
| 695 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 696 index_id); | |
| 697 } | |
| 698 | |
| 699 void DatabaseImpl::IDBThreadHelper::RenameIndex( | |
| 700 int64_t transaction_id, | |
| 701 int64_t object_store_id, | |
| 702 int64_t index_id, | |
| 703 const base::string16& new_name) { | |
| 704 if (!connection_->IsConnected()) | |
| 705 return; | |
| 706 | |
| 707 connection_->database()->RenameIndex( | |
| 708 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, | |
| 709 index_id, new_name); | |
| 710 } | |
| 711 | |
| 712 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) { | |
| 713 if (!connection_->IsConnected()) | |
| 714 return; | |
| 715 | |
| 716 connection_->database()->Abort( | |
| 717 dispatcher_host_->HostTransactionId(transaction_id)); | |
| 718 } | |
| 719 | |
| 720 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) { | |
| 721 if (!connection_->IsConnected()) | |
| 722 return; | |
| 723 | |
| 724 int64_t host_transaction_id = | |
| 725 dispatcher_host_->HostTransactionId(transaction_id); | |
| 726 // May have been aborted by back end before front-end could request commit. | |
| 727 int64_t transaction_size; | |
| 728 if (!dispatcher_host_->GetTransactionSize(host_transaction_id, | |
| 729 &transaction_size)) | |
| 730 return; | |
| 731 | |
| 732 // Always allow empty or delete-only transactions. | |
| 733 if (transaction_size == 0) { | |
| 734 connection_->database()->Commit(host_transaction_id); | |
| 735 return; | |
| 736 } | |
| 737 | |
| 738 dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota( | |
| 739 dispatcher_host_->context()->TaskRunner(), GURL(origin_.Serialize()), | |
|
dcheng
2016/11/03 04:27:04
origin_.GetURL()
Reilly Grant (use Gerrit)
2016/11/03 21:32:22
Done.
| |
| 740 storage::kStorageTypeTemporary, | |
| 741 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, | |
| 742 weak_factory_.GetWeakPtr(), transaction_id)); | |
| 743 } | |
| 744 | |
| 745 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( | |
| 746 int64_t transaction_id, | |
| 747 storage::QuotaStatusCode status, | |
| 748 int64_t usage, | |
| 749 int64_t quota) { | |
| 750 // May have disconnected while quota check was pending. | |
| 751 if (!connection_->IsConnected()) | |
| 752 return; | |
| 753 | |
| 754 int64_t host_transaction_id = | |
| 755 dispatcher_host_->HostTransactionId(transaction_id); | |
| 756 // May have aborted while quota check was pending. | |
| 757 int64_t transaction_size; | |
| 758 if (!dispatcher_host_->GetTransactionSize(host_transaction_id, | |
| 759 &transaction_size)) | |
| 760 return; | |
| 761 | |
| 762 if (status == storage::kQuotaStatusOk && usage + transaction_size <= quota) { | |
| 763 connection_->database()->Commit(host_transaction_id); | |
| 764 } else { | |
| 765 connection_->database()->Abort( | |
| 766 host_transaction_id, | |
| 767 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); | |
| 768 } | |
| 769 } | |
| 770 | |
| 771 } // namespace content | |
| OLD | NEW |