| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/database_impl.h" | 5 #include "content/browser/indexed_db/database_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
| 10 #include "base/sequence_checker.h" |
| 10 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 11 #include "base/threading/thread_checker.h" | |
| 12 #include "base/threading/thread_task_runner_handle.h" | |
| 13 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/browser/indexed_db/indexed_db_connection.h" | 14 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 17 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 16 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 18 #include "content/browser/indexed_db/indexed_db_transaction.h" | 17 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 19 #include "content/browser/indexed_db/indexed_db_value.h" | 18 #include "content/browser/indexed_db/indexed_db_value.h" |
| 20 #include "storage/browser/blob/blob_storage_context.h" | 19 #include "storage/browser/blob/blob_storage_context.h" |
| 21 #include "storage/browser/quota/quota_manager_proxy.h" | 20 #include "storage/browser/quota/quota_manager_proxy.h" |
| 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 23 | 22 |
| 24 using std::swap; | 23 using std::swap; |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 class IndexedDBDatabaseError; | 26 class IndexedDBDatabaseError; |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 const char kInvalidBlobUuid[] = "Blob does not exist"; | 29 const char kInvalidBlobUuid[] = "Blob does not exist"; |
| 31 const char kInvalidBlobFilePath[] = "Blob file path is invalid"; | 30 const char kInvalidBlobFilePath[] = "Blob file path is invalid"; |
| 32 } // namespace | 31 } // namespace |
| 33 | 32 |
| 34 // Expect to be created on IO thread, and called/destroyed on IDB thread. | 33 // Expect to be created on IO thread, and called/destroyed on IDB sequence. |
| 35 class DatabaseImpl::IDBThreadHelper { | 34 class DatabaseImpl::IDBSequenceHelper { |
| 36 public: | 35 public: |
| 37 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection, | 36 IDBSequenceHelper(std::unique_ptr<IndexedDBConnection> connection, |
| 38 const url::Origin& origin, | 37 const url::Origin& origin, |
| 39 scoped_refptr<IndexedDBContextImpl> indexed_db_context); | 38 scoped_refptr<IndexedDBContextImpl> indexed_db_context); |
| 40 ~IDBThreadHelper(); | 39 ~IDBSequenceHelper(); |
| 41 | 40 |
| 42 void ConnectionOpened(); | 41 void ConnectionOpened(); |
| 43 | 42 |
| 44 void CreateObjectStore(int64_t transaction_id, | 43 void CreateObjectStore(int64_t transaction_id, |
| 45 int64_t object_store_id, | 44 int64_t object_store_id, |
| 46 const base::string16& name, | 45 const base::string16& name, |
| 47 const IndexedDBKeyPath& key_path, | 46 const IndexedDBKeyPath& key_path, |
| 48 bool auto_increment); | 47 bool auto_increment); |
| 49 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); | 48 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); |
| 50 void RenameObjectStore(int64_t transaction_id, | 49 void RenameObjectStore(int64_t transaction_id, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, | 132 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, |
| 134 storage::QuotaStatusCode status, | 133 storage::QuotaStatusCode status, |
| 135 int64_t usage, | 134 int64_t usage, |
| 136 int64_t quota); | 135 int64_t quota); |
| 137 void AckReceivedBlobs(const std::vector<std::string>& uuids); | 136 void AckReceivedBlobs(const std::vector<std::string>& uuids); |
| 138 | 137 |
| 139 private: | 138 private: |
| 140 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 139 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
| 141 std::unique_ptr<IndexedDBConnection> connection_; | 140 std::unique_ptr<IndexedDBConnection> connection_; |
| 142 const url::Origin origin_; | 141 const url::Origin origin_; |
| 143 base::ThreadChecker idb_thread_checker_; | 142 SEQUENCE_CHECKER(sequence_checker_); |
| 144 base::WeakPtrFactory<IDBThreadHelper> weak_factory_; | 143 base::WeakPtrFactory<IDBSequenceHelper> weak_factory_; |
| 145 }; | 144 }; |
| 146 | 145 |
| 147 DatabaseImpl::DatabaseImpl(std::unique_ptr<IndexedDBConnection> connection, | 146 DatabaseImpl::DatabaseImpl(std::unique_ptr<IndexedDBConnection> connection, |
| 148 const url::Origin& origin, | 147 const url::Origin& origin, |
| 149 IndexedDBDispatcherHost* dispatcher_host, | 148 IndexedDBDispatcherHost* dispatcher_host, |
| 150 scoped_refptr<base::SequencedTaskRunner> idb_runner) | 149 scoped_refptr<base::SequencedTaskRunner> idb_runner) |
| 151 : dispatcher_host_(dispatcher_host), | 150 : dispatcher_host_(dispatcher_host), |
| 152 origin_(origin), | 151 origin_(origin), |
| 153 idb_runner_(std::move(idb_runner)) { | 152 idb_runner_(std::move(idb_runner)) { |
| 154 DCHECK(connection); | 153 DCHECK(connection); |
| 155 helper_ = new IDBThreadHelper(std::move(connection), origin, | 154 helper_ = new IDBSequenceHelper(std::move(connection), origin, |
| 156 dispatcher_host->context()); | 155 dispatcher_host->context()); |
| 157 idb_runner_->PostTask(FROM_HERE, | 156 idb_runner_->PostTask(FROM_HERE, |
| 158 base::Bind(&IDBThreadHelper::ConnectionOpened, | 157 base::Bind(&IDBSequenceHelper::ConnectionOpened, |
| 159 base::Unretained(helper_))); | 158 base::Unretained(helper_))); |
| 160 } | 159 } |
| 161 | 160 |
| 162 DatabaseImpl::~DatabaseImpl() { | 161 DatabaseImpl::~DatabaseImpl() { |
| 163 idb_runner_->DeleteSoon(FROM_HERE, helper_); | 162 idb_runner_->DeleteSoon(FROM_HERE, helper_); |
| 164 } | 163 } |
| 165 | 164 |
| 166 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, | 165 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, |
| 167 int64_t object_store_id, | 166 int64_t object_store_id, |
| 168 const base::string16& name, | 167 const base::string16& name, |
| 169 const IndexedDBKeyPath& key_path, | 168 const IndexedDBKeyPath& key_path, |
| 170 bool auto_increment) { | 169 bool auto_increment) { |
| 171 idb_runner_->PostTask( | 170 idb_runner_->PostTask( |
| 172 FROM_HERE, base::Bind(&IDBThreadHelper::CreateObjectStore, | 171 FROM_HERE, base::Bind(&IDBSequenceHelper::CreateObjectStore, |
| 173 base::Unretained(helper_), transaction_id, | 172 base::Unretained(helper_), transaction_id, |
| 174 object_store_id, name, key_path, auto_increment)); | 173 object_store_id, name, key_path, auto_increment)); |
| 175 } | 174 } |
| 176 | 175 |
| 177 void DatabaseImpl::DeleteObjectStore(int64_t transaction_id, | 176 void DatabaseImpl::DeleteObjectStore(int64_t transaction_id, |
| 178 int64_t object_store_id) { | 177 int64_t object_store_id) { |
| 179 idb_runner_->PostTask( | 178 idb_runner_->PostTask( |
| 180 FROM_HERE, | 179 FROM_HERE, |
| 181 base::Bind(&IDBThreadHelper::DeleteObjectStore, base::Unretained(helper_), | 180 base::Bind(&IDBSequenceHelper::DeleteObjectStore, |
| 182 transaction_id, object_store_id)); | 181 base::Unretained(helper_), transaction_id, object_store_id)); |
| 183 } | 182 } |
| 184 | 183 |
| 185 void DatabaseImpl::RenameObjectStore(int64_t transaction_id, | 184 void DatabaseImpl::RenameObjectStore(int64_t transaction_id, |
| 186 int64_t object_store_id, | 185 int64_t object_store_id, |
| 187 const base::string16& new_name) { | 186 const base::string16& new_name) { |
| 188 idb_runner_->PostTask( | 187 idb_runner_->PostTask(FROM_HERE, |
| 189 FROM_HERE, | 188 base::Bind(&IDBSequenceHelper::RenameObjectStore, |
| 190 base::Bind(&IDBThreadHelper::RenameObjectStore, base::Unretained(helper_), | 189 base::Unretained(helper_), transaction_id, |
| 191 transaction_id, object_store_id, new_name)); | 190 object_store_id, new_name)); |
| 192 } | 191 } |
| 193 | 192 |
| 194 void DatabaseImpl::CreateTransaction( | 193 void DatabaseImpl::CreateTransaction( |
| 195 int64_t transaction_id, | 194 int64_t transaction_id, |
| 196 const std::vector<int64_t>& object_store_ids, | 195 const std::vector<int64_t>& object_store_ids, |
| 197 blink::WebIDBTransactionMode mode) { | 196 blink::WebIDBTransactionMode mode) { |
| 198 idb_runner_->PostTask( | 197 idb_runner_->PostTask(FROM_HERE, |
| 199 FROM_HERE, | 198 base::Bind(&IDBSequenceHelper::CreateTransaction, |
| 200 base::Bind(&IDBThreadHelper::CreateTransaction, base::Unretained(helper_), | 199 base::Unretained(helper_), transaction_id, |
| 201 transaction_id, object_store_ids, mode)); | 200 object_store_ids, mode)); |
| 202 } | 201 } |
| 203 | 202 |
| 204 void DatabaseImpl::Close() { | 203 void DatabaseImpl::Close() { |
| 205 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Close, | 204 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBSequenceHelper::Close, |
| 206 base::Unretained(helper_))); | 205 base::Unretained(helper_))); |
| 207 } | 206 } |
| 208 | 207 |
| 209 void DatabaseImpl::VersionChangeIgnored() { | 208 void DatabaseImpl::VersionChangeIgnored() { |
| 210 idb_runner_->PostTask(FROM_HERE, | 209 idb_runner_->PostTask(FROM_HERE, |
| 211 base::Bind(&IDBThreadHelper::VersionChangeIgnored, | 210 base::Bind(&IDBSequenceHelper::VersionChangeIgnored, |
| 212 base::Unretained(helper_))); | 211 base::Unretained(helper_))); |
| 213 } | 212 } |
| 214 | 213 |
| 215 void DatabaseImpl::AddObserver(int64_t transaction_id, | 214 void DatabaseImpl::AddObserver(int64_t transaction_id, |
| 216 int32_t observer_id, | 215 int32_t observer_id, |
| 217 bool include_transaction, | 216 bool include_transaction, |
| 218 bool no_records, | 217 bool no_records, |
| 219 bool values, | 218 bool values, |
| 220 uint16_t operation_types) { | 219 uint16_t operation_types) { |
| 221 idb_runner_->PostTask( | 220 idb_runner_->PostTask( |
| 222 FROM_HERE, | 221 FROM_HERE, |
| 223 base::Bind(&IDBThreadHelper::AddObserver, base::Unretained(helper_), | 222 base::Bind(&IDBSequenceHelper::AddObserver, base::Unretained(helper_), |
| 224 transaction_id, observer_id, include_transaction, no_records, | 223 transaction_id, observer_id, include_transaction, no_records, |
| 225 values, operation_types)); | 224 values, operation_types)); |
| 226 } | 225 } |
| 227 | 226 |
| 228 void DatabaseImpl::RemoveObservers(const std::vector<int32_t>& observers) { | 227 void DatabaseImpl::RemoveObservers(const std::vector<int32_t>& observers) { |
| 229 idb_runner_->PostTask(FROM_HERE, | 228 idb_runner_->PostTask(FROM_HERE, |
| 230 base::Bind(&IDBThreadHelper::RemoveObservers, | 229 base::Bind(&IDBSequenceHelper::RemoveObservers, |
| 231 base::Unretained(helper_), observers)); | 230 base::Unretained(helper_), observers)); |
| 232 } | 231 } |
| 233 | 232 |
| 234 void DatabaseImpl::Get( | 233 void DatabaseImpl::Get( |
| 235 int64_t transaction_id, | 234 int64_t transaction_id, |
| 236 int64_t object_store_id, | 235 int64_t object_store_id, |
| 237 int64_t index_id, | 236 int64_t index_id, |
| 238 const IndexedDBKeyRange& key_range, | 237 const IndexedDBKeyRange& key_range, |
| 239 bool key_only, | 238 bool key_only, |
| 240 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 239 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 241 scoped_refptr<IndexedDBCallbacks> callbacks( | 240 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 242 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, | 241 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 243 std::move(callbacks_info), idb_runner_)); | 242 std::move(callbacks_info), idb_runner_)); |
| 244 idb_runner_->PostTask( | 243 idb_runner_->PostTask( |
| 245 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_), | 244 FROM_HERE, base::Bind(&IDBSequenceHelper::Get, base::Unretained(helper_), |
| 246 transaction_id, object_store_id, index_id, | 245 transaction_id, object_store_id, index_id, |
| 247 key_range, key_only, base::Passed(&callbacks))); | 246 key_range, key_only, base::Passed(&callbacks))); |
| 248 } | 247 } |
| 249 | 248 |
| 250 void DatabaseImpl::GetAll( | 249 void DatabaseImpl::GetAll( |
| 251 int64_t transaction_id, | 250 int64_t transaction_id, |
| 252 int64_t object_store_id, | 251 int64_t object_store_id, |
| 253 int64_t index_id, | 252 int64_t index_id, |
| 254 const IndexedDBKeyRange& key_range, | 253 const IndexedDBKeyRange& key_range, |
| 255 bool key_only, | 254 bool key_only, |
| 256 int64_t max_count, | 255 int64_t max_count, |
| 257 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 256 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 258 scoped_refptr<IndexedDBCallbacks> callbacks( | 257 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 259 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, | 258 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 260 std::move(callbacks_info), idb_runner_)); | 259 std::move(callbacks_info), idb_runner_)); |
| 261 idb_runner_->PostTask( | 260 idb_runner_->PostTask( |
| 262 FROM_HERE, | 261 FROM_HERE, |
| 263 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_), | 262 base::Bind(&IDBSequenceHelper::GetAll, base::Unretained(helper_), |
| 264 transaction_id, object_store_id, index_id, key_range, key_only, | 263 transaction_id, object_store_id, index_id, key_range, key_only, |
| 265 max_count, base::Passed(&callbacks))); | 264 max_count, base::Passed(&callbacks))); |
| 266 } | 265 } |
| 267 | 266 |
| 268 void DatabaseImpl::Put( | 267 void DatabaseImpl::Put( |
| 269 int64_t transaction_id, | 268 int64_t transaction_id, |
| 270 int64_t object_store_id, | 269 int64_t object_store_id, |
| 271 ::indexed_db::mojom::ValuePtr value, | 270 ::indexed_db::mojom::ValuePtr value, |
| 272 const IndexedDBKey& key, | 271 const IndexedDBKey& key, |
| 273 blink::WebIDBPutMode mode, | 272 blink::WebIDBPutMode mode, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 293 | 292 |
| 294 // Due to known issue crbug.com/351753, blobs can die while being passed to | 293 // Due to known issue crbug.com/351753, blobs can die while being passed to |
| 295 // a different process. So this case must be handled gracefully. | 294 // a different process. So this case must be handled gracefully. |
| 296 // TODO(dmurph): Revert back to using mojo::ReportBadMessage once fixed. | 295 // TODO(dmurph): Revert back to using mojo::ReportBadMessage once fixed. |
| 297 UMA_HISTOGRAM_BOOLEAN("Storage.IndexedDB.PutValidBlob", | 296 UMA_HISTOGRAM_BOOLEAN("Storage.IndexedDB.PutValidBlob", |
| 298 handle.get() != nullptr); | 297 handle.get() != nullptr); |
| 299 if (!handle) { | 298 if (!handle) { |
| 300 IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, | 299 IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, |
| 301 kInvalidBlobUuid); | 300 kInvalidBlobUuid); |
| 302 idb_runner_->PostTask( | 301 idb_runner_->PostTask( |
| 303 FROM_HERE, base::Bind(&IDBThreadHelper::AbortWithError, | 302 FROM_HERE, base::Bind(&IDBSequenceHelper::AbortWithError, |
| 304 base::Unretained(helper_), transaction_id, | 303 base::Unretained(helper_), transaction_id, |
| 305 base::Passed(&callbacks), error)); | 304 base::Passed(&callbacks), error)); |
| 306 return; | 305 return; |
| 307 } | 306 } |
| 308 uint64_t size = handle->size(); | 307 uint64_t size = handle->size(); |
| 309 UMA_HISTOGRAM_MEMORY_KB("Storage.IndexedDB.PutBlobSizeKB", size / 1024ull); | 308 UMA_HISTOGRAM_MEMORY_KB("Storage.IndexedDB.PutBlobSizeKB", size / 1024ull); |
| 310 total_blob_size += size; | 309 total_blob_size += size; |
| 311 handles[i] = std::move(handle); | 310 handles[i] = std::move(handle); |
| 312 | 311 |
| 313 if (info->file) { | 312 if (info->file) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 331 blob_info.size()); | 330 blob_info.size()); |
| 332 uint64_t blob_size = 0; | 331 uint64_t blob_size = 0; |
| 333 total_blob_size.AssignIfValid(&blob_size); | 332 total_blob_size.AssignIfValid(&blob_size); |
| 334 if (blob_size != 0) { | 333 if (blob_size != 0) { |
| 335 // 1KB to 1GB. | 334 // 1KB to 1GB. |
| 336 UMA_HISTOGRAM_COUNTS_1M("WebCore.IndexedDB.PutBlobsTotalSize", | 335 UMA_HISTOGRAM_COUNTS_1M("WebCore.IndexedDB.PutBlobsTotalSize", |
| 337 blob_size / 1024); | 336 blob_size / 1024); |
| 338 } | 337 } |
| 339 idb_runner_->PostTask( | 338 idb_runner_->PostTask( |
| 340 FROM_HERE, | 339 FROM_HERE, |
| 341 base::Bind(&IDBThreadHelper::Put, base::Unretained(helper_), | 340 base::Bind(&IDBSequenceHelper::Put, base::Unretained(helper_), |
| 342 transaction_id, object_store_id, base::Passed(&value), | 341 transaction_id, object_store_id, base::Passed(&value), |
| 343 base::Passed(&handles), base::Passed(&blob_info), key, mode, | 342 base::Passed(&handles), base::Passed(&blob_info), key, mode, |
| 344 index_keys, base::Passed(&callbacks))); | 343 index_keys, base::Passed(&callbacks))); |
| 345 } | 344 } |
| 346 | 345 |
| 347 void DatabaseImpl::SetIndexKeys( | 346 void DatabaseImpl::SetIndexKeys( |
| 348 int64_t transaction_id, | 347 int64_t transaction_id, |
| 349 int64_t object_store_id, | 348 int64_t object_store_id, |
| 350 const IndexedDBKey& primary_key, | 349 const IndexedDBKey& primary_key, |
| 351 const std::vector<IndexedDBIndexKeys>& index_keys) { | 350 const std::vector<IndexedDBIndexKeys>& index_keys) { |
| 352 idb_runner_->PostTask( | 351 idb_runner_->PostTask( |
| 353 FROM_HERE, | 352 FROM_HERE, |
| 354 base::Bind(&IDBThreadHelper::SetIndexKeys, base::Unretained(helper_), | 353 base::Bind(&IDBSequenceHelper::SetIndexKeys, base::Unretained(helper_), |
| 355 transaction_id, object_store_id, primary_key, index_keys)); | 354 transaction_id, object_store_id, primary_key, index_keys)); |
| 356 } | 355 } |
| 357 | 356 |
| 358 void DatabaseImpl::SetIndexesReady(int64_t transaction_id, | 357 void DatabaseImpl::SetIndexesReady(int64_t transaction_id, |
| 359 int64_t object_store_id, | 358 int64_t object_store_id, |
| 360 const std::vector<int64_t>& index_ids) { | 359 const std::vector<int64_t>& index_ids) { |
| 361 idb_runner_->PostTask( | 360 idb_runner_->PostTask( |
| 362 FROM_HERE, | 361 FROM_HERE, |
| 363 base::Bind(&IDBThreadHelper::SetIndexesReady, base::Unretained(helper_), | 362 base::Bind(&IDBSequenceHelper::SetIndexesReady, base::Unretained(helper_), |
| 364 transaction_id, object_store_id, index_ids)); | 363 transaction_id, object_store_id, index_ids)); |
| 365 } | 364 } |
| 366 | 365 |
| 367 void DatabaseImpl::OpenCursor( | 366 void DatabaseImpl::OpenCursor( |
| 368 int64_t transaction_id, | 367 int64_t transaction_id, |
| 369 int64_t object_store_id, | 368 int64_t object_store_id, |
| 370 int64_t index_id, | 369 int64_t index_id, |
| 371 const IndexedDBKeyRange& key_range, | 370 const IndexedDBKeyRange& key_range, |
| 372 blink::WebIDBCursorDirection direction, | 371 blink::WebIDBCursorDirection direction, |
| 373 bool key_only, | 372 bool key_only, |
| 374 blink::WebIDBTaskType task_type, | 373 blink::WebIDBTaskType task_type, |
| 375 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 374 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 376 scoped_refptr<IndexedDBCallbacks> callbacks( | 375 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 377 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, | 376 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 378 std::move(callbacks_info), idb_runner_)); | 377 std::move(callbacks_info), idb_runner_)); |
| 379 idb_runner_->PostTask( | 378 idb_runner_->PostTask( |
| 380 FROM_HERE, | 379 FROM_HERE, |
| 381 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_), | 380 base::Bind(&IDBSequenceHelper::OpenCursor, base::Unretained(helper_), |
| 382 transaction_id, object_store_id, index_id, key_range, | 381 transaction_id, object_store_id, index_id, key_range, |
| 383 direction, key_only, task_type, base::Passed(&callbacks))); | 382 direction, key_only, task_type, base::Passed(&callbacks))); |
| 384 } | 383 } |
| 385 | 384 |
| 386 void DatabaseImpl::Count( | 385 void DatabaseImpl::Count( |
| 387 int64_t transaction_id, | 386 int64_t transaction_id, |
| 388 int64_t object_store_id, | 387 int64_t object_store_id, |
| 389 int64_t index_id, | 388 int64_t index_id, |
| 390 const IndexedDBKeyRange& key_range, | 389 const IndexedDBKeyRange& key_range, |
| 391 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 390 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 392 scoped_refptr<IndexedDBCallbacks> callbacks( | 391 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 393 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, | 392 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 394 std::move(callbacks_info), idb_runner_)); | 393 std::move(callbacks_info), idb_runner_)); |
| 395 idb_runner_->PostTask( | 394 idb_runner_->PostTask( |
| 396 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_), | 395 FROM_HERE, |
| 397 transaction_id, object_store_id, index_id, | 396 base::Bind(&IDBSequenceHelper::Count, base::Unretained(helper_), |
| 398 key_range, base::Passed(&callbacks))); | 397 transaction_id, object_store_id, index_id, key_range, |
| 398 base::Passed(&callbacks))); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void DatabaseImpl::DeleteRange( | 401 void DatabaseImpl::DeleteRange( |
| 402 int64_t transaction_id, | 402 int64_t transaction_id, |
| 403 int64_t object_store_id, | 403 int64_t object_store_id, |
| 404 const IndexedDBKeyRange& key_range, | 404 const IndexedDBKeyRange& key_range, |
| 405 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 405 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 406 scoped_refptr<IndexedDBCallbacks> callbacks( | 406 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 407 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, | 407 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 408 std::move(callbacks_info), idb_runner_)); | 408 std::move(callbacks_info), idb_runner_)); |
| 409 idb_runner_->PostTask( | 409 idb_runner_->PostTask( |
| 410 FROM_HERE, | 410 FROM_HERE, |
| 411 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_), | 411 base::Bind(&IDBSequenceHelper::DeleteRange, base::Unretained(helper_), |
| 412 transaction_id, object_store_id, key_range, | 412 transaction_id, object_store_id, key_range, |
| 413 base::Passed(&callbacks))); | 413 base::Passed(&callbacks))); |
| 414 } | 414 } |
| 415 | 415 |
| 416 void DatabaseImpl::Clear( | 416 void DatabaseImpl::Clear( |
| 417 int64_t transaction_id, | 417 int64_t transaction_id, |
| 418 int64_t object_store_id, | 418 int64_t object_store_id, |
| 419 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 419 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 420 scoped_refptr<IndexedDBCallbacks> callbacks( | 420 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 421 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, | 421 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 422 std::move(callbacks_info), idb_runner_)); | 422 std::move(callbacks_info), idb_runner_)); |
| 423 idb_runner_->PostTask( | 423 idb_runner_->PostTask( |
| 424 FROM_HERE, | 424 FROM_HERE, |
| 425 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_), | 425 base::Bind(&IDBSequenceHelper::Clear, base::Unretained(helper_), |
| 426 transaction_id, object_store_id, base::Passed(&callbacks))); | 426 transaction_id, object_store_id, base::Passed(&callbacks))); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void DatabaseImpl::CreateIndex(int64_t transaction_id, | 429 void DatabaseImpl::CreateIndex(int64_t transaction_id, |
| 430 int64_t object_store_id, | 430 int64_t object_store_id, |
| 431 int64_t index_id, | 431 int64_t index_id, |
| 432 const base::string16& name, | 432 const base::string16& name, |
| 433 const IndexedDBKeyPath& key_path, | 433 const IndexedDBKeyPath& key_path, |
| 434 bool unique, | 434 bool unique, |
| 435 bool multi_entry) { | 435 bool multi_entry) { |
| 436 idb_runner_->PostTask( | 436 idb_runner_->PostTask( |
| 437 FROM_HERE, | 437 FROM_HERE, |
| 438 base::Bind(&IDBThreadHelper::CreateIndex, base::Unretained(helper_), | 438 base::Bind(&IDBSequenceHelper::CreateIndex, base::Unretained(helper_), |
| 439 transaction_id, object_store_id, index_id, name, key_path, | 439 transaction_id, object_store_id, index_id, name, key_path, |
| 440 unique, multi_entry)); | 440 unique, multi_entry)); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void DatabaseImpl::DeleteIndex(int64_t transaction_id, | 443 void DatabaseImpl::DeleteIndex(int64_t transaction_id, |
| 444 int64_t object_store_id, | 444 int64_t object_store_id, |
| 445 int64_t index_id) { | 445 int64_t index_id) { |
| 446 idb_runner_->PostTask( | 446 idb_runner_->PostTask( |
| 447 FROM_HERE, | 447 FROM_HERE, |
| 448 base::Bind(&IDBThreadHelper::DeleteIndex, base::Unretained(helper_), | 448 base::Bind(&IDBSequenceHelper::DeleteIndex, base::Unretained(helper_), |
| 449 transaction_id, object_store_id, index_id)); | 449 transaction_id, object_store_id, index_id)); |
| 450 } | 450 } |
| 451 | 451 |
| 452 void DatabaseImpl::RenameIndex(int64_t transaction_id, | 452 void DatabaseImpl::RenameIndex(int64_t transaction_id, |
| 453 int64_t object_store_id, | 453 int64_t object_store_id, |
| 454 int64_t index_id, | 454 int64_t index_id, |
| 455 const base::string16& new_name) { | 455 const base::string16& new_name) { |
| 456 idb_runner_->PostTask( | 456 idb_runner_->PostTask( |
| 457 FROM_HERE, | 457 FROM_HERE, |
| 458 base::Bind(&IDBThreadHelper::RenameIndex, base::Unretained(helper_), | 458 base::Bind(&IDBSequenceHelper::RenameIndex, base::Unretained(helper_), |
| 459 transaction_id, object_store_id, index_id, new_name)); | 459 transaction_id, object_store_id, index_id, new_name)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void DatabaseImpl::Abort(int64_t transaction_id) { | 462 void DatabaseImpl::Abort(int64_t transaction_id) { |
| 463 idb_runner_->PostTask( | 463 idb_runner_->PostTask(FROM_HERE, |
| 464 FROM_HERE, base::Bind(&IDBThreadHelper::Abort, base::Unretained(helper_), | 464 base::Bind(&IDBSequenceHelper::Abort, |
| 465 transaction_id)); | 465 base::Unretained(helper_), transaction_id)); |
| 466 } | 466 } |
| 467 | 467 |
| 468 void DatabaseImpl::Commit(int64_t transaction_id) { | 468 void DatabaseImpl::Commit(int64_t transaction_id) { |
| 469 idb_runner_->PostTask( | 469 idb_runner_->PostTask(FROM_HERE, |
| 470 FROM_HERE, base::Bind(&IDBThreadHelper::Commit, base::Unretained(helper_), | 470 base::Bind(&IDBSequenceHelper::Commit, |
| 471 transaction_id)); | 471 base::Unretained(helper_), transaction_id)); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { | 474 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { |
| 475 for (const auto& uuid : uuids) | 475 for (const auto& uuid : uuids) |
| 476 dispatcher_host_->DropBlobData(uuid); | 476 dispatcher_host_->DropBlobData(uuid); |
| 477 } | 477 } |
| 478 | 478 |
| 479 DatabaseImpl::IDBThreadHelper::IDBThreadHelper( | 479 DatabaseImpl::IDBSequenceHelper::IDBSequenceHelper( |
| 480 std::unique_ptr<IndexedDBConnection> connection, | 480 std::unique_ptr<IndexedDBConnection> connection, |
| 481 const url::Origin& origin, | 481 const url::Origin& origin, |
| 482 scoped_refptr<IndexedDBContextImpl> indexed_db_context) | 482 scoped_refptr<IndexedDBContextImpl> indexed_db_context) |
| 483 : indexed_db_context_(indexed_db_context), | 483 : indexed_db_context_(indexed_db_context), |
| 484 connection_(std::move(connection)), | 484 connection_(std::move(connection)), |
| 485 origin_(origin), | 485 origin_(origin), |
| 486 weak_factory_(this) { | 486 weak_factory_(this) { |
| 487 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 487 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 488 idb_thread_checker_.DetachFromThread(); | 488 DETACH_FROM_SEQUENCE(sequence_checker_); |
| 489 } | 489 } |
| 490 | 490 |
| 491 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() { | 491 DatabaseImpl::IDBSequenceHelper::~IDBSequenceHelper() { |
| 492 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 492 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 493 if (connection_->IsConnected()) | 493 if (connection_->IsConnected()) |
| 494 connection_->Close(); | 494 connection_->Close(); |
| 495 indexed_db_context_->ConnectionClosed(origin_, connection_.get()); | 495 indexed_db_context_->ConnectionClosed(origin_, connection_.get()); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void DatabaseImpl::IDBThreadHelper::ConnectionOpened() { | 498 void DatabaseImpl::IDBSequenceHelper::ConnectionOpened() { |
| 499 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 499 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 500 indexed_db_context_->ConnectionOpened(origin_, connection_.get()); | 500 indexed_db_context_->ConnectionOpened(origin_, connection_.get()); |
| 501 } | 501 } |
| 502 | 502 |
| 503 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( | 503 void DatabaseImpl::IDBSequenceHelper::CreateObjectStore( |
| 504 int64_t transaction_id, | 504 int64_t transaction_id, |
| 505 int64_t object_store_id, | 505 int64_t object_store_id, |
| 506 const base::string16& name, | 506 const base::string16& name, |
| 507 const IndexedDBKeyPath& key_path, | 507 const IndexedDBKeyPath& key_path, |
| 508 bool auto_increment) { | 508 bool auto_increment) { |
| 509 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 509 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 510 if (!connection_->IsConnected()) | 510 if (!connection_->IsConnected()) |
| 511 return; | 511 return; |
| 512 | 512 |
| 513 IndexedDBTransaction* transaction = | 513 IndexedDBTransaction* transaction = |
| 514 connection_->GetTransaction(transaction_id); | 514 connection_->GetTransaction(transaction_id); |
| 515 if (!transaction) | 515 if (!transaction) |
| 516 return; | 516 return; |
| 517 | 517 |
| 518 connection_->database()->CreateObjectStore(transaction, object_store_id, name, | 518 connection_->database()->CreateObjectStore(transaction, object_store_id, name, |
| 519 key_path, auto_increment); | 519 key_path, auto_increment); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id, | 522 void DatabaseImpl::IDBSequenceHelper::DeleteObjectStore( |
| 523 int64_t object_store_id) { | 523 int64_t transaction_id, |
| 524 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 524 int64_t object_store_id) { |
| 525 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 525 if (!connection_->IsConnected()) | 526 if (!connection_->IsConnected()) |
| 526 return; | 527 return; |
| 527 | 528 |
| 528 IndexedDBTransaction* transaction = | 529 IndexedDBTransaction* transaction = |
| 529 connection_->GetTransaction(transaction_id); | 530 connection_->GetTransaction(transaction_id); |
| 530 if (!transaction) | 531 if (!transaction) |
| 531 return; | 532 return; |
| 532 | 533 |
| 533 connection_->database()->DeleteObjectStore(transaction, object_store_id); | 534 connection_->database()->DeleteObjectStore(transaction, object_store_id); |
| 534 } | 535 } |
| 535 | 536 |
| 536 void DatabaseImpl::IDBThreadHelper::RenameObjectStore( | 537 void DatabaseImpl::IDBSequenceHelper::RenameObjectStore( |
| 537 int64_t transaction_id, | 538 int64_t transaction_id, |
| 538 int64_t object_store_id, | 539 int64_t object_store_id, |
| 539 const base::string16& new_name) { | 540 const base::string16& new_name) { |
| 540 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 541 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 541 if (!connection_->IsConnected()) | 542 if (!connection_->IsConnected()) |
| 542 return; | 543 return; |
| 543 | 544 |
| 544 IndexedDBTransaction* transaction = | 545 IndexedDBTransaction* transaction = |
| 545 connection_->GetTransaction(transaction_id); | 546 connection_->GetTransaction(transaction_id); |
| 546 if (!transaction) | 547 if (!transaction) |
| 547 return; | 548 return; |
| 548 | 549 |
| 549 connection_->database()->RenameObjectStore(transaction, object_store_id, | 550 connection_->database()->RenameObjectStore(transaction, object_store_id, |
| 550 new_name); | 551 new_name); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void DatabaseImpl::IDBThreadHelper::CreateTransaction( | 554 void DatabaseImpl::IDBSequenceHelper::CreateTransaction( |
| 554 int64_t transaction_id, | 555 int64_t transaction_id, |
| 555 const std::vector<int64_t>& object_store_ids, | 556 const std::vector<int64_t>& object_store_ids, |
| 556 blink::WebIDBTransactionMode mode) { | 557 blink::WebIDBTransactionMode mode) { |
| 557 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 558 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 558 if (!connection_->IsConnected()) | 559 if (!connection_->IsConnected()) |
| 559 return; | 560 return; |
| 560 | 561 |
| 561 // Can't call BadMessage as we're no longer on the IO thread. So ignore. | 562 // Can't call BadMessage as we're no longer on the IO thread. So ignore. |
| 562 if (connection_->GetTransaction(transaction_id)) | 563 if (connection_->GetTransaction(transaction_id)) |
| 563 return; | 564 return; |
| 564 | 565 |
| 565 connection_->database()->CreateTransaction(transaction_id, connection_.get(), | 566 connection_->database()->CreateTransaction(transaction_id, connection_.get(), |
| 566 object_store_ids, mode); | 567 object_store_ids, mode); |
| 567 } | 568 } |
| 568 | 569 |
| 569 void DatabaseImpl::IDBThreadHelper::Close() { | 570 void DatabaseImpl::IDBSequenceHelper::Close() { |
| 570 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 571 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 571 if (!connection_->IsConnected()) | 572 if (!connection_->IsConnected()) |
| 572 return; | 573 return; |
| 573 | 574 |
| 574 connection_->Close(); | 575 connection_->Close(); |
| 575 } | 576 } |
| 576 | 577 |
| 577 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() { | 578 void DatabaseImpl::IDBSequenceHelper::VersionChangeIgnored() { |
| 578 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 579 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 579 if (!connection_->IsConnected()) | 580 if (!connection_->IsConnected()) |
| 580 return; | 581 return; |
| 581 | 582 |
| 582 connection_->VersionChangeIgnored(); | 583 connection_->VersionChangeIgnored(); |
| 583 } | 584 } |
| 584 | 585 |
| 585 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id, | 586 void DatabaseImpl::IDBSequenceHelper::AddObserver(int64_t transaction_id, |
| 586 int32_t observer_id, | 587 int32_t observer_id, |
| 587 bool include_transaction, | 588 bool include_transaction, |
| 588 bool no_records, | 589 bool no_records, |
| 589 bool values, | 590 bool values, |
| 590 uint16_t operation_types) { | 591 uint16_t operation_types) { |
| 591 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 592 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 592 if (!connection_->IsConnected()) | 593 if (!connection_->IsConnected()) |
| 593 return; | 594 return; |
| 594 | 595 |
| 595 IndexedDBTransaction* transaction = | 596 IndexedDBTransaction* transaction = |
| 596 connection_->GetTransaction(transaction_id); | 597 connection_->GetTransaction(transaction_id); |
| 597 if (!transaction) | 598 if (!transaction) |
| 598 return; | 599 return; |
| 599 | 600 |
| 600 IndexedDBObserver::Options options(include_transaction, no_records, values, | 601 IndexedDBObserver::Options options(include_transaction, no_records, values, |
| 601 operation_types); | 602 operation_types); |
| 602 connection_->database()->AddPendingObserver(transaction, observer_id, | 603 connection_->database()->AddPendingObserver(transaction, observer_id, |
| 603 options); | 604 options); |
| 604 } | 605 } |
| 605 | 606 |
| 606 void DatabaseImpl::IDBThreadHelper::RemoveObservers( | 607 void DatabaseImpl::IDBSequenceHelper::RemoveObservers( |
| 607 const std::vector<int32_t>& observers) { | 608 const std::vector<int32_t>& observers) { |
| 608 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 609 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 609 if (!connection_->IsConnected()) | 610 if (!connection_->IsConnected()) |
| 610 return; | 611 return; |
| 611 | 612 |
| 612 connection_->RemoveObservers(observers); | 613 connection_->RemoveObservers(observers); |
| 613 } | 614 } |
| 614 | 615 |
| 615 void DatabaseImpl::IDBThreadHelper::Get( | 616 void DatabaseImpl::IDBSequenceHelper::Get( |
| 616 int64_t transaction_id, | 617 int64_t transaction_id, |
| 617 int64_t object_store_id, | 618 int64_t object_store_id, |
| 618 int64_t index_id, | 619 int64_t index_id, |
| 619 const IndexedDBKeyRange& key_range, | 620 const IndexedDBKeyRange& key_range, |
| 620 bool key_only, | 621 bool key_only, |
| 621 scoped_refptr<IndexedDBCallbacks> callbacks) { | 622 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 622 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 623 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 623 if (!connection_->IsConnected()) | 624 if (!connection_->IsConnected()) |
| 624 return; | 625 return; |
| 625 | 626 |
| 626 IndexedDBTransaction* transaction = | 627 IndexedDBTransaction* transaction = |
| 627 connection_->GetTransaction(transaction_id); | 628 connection_->GetTransaction(transaction_id); |
| 628 if (!transaction) | 629 if (!transaction) |
| 629 return; | 630 return; |
| 630 | 631 |
| 631 connection_->database()->Get(transaction, object_store_id, index_id, | 632 connection_->database()->Get(transaction, object_store_id, index_id, |
| 632 base::MakeUnique<IndexedDBKeyRange>(key_range), | 633 base::MakeUnique<IndexedDBKeyRange>(key_range), |
| 633 key_only, callbacks); | 634 key_only, callbacks); |
| 634 } | 635 } |
| 635 | 636 |
| 636 void DatabaseImpl::IDBThreadHelper::GetAll( | 637 void DatabaseImpl::IDBSequenceHelper::GetAll( |
| 637 int64_t transaction_id, | 638 int64_t transaction_id, |
| 638 int64_t object_store_id, | 639 int64_t object_store_id, |
| 639 int64_t index_id, | 640 int64_t index_id, |
| 640 const IndexedDBKeyRange& key_range, | 641 const IndexedDBKeyRange& key_range, |
| 641 bool key_only, | 642 bool key_only, |
| 642 int64_t max_count, | 643 int64_t max_count, |
| 643 scoped_refptr<IndexedDBCallbacks> callbacks) { | 644 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 644 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 645 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 645 if (!connection_->IsConnected()) | 646 if (!connection_->IsConnected()) |
| 646 return; | 647 return; |
| 647 | 648 |
| 648 IndexedDBTransaction* transaction = | 649 IndexedDBTransaction* transaction = |
| 649 connection_->GetTransaction(transaction_id); | 650 connection_->GetTransaction(transaction_id); |
| 650 if (!transaction) | 651 if (!transaction) |
| 651 return; | 652 return; |
| 652 | 653 |
| 653 connection_->database()->GetAll( | 654 connection_->database()->GetAll( |
| 654 transaction, object_store_id, index_id, | 655 transaction, object_store_id, index_id, |
| 655 base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, max_count, | 656 base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, max_count, |
| 656 std::move(callbacks)); | 657 std::move(callbacks)); |
| 657 } | 658 } |
| 658 | 659 |
| 659 void DatabaseImpl::IDBThreadHelper::Put( | 660 void DatabaseImpl::IDBSequenceHelper::Put( |
| 660 int64_t transaction_id, | 661 int64_t transaction_id, |
| 661 int64_t object_store_id, | 662 int64_t object_store_id, |
| 662 ::indexed_db::mojom::ValuePtr mojo_value, | 663 ::indexed_db::mojom::ValuePtr mojo_value, |
| 663 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, | 664 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, |
| 664 std::vector<IndexedDBBlobInfo> blob_info, | 665 std::vector<IndexedDBBlobInfo> blob_info, |
| 665 const IndexedDBKey& key, | 666 const IndexedDBKey& key, |
| 666 blink::WebIDBPutMode mode, | 667 blink::WebIDBPutMode mode, |
| 667 const std::vector<IndexedDBIndexKeys>& index_keys, | 668 const std::vector<IndexedDBIndexKeys>& index_keys, |
| 668 scoped_refptr<IndexedDBCallbacks> callbacks) { | 669 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 669 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 670 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 670 if (!connection_->IsConnected()) | 671 if (!connection_->IsConnected()) |
| 671 return; | 672 return; |
| 672 | 673 |
| 673 IndexedDBTransaction* transaction = | 674 IndexedDBTransaction* transaction = |
| 674 connection_->GetTransaction(transaction_id); | 675 connection_->GetTransaction(transaction_id); |
| 675 if (!transaction) | 676 if (!transaction) |
| 676 return; | 677 return; |
| 677 | 678 |
| 678 // Value size recorded in IDBObjectStore before we can auto-wrap in a blob. | 679 // Value size recorded in IDBObjectStore before we can auto-wrap in a blob. |
| 679 // 1KB to 10MB. | 680 // 1KB to 10MB. |
| 680 UMA_HISTOGRAM_COUNTS_10000("WebCore.IndexedDB.PutKeySize", | 681 UMA_HISTOGRAM_COUNTS_10000("WebCore.IndexedDB.PutKeySize", |
| 681 key.size_estimate() / 1024); | 682 key.size_estimate() / 1024); |
| 682 | 683 |
| 683 uint64_t commit_size = mojo_value->bits.size() + key.size_estimate(); | 684 uint64_t commit_size = mojo_value->bits.size() + key.size_estimate(); |
| 684 IndexedDBValue value; | 685 IndexedDBValue value; |
| 685 swap(value.bits, mojo_value->bits); | 686 swap(value.bits, mojo_value->bits); |
| 686 swap(value.blob_info, blob_info); | 687 swap(value.blob_info, blob_info); |
| 687 connection_->database()->Put(transaction, object_store_id, &value, &handles, | 688 connection_->database()->Put(transaction, object_store_id, &value, &handles, |
| 688 base::MakeUnique<IndexedDBKey>(key), mode, | 689 base::MakeUnique<IndexedDBKey>(key), mode, |
| 689 std::move(callbacks), index_keys); | 690 std::move(callbacks), index_keys); |
| 690 | 691 |
| 691 // Size can't be big enough to overflow because it represents the | 692 // Size can't be big enough to overflow because it represents the |
| 692 // actual bytes passed through IPC. | 693 // actual bytes passed through IPC. |
| 693 transaction->set_size(transaction->size() + commit_size); | 694 transaction->set_size(transaction->size() + commit_size); |
| 694 } | 695 } |
| 695 | 696 |
| 696 void DatabaseImpl::IDBThreadHelper::SetIndexKeys( | 697 void DatabaseImpl::IDBSequenceHelper::SetIndexKeys( |
| 697 int64_t transaction_id, | 698 int64_t transaction_id, |
| 698 int64_t object_store_id, | 699 int64_t object_store_id, |
| 699 const IndexedDBKey& primary_key, | 700 const IndexedDBKey& primary_key, |
| 700 const std::vector<IndexedDBIndexKeys>& index_keys) { | 701 const std::vector<IndexedDBIndexKeys>& index_keys) { |
| 701 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 702 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 702 if (!connection_->IsConnected()) | 703 if (!connection_->IsConnected()) |
| 703 return; | 704 return; |
| 704 | 705 |
| 705 IndexedDBTransaction* transaction = | 706 IndexedDBTransaction* transaction = |
| 706 connection_->GetTransaction(transaction_id); | 707 connection_->GetTransaction(transaction_id); |
| 707 if (!transaction) | 708 if (!transaction) |
| 708 return; | 709 return; |
| 709 | 710 |
| 710 connection_->database()->SetIndexKeys( | 711 connection_->database()->SetIndexKeys( |
| 711 transaction, object_store_id, base::MakeUnique<IndexedDBKey>(primary_key), | 712 transaction, object_store_id, base::MakeUnique<IndexedDBKey>(primary_key), |
| 712 index_keys); | 713 index_keys); |
| 713 } | 714 } |
| 714 | 715 |
| 715 void DatabaseImpl::IDBThreadHelper::SetIndexesReady( | 716 void DatabaseImpl::IDBSequenceHelper::SetIndexesReady( |
| 716 int64_t transaction_id, | 717 int64_t transaction_id, |
| 717 int64_t object_store_id, | 718 int64_t object_store_id, |
| 718 const std::vector<int64_t>& index_ids) { | 719 const std::vector<int64_t>& index_ids) { |
| 719 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 720 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 720 if (!connection_->IsConnected()) | 721 if (!connection_->IsConnected()) |
| 721 return; | 722 return; |
| 722 | 723 |
| 723 IndexedDBTransaction* transaction = | 724 IndexedDBTransaction* transaction = |
| 724 connection_->GetTransaction(transaction_id); | 725 connection_->GetTransaction(transaction_id); |
| 725 if (!transaction) | 726 if (!transaction) |
| 726 return; | 727 return; |
| 727 | 728 |
| 728 connection_->database()->SetIndexesReady(transaction, object_store_id, | 729 connection_->database()->SetIndexesReady(transaction, object_store_id, |
| 729 index_ids); | 730 index_ids); |
| 730 } | 731 } |
| 731 | 732 |
| 732 void DatabaseImpl::IDBThreadHelper::OpenCursor( | 733 void DatabaseImpl::IDBSequenceHelper::OpenCursor( |
| 733 int64_t transaction_id, | 734 int64_t transaction_id, |
| 734 int64_t object_store_id, | 735 int64_t object_store_id, |
| 735 int64_t index_id, | 736 int64_t index_id, |
| 736 const IndexedDBKeyRange& key_range, | 737 const IndexedDBKeyRange& key_range, |
| 737 blink::WebIDBCursorDirection direction, | 738 blink::WebIDBCursorDirection direction, |
| 738 bool key_only, | 739 bool key_only, |
| 739 blink::WebIDBTaskType task_type, | 740 blink::WebIDBTaskType task_type, |
| 740 scoped_refptr<IndexedDBCallbacks> callbacks) { | 741 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 741 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 742 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 742 if (!connection_->IsConnected()) | 743 if (!connection_->IsConnected()) |
| 743 return; | 744 return; |
| 744 | 745 |
| 745 IndexedDBTransaction* transaction = | 746 IndexedDBTransaction* transaction = |
| 746 connection_->GetTransaction(transaction_id); | 747 connection_->GetTransaction(transaction_id); |
| 747 if (!transaction) | 748 if (!transaction) |
| 748 return; | 749 return; |
| 749 | 750 |
| 750 connection_->database()->OpenCursor( | 751 connection_->database()->OpenCursor( |
| 751 transaction, object_store_id, index_id, | 752 transaction, object_store_id, index_id, |
| 752 base::MakeUnique<IndexedDBKeyRange>(key_range), direction, key_only, | 753 base::MakeUnique<IndexedDBKeyRange>(key_range), direction, key_only, |
| 753 task_type, std::move(callbacks)); | 754 task_type, std::move(callbacks)); |
| 754 } | 755 } |
| 755 | 756 |
| 756 void DatabaseImpl::IDBThreadHelper::Count( | 757 void DatabaseImpl::IDBSequenceHelper::Count( |
| 757 int64_t transaction_id, | 758 int64_t transaction_id, |
| 758 int64_t object_store_id, | 759 int64_t object_store_id, |
| 759 int64_t index_id, | 760 int64_t index_id, |
| 760 const IndexedDBKeyRange& key_range, | 761 const IndexedDBKeyRange& key_range, |
| 761 scoped_refptr<IndexedDBCallbacks> callbacks) { | 762 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 762 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 763 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 763 if (!connection_->IsConnected()) | 764 if (!connection_->IsConnected()) |
| 764 return; | 765 return; |
| 765 | 766 |
| 766 IndexedDBTransaction* transaction = | 767 IndexedDBTransaction* transaction = |
| 767 connection_->GetTransaction(transaction_id); | 768 connection_->GetTransaction(transaction_id); |
| 768 if (!transaction) | 769 if (!transaction) |
| 769 return; | 770 return; |
| 770 | 771 |
| 771 connection_->database()->Count(transaction, object_store_id, index_id, | 772 connection_->database()->Count(transaction, object_store_id, index_id, |
| 772 base::MakeUnique<IndexedDBKeyRange>(key_range), | 773 base::MakeUnique<IndexedDBKeyRange>(key_range), |
| 773 std::move(callbacks)); | 774 std::move(callbacks)); |
| 774 } | 775 } |
| 775 | 776 |
| 776 void DatabaseImpl::IDBThreadHelper::DeleteRange( | 777 void DatabaseImpl::IDBSequenceHelper::DeleteRange( |
| 777 int64_t transaction_id, | 778 int64_t transaction_id, |
| 778 int64_t object_store_id, | 779 int64_t object_store_id, |
| 779 const IndexedDBKeyRange& key_range, | 780 const IndexedDBKeyRange& key_range, |
| 780 scoped_refptr<IndexedDBCallbacks> callbacks) { | 781 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 781 if (!connection_->IsConnected()) | 782 if (!connection_->IsConnected()) |
| 782 return; | 783 return; |
| 783 | 784 |
| 784 IndexedDBTransaction* transaction = | 785 IndexedDBTransaction* transaction = |
| 785 connection_->GetTransaction(transaction_id); | 786 connection_->GetTransaction(transaction_id); |
| 786 if (!transaction) | 787 if (!transaction) |
| 787 return; | 788 return; |
| 788 | 789 |
| 789 connection_->database()->DeleteRange( | 790 connection_->database()->DeleteRange( |
| 790 transaction, object_store_id, | 791 transaction, object_store_id, |
| 791 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks)); | 792 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks)); |
| 792 } | 793 } |
| 793 | 794 |
| 794 void DatabaseImpl::IDBThreadHelper::Clear( | 795 void DatabaseImpl::IDBSequenceHelper::Clear( |
| 795 int64_t transaction_id, | 796 int64_t transaction_id, |
| 796 int64_t object_store_id, | 797 int64_t object_store_id, |
| 797 scoped_refptr<IndexedDBCallbacks> callbacks) { | 798 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 798 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 799 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 799 if (!connection_->IsConnected()) | 800 if (!connection_->IsConnected()) |
| 800 return; | 801 return; |
| 801 | 802 |
| 802 IndexedDBTransaction* transaction = | 803 IndexedDBTransaction* transaction = |
| 803 connection_->GetTransaction(transaction_id); | 804 connection_->GetTransaction(transaction_id); |
| 804 if (!transaction) | 805 if (!transaction) |
| 805 return; | 806 return; |
| 806 | 807 |
| 807 connection_->database()->Clear(transaction, object_store_id, callbacks); | 808 connection_->database()->Clear(transaction, object_store_id, callbacks); |
| 808 } | 809 } |
| 809 | 810 |
| 810 void DatabaseImpl::IDBThreadHelper::CreateIndex( | 811 void DatabaseImpl::IDBSequenceHelper::CreateIndex( |
| 811 int64_t transaction_id, | 812 int64_t transaction_id, |
| 812 int64_t object_store_id, | 813 int64_t object_store_id, |
| 813 int64_t index_id, | 814 int64_t index_id, |
| 814 const base::string16& name, | 815 const base::string16& name, |
| 815 const IndexedDBKeyPath& key_path, | 816 const IndexedDBKeyPath& key_path, |
| 816 bool unique, | 817 bool unique, |
| 817 bool multi_entry) { | 818 bool multi_entry) { |
| 818 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 819 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 819 if (!connection_->IsConnected()) | 820 if (!connection_->IsConnected()) |
| 820 return; | 821 return; |
| 821 | 822 |
| 822 IndexedDBTransaction* transaction = | 823 IndexedDBTransaction* transaction = |
| 823 connection_->GetTransaction(transaction_id); | 824 connection_->GetTransaction(transaction_id); |
| 824 if (!transaction) | 825 if (!transaction) |
| 825 return; | 826 return; |
| 826 | 827 |
| 827 connection_->database()->CreateIndex(transaction, object_store_id, index_id, | 828 connection_->database()->CreateIndex(transaction, object_store_id, index_id, |
| 828 name, key_path, unique, multi_entry); | 829 name, key_path, unique, multi_entry); |
| 829 } | 830 } |
| 830 | 831 |
| 831 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id, | 832 void DatabaseImpl::IDBSequenceHelper::DeleteIndex(int64_t transaction_id, |
| 832 int64_t object_store_id, | 833 int64_t object_store_id, |
| 833 int64_t index_id) { | 834 int64_t index_id) { |
| 834 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 835 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 835 if (!connection_->IsConnected()) | 836 if (!connection_->IsConnected()) |
| 836 return; | 837 return; |
| 837 | 838 |
| 838 IndexedDBTransaction* transaction = | 839 IndexedDBTransaction* transaction = |
| 839 connection_->GetTransaction(transaction_id); | 840 connection_->GetTransaction(transaction_id); |
| 840 if (!transaction) | 841 if (!transaction) |
| 841 return; | 842 return; |
| 842 | 843 |
| 843 connection_->database()->DeleteIndex(transaction, object_store_id, index_id); | 844 connection_->database()->DeleteIndex(transaction, object_store_id, index_id); |
| 844 } | 845 } |
| 845 | 846 |
| 846 void DatabaseImpl::IDBThreadHelper::RenameIndex( | 847 void DatabaseImpl::IDBSequenceHelper::RenameIndex( |
| 847 int64_t transaction_id, | 848 int64_t transaction_id, |
| 848 int64_t object_store_id, | 849 int64_t object_store_id, |
| 849 int64_t index_id, | 850 int64_t index_id, |
| 850 const base::string16& new_name) { | 851 const base::string16& new_name) { |
| 851 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 852 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 852 if (!connection_->IsConnected()) | 853 if (!connection_->IsConnected()) |
| 853 return; | 854 return; |
| 854 | 855 |
| 855 IndexedDBTransaction* transaction = | 856 IndexedDBTransaction* transaction = |
| 856 connection_->GetTransaction(transaction_id); | 857 connection_->GetTransaction(transaction_id); |
| 857 if (!transaction) | 858 if (!transaction) |
| 858 return; | 859 return; |
| 859 | 860 |
| 860 connection_->database()->RenameIndex(transaction, object_store_id, index_id, | 861 connection_->database()->RenameIndex(transaction, object_store_id, index_id, |
| 861 new_name); | 862 new_name); |
| 862 } | 863 } |
| 863 | 864 |
| 864 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) { | 865 void DatabaseImpl::IDBSequenceHelper::Abort(int64_t transaction_id) { |
| 865 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 866 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 866 if (!connection_->IsConnected()) | 867 if (!connection_->IsConnected()) |
| 867 return; | 868 return; |
| 868 | 869 |
| 869 IndexedDBTransaction* transaction = | 870 IndexedDBTransaction* transaction = |
| 870 connection_->GetTransaction(transaction_id); | 871 connection_->GetTransaction(transaction_id); |
| 871 if (!transaction) | 872 if (!transaction) |
| 872 return; | 873 return; |
| 873 | 874 |
| 874 connection_->AbortTransaction( | 875 connection_->AbortTransaction( |
| 875 transaction, | 876 transaction, |
| 876 IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionAbortError, | 877 IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionAbortError, |
| 877 "Transaction aborted by user.")); | 878 "Transaction aborted by user.")); |
| 878 } | 879 } |
| 879 | 880 |
| 880 void DatabaseImpl::IDBThreadHelper::AbortWithError( | 881 void DatabaseImpl::IDBSequenceHelper::AbortWithError( |
| 881 int64_t transaction_id, | 882 int64_t transaction_id, |
| 882 scoped_refptr<IndexedDBCallbacks> callbacks, | 883 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 883 const IndexedDBDatabaseError& error) { | 884 const IndexedDBDatabaseError& error) { |
| 884 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 885 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 885 | 886 |
| 886 callbacks->OnError(error); | 887 callbacks->OnError(error); |
| 887 | 888 |
| 888 if (!connection_->IsConnected()) | 889 if (!connection_->IsConnected()) |
| 889 return; | 890 return; |
| 890 | 891 |
| 891 IndexedDBTransaction* transaction = | 892 IndexedDBTransaction* transaction = |
| 892 connection_->GetTransaction(transaction_id); | 893 connection_->GetTransaction(transaction_id); |
| 893 if (!transaction) | 894 if (!transaction) |
| 894 return; | 895 return; |
| 895 | 896 |
| 896 connection_->AbortTransaction(transaction, error); | 897 connection_->AbortTransaction(transaction, error); |
| 897 } | 898 } |
| 898 | 899 |
| 899 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) { | 900 void DatabaseImpl::IDBSequenceHelper::Commit(int64_t transaction_id) { |
| 900 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 901 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 901 if (!connection_->IsConnected()) | 902 if (!connection_->IsConnected()) |
| 902 return; | 903 return; |
| 903 | 904 |
| 904 IndexedDBTransaction* transaction = | 905 IndexedDBTransaction* transaction = |
| 905 connection_->GetTransaction(transaction_id); | 906 connection_->GetTransaction(transaction_id); |
| 906 if (!transaction) | 907 if (!transaction) |
| 907 return; | 908 return; |
| 908 | 909 |
| 909 // Always allow empty or delete-only transactions. | 910 // Always allow empty or delete-only transactions. |
| 910 if (transaction->size() == 0) { | 911 if (transaction->size() == 0) { |
| 911 connection_->database()->Commit(transaction); | 912 connection_->database()->Commit(transaction); |
| 912 return; | 913 return; |
| 913 } | 914 } |
| 914 | 915 |
| 915 indexed_db_context_->quota_manager_proxy()->GetUsageAndQuota( | 916 indexed_db_context_->quota_manager_proxy()->GetUsageAndQuota( |
| 916 indexed_db_context_->TaskRunner(), origin_.GetURL(), | 917 indexed_db_context_->TaskRunner(), origin_.GetURL(), |
| 917 storage::kStorageTypeTemporary, | 918 storage::kStorageTypeTemporary, |
| 918 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, | 919 base::Bind(&IDBSequenceHelper::OnGotUsageAndQuotaForCommit, |
| 919 weak_factory_.GetWeakPtr(), transaction_id)); | 920 weak_factory_.GetWeakPtr(), transaction_id)); |
| 920 } | 921 } |
| 921 | 922 |
| 922 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( | 923 void DatabaseImpl::IDBSequenceHelper::OnGotUsageAndQuotaForCommit( |
| 923 int64_t transaction_id, | 924 int64_t transaction_id, |
| 924 storage::QuotaStatusCode status, | 925 storage::QuotaStatusCode status, |
| 925 int64_t usage, | 926 int64_t usage, |
| 926 int64_t quota) { | 927 int64_t quota) { |
| 927 DCHECK(idb_thread_checker_.CalledOnValidThread()); | 928 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 928 // May have disconnected while quota check was pending. | 929 // May have disconnected while quota check was pending. |
| 929 if (!connection_->IsConnected()) | 930 if (!connection_->IsConnected()) |
| 930 return; | 931 return; |
| 931 | 932 |
| 932 IndexedDBTransaction* transaction = | 933 IndexedDBTransaction* transaction = |
| 933 connection_->GetTransaction(transaction_id); | 934 connection_->GetTransaction(transaction_id); |
| 934 if (!transaction) | 935 if (!transaction) |
| 935 return; | 936 return; |
| 936 | 937 |
| 937 if (status == storage::kQuotaStatusOk && | 938 if (status == storage::kQuotaStatusOk && |
| 938 usage + transaction->size() <= quota) { | 939 usage + transaction->size() <= quota) { |
| 939 connection_->database()->Commit(transaction); | 940 connection_->database()->Commit(transaction); |
| 940 } else { | 941 } else { |
| 941 connection_->AbortTransaction( | 942 connection_->AbortTransaction( |
| 942 transaction, | 943 transaction, |
| 943 IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionQuotaError)); | 944 IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionQuotaError)); |
| 944 } | 945 } |
| 945 } | 946 } |
| 946 | 947 |
| 947 } // namespace content | 948 } // namespace content |
| OLD | NEW |