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

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

Issue 1231493002: mandoline filesystem: Save cookie data to the mojo:filesystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT Created 5 years, 5 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 <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
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
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
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 CookieCryptoDelegate* crypto_delegate) 1360 CookieCryptoDelegate* crypto_delegate)
1355 : backend_(new Backend(path, 1361 : backend_(new Backend(path,
1356 client_task_runner, 1362 client_task_runner,
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 if (backend_)
1371 backend_->DeleteAllInList(cookies);
1372 }
1373
1374 void SQLitePersistentCookieStore::Close(const base::Closure& callback) {
1375 if (backend_) {
1376 backend_->Close(callback);
1377
1378 // We release our reference to the Backend, though it will probably still
1379 // have a reference if the background runner has not run
1380 // Backend::InternalBackgroundClose() yet.
1381 backend_ = nullptr;
1382 }
1365 } 1383 }
1366 1384
1367 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { 1385 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
1368 backend_->Load(loaded_callback); 1386 if (backend_)
1387 backend_->Load(loaded_callback);
1388 else
1389 loaded_callback.Run(std::vector<CanonicalCookie*>());
1369 } 1390 }
1370 1391
1371 void SQLitePersistentCookieStore::LoadCookiesForKey( 1392 void SQLitePersistentCookieStore::LoadCookiesForKey(
1372 const std::string& key, 1393 const std::string& key,
1373 const LoadedCallback& loaded_callback) { 1394 const LoadedCallback& loaded_callback) {
1374 backend_->LoadCookiesForKey(key, loaded_callback); 1395 if (backend_)
1396 backend_->LoadCookiesForKey(key, loaded_callback);
1397 else
1398 loaded_callback.Run(std::vector<CanonicalCookie*>());
1375 } 1399 }
1376 1400
1377 void SQLitePersistentCookieStore::AddCookie(const CanonicalCookie& cc) { 1401 void SQLitePersistentCookieStore::AddCookie(const CanonicalCookie& cc) {
1378 backend_->AddCookie(cc); 1402 if (backend_)
1403 backend_->AddCookie(cc);
1379 } 1404 }
1380 1405
1381 void SQLitePersistentCookieStore::UpdateCookieAccessTime( 1406 void SQLitePersistentCookieStore::UpdateCookieAccessTime(
1382 const CanonicalCookie& cc) { 1407 const CanonicalCookie& cc) {
1383 backend_->UpdateCookieAccessTime(cc); 1408 if (backend_)
1409 backend_->UpdateCookieAccessTime(cc);
1384 } 1410 }
1385 1411
1386 void SQLitePersistentCookieStore::DeleteCookie(const CanonicalCookie& cc) { 1412 void SQLitePersistentCookieStore::DeleteCookie(const CanonicalCookie& cc) {
1387 backend_->DeleteCookie(cc); 1413 if (backend_)
1414 backend_->DeleteCookie(cc);
1388 } 1415 }
1389 1416
1390 void SQLitePersistentCookieStore::SetForceKeepSessionState() { 1417 void SQLitePersistentCookieStore::SetForceKeepSessionState() {
1391 // This store never discards session-only cookies, so this call has no effect. 1418 // This store never discards session-only cookies, so this call has no effect.
1392 } 1419 }
1393 1420
1394 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { 1421 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) {
1395 backend_->Flush(callback); 1422 if (backend_)
1423 backend_->Flush(callback);
1396 } 1424 }
1397 1425
1398 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 1426 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
1399 backend_->Close(); 1427 Close(base::Closure());
1400 // 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.
1402 } 1428 }
1403 1429
1404 } // namespace net 1430 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698