| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 5 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 15 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/fileapi/fileapi_message_filter.h" | 16 #include "content/browser/fileapi/fileapi_message_filter.h" |
| 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 17 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 18 #include "content/browser/indexed_db/indexed_db_connection.h" | 18 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 19 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 20 #include "content/browser/indexed_db/indexed_db_cursor.h" | 20 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 21 #include "content/browser/indexed_db/indexed_db_database_error.h" | 21 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 22 #include "content/browser/indexed_db/indexed_db_return_value.h" | 22 #include "content/browser/indexed_db/indexed_db_return_value.h" |
| 23 #include "content/browser/indexed_db/indexed_db_tracing.h" | 23 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 24 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 24 #include "content/browser/indexed_db/indexed_db_value.h" | 25 #include "content/browser/indexed_db/indexed_db_value.h" |
| 25 #include "content/common/indexed_db/indexed_db_constants.h" | 26 #include "content/common/indexed_db/indexed_db_constants.h" |
| 26 #include "content/common/indexed_db/indexed_db_messages.h" | 27 #include "content/common/indexed_db/indexed_db_messages.h" |
| 27 #include "content/common/indexed_db/indexed_db_metadata.h" | 28 #include "content/common/indexed_db/indexed_db_metadata.h" |
| 28 #include "storage/browser/blob/blob_storage_context.h" | 29 #include "storage/browser/blob/blob_storage_context.h" |
| 29 #include "storage/browser/blob/shareable_file_reference.h" | 30 #include "storage/browser/blob/shareable_file_reference.h" |
| 30 #include "storage/browser/quota/quota_manager.h" | 31 #include "storage/browser/quota/quota_manager.h" |
| 31 | 32 |
| 32 using indexed_db::mojom::CallbacksAssociatedPtrInfo; | 33 using indexed_db::mojom::CallbacksAssociatedPtrInfo; |
| 33 using storage::ShareableFileReference; | 34 using storage::ShareableFileReference; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 UMA_HISTOGRAM_MEDIUM_TIMES( | 168 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 168 "WebCore.IndexedDB.OpenTime.Blocked", | 169 "WebCore.IndexedDB.OpenTime.Blocked", |
| 169 base::TimeTicks::Now() - connection_open_start_time_); | 170 base::TimeTicks::Now() - connection_open_start_time_); |
| 170 connection_open_start_time_ = base::TimeTicks(); | 171 connection_open_start_time_ = base::TimeTicks(); |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 | 174 |
| 174 void IndexedDBCallbacks::OnUpgradeNeeded( | 175 void IndexedDBCallbacks::OnUpgradeNeeded( |
| 175 int64_t old_version, | 176 int64_t old_version, |
| 176 std::unique_ptr<IndexedDBConnection> connection, | 177 std::unique_ptr<IndexedDBConnection> connection, |
| 178 IndexedDBTransaction* transaction, |
| 177 const IndexedDBDatabaseMetadata& metadata, | 179 const IndexedDBDatabaseMetadata& metadata, |
| 178 const IndexedDBDataLossInfo& data_loss_info) { | 180 const IndexedDBDataLossInfo& data_loss_info) { |
| 179 DCHECK(thread_checker_.CalledOnValidThread()); | 181 DCHECK(thread_checker_.CalledOnValidThread()); |
| 180 DCHECK(dispatcher_host_); | 182 DCHECK(dispatcher_host_); |
| 181 DCHECK(io_helper_); | 183 DCHECK(io_helper_); |
| 182 DCHECK_NE(kNoTransaction, host_transaction_id_); | 184 DCHECK_NE(kNoTransaction, host_transaction_id_); |
| 183 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 185 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 184 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 186 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 185 | 187 |
| 186 data_loss_ = data_loss_info.status; | 188 data_loss_ = data_loss_info.status; |
| 187 dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_); | |
| 188 int32_t ipc_database_id = | 189 int32_t ipc_database_id = |
| 189 dispatcher_host_->Add(connection.release(), origin_); | 190 dispatcher_host_->Add(std::move(connection), origin_); |
| 190 if (ipc_database_id < 0) | 191 if (ipc_database_id < 0) |
| 191 return; | 192 return; |
| 192 | 193 |
| 193 ipc_database_id_ = ipc_database_id; | 194 ipc_database_id_ = ipc_database_id; |
| 194 | 195 |
| 195 BrowserThread::PostTask( | 196 BrowserThread::PostTask( |
| 196 BrowserThread::IO, FROM_HERE, | 197 BrowserThread::IO, FROM_HERE, |
| 197 base::Bind(&IOThreadHelper::SendUpgradeNeeded, | 198 base::Bind(&IOThreadHelper::SendUpgradeNeeded, |
| 198 base::Unretained(io_helper_.get()), ipc_database_id, | 199 base::Unretained(io_helper_.get()), ipc_database_id, |
| 199 old_version, data_loss_info.status, data_loss_info.message, | 200 old_version, data_loss_info.status, data_loss_info.message, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 215 DCHECK(io_helper_); | 216 DCHECK(io_helper_); |
| 216 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 217 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 217 DCHECK_NE(kNoTransaction, host_transaction_id_); | 218 DCHECK_NE(kNoTransaction, host_transaction_id_); |
| 218 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); | 219 DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection); |
| 219 | 220 |
| 220 scoped_refptr<IndexedDBCallbacks> self(this); | 221 scoped_refptr<IndexedDBCallbacks> self(this); |
| 221 | 222 |
| 222 int32_t ipc_object_id = kNoDatabase; | 223 int32_t ipc_object_id = kNoDatabase; |
| 223 // Only register if the connection was not previously sent in OnUpgradeNeeded. | 224 // Only register if the connection was not previously sent in OnUpgradeNeeded. |
| 224 if (ipc_database_id_ == kNoDatabase) { | 225 if (ipc_database_id_ == kNoDatabase) { |
| 225 ipc_object_id = dispatcher_host_->Add(connection.release(), origin_); | 226 ipc_object_id = dispatcher_host_->Add(std::move(connection), origin_); |
| 226 } | 227 } |
| 227 | 228 |
| 228 BrowserThread::PostTask( | 229 BrowserThread::PostTask( |
| 229 BrowserThread::IO, FROM_HERE, | 230 BrowserThread::IO, FROM_HERE, |
| 230 base::Bind(&IOThreadHelper::SendSuccessDatabase, | 231 base::Bind(&IOThreadHelper::SendSuccessDatabase, |
| 231 base::Unretained(io_helper_.get()), ipc_object_id, metadata)); | 232 base::Unretained(io_helper_.get()), ipc_object_id, metadata)); |
| 232 dispatcher_host_ = nullptr; | 233 dispatcher_host_ = nullptr; |
| 233 | 234 |
| 234 if (!connection_open_start_time_.is_null()) { | 235 if (!connection_open_start_time_.is_null()) { |
| 235 UMA_HISTOGRAM_MEDIUM_TIMES( | 236 UMA_HISTOGRAM_MEDIUM_TIMES( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 const std::vector<IndexedDBBlobInfo>& blob_info, | 348 const std::vector<IndexedDBBlobInfo>& blob_info, |
| 348 const base::Closure& callback) { | 349 const base::Closure& callback) { |
| 349 for (const auto& iter : blob_info) { | 350 for (const auto& iter : blob_info) { |
| 350 if (!iter.mark_used_callback().is_null()) | 351 if (!iter.mark_used_callback().is_null()) |
| 351 iter.mark_used_callback().Run(); | 352 iter.mark_used_callback().Run(); |
| 352 } | 353 } |
| 353 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 354 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 354 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); | 355 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback); |
| 355 } | 356 } |
| 356 | 357 |
| 357 void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor, | 358 void IndexedDBCallbacks::OnSuccess(std::unique_ptr<IndexedDBCursor> cursor, |
| 358 const IndexedDBKey& key, | 359 const IndexedDBKey& key, |
| 359 const IndexedDBKey& primary_key, | 360 const IndexedDBKey& primary_key, |
| 360 IndexedDBValue* value) { | 361 IndexedDBValue* value) { |
| 361 DCHECK(thread_checker_.CalledOnValidThread()); | 362 DCHECK(thread_checker_.CalledOnValidThread()); |
| 362 DCHECK(dispatcher_host_); | 363 DCHECK(dispatcher_host_); |
| 363 DCHECK(!io_helper_); | 364 DCHECK(!io_helper_); |
| 364 | 365 |
| 365 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 366 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 366 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 367 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 367 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 368 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 368 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 369 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 369 | 370 |
| 370 int32_t ipc_object_id = dispatcher_host_->Add(cursor.get()); | 371 int32_t ipc_object_id = dispatcher_host_->Add(std::move(cursor)); |
| 371 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( | 372 std::unique_ptr<IndexedDBMsg_CallbacksSuccessIDBCursor_Params> params( |
| 372 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); | 373 new IndexedDBMsg_CallbacksSuccessIDBCursor_Params()); |
| 373 params->ipc_thread_id = ipc_thread_id_; | 374 params->ipc_thread_id = ipc_thread_id_; |
| 374 params->ipc_callbacks_id = ipc_callbacks_id_; | 375 params->ipc_callbacks_id = ipc_callbacks_id_; |
| 375 params->ipc_cursor_id = ipc_object_id; | 376 params->ipc_cursor_id = ipc_object_id; |
| 376 params->key = key; | 377 params->key = key; |
| 377 params->primary_key = primary_key; | 378 params->primary_key = primary_key; |
| 378 if (value && !value->empty()) | 379 if (value && !value->empty()) |
| 379 std::swap(params->value.bits, value->bits); | 380 std::swap(params->value.bits, value->bits); |
| 380 // TODO(alecflett): Avoid a copy here: the whole params object is | 381 // TODO(alecflett): Avoid a copy here: the whole params object is |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 int32_t database_id, | 687 int32_t database_id, |
| 687 const content::IndexedDBDatabaseMetadata& metadata) { | 688 const content::IndexedDBDatabaseMetadata& metadata) { |
| 688 callbacks_->SuccessDatabase(database_id, metadata); | 689 callbacks_->SuccessDatabase(database_id, metadata); |
| 689 } | 690 } |
| 690 | 691 |
| 691 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { | 692 void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) { |
| 692 callbacks_->SuccessInteger(value); | 693 callbacks_->SuccessInteger(value); |
| 693 } | 694 } |
| 694 | 695 |
| 695 } // namespace content | 696 } // namespace content |
| OLD | NEW |