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

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

Issue 2937963003: Shift cookie system callbacks to OnceCallback to impedance match mojo. (Closed)
Patch Set: Finish Merge Created 3 years, 6 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 (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 "net/extras/sqlite/sqlite_persistent_cookie_store.h" 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Batch a cookie addition. 117 // Batch a cookie addition.
118 void AddCookie(const CanonicalCookie& cc); 118 void AddCookie(const CanonicalCookie& cc);
119 119
120 // Batch a cookie access time update. 120 // Batch a cookie access time update.
121 void UpdateCookieAccessTime(const CanonicalCookie& cc); 121 void UpdateCookieAccessTime(const CanonicalCookie& cc);
122 122
123 // Batch a cookie deletion. 123 // Batch a cookie deletion.
124 void DeleteCookie(const CanonicalCookie& cc); 124 void DeleteCookie(const CanonicalCookie& cc);
125 125
126 // Commit pending operations as soon as possible. 126 // Commit pending operations as soon as possible.
127 void Flush(const base::Closure& callback); 127 void Flush(base::OnceClosure callback);
128 128
129 // Commit any pending operations and close the database. This must be called 129 // Commit any pending operations and close the database. This must be called
130 // before the object is destructed. 130 // before the object is destructed.
131 void Close(const base::Closure& callback); 131 void Close(const base::Closure& callback);
132 132
133 // Post background delete of all cookies that match |cookies|. 133 // Post background delete of all cookies that match |cookies|.
134 void DeleteAllInList(const std::list<CookieOrigin>& cookies); 134 void DeleteAllInList(const std::list<CookieOrigin>& cookies);
135 135
136 private: 136 private:
137 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; 137 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 const LoadedCallback& loaded_callback, 175 const LoadedCallback& loaded_callback,
176 const base::Time& posted_at); 176 const base::Time& posted_at);
177 177
178 // Notifies the CookieMonster when loading completes for a specific domain key 178 // Notifies the CookieMonster when loading completes for a specific domain key
179 // or for all domain keys. Triggers the callback and passes it all cookies 179 // or for all domain keys. Triggers the callback and passes it all cookies
180 // that have been loaded from DB since last IO notification. 180 // that have been loaded from DB since last IO notification.
181 void Notify(const LoadedCallback& loaded_callback, bool load_success); 181 void Notify(const LoadedCallback& loaded_callback, bool load_success);
182 182
183 // Flushes (Commits) pending operations on the background runner, and invokes 183 // Flushes (Commits) pending operations on the background runner, and invokes
184 // |callback| on the client thread when done. 184 // |callback| on the client thread when done.
185 void FlushAndNotifyInBackground(const base::Closure& callback); 185 void FlushAndNotifyInBackground(base::OnceClosure callback);
186 186
187 // Sends notification when the entire store is loaded, and reports metrics 187 // Sends notification when the entire store is loaded, and reports metrics
188 // for the total time to load and aggregated results from any priority loads 188 // for the total time to load and aggregated results from any priority loads
189 // that occurred. 189 // that occurred.
190 void CompleteLoadInForeground(const LoadedCallback& loaded_callback, 190 void CompleteLoadInForeground(const LoadedCallback& loaded_callback,
191 bool load_success); 191 bool load_success);
192 192
193 // Sends notification when a single priority load completes. Updates priority 193 // Sends notification when a single priority load completes. Updates priority
194 // load metric data. The data is sent only after the final load completes. 194 // load metric data. The data is sent only after the final load completes.
195 void CompleteLoadForKeyInForeground(const LoadedCallback& loaded_callback, 195 void CompleteLoadForKeyInForeground(const LoadedCallback& loaded_callback,
(...skipping 28 matching lines...) Expand all
224 void InternalBackgroundClose(const base::Closure& callback); 224 void InternalBackgroundClose(const base::Closure& callback);
225 225
226 void DeleteSessionCookiesOnStartup(); 226 void DeleteSessionCookiesOnStartup();
227 227
228 void BackgroundDeleteAllInList(const std::list<CookieOrigin>& cookies); 228 void BackgroundDeleteAllInList(const std::list<CookieOrigin>& cookies);
229 229
230 void DatabaseErrorCallback(int error, sql::Statement* stmt); 230 void DatabaseErrorCallback(int error, sql::Statement* stmt);
231 void KillDatabase(); 231 void KillDatabase();
232 232
233 void PostBackgroundTask(const tracked_objects::Location& origin, 233 void PostBackgroundTask(const tracked_objects::Location& origin,
234 const base::Closure& task); 234 base::OnceClosure task);
235 void PostClientTask(const tracked_objects::Location& origin, 235 void PostClientTask(const tracked_objects::Location& origin,
236 const base::Closure& task); 236 base::OnceClosure task);
237 237
238 // Shared code between the different load strategies to be used after all 238 // Shared code between the different load strategies to be used after all
239 // cookies have been loaded. 239 // cookies have been loaded.
240 void FinishedLoadingCookies(const LoadedCallback& loaded_callback, 240 void FinishedLoadingCookies(const LoadedCallback& loaded_callback,
241 bool success); 241 bool success);
242 242
243 const base::FilePath path_; 243 const base::FilePath path_;
244 std::unique_ptr<sql::Connection> db_; 244 std::unique_ptr<sql::Connection> db_;
245 sql::MetaTable meta_table_; 245 sql::MetaTable meta_table_;
246 246
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 539 }
540 540
541 PostClientTask( 541 PostClientTask(
542 FROM_HERE, 542 FROM_HERE,
543 base::Bind( 543 base::Bind(
544 &SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground, 544 &SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground,
545 this, loaded_callback, success, posted_at)); 545 this, loaded_callback, success, posted_at));
546 } 546 }
547 547
548 void SQLitePersistentCookieStore::Backend::FlushAndNotifyInBackground( 548 void SQLitePersistentCookieStore::Backend::FlushAndNotifyInBackground(
549 const base::Closure& callback) { 549 base::OnceClosure callback) {
550 Commit(); 550 Commit();
551 if (!callback.is_null()) 551 if (!callback.is_null())
552 PostClientTask(FROM_HERE, callback); 552 PostClientTask(FROM_HERE, std::move(callback));
553 } 553 }
554 554
555 void SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground( 555 void SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground(
556 const LoadedCallback& loaded_callback, 556 const LoadedCallback& loaded_callback,
557 bool load_success, 557 bool load_success,
558 const ::Time& requested_at) { 558 const ::Time& requested_at) {
559 DCHECK(client_task_runner_->RunsTasksInCurrentSequence()); 559 DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
560 560
561 UMA_HISTOGRAM_CUSTOM_TIMES("Cookie.TimeKeyLoadTotalWait", 561 UMA_HISTOGRAM_CUSTOM_TIMES("Cookie.TimeKeyLoadTotalWait",
562 base::Time::Now() - requested_at, 562 base::Time::Now() - requested_at,
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 default: 1194 default:
1195 NOTREACHED(); 1195 NOTREACHED();
1196 break; 1196 break;
1197 } 1197 }
1198 } 1198 }
1199 bool succeeded = transaction.Commit(); 1199 bool succeeded = transaction.Commit();
1200 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults", 1200 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults",
1201 succeeded ? 0 : 1, 2); 1201 succeeded ? 0 : 1, 2);
1202 } 1202 }
1203 1203
1204 void SQLitePersistentCookieStore::Backend::Flush( 1204 void SQLitePersistentCookieStore::Backend::Flush(base::OnceClosure callback) {
1205 const base::Closure& callback) {
1206 DCHECK(!background_task_runner_->RunsTasksInCurrentSequence()); 1205 DCHECK(!background_task_runner_->RunsTasksInCurrentSequence());
1207 PostBackgroundTask(FROM_HERE, base::Bind(&Backend::FlushAndNotifyInBackground, 1206 PostBackgroundTask(FROM_HERE,
1208 this, callback)); 1207 base::BindOnce(&Backend::FlushAndNotifyInBackground, this,
1208 std::move(callback)));
1209 } 1209 }
1210 1210
1211 // Fire off a close message to the background runner. We could still have a 1211 // Fire off a close message to the background runner. We could still have a
1212 // pending commit timer or Load operations holding references on us, but if/when 1212 // pending commit timer or Load operations holding references on us, but if/when
1213 // this fires we will already have been cleaned up and it will be ignored. 1213 // this fires we will already have been cleaned up and it will be ignored.
1214 void SQLitePersistentCookieStore::Backend::Close( 1214 void SQLitePersistentCookieStore::Backend::Close(
1215 const base::Closure& callback) { 1215 const base::Closure& callback) {
1216 if (background_task_runner_->RunsTasksInCurrentSequence()) { 1216 if (background_task_runner_->RunsTasksInCurrentSequence()) {
1217 InternalBackgroundClose(callback); 1217 InternalBackgroundClose(callback);
1218 } else { 1218 } else {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 if (!del_smt.Run()) 1335 if (!del_smt.Run())
1336 NOTREACHED() << "Could not delete a cookie from the DB."; 1336 NOTREACHED() << "Could not delete a cookie from the DB.";
1337 } 1337 }
1338 1338
1339 if (!transaction.Commit()) 1339 if (!transaction.Commit())
1340 LOG(WARNING) << "Unable to delete cookies on shutdown."; 1340 LOG(WARNING) << "Unable to delete cookies on shutdown.";
1341 } 1341 }
1342 1342
1343 void SQLitePersistentCookieStore::Backend::PostBackgroundTask( 1343 void SQLitePersistentCookieStore::Backend::PostBackgroundTask(
1344 const tracked_objects::Location& origin, 1344 const tracked_objects::Location& origin,
1345 const base::Closure& task) { 1345 base::OnceClosure task) {
1346 if (!background_task_runner_->PostTask(origin, task)) { 1346 if (!background_task_runner_->PostTask(origin, std::move(task))) {
1347 LOG(WARNING) << "Failed to post task from " << origin.ToString() 1347 LOG(WARNING) << "Failed to post task from " << origin.ToString()
1348 << " to background_task_runner_."; 1348 << " to background_task_runner_.";
1349 } 1349 }
1350 } 1350 }
1351 1351
1352 void SQLitePersistentCookieStore::Backend::PostClientTask( 1352 void SQLitePersistentCookieStore::Backend::PostClientTask(
1353 const tracked_objects::Location& origin, 1353 const tracked_objects::Location& origin,
1354 const base::Closure& task) { 1354 base::OnceClosure task) {
1355 if (!client_task_runner_->PostTask(origin, task)) { 1355 if (!client_task_runner_->PostTask(origin, std::move(task))) {
1356 LOG(WARNING) << "Failed to post task from " << origin.ToString() 1356 LOG(WARNING) << "Failed to post task from " << origin.ToString()
1357 << " to client_task_runner_."; 1357 << " to client_task_runner_.";
1358 } 1358 }
1359 } 1359 }
1360 1360
1361 void SQLitePersistentCookieStore::Backend::FinishedLoadingCookies( 1361 void SQLitePersistentCookieStore::Backend::FinishedLoadingCookies(
1362 const LoadedCallback& loaded_callback, 1362 const LoadedCallback& loaded_callback,
1363 bool success) { 1363 bool success) {
1364 PostClientTask(FROM_HERE, base::Bind(&Backend::CompleteLoadInForeground, this, 1364 PostClientTask(FROM_HERE, base::Bind(&Backend::CompleteLoadInForeground, this,
1365 loaded_callback, success)); 1365 loaded_callback, success));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 1426
1427 void SQLitePersistentCookieStore::DeleteCookie(const CanonicalCookie& cc) { 1427 void SQLitePersistentCookieStore::DeleteCookie(const CanonicalCookie& cc) {
1428 if (backend_) 1428 if (backend_)
1429 backend_->DeleteCookie(cc); 1429 backend_->DeleteCookie(cc);
1430 } 1430 }
1431 1431
1432 void SQLitePersistentCookieStore::SetForceKeepSessionState() { 1432 void SQLitePersistentCookieStore::SetForceKeepSessionState() {
1433 // This store never discards session-only cookies, so this call has no effect. 1433 // This store never discards session-only cookies, so this call has no effect.
1434 } 1434 }
1435 1435
1436 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { 1436 void SQLitePersistentCookieStore::Flush(base::OnceClosure callback) {
1437 if (backend_) 1437 if (backend_)
1438 backend_->Flush(callback); 1438 backend_->Flush(std::move(callback));
1439 } 1439 }
1440 1440
1441 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 1441 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
1442 Close(base::Closure()); 1442 Close(base::Closure());
1443 } 1443 }
1444 1444
1445 } // namespace net 1445 } // namespace net
OLDNEW
« net/cookies/cookie_monster.cc ('K') | « net/extras/sqlite/sqlite_persistent_cookie_store.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698