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> |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 const IndexedDBDataLossInfo& data_loss_info) { | 219 const IndexedDBDataLossInfo& data_loss_info) { |
220 DCHECK(thread_checker_.CalledOnValidThread()); | 220 DCHECK(thread_checker_.CalledOnValidThread()); |
221 DCHECK(dispatcher_host_); | 221 DCHECK(dispatcher_host_); |
222 DCHECK(io_helper_); | 222 DCHECK(io_helper_); |
223 | 223 |
224 DCHECK(!database_sent_); | 224 DCHECK(!database_sent_); |
225 | 225 |
226 data_loss_ = data_loss_info.status; | 226 data_loss_ = data_loss_info.status; |
227 database_sent_ = true; | 227 database_sent_ = true; |
228 auto database = base::MakeUnique<DatabaseImpl>(std::move(connection), origin_, | 228 auto database = base::MakeUnique<DatabaseImpl>(std::move(connection), origin_, |
229 dispatcher_host_); | 229 dispatcher_host_.get()); |
230 | 230 |
231 BrowserThread::PostTask( | 231 BrowserThread::PostTask( |
232 BrowserThread::IO, FROM_HERE, | 232 BrowserThread::IO, FROM_HERE, |
233 base::Bind(&IOThreadHelper::SendUpgradeNeeded, | 233 base::Bind(&IOThreadHelper::SendUpgradeNeeded, |
234 base::Unretained(io_helper_.get()), base::Passed(&database), | 234 base::Unretained(io_helper_.get()), base::Passed(&database), |
235 old_version, data_loss_info.status, data_loss_info.message, | 235 old_version, data_loss_info.status, data_loss_info.message, |
236 metadata)); | 236 metadata)); |
237 | 237 |
238 if (!connection_open_start_time_.is_null()) { | 238 if (!connection_open_start_time_.is_null()) { |
239 UMA_HISTOGRAM_MEDIUM_TIMES( | 239 UMA_HISTOGRAM_MEDIUM_TIMES( |
(...skipping 11 matching lines...) Expand all Loading... |
251 DCHECK(io_helper_); | 251 DCHECK(io_helper_); |
252 | 252 |
253 DCHECK_EQ(database_sent_, !connection); | 253 DCHECK_EQ(database_sent_, !connection); |
254 | 254 |
255 scoped_refptr<IndexedDBCallbacks> self(this); | 255 scoped_refptr<IndexedDBCallbacks> self(this); |
256 | 256 |
257 // Only send a new Database if the connection was not previously sent in | 257 // Only send a new Database if the connection was not previously sent in |
258 // OnUpgradeNeeded. | 258 // OnUpgradeNeeded. |
259 std::unique_ptr<DatabaseImpl> database; | 259 std::unique_ptr<DatabaseImpl> database; |
260 if (!database_sent_) { | 260 if (!database_sent_) { |
261 database.reset( | 261 database.reset(new DatabaseImpl(std::move(connection), origin_, |
262 new DatabaseImpl(std::move(connection), origin_, dispatcher_host_)); | 262 dispatcher_host_.get())); |
263 } | 263 } |
264 | 264 |
265 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 265 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
266 base::Bind(&IOThreadHelper::SendSuccessDatabase, | 266 base::Bind(&IOThreadHelper::SendSuccessDatabase, |
267 base::Unretained(io_helper_.get()), | 267 base::Unretained(io_helper_.get()), |
268 base::Passed(&database), metadata)); | 268 base::Passed(&database), metadata)); |
269 dispatcher_host_ = nullptr; | 269 dispatcher_host_ = nullptr; |
270 | 270 |
271 if (!connection_open_start_time_.is_null()) { | 271 if (!connection_open_start_time_.is_null()) { |
272 UMA_HISTOGRAM_MEDIUM_TIMES( | 272 UMA_HISTOGRAM_MEDIUM_TIMES( |
273 "WebCore.IndexedDB.OpenTime.Success", | 273 "WebCore.IndexedDB.OpenTime.Success", |
274 base::TimeTicks::Now() - connection_open_start_time_); | 274 base::TimeTicks::Now() - connection_open_start_time_); |
275 connection_open_start_time_ = base::TimeTicks(); | 275 connection_open_start_time_ = base::TimeTicks(); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 void IndexedDBCallbacks::OnSuccess(std::unique_ptr<IndexedDBCursor> cursor, | 279 void IndexedDBCallbacks::OnSuccess(std::unique_ptr<IndexedDBCursor> cursor, |
280 const IndexedDBKey& key, | 280 const IndexedDBKey& key, |
281 const IndexedDBKey& primary_key, | 281 const IndexedDBKey& primary_key, |
282 IndexedDBValue* value) { | 282 IndexedDBValue* value) { |
283 DCHECK(thread_checker_.CalledOnValidThread()); | 283 DCHECK(thread_checker_.CalledOnValidThread()); |
284 DCHECK(dispatcher_host_); | 284 DCHECK(dispatcher_host_); |
285 DCHECK(io_helper_); | 285 DCHECK(io_helper_); |
286 | 286 |
287 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 287 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
288 | 288 |
289 auto cursor_impl = base::MakeUnique<CursorImpl>(std::move(cursor), origin_, | 289 auto cursor_impl = base::MakeUnique<CursorImpl>(std::move(cursor), origin_, |
290 dispatcher_host_); | 290 dispatcher_host_.get()); |
291 | 291 |
292 ::indexed_db::mojom::ValuePtr mojo_value; | 292 ::indexed_db::mojom::ValuePtr mojo_value; |
293 std::vector<IndexedDBBlobInfo> blob_info; | 293 std::vector<IndexedDBBlobInfo> blob_info; |
294 if (value) { | 294 if (value) { |
295 mojo_value = ConvertAndEraseValue(value); | 295 mojo_value = ConvertAndEraseValue(value); |
296 blob_info.swap(value->blob_info); | 296 blob_info.swap(value->blob_info); |
297 } | 297 } |
298 | 298 |
299 BrowserThread::PostTask( | 299 BrowserThread::PostTask( |
300 BrowserThread::IO, FROM_HERE, | 300 BrowserThread::IO, FROM_HERE, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 std::unique_ptr<DatabaseImpl> database, | 473 std::unique_ptr<DatabaseImpl> database, |
474 int64_t old_version, | 474 int64_t old_version, |
475 blink::WebIDBDataLoss data_loss, | 475 blink::WebIDBDataLoss data_loss, |
476 const std::string& data_loss_message, | 476 const std::string& data_loss_message, |
477 const content::IndexedDBDatabaseMetadata& metadata) { | 477 const content::IndexedDBDatabaseMetadata& metadata) { |
478 if (!callbacks_) | 478 if (!callbacks_) |
479 return; | 479 return; |
480 | 480 |
481 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; | 481 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; |
482 auto request = mojo::MakeRequest(&ptr_info); | 482 auto request = mojo::MakeRequest(&ptr_info); |
483 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request)); | 483 |
| 484 dispatcher_host_->AddDatabaseBinding(std::move(database), std::move(request)); |
484 callbacks_->UpgradeNeeded(std::move(ptr_info), old_version, data_loss, | 485 callbacks_->UpgradeNeeded(std::move(ptr_info), old_version, data_loss, |
485 data_loss_message, metadata); | 486 data_loss_message, metadata); |
486 } | 487 } |
487 | 488 |
488 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( | 489 void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase( |
489 std::unique_ptr<DatabaseImpl> database, | 490 std::unique_ptr<DatabaseImpl> database, |
490 const content::IndexedDBDatabaseMetadata& metadata) { | 491 const content::IndexedDBDatabaseMetadata& metadata) { |
491 if (!callbacks_) | 492 if (!callbacks_) |
492 return; | 493 return; |
493 | 494 |
494 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; | 495 ::indexed_db::mojom::DatabaseAssociatedPtrInfo ptr_info; |
495 if (database) { | 496 if (database) { |
496 auto request = mojo::MakeRequest(&ptr_info); | 497 auto request = mojo::MakeRequest(&ptr_info); |
497 mojo::MakeStrongAssociatedBinding(std::move(database), std::move(request)); | 498 dispatcher_host_->AddDatabaseBinding(std::move(database), |
| 499 std::move(request)); |
498 } | 500 } |
499 callbacks_->SuccessDatabase(std::move(ptr_info), metadata); | 501 callbacks_->SuccessDatabase(std::move(ptr_info), metadata); |
500 } | 502 } |
501 | 503 |
502 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( | 504 void IndexedDBCallbacks::IOThreadHelper::SendSuccessCursor( |
503 std::unique_ptr<CursorImpl> cursor, | 505 std::unique_ptr<CursorImpl> cursor, |
504 const IndexedDBKey& key, | 506 const IndexedDBKey& key, |
505 const IndexedDBKey& primary_key, | 507 const IndexedDBKey& primary_key, |
506 ::indexed_db::mojom::ValuePtr value, | 508 ::indexed_db::mojom::ValuePtr value, |
507 const std::vector<IndexedDBBlobInfo>& blob_info) { | 509 const std::vector<IndexedDBBlobInfo>& blob_info) { |
508 if (!callbacks_) | 510 if (!callbacks_) |
509 return; | 511 return; |
510 | 512 |
511 if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info)) | 513 if (value && !CreateAllBlobs(blob_info, &value->blob_or_file_info)) |
512 return; | 514 return; |
513 | 515 |
514 ::indexed_db::mojom::CursorAssociatedPtrInfo ptr_info; | 516 ::indexed_db::mojom::CursorAssociatedPtrInfo ptr_info; |
515 auto request = mojo::MakeRequest(&ptr_info); | 517 auto request = mojo::MakeRequest(&ptr_info); |
516 mojo::MakeStrongAssociatedBinding(std::move(cursor), std::move(request)); | 518 dispatcher_host_->AddCursorBinding(std::move(cursor), std::move(request)); |
517 callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key, | 519 callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key, |
518 std::move(value)); | 520 std::move(value)); |
519 } | 521 } |
520 | 522 |
521 void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue( | 523 void IndexedDBCallbacks::IOThreadHelper::SendSuccessValue( |
522 ::indexed_db::mojom::ReturnValuePtr value, | 524 ::indexed_db::mojom::ReturnValuePtr value, |
523 const std::vector<IndexedDBBlobInfo>& blob_info) { | 525 const std::vector<IndexedDBBlobInfo>& blob_info) { |
524 if (!callbacks_) | 526 if (!callbacks_) |
525 return; | 527 return; |
526 | 528 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 (*blob_or_file_info)[i]->uuid = CreateBlobData(blob_info[i]); | 624 (*blob_or_file_info)[i]->uuid = CreateBlobData(blob_info[i]); |
623 return true; | 625 return true; |
624 } | 626 } |
625 | 627 |
626 void IndexedDBCallbacks::IOThreadHelper::OnConnectionError() { | 628 void IndexedDBCallbacks::IOThreadHelper::OnConnectionError() { |
627 callbacks_.reset(); | 629 callbacks_.reset(); |
628 dispatcher_host_ = nullptr; | 630 dispatcher_host_ = nullptr; |
629 } | 631 } |
630 | 632 |
631 } // namespace content | 633 } // namespace content |
OLD | NEW |