OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/extras/sqlite/sqlite_channel_id_store.h" | 5 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 120 |
121 private: | 121 private: |
122 OperationType op_; | 122 OperationType op_; |
123 DefaultChannelIDStore::ChannelID channel_id_; | 123 DefaultChannelIDStore::ChannelID channel_id_; |
124 }; | 124 }; |
125 | 125 |
126 private: | 126 private: |
127 // Batch a channel id operation (add or delete). | 127 // Batch a channel id operation (add or delete). |
128 void BatchOperation(PendingOperation::OperationType op, | 128 void BatchOperation(PendingOperation::OperationType op, |
129 const DefaultChannelIDStore::ChannelID& channel_id); | 129 const DefaultChannelIDStore::ChannelID& channel_id); |
130 // Prunes the list of pending operations to remove any operations for an | |
131 // identifier in |server_identifiers|. | |
132 void PrunePendingOperationsForDeletes( | |
133 const std::list<std::string>& server_identifiers); | |
130 // Commit our pending operations to the database. | 134 // Commit our pending operations to the database. |
131 void Commit(); | 135 void Commit(); |
132 // Close() executed on the background task runner. | 136 // Close() executed on the background task runner. |
133 void InternalBackgroundClose(); | 137 void InternalBackgroundClose(); |
134 | 138 |
135 void BackgroundDeleteAllInList( | 139 void BackgroundDeleteAllInList( |
136 const std::list<std::string>& server_identifiers); | 140 const std::list<std::string>& server_identifiers); |
137 | 141 |
138 void DatabaseErrorCallback(int error, sql::Statement* stmt); | 142 void DatabaseErrorCallback(int error, sql::Statement* stmt); |
139 void KillDatabase(); | 143 void KillDatabase(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 FROM_HERE, | 474 FROM_HERE, |
471 base::Bind(&Backend::Commit, this), | 475 base::Bind(&Backend::Commit, this), |
472 base::TimeDelta::FromMilliseconds(kCommitIntervalMs)); | 476 base::TimeDelta::FromMilliseconds(kCommitIntervalMs)); |
473 } else if (num_pending == kCommitAfterBatchSize) { | 477 } else if (num_pending == kCommitAfterBatchSize) { |
474 // We've reached a big enough batch, fire off a commit now. | 478 // We've reached a big enough batch, fire off a commit now. |
475 background_task_runner_->PostTask(FROM_HERE, | 479 background_task_runner_->PostTask(FROM_HERE, |
476 base::Bind(&Backend::Commit, this)); | 480 base::Bind(&Backend::Commit, this)); |
477 } | 481 } |
478 } | 482 } |
479 | 483 |
484 void SQLiteChannelIDStore::Backend::PrunePendingOperationsForDeletes( | |
485 const std::list<std::string>& server_identifiers) { | |
486 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | |
487 base::AutoLock locked(lock_); | |
rohitrao (ping after 24h)
2015/04/06 18:42:22
I did not see a way to avoid locking around this w
| |
488 | |
489 for (PendingOperationsList::iterator it = pending_.begin(); | |
490 it != pending_.end();) { | |
491 bool remove = | |
492 std::find(server_identifiers.begin(), server_identifiers.end(), | |
493 (*it)->channel_id().server_identifier()) != | |
494 server_identifiers.end(); | |
495 | |
496 if (remove) { | |
497 scoped_ptr<PendingOperation> po(*it); | |
498 it = pending_.erase(it); | |
499 --num_pending_; | |
500 } else { | |
501 ++it; | |
502 } | |
503 } | |
504 } | |
505 | |
480 void SQLiteChannelIDStore::Backend::Commit() { | 506 void SQLiteChannelIDStore::Backend::Commit() { |
481 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 507 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
482 | 508 |
483 PendingOperationsList ops; | 509 PendingOperationsList ops; |
484 { | 510 { |
485 base::AutoLock locked(lock_); | 511 base::AutoLock locked(lock_); |
486 pending_.swap(ops); | 512 pending_.swap(ops); |
487 num_pending_ = 0; | 513 num_pending_ = 0; |
488 } | 514 } |
489 | 515 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 db_.reset(); | 586 db_.reset(); |
561 } | 587 } |
562 | 588 |
563 void SQLiteChannelIDStore::Backend::BackgroundDeleteAllInList( | 589 void SQLiteChannelIDStore::Backend::BackgroundDeleteAllInList( |
564 const std::list<std::string>& server_identifiers) { | 590 const std::list<std::string>& server_identifiers) { |
565 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 591 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
566 | 592 |
567 if (!db_.get()) | 593 if (!db_.get()) |
568 return; | 594 return; |
569 | 595 |
596 // Force a commit of any pending writes before issuing deletes. | |
mef
2015/04/06 20:17:44
I think this comment is stale.
rohitrao (ping after 24h)
2015/04/07 14:21:37
Done.
| |
597 PrunePendingOperationsForDeletes(server_identifiers); | |
598 | |
570 sql::Statement del_smt(db_->GetCachedStatement( | 599 sql::Statement del_smt(db_->GetCachedStatement( |
571 SQL_FROM_HERE, "DELETE FROM origin_bound_certs WHERE origin=?")); | 600 SQL_FROM_HERE, "DELETE FROM origin_bound_certs WHERE origin=?")); |
572 if (!del_smt.is_valid()) { | 601 if (!del_smt.is_valid()) { |
573 LOG(WARNING) << "Unable to delete channel ids."; | 602 LOG(WARNING) << "Unable to delete channel ids."; |
574 return; | 603 return; |
575 } | 604 } |
576 | 605 |
577 sql::Transaction transaction(db_.get()); | 606 sql::Transaction transaction(db_.get()); |
578 if (!transaction.Begin()) { | 607 if (!transaction.Begin()) { |
579 LOG(WARNING) << "Unable to delete channel ids."; | 608 LOG(WARNING) << "Unable to delete channel ids."; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 backend_->SetForceKeepSessionState(); | 656 backend_->SetForceKeepSessionState(); |
628 } | 657 } |
629 | 658 |
630 SQLiteChannelIDStore::~SQLiteChannelIDStore() { | 659 SQLiteChannelIDStore::~SQLiteChannelIDStore() { |
631 backend_->Close(); | 660 backend_->Close(); |
632 // We release our reference to the Backend, though it will probably still have | 661 // We release our reference to the Backend, though it will probably still have |
633 // a reference if the background task runner has not run Close() yet. | 662 // a reference if the background task runner has not run Close() yet. |
634 } | 663 } |
635 | 664 |
636 } // namespace net | 665 } // namespace net |
OLD | NEW |