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 DeleteSessionCookies(); |
| 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. |
222 // If you open the DB with an older version on Mac or Linux, the times will | 228 // |
223 // look wonky, but the file will likely be usable. On Windows version 3 and 4 | 229 // Version 5 adds the columns has_expires and is_persistent, so that the |
224 // are the same. | 230 // database can store session cookies as well as persistent cookies. Databases |
| 231 // of version 5 are incompatible with older versions of code. If a database of |
| 232 // version 5 is read by older code, session cookies will be treated as normal |
| 233 // cookies. |
| 234 // |
| 235 // In version 4, we migrated the time epoch. If you open the DB with an older |
| 236 // version on Mac or Linux, the times will look wonky, but the file will likely |
| 237 // be usable. On Windows version 3 and 4 are the same. |
225 // | 238 // |
226 // Version 3 updated the database to include the last access time, so we can | 239 // 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 | 240 // expire them in decreasing order of use when we've reached the maximum |
228 // number of cookies. | 241 // number of cookies. |
229 static const int kCurrentVersionNumber = 4; | 242 static const int kCurrentVersionNumber = 5; |
230 static const int kCompatibleVersionNumber = 3; | 243 static const int kCompatibleVersionNumber = 5; |
231 | 244 |
232 namespace { | 245 namespace { |
233 | 246 |
234 // Increments a specified TimeDelta by the duration between this object's | 247 // Increments a specified TimeDelta by the duration between this object's |
235 // constructor and destructor. Not thread safe. Multiple instances may be | 248 // constructor and destructor. Not thread safe. Multiple instances may be |
236 // created with the same delta instance as long as their lifetimes are nested. | 249 // created with the same delta instance as long as their lifetimes are nested. |
237 // The shortest lived instances have no impact. | 250 // The shortest lived instances have no impact. |
238 class IncrementTimeDelta { | 251 class IncrementTimeDelta { |
239 public: | 252 public: |
240 explicit IncrementTimeDelta(base::TimeDelta* delta) : | 253 explicit IncrementTimeDelta(base::TimeDelta* delta) : |
(...skipping 15 matching lines...) Expand all Loading... |
256 | 269 |
257 // Initializes the cookies table, returning true on success. | 270 // Initializes the cookies table, returning true on success. |
258 bool InitTable(sql::Connection* db) { | 271 bool InitTable(sql::Connection* db) { |
259 if (!db->DoesTableExist("cookies")) { | 272 if (!db->DoesTableExist("cookies")) { |
260 if (!db->Execute("CREATE TABLE cookies (" | 273 if (!db->Execute("CREATE TABLE cookies (" |
261 "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," | 274 "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," |
262 "host_key TEXT NOT NULL," | 275 "host_key TEXT NOT NULL," |
263 "name TEXT NOT NULL," | 276 "name TEXT NOT NULL," |
264 "value TEXT NOT NULL," | 277 "value TEXT NOT NULL," |
265 "path TEXT NOT NULL," | 278 "path TEXT NOT NULL," |
266 // We only store persistent, so we know it expires | |
267 "expires_utc INTEGER NOT NULL," | 279 "expires_utc INTEGER NOT NULL," |
268 "secure INTEGER NOT NULL," | 280 "secure INTEGER NOT NULL," |
269 "httponly INTEGER NOT NULL," | 281 "httponly INTEGER NOT NULL," |
270 "last_access_utc INTEGER NOT NULL)")) | 282 "last_access_utc INTEGER NOT NULL, " |
| 283 "has_expires INTEGER NOT NULL DEFAULT 1, " |
| 284 "persistent INTEGER NOT NULL DEFAULT 1)")) |
271 return false; | 285 return false; |
272 } | 286 } |
273 | 287 |
274 // Try to create the index every time. Older versions did not have this index, | 288 // 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. | 289 // 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" | 290 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" |
277 " (creation_utc)"); | 291 " (creation_utc)"); |
278 | 292 |
279 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); | 293 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); |
280 | 294 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // Otherwise notify on IO thread. | 505 // Otherwise notify on IO thread. |
492 if (load_success && keys_to_load_.size() > 0) { | 506 if (load_success && keys_to_load_.size() > 0) { |
493 BrowserThread::PostTask( | 507 BrowserThread::PostTask( |
494 BrowserThread::DB, FROM_HERE, | 508 BrowserThread::DB, FROM_HERE, |
495 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); | 509 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); |
496 } else { | 510 } else { |
497 BrowserThread::PostTask( | 511 BrowserThread::PostTask( |
498 BrowserThread::IO, FROM_HERE, | 512 BrowserThread::IO, FROM_HERE, |
499 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, | 513 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, |
500 this, loaded_callback, load_success)); | 514 this, loaded_callback, load_success)); |
| 515 if (!restore_old_session_cookies_) |
| 516 DeleteSessionCookies(); |
501 } | 517 } |
502 } | 518 } |
503 | 519 |
504 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( | 520 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( |
505 const std::set<std::string>& domains) { | 521 const std::set<std::string>& domains) { |
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
507 | 523 |
508 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, | 524 const char* sql; |
509 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " | 525 if (restore_old_session_cookies_) { |
510 "httponly, last_access_utc FROM cookies WHERE host_key = ?")); | 526 sql = |
| 527 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
| 528 "secure, httponly, last_access_utc, has_expires, persistent " |
| 529 "FROM cookies WHERE host_key = ?"; |
| 530 } else { |
| 531 sql = |
| 532 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
| 533 "secure, httponly, last_access_utc, has_expires, persistent " |
| 534 "FROM cookies WHERE host_key = ? AND persistent == 1"; |
| 535 } |
| 536 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, sql)); |
511 if (!smt) { | 537 if (!smt) { |
512 NOTREACHED() << "select statement prep failed"; | 538 NOTREACHED() << "select statement prep failed"; |
513 db_.reset(); | 539 db_.reset(); |
514 return false; | 540 return false; |
515 } | 541 } |
516 | 542 |
517 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 543 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
518 std::set<std::string>::const_iterator it = domains.begin(); | 544 std::set<std::string>::const_iterator it = domains.begin(); |
519 for (; it != domains.end(); ++it) { | 545 for (; it != domains.end(); ++it) { |
520 smt.BindString(0, *it); | 546 smt.BindString(0, *it); |
521 while (smt.Step()) { | 547 while (smt.Step()) { |
522 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 548 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( |
523 new net::CookieMonster::CanonicalCookie( | 549 new net::CookieMonster::CanonicalCookie( |
524 // The "source" URL is not used with persisted cookies. | 550 // The "source" URL is not used with persisted cookies. |
525 GURL(), // Source | 551 GURL(), // Source |
526 smt.ColumnString(2), // name | 552 smt.ColumnString(2), // name |
527 smt.ColumnString(3), // value | 553 smt.ColumnString(3), // value |
528 smt.ColumnString(1), // domain | 554 smt.ColumnString(1), // domain |
529 smt.ColumnString(4), // path | 555 smt.ColumnString(4), // path |
530 std::string(), // TODO(abarth): Persist mac_key | 556 std::string(), // TODO(abarth): Persist mac_key |
531 std::string(), // TODO(abarth): Persist mac_algorithm | 557 std::string(), // TODO(abarth): Persist mac_algorithm |
532 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | 558 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc |
533 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc | 559 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc |
534 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc | 560 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc |
535 smt.ColumnInt(6) != 0, // secure | 561 smt.ColumnInt(6) != 0, // secure |
536 smt.ColumnInt(7) != 0, // httponly | 562 smt.ColumnInt(7) != 0, // httponly |
537 true, // has_expires | 563 smt.ColumnInt(9) != 0, // has_expires |
538 true)); // is_persistent | 564 smt.ColumnInt(10) != 0)); // is_persistent |
539 DLOG_IF(WARNING, | 565 DLOG_IF(WARNING, |
540 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; | 566 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; |
541 cookies.push_back(cc.release()); | 567 cookies.push_back(cc.release()); |
542 } | 568 } |
543 smt.Reset(); | 569 smt.Reset(); |
544 } | 570 } |
545 { | 571 { |
546 base::AutoLock locked(lock_); | 572 base::AutoLock locked(lock_); |
547 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); | 573 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); |
548 } | 574 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 "SET last_access_utc = last_access_utc + 11644473600000000 " | 632 "SET last_access_utc = last_access_utc + 11644473600000000 " |
607 "WHERE rowid IN " | 633 "WHERE rowid IN " |
608 "(SELECT rowid FROM cookies WHERE " | 634 "(SELECT rowid FROM cookies WHERE " |
609 "last_access_utc > 0 AND last_access_utc < 11644473600000000)"); | 635 "last_access_utc > 0 AND last_access_utc < 11644473600000000)"); |
610 #endif | 636 #endif |
611 ++cur_version; | 637 ++cur_version; |
612 meta_table_.SetVersionNumber(cur_version); | 638 meta_table_.SetVersionNumber(cur_version); |
613 transaction.Commit(); | 639 transaction.Commit(); |
614 } | 640 } |
615 | 641 |
| 642 if (cur_version == 4) { |
| 643 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 644 sql::Transaction transaction(db_.get()); |
| 645 if (!transaction.Begin()) |
| 646 return false; |
| 647 if (!db_->Execute("ALTER TABLE cookies " |
| 648 "ADD COLUMN has_expires INTEGER DEFAULT 1") || |
| 649 !db_->Execute("ALTER TABLE cookies " |
| 650 "ADD COLUMN persistent INTEGER DEFAULT 1")) { |
| 651 LOG(WARNING) << "Unable to update cookie database to version 5."; |
| 652 return false; |
| 653 } |
| 654 ++cur_version; |
| 655 meta_table_.SetVersionNumber(cur_version); |
| 656 meta_table_.SetCompatibleVersionNumber( |
| 657 std::min(cur_version, kCompatibleVersionNumber)); |
| 658 transaction.Commit(); |
| 659 UMA_HISTOGRAM_TIMES("Cookie.TimeDatabaseMigrationToV5", |
| 660 base::TimeTicks::Now() - start_time); |
| 661 } |
| 662 |
616 // Put future migration cases here. | 663 // Put future migration cases here. |
617 | 664 |
618 // When the version is too old, we just try to continue anyway, there should | 665 // 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. | 666 // not be a released product that makes a database too old for us to handle. |
620 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 667 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
621 "Cookie database version " << cur_version << " is too old to handle."; | 668 "Cookie database version " << cur_version << " is too old to handle."; |
622 | 669 |
623 return true; | 670 return true; |
624 } | 671 } |
625 | 672 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 pending_.swap(ops); | 726 pending_.swap(ops); |
680 num_pending_ = 0; | 727 num_pending_ = 0; |
681 } | 728 } |
682 | 729 |
683 // Maybe an old timer fired or we are already Close()'ed. | 730 // Maybe an old timer fired or we are already Close()'ed. |
684 if (!db_.get() || ops.empty()) | 731 if (!db_.get() || ops.empty()) |
685 return; | 732 return; |
686 | 733 |
687 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 734 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
688 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " | 735 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " |
689 "expires_utc, secure, httponly, last_access_utc) " | 736 "expires_utc, secure, httponly, last_access_utc, has_expires, " |
690 "VALUES (?,?,?,?,?,?,?,?,?)")); | 737 "persistent) " |
| 738 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); |
691 if (!add_smt) { | 739 if (!add_smt) { |
692 NOTREACHED(); | 740 NOTREACHED(); |
693 return; | 741 return; |
694 } | 742 } |
695 | 743 |
696 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 744 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
697 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); | 745 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); |
698 if (!update_access_smt) { | 746 if (!update_access_smt) { |
699 NOTREACHED(); | 747 NOTREACHED(); |
700 return; | 748 return; |
(...skipping 20 matching lines...) Expand all Loading... |
721 add_smt.Reset(); | 769 add_smt.Reset(); |
722 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); | 770 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); |
723 add_smt.BindString(1, po->cc().Domain()); | 771 add_smt.BindString(1, po->cc().Domain()); |
724 add_smt.BindString(2, po->cc().Name()); | 772 add_smt.BindString(2, po->cc().Name()); |
725 add_smt.BindString(3, po->cc().Value()); | 773 add_smt.BindString(3, po->cc().Value()); |
726 add_smt.BindString(4, po->cc().Path()); | 774 add_smt.BindString(4, po->cc().Path()); |
727 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); | 775 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); |
728 add_smt.BindInt(6, po->cc().IsSecure()); | 776 add_smt.BindInt(6, po->cc().IsSecure()); |
729 add_smt.BindInt(7, po->cc().IsHttpOnly()); | 777 add_smt.BindInt(7, po->cc().IsHttpOnly()); |
730 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); | 778 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); |
| 779 add_smt.BindInt(9, po->cc().DoesExpire()); |
| 780 add_smt.BindInt(10, po->cc().IsPersistent()); |
731 if (!add_smt.Run()) | 781 if (!add_smt.Run()) |
732 NOTREACHED() << "Could not add a cookie to the DB."; | 782 NOTREACHED() << "Could not add a cookie to the DB."; |
733 break; | 783 break; |
734 | 784 |
735 case PendingOperation::COOKIE_UPDATEACCESS: | 785 case PendingOperation::COOKIE_UPDATEACCESS: |
736 update_access_smt.Reset(); | 786 update_access_smt.Reset(); |
737 update_access_smt.BindInt64(0, | 787 update_access_smt.BindInt64(0, |
738 po->cc().LastAccessDate().ToInternalValue()); | 788 po->cc().LastAccessDate().ToInternalValue()); |
739 update_access_smt.BindInt64(1, | 789 update_access_smt.BindInt64(1, |
740 po->cc().CreationDate().ToInternalValue()); | 790 po->cc().CreationDate().ToInternalValue()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 844 |
795 if (clear_local_state_on_exit_) | 845 if (clear_local_state_on_exit_) |
796 file_util::Delete(path_, false); | 846 file_util::Delete(path_, false); |
797 } | 847 } |
798 | 848 |
799 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( | 849 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( |
800 bool clear_local_state) { | 850 bool clear_local_state) { |
801 base::AutoLock locked(lock_); | 851 base::AutoLock locked(lock_); |
802 clear_local_state_on_exit_ = clear_local_state; | 852 clear_local_state_on_exit_ = clear_local_state; |
803 } | 853 } |
804 SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path) | 854 |
805 : backend_(new Backend(path)) { | 855 void SQLitePersistentCookieStore::Backend::DeleteSessionCookies() { |
| 856 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 857 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0")) |
| 858 LOG(WARNING) << "Unable to delete session cookies."; |
| 859 } |
| 860 |
| 861 SQLitePersistentCookieStore::SQLitePersistentCookieStore( |
| 862 const FilePath& path, |
| 863 bool restore_old_session_cookies) |
| 864 : backend_(new Backend(path, restore_old_session_cookies)) { |
806 } | 865 } |
807 | 866 |
808 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 867 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
809 if (backend_.get()) { | 868 if (backend_.get()) { |
810 backend_->Close(); | 869 backend_->Close(); |
811 // Release our reference, it will probably still have a reference if the | 870 // Release our reference, it will probably still have a reference if the |
812 // background thread has not run Close() yet. | 871 // background thread has not run Close() yet. |
813 backend_ = NULL; | 872 backend_ = NULL; |
814 } | 873 } |
815 } | 874 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 if (backend_.get()) | 906 if (backend_.get()) |
848 backend_->SetClearLocalStateOnExit(clear_local_state); | 907 backend_->SetClearLocalStateOnExit(clear_local_state); |
849 } | 908 } |
850 | 909 |
851 void SQLitePersistentCookieStore::Flush(Task* completion_task) { | 910 void SQLitePersistentCookieStore::Flush(Task* completion_task) { |
852 if (backend_.get()) | 911 if (backend_.get()) |
853 backend_->Flush(completion_task); | 912 backend_->Flush(completion_task); |
854 else if (completion_task) | 913 else if (completion_task) |
855 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 914 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
856 } | 915 } |
OLD | NEW |