Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: net/extras/sqlite/sqlite_channel_id_store.cc

Issue 2874973002: Flush Channel IDs when Cookies get saved to a persistent backend (Closed)
Patch Set: clean up a few things Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Post background delete of all channel ids for |server_identifiers|. 94 // Post background delete of all channel ids for |server_identifiers|.
95 void DeleteAllInList(const std::list<std::string>& server_identifiers); 95 void DeleteAllInList(const std::list<std::string>& server_identifiers);
96 96
97 // Commit any pending operations and close the database. This must be called 97 // Commit any pending operations and close the database. This must be called
98 // before the object is destructed. 98 // before the object is destructed.
99 void Close(); 99 void Close();
100 100
101 void SetForceKeepSessionState(); 101 void SetForceKeepSessionState();
102 102
103 // Commit our pending operations to the database.
104 void Commit();
105
103 private: 106 private:
104 friend class base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend>; 107 friend class base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend>;
105 108
106 // You should call Close() before destructing this object. 109 // You should call Close() before destructing this object.
107 virtual ~Backend() { 110 virtual ~Backend() {
108 DCHECK(!db_.get()) << "Close should have already been called."; 111 DCHECK(!db_.get()) << "Close should have already been called.";
109 DCHECK_EQ(0u, num_pending_); 112 DCHECK_EQ(0u, num_pending_);
110 DCHECK(pending_.empty()); 113 DCHECK(pending_.empty());
111 } 114 }
112 115
(...skipping 23 matching lines...) Expand all
136 }; 139 };
137 140
138 private: 141 private:
139 // Batch a channel id operation (add or delete). 142 // Batch a channel id operation (add or delete).
140 void BatchOperation(PendingOperation::OperationType op, 143 void BatchOperation(PendingOperation::OperationType op,
141 const DefaultChannelIDStore::ChannelID& channel_id); 144 const DefaultChannelIDStore::ChannelID& channel_id);
142 // Prunes the list of pending operations to remove any operations for an 145 // Prunes the list of pending operations to remove any operations for an
143 // identifier in |server_identifiers|. 146 // identifier in |server_identifiers|.
144 void PrunePendingOperationsForDeletes( 147 void PrunePendingOperationsForDeletes(
145 const std::list<std::string>& server_identifiers); 148 const std::list<std::string>& server_identifiers);
146 // Commit our pending operations to the database.
147 void Commit();
148 // Close() executed on the background task runner. 149 // Close() executed on the background task runner.
149 void InternalBackgroundClose(); 150 void InternalBackgroundClose();
150 151
151 void BackgroundDeleteAllInList( 152 void BackgroundDeleteAllInList(
152 const std::list<std::string>& server_identifiers); 153 const std::list<std::string>& server_identifiers);
153 154
154 void DatabaseErrorCallback(int error, sql::Statement* stmt); 155 void DatabaseErrorCallback(int error, sql::Statement* stmt);
155 void KillDatabase(); 156 void KillDatabase();
156 157
157 const base::FilePath path_; 158 const base::FilePath path_;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 // Perform deletion on background task runner. 475 // Perform deletion on background task runner.
475 background_task_runner_->PostTask( 476 background_task_runner_->PostTask(
476 FROM_HERE, 477 FROM_HERE,
477 base::Bind( 478 base::Bind(
478 &Backend::BackgroundDeleteAllInList, this, server_identifiers)); 479 &Backend::BackgroundDeleteAllInList, this, server_identifiers));
479 } 480 }
480 481
481 void SQLiteChannelIDStore::Backend::BatchOperation( 482 void SQLiteChannelIDStore::Backend::BatchOperation(
482 PendingOperation::OperationType op, 483 PendingOperation::OperationType op,
483 const DefaultChannelIDStore::ChannelID& channel_id) { 484 const DefaultChannelIDStore::ChannelID& channel_id) {
484 // These thresholds used to be 30 seconds or 512 outstanding operations (the 485 // Commit every 30 seconds.
485 // same values used in CookieMonster). Since cookies can be bound to Channel 486 static const int kCommitIntervalMs = 30 * 1000;
486 // IDs, it's possible for a cookie to get committed to the cookie database 487 // Commit right away if we have more than 512 outstanding operations.
487 // before the Channel ID it is bound to gets committed. Decreasing these 488 static const size_t kCommitAfterBatchSize = 512;
488 // thresholds increases the chance that the Channel ID will be committed
489 // before or at the same time as the cookie.
490
491 // Commit every 2 seconds.
492 static const int kCommitIntervalMs = 2 * 1000;
493 // Commit right away if we have more than 3 outstanding operations.
494 static const size_t kCommitAfterBatchSize = 3;
495 489
496 // We do a full copy of the cert here, and hopefully just here. 490 // We do a full copy of the cert here, and hopefully just here.
497 std::unique_ptr<PendingOperation> po(new PendingOperation(op, channel_id)); 491 std::unique_ptr<PendingOperation> po(new PendingOperation(op, channel_id));
498 492
499 PendingOperationsList::size_type num_pending; 493 PendingOperationsList::size_type num_pending;
500 { 494 {
501 base::AutoLock locked(lock_); 495 base::AutoLock locked(lock_);
502 pending_.push_back(po.release()); 496 pending_.push_back(po.release());
503 num_pending = ++num_pending_; 497 num_pending = ++num_pending_;
504 } 498 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 674
681 void SQLiteChannelIDStore::DeleteAllInList( 675 void SQLiteChannelIDStore::DeleteAllInList(
682 const std::list<std::string>& server_identifiers) { 676 const std::list<std::string>& server_identifiers) {
683 backend_->DeleteAllInList(server_identifiers); 677 backend_->DeleteAllInList(server_identifiers);
684 } 678 }
685 679
686 void SQLiteChannelIDStore::SetForceKeepSessionState() { 680 void SQLiteChannelIDStore::SetForceKeepSessionState() {
687 backend_->SetForceKeepSessionState(); 681 backend_->SetForceKeepSessionState();
688 } 682 }
689 683
684 void SQLiteChannelIDStore::Flush() {
685 backend_->Commit();
686 }
687
690 SQLiteChannelIDStore::~SQLiteChannelIDStore() { 688 SQLiteChannelIDStore::~SQLiteChannelIDStore() {
691 backend_->Close(); 689 backend_->Close();
692 // We release our reference to the Backend, though it will probably still have 690 // We release our reference to the Backend, though it will probably still have
693 // a reference if the background task runner has not run Close() yet. 691 // a reference if the background task runner has not run Close() yet.
694 } 692 }
695 693
696 } // namespace net 694 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698