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 "net/extras/sqlite/sqlite_persistent_cookie_store.h" | 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 // Loads cookies for the domain key (eTLD+1) on background runner. | 174 // Loads cookies for the domain key (eTLD+1) on background runner. |
| 175 void LoadKeyAndNotifyInBackground(const std::string& domains, | 175 void LoadKeyAndNotifyInBackground(const std::string& domains, |
| 176 const LoadedCallback& loaded_callback, | 176 const LoadedCallback& loaded_callback, |
| 177 const base::Time& posted_at); | 177 const base::Time& posted_at); |
| 178 | 178 |
| 179 // Notifies the CookieMonster when loading completes for a specific domain key | 179 // Notifies the CookieMonster when loading completes for a specific domain key |
| 180 // or for all domain keys. Triggers the callback and passes it all cookies | 180 // or for all domain keys. Triggers the callback and passes it all cookies |
| 181 // that have been loaded from DB since last IO notification. | 181 // that have been loaded from DB since last IO notification. |
| 182 void Notify(const LoadedCallback& loaded_callback, bool load_success); | 182 void Notify(const LoadedCallback& loaded_callback, bool load_success); |
| 183 | 183 |
| 184 // Flushes (Commits) pending operations on the background runner, and invokes | |
| 185 // |callback| on the client thread when done. | |
| 186 void FlushAndNotifyInBackground(const base::Closure& callback); | |
| 187 | |
| 184 // Sends notification when the entire store is loaded, and reports metrics | 188 // Sends notification when the entire store is loaded, and reports metrics |
| 185 // for the total time to load and aggregated results from any priority loads | 189 // for the total time to load and aggregated results from any priority loads |
| 186 // that occurred. | 190 // that occurred. |
| 187 void CompleteLoadInForeground(const LoadedCallback& loaded_callback, | 191 void CompleteLoadInForeground(const LoadedCallback& loaded_callback, |
| 188 bool load_success); | 192 bool load_success); |
| 189 | 193 |
| 190 // Sends notification when a single priority load completes. Updates priority | 194 // Sends notification when a single priority load completes. Updates priority |
| 191 // load metric data. The data is sent only after the final load completes. | 195 // load metric data. The data is sent only after the final load completes. |
| 192 void CompleteLoadForKeyInForeground(const LoadedCallback& loaded_callback, | 196 void CompleteLoadForKeyInForeground(const LoadedCallback& loaded_callback, |
| 193 bool load_success, | 197 bool load_success, |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 } | 505 } |
| 502 } | 506 } |
| 503 | 507 |
| 504 PostClientTask( | 508 PostClientTask( |
| 505 FROM_HERE, | 509 FROM_HERE, |
| 506 base::Bind( | 510 base::Bind( |
| 507 &SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground, | 511 &SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground, |
| 508 this, loaded_callback, success, posted_at)); | 512 this, loaded_callback, success, posted_at)); |
| 509 } | 513 } |
| 510 | 514 |
| 515 void SQLitePersistentCookieStore::Backend::FlushAndNotifyInBackground( | |
| 516 const base::Closure& callback) { | |
|
Mike West
2016/03/01 13:59:28
Combining these makes good sense, thank you.
| |
| 517 Commit(); | |
| 518 if (!callback.is_null()) | |
| 519 PostClientTask(FROM_HERE, callback); | |
| 520 } | |
| 521 | |
| 511 void SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground( | 522 void SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground( |
| 512 const LoadedCallback& loaded_callback, | 523 const LoadedCallback& loaded_callback, |
| 513 bool load_success, | 524 bool load_success, |
| 514 const ::Time& requested_at) { | 525 const ::Time& requested_at) { |
| 515 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); | 526 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); |
| 516 | 527 |
| 517 UMA_HISTOGRAM_CUSTOM_TIMES("Cookie.TimeKeyLoadTotalWait", | 528 UMA_HISTOGRAM_CUSTOM_TIMES("Cookie.TimeKeyLoadTotalWait", |
| 518 base::Time::Now() - requested_at, | 529 base::Time::Now() - requested_at, |
| 519 base::TimeDelta::FromMilliseconds(1), | 530 base::TimeDelta::FromMilliseconds(1), |
| 520 base::TimeDelta::FromMinutes(1), 50); | 531 base::TimeDelta::FromMinutes(1), 50); |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 } | 1163 } |
| 1153 } | 1164 } |
| 1154 bool succeeded = transaction.Commit(); | 1165 bool succeeded = transaction.Commit(); |
| 1155 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults", | 1166 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults", |
| 1156 succeeded ? 0 : 1, 2); | 1167 succeeded ? 0 : 1, 2); |
| 1157 } | 1168 } |
| 1158 | 1169 |
| 1159 void SQLitePersistentCookieStore::Backend::Flush( | 1170 void SQLitePersistentCookieStore::Backend::Flush( |
| 1160 const base::Closure& callback) { | 1171 const base::Closure& callback) { |
| 1161 DCHECK(!background_task_runner_->RunsTasksOnCurrentThread()); | 1172 DCHECK(!background_task_runner_->RunsTasksOnCurrentThread()); |
| 1162 PostBackgroundTask(FROM_HERE, base::Bind(&Backend::Commit, this)); | 1173 PostBackgroundTask(FROM_HERE, base::Bind(&Backend::FlushAndNotifyInBackground, |
| 1163 | 1174 this, callback)); |
| 1164 if (!callback.is_null()) { | |
| 1165 // We want the completion task to run immediately after Commit() returns. | |
| 1166 // Posting it from here means there is less chance of another task getting | |
| 1167 // onto the message queue first, than if we posted it from Commit() itself. | |
| 1168 PostBackgroundTask(FROM_HERE, callback); | |
| 1169 } | |
| 1170 } | 1175 } |
| 1171 | 1176 |
| 1172 // Fire off a close message to the background runner. We could still have a | 1177 // Fire off a close message to the background runner. We could still have a |
| 1173 // pending commit timer or Load operations holding references on us, but if/when | 1178 // pending commit timer or Load operations holding references on us, but if/when |
| 1174 // this fires we will already have been cleaned up and it will be ignored. | 1179 // this fires we will already have been cleaned up and it will be ignored. |
| 1175 void SQLitePersistentCookieStore::Backend::Close( | 1180 void SQLitePersistentCookieStore::Backend::Close( |
| 1176 const base::Closure& callback) { | 1181 const base::Closure& callback) { |
| 1177 if (background_task_runner_->RunsTasksOnCurrentThread()) { | 1182 if (background_task_runner_->RunsTasksOnCurrentThread()) { |
| 1178 InternalBackgroundClose(callback); | 1183 InternalBackgroundClose(callback); |
| 1179 } else { | 1184 } else { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1350 backend_->Close(callback); | 1355 backend_->Close(callback); |
| 1351 | 1356 |
| 1352 // We release our reference to the Backend, though it will probably still | 1357 // We release our reference to the Backend, though it will probably still |
| 1353 // have a reference if the background runner has not run | 1358 // have a reference if the background runner has not run |
| 1354 // Backend::InternalBackgroundClose() yet. | 1359 // Backend::InternalBackgroundClose() yet. |
| 1355 backend_ = nullptr; | 1360 backend_ = nullptr; |
| 1356 } | 1361 } |
| 1357 } | 1362 } |
| 1358 | 1363 |
| 1359 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { | 1364 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
| 1365 DCHECK(!loaded_callback.is_null()); | |
| 1360 if (backend_) | 1366 if (backend_) |
| 1361 backend_->Load(loaded_callback); | 1367 backend_->Load(loaded_callback); |
| 1362 else | 1368 else |
| 1363 loaded_callback.Run(std::vector<CanonicalCookie*>()); | 1369 loaded_callback.Run(std::vector<CanonicalCookie*>()); |
| 1364 } | 1370 } |
| 1365 | 1371 |
| 1366 void SQLitePersistentCookieStore::LoadCookiesForKey( | 1372 void SQLitePersistentCookieStore::LoadCookiesForKey( |
| 1367 const std::string& key, | 1373 const std::string& key, |
| 1368 const LoadedCallback& loaded_callback) { | 1374 const LoadedCallback& loaded_callback) { |
| 1375 DCHECK(!loaded_callback.is_null()); | |
| 1369 if (backend_) | 1376 if (backend_) |
| 1370 backend_->LoadCookiesForKey(key, loaded_callback); | 1377 backend_->LoadCookiesForKey(key, loaded_callback); |
| 1371 else | 1378 else |
| 1372 loaded_callback.Run(std::vector<CanonicalCookie*>()); | 1379 loaded_callback.Run(std::vector<CanonicalCookie*>()); |
| 1373 } | 1380 } |
| 1374 | 1381 |
| 1375 void SQLitePersistentCookieStore::AddCookie(const CanonicalCookie& cc) { | 1382 void SQLitePersistentCookieStore::AddCookie(const CanonicalCookie& cc) { |
| 1376 if (backend_) | 1383 if (backend_) |
| 1377 backend_->AddCookie(cc); | 1384 backend_->AddCookie(cc); |
| 1378 } | 1385 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1395 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 1402 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
| 1396 if (backend_) | 1403 if (backend_) |
| 1397 backend_->Flush(callback); | 1404 backend_->Flush(callback); |
| 1398 } | 1405 } |
| 1399 | 1406 |
| 1400 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 1407 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
| 1401 Close(base::Closure()); | 1408 Close(base::Closure()); |
| 1402 } | 1409 } |
| 1403 | 1410 |
| 1404 } // namespace net | 1411 } // namespace net |
| OLD | NEW |