Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 for (size_t i = 0; i < values.size(); ++i) { | 278 for (size_t i = 0; i < values.size(); ++i) { |
| 279 if (!CreateAllBlobs(values[i].blob_info, | 279 if (!CreateAllBlobs(values[i].blob_info, |
| 280 ¶ms->values[i].blob_or_file_info, dispatcher_host)) | 280 ¶ms->values[i].blob_or_file_info, dispatcher_host)) |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 dispatcher_host->Send( | 284 dispatcher_host->Send( |
| 285 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params)); | 285 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(*params)); |
| 286 } | 286 } |
| 287 | 287 |
| 288 static void BlobLookupForGetAll( | |
| 289 IndexedDBMsg_CallbacksSuccessArray_Params* params, | |
| 290 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | |
| 291 const std::vector<IndexedDBReturnValue>& values) { | |
| 292 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 293 DCHECK_EQ(values.size(), params->values.size()); | |
| 294 | |
| 295 for (size_t i = 0; i < values.size(); ++i) { | |
| 296 if (!CreateAllBlobs(values[i].blob_info, | |
| 297 ¶ms->values.at(i).blob_or_file_info, | |
|
jsbell
2015/04/28 00:06:53
Why at() rather than [] ?
cmumford
2015/04/29 23:17:46
I usually only use at() when it's a pointer. I pre
| |
| 298 dispatcher_host)) | |
| 299 return; | |
| 300 } | |
| 301 | |
| 302 dispatcher_host->Send(new IndexedDBMsg_CallbacksSuccessArray(*params)); | |
| 303 } | |
| 304 | |
| 288 static void FillInBlobData( | 305 static void FillInBlobData( |
| 289 const std::vector<IndexedDBBlobInfo>& blob_info, | 306 const std::vector<IndexedDBBlobInfo>& blob_info, |
| 290 std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info) { | 307 std::vector<IndexedDBMsg_BlobOrFileInfo>* blob_or_file_info) { |
| 291 for (const auto& iter : blob_info) { | 308 for (const auto& iter : blob_info) { |
| 292 if (iter.is_file()) { | 309 if (iter.is_file()) { |
| 293 IndexedDBMsg_BlobOrFileInfo info; | 310 IndexedDBMsg_BlobOrFileInfo info; |
| 294 info.is_file = true; | 311 info.is_file = true; |
| 295 info.mime_type = iter.type(); | 312 info.mime_type = iter.type(); |
| 296 info.file_name = iter.file_name(); | 313 info.file_name = iter.file_name(); |
| 297 info.file_path = iter.file_path().AsUTF16Unsafe(); | 314 info.file_path = iter.file_path().AsUTF16Unsafe(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 value->blob_info, | 514 value->blob_info, |
| 498 base::Bind(CreateBlobsAndSend<IndexedDBMsg_CallbacksSuccessValue_Params, | 515 base::Bind(CreateBlobsAndSend<IndexedDBMsg_CallbacksSuccessValue_Params, |
| 499 IndexedDBMsg_CallbacksSuccessValue>, | 516 IndexedDBMsg_CallbacksSuccessValue>, |
| 500 base::Owned(params.release()), dispatcher_host_, | 517 base::Owned(params.release()), dispatcher_host_, |
| 501 value->blob_info, | 518 value->blob_info, |
| 502 base::Unretained(&p->value.blob_or_file_info))); | 519 base::Unretained(&p->value.blob_or_file_info))); |
| 503 } | 520 } |
| 504 dispatcher_host_ = NULL; | 521 dispatcher_host_ = NULL; |
| 505 } | 522 } |
| 506 | 523 |
| 524 void IndexedDBCallbacks::OnSuccessArray( | |
| 525 std::vector<IndexedDBReturnValue>* values, | |
| 526 const IndexedDBKeyPath& key_path) { | |
| 527 DCHECK(dispatcher_host_.get()); | |
| 528 | |
| 529 DCHECK_EQ(kNoTransaction, host_transaction_id_); | |
| 530 DCHECK_EQ(kNoDatabase, ipc_database_id_); | |
| 531 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | |
| 532 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | |
| 533 | |
| 534 scoped_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params( | |
| 535 new IndexedDBMsg_CallbacksSuccessArray_Params()); | |
| 536 params->ipc_thread_id = ipc_thread_id_; | |
| 537 params->ipc_callbacks_id = ipc_callbacks_id_; | |
| 538 params->values.resize(values->size()); | |
| 539 | |
| 540 bool found_blob_info = false; | |
| 541 for (size_t i = 0; i < values->size(); ++i) { | |
| 542 IndexedDBMsg_ReturnValue& pvalue = params->values[i]; | |
| 543 IndexedDBReturnValue& value = (*values)[i]; | |
| 544 pvalue.bits.swap(value.bits); | |
| 545 if (!value.blob_info.empty()) { | |
| 546 found_blob_info = true; | |
| 547 FillInBlobData(value.blob_info, &pvalue.blob_or_file_info); | |
| 548 for (const auto& blob_info : value.blob_info) { | |
| 549 if (!blob_info.mark_used_callback().is_null()) | |
| 550 blob_info.mark_used_callback().Run(); | |
| 551 } | |
| 552 } | |
| 553 pvalue.primary_key = value.primary_key; | |
| 554 pvalue.key_path = key_path; | |
| 555 } | |
| 556 | |
| 557 if (found_blob_info) { | |
| 558 BrowserThread::PostTask( | |
| 559 BrowserThread::IO, FROM_HERE, | |
| 560 base::Bind(BlobLookupForGetAll, base::Owned(params.release()), | |
| 561 dispatcher_host_, *values)); | |
| 562 } else { | |
| 563 dispatcher_host_->Send( | |
| 564 new IndexedDBMsg_CallbacksSuccessArray(*params.get())); | |
| 565 } | |
| 566 dispatcher_host_ = NULL; | |
| 567 } | |
| 568 | |
| 507 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { | 569 void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { |
| 508 DCHECK(dispatcher_host_.get()); | 570 DCHECK(dispatcher_host_.get()); |
| 509 | 571 |
| 510 DCHECK_EQ(kNoCursor, ipc_cursor_id_); | 572 DCHECK_EQ(kNoCursor, ipc_cursor_id_); |
| 511 DCHECK_EQ(kNoTransaction, host_transaction_id_); | 573 DCHECK_EQ(kNoTransaction, host_transaction_id_); |
| 512 DCHECK_EQ(kNoDatabase, ipc_database_id_); | 574 DCHECK_EQ(kNoDatabase, ipc_database_id_); |
| 513 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); | 575 DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_); |
| 514 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); | 576 DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_); |
| 515 | 577 |
| 516 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( | 578 dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 545 ipc_thread_id_, ipc_callbacks_id_)); | 607 ipc_thread_id_, ipc_callbacks_id_)); |
| 546 dispatcher_host_ = NULL; | 608 dispatcher_host_ = NULL; |
| 547 } | 609 } |
| 548 | 610 |
| 549 void IndexedDBCallbacks::SetConnectionOpenStartTime( | 611 void IndexedDBCallbacks::SetConnectionOpenStartTime( |
| 550 const base::TimeTicks& start_time) { | 612 const base::TimeTicks& start_time) { |
| 551 connection_open_start_time_ = start_time; | 613 connection_open_start_time_ = start_time; |
| 552 } | 614 } |
| 553 | 615 |
| 554 } // namespace content | 616 } // namespace content |
| OLD | NEW |