Index: net/extras/sqlite/sqlite_persistent_cookie_store.cc |
diff --git a/net/extras/sqlite/sqlite_persistent_cookie_store.cc b/net/extras/sqlite/sqlite_persistent_cookie_store.cc |
index b7254a42620155cf18ac907e2a00c2669b770323..1145871df41655f40c736cc88f303a3ffdd10a87 100644 |
--- a/net/extras/sqlite/sqlite_persistent_cookie_store.cc |
+++ b/net/extras/sqlite/sqlite_persistent_cookie_store.cc |
@@ -181,6 +181,10 @@ class SQLitePersistentCookieStore::Backend |
// that have been loaded from DB since last IO notification. |
void Notify(const LoadedCallback& loaded_callback, bool load_success); |
+ // Flushes (Commits) pending operations on the background runner, and invokes |
+ // |callback| on the client thread when done. |
+ void FlushAndNotifyInBackground(const base::Closure& callback); |
+ |
// Sends notification when the entire store is loaded, and reports metrics |
// for the total time to load and aggregated results from any priority loads |
// that occurred. |
@@ -508,6 +512,13 @@ void SQLitePersistentCookieStore::Backend::LoadKeyAndNotifyInBackground( |
this, loaded_callback, success, posted_at)); |
} |
+void SQLitePersistentCookieStore::Backend::FlushAndNotifyInBackground( |
+ const base::Closure& callback) { |
Mike West
2016/03/01 13:59:28
Combining these makes good sense, thank you.
|
+ Commit(); |
+ if (!callback.is_null()) |
+ PostClientTask(FROM_HERE, callback); |
+} |
+ |
void SQLitePersistentCookieStore::Backend::CompleteLoadForKeyInForeground( |
const LoadedCallback& loaded_callback, |
bool load_success, |
@@ -1159,14 +1170,8 @@ void SQLitePersistentCookieStore::Backend::Commit() { |
void SQLitePersistentCookieStore::Backend::Flush( |
const base::Closure& callback) { |
DCHECK(!background_task_runner_->RunsTasksOnCurrentThread()); |
- PostBackgroundTask(FROM_HERE, base::Bind(&Backend::Commit, this)); |
- |
- if (!callback.is_null()) { |
- // We want the completion task to run immediately after Commit() returns. |
- // Posting it from here means there is less chance of another task getting |
- // onto the message queue first, than if we posted it from Commit() itself. |
- PostBackgroundTask(FROM_HERE, callback); |
- } |
+ PostBackgroundTask(FROM_HERE, base::Bind(&Backend::FlushAndNotifyInBackground, |
+ this, callback)); |
} |
// Fire off a close message to the background runner. We could still have a |
@@ -1357,6 +1362,7 @@ void SQLitePersistentCookieStore::Close(const base::Closure& callback) { |
} |
void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
+ DCHECK(!loaded_callback.is_null()); |
if (backend_) |
backend_->Load(loaded_callback); |
else |
@@ -1366,6 +1372,7 @@ void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
void SQLitePersistentCookieStore::LoadCookiesForKey( |
const std::string& key, |
const LoadedCallback& loaded_callback) { |
+ DCHECK(!loaded_callback.is_null()); |
if (backend_) |
backend_->LoadCookiesForKey(key, loaded_callback); |
else |