Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // CompleteLoadForKeyOnIOThread to the IO thread to notify the caller of | 51 // CompleteLoadForKeyOnIOThread to the IO thread to notify the caller of |
| 52 // SQLitePersistentCookieStore::LoadCookiesForKey that that load is complete. | 52 // SQLitePersistentCookieStore::LoadCookiesForKey that that load is complete. |
| 53 // | 53 // |
| 54 // Subsequent to loading, mutations may be queued by any thread using | 54 // Subsequent to loading, mutations may be queued by any thread using |
| 55 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to | 55 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to |
| 56 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), | 56 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), |
| 57 // whichever occurs first. | 57 // whichever occurs first. |
| 58 class SQLitePersistentCookieStore::Backend | 58 class SQLitePersistentCookieStore::Backend |
| 59 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { | 59 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { |
| 60 public: | 60 public: |
| 61 explicit Backend(const FilePath& path) | 61 Backend(const FilePath& path, bool restore_old_session_cookies) |
| 62 : path_(path), | 62 : path_(path), |
| 63 db_(NULL), | 63 db_(NULL), |
| 64 num_pending_(0), | 64 num_pending_(0), |
| 65 clear_local_state_on_exit_(false), | 65 clear_local_state_on_exit_(false), |
| 66 initialized_(false), | 66 initialized_(false), |
| 67 restore_old_session_cookies_(restore_old_session_cookies), | |
| 67 num_priority_waiting_(0), | 68 num_priority_waiting_(0), |
| 68 total_priority_requests_(0) { | 69 total_priority_requests_(0) { |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Creates or loads the SQLite database. | 72 // Creates or loads the SQLite database. |
| 72 void Load(const LoadedCallback& loaded_callback); | 73 void Load(const LoadedCallback& loaded_callback); |
| 73 | 74 |
| 74 // Loads cookies for the domain key (eTLD+1). | 75 // Loads cookies for the domain key (eTLD+1). |
| 75 void LoadCookiesForKey(const std::string& domain, | 76 void LoadCookiesForKey(const std::string& domain, |
| 76 const LoadedCallback& loaded_callback); | 77 const LoadedCallback& loaded_callback); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 bool LoadCookiesForDomains(const std::set<std::string>& key); | 170 bool LoadCookiesForDomains(const std::set<std::string>& key); |
| 170 | 171 |
| 171 // Batch a cookie operation (add or delete) | 172 // Batch a cookie operation (add or delete) |
| 172 void BatchOperation(PendingOperation::OperationType op, | 173 void BatchOperation(PendingOperation::OperationType op, |
| 173 const net::CookieMonster::CanonicalCookie& cc); | 174 const net::CookieMonster::CanonicalCookie& cc); |
| 174 // Commit our pending operations to the database. | 175 // Commit our pending operations to the database. |
| 175 void Commit(); | 176 void Commit(); |
| 176 // Close() executed on the background thread. | 177 // Close() executed on the background thread. |
| 177 void InternalBackgroundClose(); | 178 void InternalBackgroundClose(); |
| 178 | 179 |
| 180 void DeleteSessionCookiesOnDBThread(); | |
| 181 | |
| 179 FilePath path_; | 182 FilePath path_; |
| 180 scoped_ptr<sql::Connection> db_; | 183 scoped_ptr<sql::Connection> db_; |
| 181 sql::MetaTable meta_table_; | 184 sql::MetaTable meta_table_; |
| 182 | 185 |
| 183 typedef std::list<PendingOperation*> PendingOperationsList; | 186 typedef std::list<PendingOperation*> PendingOperationsList; |
| 184 PendingOperationsList pending_; | 187 PendingOperationsList pending_; |
| 185 PendingOperationsList::size_type num_pending_; | 188 PendingOperationsList::size_type num_pending_; |
| 186 // True if the persistent store should be deleted upon destruction. | 189 // True if the persistent store should be deleted upon destruction. |
| 187 bool clear_local_state_on_exit_; | 190 bool clear_local_state_on_exit_; |
| 188 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| | 191 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| |
| 189 base::Lock lock_; | 192 base::Lock lock_; |
| 190 | 193 |
| 191 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce | 194 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce |
| 192 // the number of messages sent to the IO thread. Sent back in response to | 195 // the number of messages sent to the IO thread. Sent back in response to |
| 193 // individual load requests for domain keys or when all loading completes. | 196 // individual load requests for domain keys or when all loading completes. |
| 194 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; | 197 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; |
| 195 | 198 |
| 196 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. | 199 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. |
| 197 std::map<std::string, std::set<std::string> > keys_to_load_; | 200 std::map<std::string, std::set<std::string> > keys_to_load_; |
| 198 | 201 |
| 199 // Indicates if DB has been initialized. | 202 // Indicates if DB has been initialized. |
| 200 bool initialized_; | 203 bool initialized_; |
| 201 | 204 |
| 205 // If false, we should filter out session cookies when reading the DB. | |
| 206 bool restore_old_session_cookies_; | |
| 207 | |
| 202 // The cumulative time spent loading the cookies on the DB thread. Incremented | 208 // The cumulative time spent loading the cookies on the DB thread. Incremented |
| 203 // and reported from the DB thread. | 209 // and reported from the DB thread. |
| 204 base::TimeDelta cookie_load_duration_; | 210 base::TimeDelta cookie_load_duration_; |
| 205 | 211 |
| 206 // Guards the following metrics-related properties (only accessed when | 212 // Guards the following metrics-related properties (only accessed when |
| 207 // starting/completing priority loads or completing the total load). | 213 // starting/completing priority loads or completing the total load). |
| 208 base::Lock metrics_lock_; | 214 base::Lock metrics_lock_; |
| 209 int num_priority_waiting_; | 215 int num_priority_waiting_; |
| 210 // The total number of priority requests. | 216 // The total number of priority requests. |
| 211 int total_priority_requests_; | 217 int total_priority_requests_; |
| 212 // The time when |num_priority_waiting_| incremented to 1. | 218 // The time when |num_priority_waiting_| incremented to 1. |
| 213 base::Time current_priority_wait_start_; | 219 base::Time current_priority_wait_start_; |
| 214 // The cumulative duration of time when |num_priority_waiting_| was greater | 220 // The cumulative duration of time when |num_priority_waiting_| was greater |
| 215 // than 1. | 221 // than 1. |
| 216 base::TimeDelta priority_wait_duration_; | 222 base::TimeDelta priority_wait_duration_; |
| 217 | 223 |
| 218 DISALLOW_COPY_AND_ASSIGN(Backend); | 224 DISALLOW_COPY_AND_ASSIGN(Backend); |
| 219 }; | 225 }; |
| 220 | 226 |
| 221 // Version number of the database. In version 4, we migrated the time epoch. | 227 // Version number of the database. In version 4, we migrated the time epoch. |
| 222 // If you open the DB with an older version on Mac or Linux, the times will | 228 // If you open the DB with an older version on Mac or Linux, the times will |
| 223 // look wonky, but the file will likely be usable. On Windows version 3 and 4 | 229 // look wonky, but the file will likely be usable. On Windows version 3 and 4 |
| 224 // are the same. | 230 // are the same. |
| 225 // | 231 // |
| 226 // Version 3 updated the database to include the last access time, so we can | 232 // Version 3 updated the database to include the last access time, so we can |
| 227 // expire them in decreasing order of use when we've reached the maximum | 233 // expire them in decreasing order of use when we've reached the maximum |
| 228 // number of cookies. | 234 // number of cookies. |
| 229 static const int kCurrentVersionNumber = 4; | 235 static const int kCurrentVersionNumber = 5; |
| 230 static const int kCompatibleVersionNumber = 3; | 236 static const int kCompatibleVersionNumber = 5; |
| 231 | 237 |
| 232 namespace { | 238 namespace { |
| 233 | 239 |
| 234 // Increments a specified TimeDelta by the duration between this object's | 240 // Increments a specified TimeDelta by the duration between this object's |
| 235 // constructor and destructor. Not thread safe. Multiple instances may be | 241 // constructor and destructor. Not thread safe. Multiple instances may be |
| 236 // created with the same delta instance as long as their lifetimes are nested. | 242 // created with the same delta instance as long as their lifetimes are nested. |
| 237 // The shortest lived instances have no impact. | 243 // The shortest lived instances have no impact. |
| 238 class IncrementTimeDelta { | 244 class IncrementTimeDelta { |
| 239 public: | 245 public: |
| 240 explicit IncrementTimeDelta(base::TimeDelta* delta) : | 246 explicit IncrementTimeDelta(base::TimeDelta* delta) : |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 256 | 262 |
| 257 // Initializes the cookies table, returning true on success. | 263 // Initializes the cookies table, returning true on success. |
| 258 bool InitTable(sql::Connection* db) { | 264 bool InitTable(sql::Connection* db) { |
| 259 if (!db->DoesTableExist("cookies")) { | 265 if (!db->DoesTableExist("cookies")) { |
| 260 if (!db->Execute("CREATE TABLE cookies (" | 266 if (!db->Execute("CREATE TABLE cookies (" |
| 261 "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," | 267 "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," |
| 262 "host_key TEXT NOT NULL," | 268 "host_key TEXT NOT NULL," |
| 263 "name TEXT NOT NULL," | 269 "name TEXT NOT NULL," |
| 264 "value TEXT NOT NULL," | 270 "value TEXT NOT NULL," |
| 265 "path TEXT NOT NULL," | 271 "path TEXT NOT NULL," |
| 266 // We only store persistent, so we know it expires | |
| 267 "expires_utc INTEGER NOT NULL," | 272 "expires_utc INTEGER NOT NULL," |
| 268 "secure INTEGER NOT NULL," | 273 "secure INTEGER NOT NULL," |
| 269 "httponly INTEGER NOT NULL," | 274 "httponly INTEGER NOT NULL," |
| 270 "last_access_utc INTEGER NOT NULL)")) | 275 "last_access_utc INTEGER NOT NULL, " |
| 276 "has_expires INTEGER NOT NULL DEFAULT 1, " | |
| 277 "persistent INTEGER NOT NULL DEFAULT 1)")) | |
| 271 return false; | 278 return false; |
| 272 } | 279 } |
| 273 | 280 |
| 274 // Try to create the index every time. Older versions did not have this index, | 281 // Try to create the index every time. Older versions did not have this index, |
| 275 // so we want those people to get it. Ignore errors, since it may exist. | 282 // so we want those people to get it. Ignore errors, since it may exist. |
| 276 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" | 283 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" |
| 277 " (creation_utc)"); | 284 " (creation_utc)"); |
| 278 | 285 |
| 279 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); | 286 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); |
| 280 | 287 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 // Otherwise notify on IO thread. | 498 // Otherwise notify on IO thread. |
| 492 if (load_success && keys_to_load_.size() > 0) { | 499 if (load_success && keys_to_load_.size() > 0) { |
| 493 BrowserThread::PostTask( | 500 BrowserThread::PostTask( |
| 494 BrowserThread::DB, FROM_HERE, | 501 BrowserThread::DB, FROM_HERE, |
| 495 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); | 502 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); |
| 496 } else { | 503 } else { |
| 497 BrowserThread::PostTask( | 504 BrowserThread::PostTask( |
| 498 BrowserThread::IO, FROM_HERE, | 505 BrowserThread::IO, FROM_HERE, |
| 499 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, | 506 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, |
| 500 this, loaded_callback, load_success)); | 507 this, loaded_callback, load_success)); |
| 508 if (!restore_old_session_cookies_) | |
| 509 DeleteSessionCookiesOnDBThread(); | |
| 501 } | 510 } |
| 502 } | 511 } |
| 503 | 512 |
| 504 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( | 513 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( |
| 505 const std::set<std::string>& domains) { | 514 const std::set<std::string>& domains) { |
| 506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 507 | 516 |
| 508 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, | 517 const char* sql; |
| 509 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " | 518 if (restore_old_session_cookies_) { |
| 510 "httponly, last_access_utc FROM cookies WHERE host_key = ?")); | 519 sql = |
| 520 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | |
| 521 "secure, httponly, last_access_utc, has_expires, persistent " | |
| 522 "FROM cookies WHERE host_key = ?"; | |
| 523 } else { | |
| 524 sql = | |
| 525 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | |
| 526 "secure, httponly, last_access_utc, has_expires, persistent " | |
| 527 "FROM cookies WHERE host_key = ? AND persistent == 1"; | |
| 528 } | |
| 529 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, sql)); | |
| 511 if (!smt) { | 530 if (!smt) { |
| 512 NOTREACHED() << "select statement prep failed"; | 531 NOTREACHED() << "select statement prep failed"; |
| 513 db_.reset(); | 532 db_.reset(); |
| 514 return false; | 533 return false; |
| 515 } | 534 } |
| 516 | 535 |
| 517 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 536 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
| 518 std::set<std::string>::const_iterator it = domains.begin(); | 537 std::set<std::string>::const_iterator it = domains.begin(); |
| 519 for (; it != domains.end(); ++it) { | 538 for (; it != domains.end(); ++it) { |
| 520 smt.BindString(0, *it); | 539 smt.BindString(0, *it); |
| 521 while (smt.Step()) { | 540 while (smt.Step()) { |
| 522 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 541 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( |
| 523 new net::CookieMonster::CanonicalCookie( | 542 new net::CookieMonster::CanonicalCookie( |
| 524 // The "source" URL is not used with persisted cookies. | 543 // The "source" URL is not used with persisted cookies. |
| 525 GURL(), // Source | 544 GURL(), // Source |
| 526 smt.ColumnString(2), // name | 545 smt.ColumnString(2), // name |
| 527 smt.ColumnString(3), // value | 546 smt.ColumnString(3), // value |
| 528 smt.ColumnString(1), // domain | 547 smt.ColumnString(1), // domain |
| 529 smt.ColumnString(4), // path | 548 smt.ColumnString(4), // path |
| 530 std::string(), // TODO(abarth): Persist mac_key | 549 std::string(), // TODO(abarth): Persist mac_key |
| 531 std::string(), // TODO(abarth): Persist mac_algorithm | 550 std::string(), // TODO(abarth): Persist mac_algorithm |
| 532 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | 551 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc |
| 533 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc | 552 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc |
| 534 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc | 553 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc |
| 535 smt.ColumnInt(6) != 0, // secure | 554 smt.ColumnInt(6) != 0, // secure |
| 536 smt.ColumnInt(7) != 0, // httponly | 555 smt.ColumnInt(7) != 0, // httponly |
| 537 true, // has_expires | 556 smt.ColumnInt(9) != 0, // has_expires |
| 538 true)); // is_persistent | 557 smt.ColumnInt(10) != 0)); // is_persistent |
| 539 DLOG_IF(WARNING, | 558 DLOG_IF(WARNING, |
| 540 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; | 559 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; |
| 541 cookies.push_back(cc.release()); | 560 cookies.push_back(cc.release()); |
| 542 } | 561 } |
| 543 smt.Reset(); | 562 smt.Reset(); |
| 544 } | 563 } |
| 545 { | 564 { |
| 546 base::AutoLock locked(lock_); | 565 base::AutoLock locked(lock_); |
| 547 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); | 566 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); |
| 548 } | 567 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 "SET last_access_utc = last_access_utc + 11644473600000000 " | 625 "SET last_access_utc = last_access_utc + 11644473600000000 " |
| 607 "WHERE rowid IN " | 626 "WHERE rowid IN " |
| 608 "(SELECT rowid FROM cookies WHERE " | 627 "(SELECT rowid FROM cookies WHERE " |
| 609 "last_access_utc > 0 AND last_access_utc < 11644473600000000)"); | 628 "last_access_utc > 0 AND last_access_utc < 11644473600000000)"); |
| 610 #endif | 629 #endif |
| 611 ++cur_version; | 630 ++cur_version; |
| 612 meta_table_.SetVersionNumber(cur_version); | 631 meta_table_.SetVersionNumber(cur_version); |
| 613 transaction.Commit(); | 632 transaction.Commit(); |
| 614 } | 633 } |
| 615 | 634 |
| 635 if (cur_version == 4) { | |
| 636 const base::TimeTicks start_time = base::TimeTicks::Now(); | |
| 637 sql::Transaction transaction(db_.get()); | |
| 638 if (!transaction.Begin()) | |
| 639 return false; | |
| 640 if (!db_->Execute("ALTER TABLE cookies " | |
| 641 "ADD COLUMN has_expires INTEGER DEFAULT 1") || | |
| 642 !db_->Execute("ALTER TABLE cookies " | |
| 643 "ADD COLUMN persistent INTEGER DEFAULT 1")) { | |
| 644 LOG(WARNING) << "Unable to update cookie database to version 5."; | |
| 645 return false; | |
| 646 } | |
| 647 ++cur_version; | |
| 648 meta_table_.SetVersionNumber(cur_version); | |
| 649 meta_table_.SetCompatibleVersionNumber( | |
| 650 std::min(cur_version, kCompatibleVersionNumber)); | |
| 651 transaction.Commit(); | |
| 652 UMA_HISTOGRAM_TIMES("Cookie.TimeDatabaseMigrationToV5", | |
| 653 base::TimeTicks::Now() - start_time); | |
| 654 } | |
| 655 | |
| 616 // Put future migration cases here. | 656 // Put future migration cases here. |
| 617 | 657 |
| 618 // When the version is too old, we just try to continue anyway, there should | 658 // When the version is too old, we just try to continue anyway, there should |
| 619 // not be a released product that makes a database too old for us to handle. | 659 // not be a released product that makes a database too old for us to handle. |
| 620 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 660 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
| 621 "Cookie database version " << cur_version << " is too old to handle."; | 661 "Cookie database version " << cur_version << " is too old to handle."; |
| 622 | 662 |
| 623 return true; | 663 return true; |
| 624 } | 664 } |
| 625 | 665 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 pending_.swap(ops); | 719 pending_.swap(ops); |
| 680 num_pending_ = 0; | 720 num_pending_ = 0; |
| 681 } | 721 } |
| 682 | 722 |
| 683 // Maybe an old timer fired or we are already Close()'ed. | 723 // Maybe an old timer fired or we are already Close()'ed. |
| 684 if (!db_.get() || ops.empty()) | 724 if (!db_.get() || ops.empty()) |
| 685 return; | 725 return; |
| 686 | 726 |
| 687 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 727 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
| 688 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " | 728 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " |
| 689 "expires_utc, secure, httponly, last_access_utc) " | 729 "expires_utc, secure, httponly, last_access_utc, has_expires, " |
| 690 "VALUES (?,?,?,?,?,?,?,?,?)")); | 730 "persistent) " |
| 731 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); | |
| 691 if (!add_smt) { | 732 if (!add_smt) { |
| 692 NOTREACHED(); | 733 NOTREACHED(); |
| 693 return; | 734 return; |
| 694 } | 735 } |
| 695 | 736 |
| 696 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 737 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
| 697 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); | 738 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); |
| 698 if (!update_access_smt) { | 739 if (!update_access_smt) { |
| 699 NOTREACHED(); | 740 NOTREACHED(); |
| 700 return; | 741 return; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 721 add_smt.Reset(); | 762 add_smt.Reset(); |
| 722 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); | 763 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); |
| 723 add_smt.BindString(1, po->cc().Domain()); | 764 add_smt.BindString(1, po->cc().Domain()); |
| 724 add_smt.BindString(2, po->cc().Name()); | 765 add_smt.BindString(2, po->cc().Name()); |
| 725 add_smt.BindString(3, po->cc().Value()); | 766 add_smt.BindString(3, po->cc().Value()); |
| 726 add_smt.BindString(4, po->cc().Path()); | 767 add_smt.BindString(4, po->cc().Path()); |
| 727 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); | 768 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); |
| 728 add_smt.BindInt(6, po->cc().IsSecure()); | 769 add_smt.BindInt(6, po->cc().IsSecure()); |
| 729 add_smt.BindInt(7, po->cc().IsHttpOnly()); | 770 add_smt.BindInt(7, po->cc().IsHttpOnly()); |
| 730 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); | 771 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); |
| 772 add_smt.BindInt(9, po->cc().DoesExpire()); | |
| 773 add_smt.BindInt(10, po->cc().IsPersistent()); | |
| 731 if (!add_smt.Run()) | 774 if (!add_smt.Run()) |
| 732 NOTREACHED() << "Could not add a cookie to the DB."; | 775 NOTREACHED() << "Could not add a cookie to the DB."; |
| 733 break; | 776 break; |
| 734 | 777 |
| 735 case PendingOperation::COOKIE_UPDATEACCESS: | 778 case PendingOperation::COOKIE_UPDATEACCESS: |
| 736 update_access_smt.Reset(); | 779 update_access_smt.Reset(); |
| 737 update_access_smt.BindInt64(0, | 780 update_access_smt.BindInt64(0, |
| 738 po->cc().LastAccessDate().ToInternalValue()); | 781 po->cc().LastAccessDate().ToInternalValue()); |
| 739 update_access_smt.BindInt64(1, | 782 update_access_smt.BindInt64(1, |
| 740 po->cc().CreationDate().ToInternalValue()); | 783 po->cc().CreationDate().ToInternalValue()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 | 837 |
| 795 if (clear_local_state_on_exit_) | 838 if (clear_local_state_on_exit_) |
| 796 file_util::Delete(path_, false); | 839 file_util::Delete(path_, false); |
| 797 } | 840 } |
| 798 | 841 |
| 799 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( | 842 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( |
| 800 bool clear_local_state) { | 843 bool clear_local_state) { |
| 801 base::AutoLock locked(lock_); | 844 base::AutoLock locked(lock_); |
| 802 clear_local_state_on_exit_ = clear_local_state; | 845 clear_local_state_on_exit_ = clear_local_state; |
| 803 } | 846 } |
| 804 SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path) | 847 |
| 805 : backend_(new Backend(path)) { | 848 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnDBThread() { |
|
erikwright (departed)
2011/11/29 13:43:22
I would move this up next to the other methods tha
marja
2011/11/29 14:58:21
Done. (Ah, true, this was leftover code.)
| |
| 849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 850 // If the store hasn't been initialized, the session cookie deletion is done | |
| 851 // after all cookies have been loaded. | |
| 852 if (!initialized_) | |
| 853 return; | |
| 854 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0")) | |
| 855 LOG(WARNING) << "Unable to delete session cookies."; | |
| 856 } | |
| 857 | |
| 858 SQLitePersistentCookieStore::SQLitePersistentCookieStore( | |
| 859 const FilePath& path, | |
| 860 bool restore_old_session_cookies) | |
| 861 : backend_(new Backend(path, restore_old_session_cookies)) { | |
| 806 } | 862 } |
| 807 | 863 |
| 808 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 864 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
| 809 if (backend_.get()) { | 865 if (backend_.get()) { |
| 810 backend_->Close(); | 866 backend_->Close(); |
| 811 // Release our reference, it will probably still have a reference if the | 867 // Release our reference, it will probably still have a reference if the |
| 812 // background thread has not run Close() yet. | 868 // background thread has not run Close() yet. |
| 813 backend_ = NULL; | 869 backend_ = NULL; |
| 814 } | 870 } |
| 815 } | 871 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 847 if (backend_.get()) | 903 if (backend_.get()) |
| 848 backend_->SetClearLocalStateOnExit(clear_local_state); | 904 backend_->SetClearLocalStateOnExit(clear_local_state); |
| 849 } | 905 } |
| 850 | 906 |
| 851 void SQLitePersistentCookieStore::Flush(Task* completion_task) { | 907 void SQLitePersistentCookieStore::Flush(Task* completion_task) { |
| 852 if (backend_.get()) | 908 if (backend_.get()) |
| 853 backend_->Flush(completion_task); | 909 backend_->Flush(completion_task); |
| 854 else if (completion_task) | 910 else if (completion_task) |
| 855 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 911 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
| 856 } | 912 } |
| OLD | NEW |