OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/net/cookie_monster_sqlite.h" | 5 #include "chrome/common/net/cookie_monster_sqlite.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 296 } |
297 | 297 |
298 // Try to create the index every time. Older versions did not have this index, | 298 // Try to create the index every time. Older versions did not have this index, |
299 // so we want those people to get it. Ignore errors, since it may exist. | 299 // so we want those people to get it. Ignore errors, since it may exist. |
300 sqlite3_exec(db, "CREATE INDEX cookie_times ON cookies (creation_utc)", | 300 sqlite3_exec(db, "CREATE INDEX cookie_times ON cookies (creation_utc)", |
301 NULL, NULL, NULL); | 301 NULL, NULL, NULL); |
302 | 302 |
303 return true; | 303 return true; |
304 } | 304 } |
305 | 305 |
306 void PrimeCache(sqlite3* db) { | |
307 // A statement must be open for the preload command to work. If the meta | |
308 // table can't be read, it probably means this is a new database and there | |
309 // is nothing to preload (so it's OK we do nothing). | |
310 SQLStatement dummy; | |
311 if (dummy.prepare(db, "SELECT * from meta") != SQLITE_OK) | |
312 return; | |
313 if (dummy.step() != SQLITE_ROW) | |
314 return; | |
315 | |
316 sqlite3Preload(db); | |
317 } | |
318 | |
319 } // namespace | 306 } // namespace |
320 | 307 |
321 bool SQLitePersistentCookieStore::Load( | 308 bool SQLitePersistentCookieStore::Load( |
322 std::vector<net::CookieMonster::KeyedCanonicalCookie>* cookies) { | 309 std::vector<net::CookieMonster::KeyedCanonicalCookie>* cookies) { |
323 DCHECK(!path_.empty()); | 310 DCHECK(!path_.empty()); |
324 sqlite3* db; | 311 sqlite3* db; |
325 if (sqlite3_open(WideToUTF8(path_).c_str(), &db) != SQLITE_OK) { | 312 if (sqlite3_open(WideToUTF8(path_).c_str(), &db) != SQLITE_OK) { |
326 NOTREACHED() << "Unable to open cookie DB."; | 313 NOTREACHED() << "Unable to open cookie DB."; |
327 return false; | 314 return false; |
328 } | 315 } |
329 | 316 |
330 if (!EnsureDatabaseVersion(db) || !InitTable(db)) { | 317 if (!EnsureDatabaseVersion(db) || !InitTable(db)) { |
331 NOTREACHED() << "Unable to initialize cookie DB."; | 318 NOTREACHED() << "Unable to initialize cookie DB."; |
332 sqlite3_close(db); | 319 sqlite3_close(db); |
333 return false; | 320 return false; |
334 } | 321 } |
335 | 322 |
336 PrimeCache(db); | 323 MetaTableHelper::PrimeCache(std::string(), db); |
337 | 324 |
338 // Slurp all the cookies into the out-vector. | 325 // Slurp all the cookies into the out-vector. |
339 SQLStatement smt; | 326 SQLStatement smt; |
340 if (smt.prepare(db, | 327 if (smt.prepare(db, |
341 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " | 328 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " |
342 "httponly, last_access_utc FROM cookies") != SQLITE_OK) { | 329 "httponly, last_access_utc FROM cookies") != SQLITE_OK) { |
343 NOTREACHED() << "select statement prep failed"; | 330 NOTREACHED() << "select statement prep failed"; |
344 sqlite3_close(db); | 331 sqlite3_close(db); |
345 return false; | 332 return false; |
346 } | 333 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 const net::CookieMonster::CanonicalCookie& cc) { | 414 const net::CookieMonster::CanonicalCookie& cc) { |
428 if (backend_.get()) | 415 if (backend_.get()) |
429 backend_->UpdateCookieAccessTime(cc); | 416 backend_->UpdateCookieAccessTime(cc); |
430 } | 417 } |
431 | 418 |
432 void SQLitePersistentCookieStore::DeleteCookie( | 419 void SQLitePersistentCookieStore::DeleteCookie( |
433 const net::CookieMonster::CanonicalCookie& cc) { | 420 const net::CookieMonster::CanonicalCookie& cc) { |
434 if (backend_.get()) | 421 if (backend_.get()) |
435 backend_->DeleteCookie(cc); | 422 backend_->DeleteCookie(cc); |
436 } | 423 } |
OLD | NEW |