| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 void UpdateCookieAccessTime(const CanonicalCookie& cc); | 122 void UpdateCookieAccessTime(const CanonicalCookie& cc); |
| 123 | 123 |
| 124 // Batch a cookie deletion. | 124 // Batch a cookie deletion. |
| 125 void DeleteCookie(const CanonicalCookie& cc); | 125 void DeleteCookie(const CanonicalCookie& cc); |
| 126 | 126 |
| 127 // Commit pending operations as soon as possible. | 127 // Commit pending operations as soon as possible. |
| 128 void Flush(const base::Closure& callback); | 128 void Flush(const base::Closure& callback); |
| 129 | 129 |
| 130 // Commit any pending operations and close the database. This must be called | 130 // Commit any pending operations and close the database. This must be called |
| 131 // before the object is destructed. | 131 // before the object is destructed. |
| 132 void Close(); | 132 void Close(const base::Closure& callback); |
| 133 | 133 |
| 134 // Post background delete of all cookies that match |cookies|. | 134 // Post background delete of all cookies that match |cookies|. |
| 135 void DeleteAllInList(const std::list<CookieOrigin>& cookies); | 135 void DeleteAllInList(const std::list<CookieOrigin>& cookies); |
| 136 | 136 |
| 137 private: | 137 private: |
| 138 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; | 138 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; |
| 139 | 139 |
| 140 // You should call Close() before destructing this object. | 140 // You should call Close() before destructing this object. |
| 141 ~Backend() { | 141 ~Backend() { |
| 142 DCHECK(!db_.get()) << "Close should have already been called."; | 142 DCHECK(!db_.get()) << "Close should have already been called."; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 // Load all cookies for a set of domains/hosts | 216 // Load all cookies for a set of domains/hosts |
| 217 bool LoadCookiesForDomains(const std::set<std::string>& key); | 217 bool LoadCookiesForDomains(const std::set<std::string>& key); |
| 218 | 218 |
| 219 // Batch a cookie operation (add or delete) | 219 // Batch a cookie operation (add or delete) |
| 220 void BatchOperation(PendingOperation::OperationType op, | 220 void BatchOperation(PendingOperation::OperationType op, |
| 221 const CanonicalCookie& cc); | 221 const CanonicalCookie& cc); |
| 222 // Commit our pending operations to the database. | 222 // Commit our pending operations to the database. |
| 223 void Commit(); | 223 void Commit(); |
| 224 // Close() executed on the background runner. | 224 // Close() executed on the background runner. |
| 225 void InternalBackgroundClose(); | 225 void InternalBackgroundClose(const base::Closure& callback); |
| 226 | 226 |
| 227 void DeleteSessionCookiesOnStartup(); | 227 void DeleteSessionCookiesOnStartup(); |
| 228 | 228 |
| 229 void DeleteSessionCookiesOnShutdown(); | 229 void DeleteSessionCookiesOnShutdown(); |
| 230 | 230 |
| 231 void BackgroundDeleteAllInList(const std::list<CookieOrigin>& cookies); | 231 void BackgroundDeleteAllInList(const std::list<CookieOrigin>& cookies); |
| 232 | 232 |
| 233 void DatabaseErrorCallback(int error, sql::Statement* stmt); | 233 void DatabaseErrorCallback(int error, sql::Statement* stmt); |
| 234 void KillDatabase(); | 234 void KillDatabase(); |
| 235 | 235 |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 // We want the completion task to run immediately after Commit() returns. | 1171 // We want the completion task to run immediately after Commit() returns. |
| 1172 // Posting it from here means there is less chance of another task getting | 1172 // Posting it from here means there is less chance of another task getting |
| 1173 // onto the message queue first, than if we posted it from Commit() itself. | 1173 // onto the message queue first, than if we posted it from Commit() itself. |
| 1174 PostBackgroundTask(FROM_HERE, callback); | 1174 PostBackgroundTask(FROM_HERE, callback); |
| 1175 } | 1175 } |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 // Fire off a close message to the background runner. We could still have a | 1178 // Fire off a close message to the background runner. We could still have a |
| 1179 // pending commit timer or Load operations holding references on us, but if/when | 1179 // pending commit timer or Load operations holding references on us, but if/when |
| 1180 // this fires we will already have been cleaned up and it will be ignored. | 1180 // this fires we will already have been cleaned up and it will be ignored. |
| 1181 void SQLitePersistentCookieStore::Backend::Close() { | 1181 void SQLitePersistentCookieStore::Backend::Close( |
| 1182 const base::Closure& callback) { |
| 1182 if (background_task_runner_->RunsTasksOnCurrentThread()) { | 1183 if (background_task_runner_->RunsTasksOnCurrentThread()) { |
| 1183 InternalBackgroundClose(); | 1184 InternalBackgroundClose(callback); |
| 1184 } else { | 1185 } else { |
| 1185 // Must close the backend on the background runner. | 1186 // Must close the backend on the background runner. |
| 1186 PostBackgroundTask(FROM_HERE, | 1187 PostBackgroundTask(FROM_HERE, base::Bind(&Backend::InternalBackgroundClose, |
| 1187 base::Bind(&Backend::InternalBackgroundClose, this)); | 1188 this, callback)); |
| 1188 } | 1189 } |
| 1189 } | 1190 } |
| 1190 | 1191 |
| 1191 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() { | 1192 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose( |
| 1193 const base::Closure& callback) { |
| 1192 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 1194 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
| 1193 | 1195 |
| 1194 if (delete_session_cookies_at_shutdown_) | 1196 if (delete_session_cookies_at_shutdown_) |
| 1195 DeleteSessionCookiesOnShutdown(); | 1197 DeleteSessionCookiesOnShutdown(); |
| 1196 | 1198 |
| 1197 // Commit any pending operations | 1199 // Commit any pending operations |
| 1198 Commit(); | 1200 Commit(); |
| 1199 | 1201 |
| 1200 meta_table_.Reset(); | 1202 meta_table_.Reset(); |
| 1201 db_.reset(); | 1203 db_.reset(); |
| 1204 |
| 1205 // We're clean now. |
| 1206 if (!callback.is_null()) |
| 1207 callback.Run(); |
| 1202 } | 1208 } |
| 1203 | 1209 |
| 1204 void SQLitePersistentCookieStore::Backend::DatabaseErrorCallback( | 1210 void SQLitePersistentCookieStore::Backend::DatabaseErrorCallback( |
| 1205 int error, | 1211 int error, |
| 1206 sql::Statement* stmt) { | 1212 sql::Statement* stmt) { |
| 1207 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 1213 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
| 1208 | 1214 |
| 1209 if (!sql::IsErrorCatastrophic(error)) | 1215 if (!sql::IsErrorCatastrophic(error)) |
| 1210 return; | 1216 return; |
| 1211 | 1217 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 background_task_runner, | 1363 background_task_runner, |
| 1358 restore_old_session_cookies, | 1364 restore_old_session_cookies, |
| 1359 crypto_delegate)) { | 1365 crypto_delegate)) { |
| 1360 } | 1366 } |
| 1361 | 1367 |
| 1362 void SQLitePersistentCookieStore::DeleteAllInList( | 1368 void SQLitePersistentCookieStore::DeleteAllInList( |
| 1363 const std::list<CookieOrigin>& cookies) { | 1369 const std::list<CookieOrigin>& cookies) { |
| 1364 backend_->DeleteAllInList(cookies); | 1370 backend_->DeleteAllInList(cookies); |
| 1365 } | 1371 } |
| 1366 | 1372 |
| 1373 void SQLitePersistentCookieStore::Close(const base::Closure& callback) { |
| 1374 backend_->Close(callback); |
| 1375 } |
| 1376 |
| 1367 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { | 1377 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
| 1368 backend_->Load(loaded_callback); | 1378 backend_->Load(loaded_callback); |
| 1369 } | 1379 } |
| 1370 | 1380 |
| 1371 void SQLitePersistentCookieStore::LoadCookiesForKey( | 1381 void SQLitePersistentCookieStore::LoadCookiesForKey( |
| 1372 const std::string& key, | 1382 const std::string& key, |
| 1373 const LoadedCallback& loaded_callback) { | 1383 const LoadedCallback& loaded_callback) { |
| 1374 backend_->LoadCookiesForKey(key, loaded_callback); | 1384 backend_->LoadCookiesForKey(key, loaded_callback); |
| 1375 } | 1385 } |
| 1376 | 1386 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1389 | 1399 |
| 1390 void SQLitePersistentCookieStore::SetForceKeepSessionState() { | 1400 void SQLitePersistentCookieStore::SetForceKeepSessionState() { |
| 1391 // This store never discards session-only cookies, so this call has no effect. | 1401 // This store never discards session-only cookies, so this call has no effect. |
| 1392 } | 1402 } |
| 1393 | 1403 |
| 1394 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 1404 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
| 1395 backend_->Flush(callback); | 1405 backend_->Flush(callback); |
| 1396 } | 1406 } |
| 1397 | 1407 |
| 1398 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 1408 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
| 1399 backend_->Close(); | 1409 backend_->Close(base::Closure()); |
| 1400 // We release our reference to the Backend, though it will probably still have | 1410 // We release our reference to the Backend, though it will probably still have |
| 1401 // a reference if the background runner has not run Close() yet. | 1411 // a reference if the background runner has not run Close() yet. |
| 1402 } | 1412 } |
| 1403 | 1413 |
| 1404 } // namespace net | 1414 } // namespace net |
| OLD | NEW |