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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 explicit Backend(const FilePath& path) |
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 return_session_cookies_(true), | |
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); |
77 | 78 |
78 // Batch a cookie addition. | 79 // Batch a cookie addition. |
79 void AddCookie(const net::CookieMonster::CanonicalCookie& cc); | 80 void AddCookie(const net::CookieMonster::CanonicalCookie& cc); |
80 | 81 |
81 // Batch a cookie access time update. | 82 // Batch a cookie access time update. |
82 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); | 83 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); |
83 | 84 |
84 // Batch a cookie deletion. | 85 // Batch a cookie deletion. |
85 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); | 86 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); |
86 | 87 |
87 // Commit pending operations as soon as possible. | 88 // Commit pending operations as soon as possible. |
88 void Flush(Task* completion_task); | 89 void Flush(Task* completion_task); |
89 | 90 |
90 // Commit any pending operations and close the database. This must be called | 91 // Commit any pending operations and close the database. This must be called |
91 // before the object is destructed. | 92 // before the object is destructed. |
92 void Close(); | 93 void Close(); |
93 | 94 |
94 void SetClearLocalStateOnExit(bool clear_local_state); | 95 void SetClearLocalStateOnExit(bool clear_local_state); |
95 | 96 |
97 void DeleteSessionCookies(); | |
98 | |
96 private: | 99 private: |
97 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; | 100 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; |
98 | 101 |
99 // You should call Close() before destructing this object. | 102 // You should call Close() before destructing this object. |
100 ~Backend() { | 103 ~Backend() { |
101 DCHECK(!db_.get()) << "Close should have already been called."; | 104 DCHECK(!db_.get()) << "Close should have already been called."; |
102 DCHECK(num_pending_ == 0 && pending_.empty()); | 105 DCHECK(num_pending_ == 0 && pending_.empty()); |
103 } | 106 } |
104 | 107 |
105 // Database upgrade statements. | 108 // Database upgrade statements. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 bool LoadCookiesForDomains(const std::set<std::string>& key); | 172 bool LoadCookiesForDomains(const std::set<std::string>& key); |
170 | 173 |
171 // Batch a cookie operation (add or delete) | 174 // Batch a cookie operation (add or delete) |
172 void BatchOperation(PendingOperation::OperationType op, | 175 void BatchOperation(PendingOperation::OperationType op, |
173 const net::CookieMonster::CanonicalCookie& cc); | 176 const net::CookieMonster::CanonicalCookie& cc); |
174 // Commit our pending operations to the database. | 177 // Commit our pending operations to the database. |
175 void Commit(); | 178 void Commit(); |
176 // Close() executed on the background thread. | 179 // Close() executed on the background thread. |
177 void InternalBackgroundClose(); | 180 void InternalBackgroundClose(); |
178 | 181 |
182 void DeleteSessionCookiesOnDBThread(); | |
183 | |
179 FilePath path_; | 184 FilePath path_; |
180 scoped_ptr<sql::Connection> db_; | 185 scoped_ptr<sql::Connection> db_; |
181 sql::MetaTable meta_table_; | 186 sql::MetaTable meta_table_; |
182 | 187 |
183 typedef std::list<PendingOperation*> PendingOperationsList; | 188 typedef std::list<PendingOperation*> PendingOperationsList; |
184 PendingOperationsList pending_; | 189 PendingOperationsList pending_; |
185 PendingOperationsList::size_type num_pending_; | 190 PendingOperationsList::size_type num_pending_; |
186 // True if the persistent store should be deleted upon destruction. | 191 // True if the persistent store should be deleted upon destruction. |
187 bool clear_local_state_on_exit_; | 192 bool clear_local_state_on_exit_; |
188 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| | 193 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| |
189 base::Lock lock_; | 194 base::Lock lock_; |
190 | 195 |
191 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce | 196 // 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 | 197 // 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. | 198 // individual load requests for domain keys or when all loading completes. |
194 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; | 199 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; |
195 | 200 |
196 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. | 201 // 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_; | 202 std::map<std::string, std::set<std::string> > keys_to_load_; |
198 | 203 |
199 // Indicates if DB has been initialized. | 204 // Indicates if DB has been initialized. |
200 bool initialized_; | 205 bool initialized_; |
201 | 206 |
207 // If false, we should filter out session cookies when reading the DB. | |
208 bool return_session_cookies_; | |
209 | |
202 // The cumulative time spent loading the cookies on the DB thread. Incremented | 210 // The cumulative time spent loading the cookies on the DB thread. Incremented |
203 // and reported from the DB thread. | 211 // and reported from the DB thread. |
204 base::TimeDelta cookie_load_duration_; | 212 base::TimeDelta cookie_load_duration_; |
205 | 213 |
206 // Guards the following metrics-related properties (only accessed when | 214 // Guards the following metrics-related properties (only accessed when |
207 // starting/completing priority loads or completing the total load). | 215 // starting/completing priority loads or completing the total load). |
208 base::Lock metrics_lock_; | 216 base::Lock metrics_lock_; |
209 int num_priority_waiting_; | 217 int num_priority_waiting_; |
210 // The total number of priority requests. | 218 // The total number of priority requests. |
211 int total_priority_requests_; | 219 int total_priority_requests_; |
212 // The time when |num_priority_waiting_| incremented to 1. | 220 // The time when |num_priority_waiting_| incremented to 1. |
213 base::Time current_priority_wait_start_; | 221 base::Time current_priority_wait_start_; |
214 // The cumulative duration of time when |num_priority_waiting_| was greater | 222 // The cumulative duration of time when |num_priority_waiting_| was greater |
215 // than 1. | 223 // than 1. |
216 base::TimeDelta priority_wait_duration_; | 224 base::TimeDelta priority_wait_duration_; |
217 | 225 |
218 DISALLOW_COPY_AND_ASSIGN(Backend); | 226 DISALLOW_COPY_AND_ASSIGN(Backend); |
219 }; | 227 }; |
220 | 228 |
221 // Version number of the database. In version 4, we migrated the time epoch. | 229 // 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 | 230 // 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 | 231 // look wonky, but the file will likely be usable. On Windows version 3 and 4 |
224 // are the same. | 232 // are the same. |
225 // | 233 // |
226 // Version 3 updated the database to include the last access time, so we can | 234 // 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 | 235 // expire them in decreasing order of use when we've reached the maximum |
228 // number of cookies. | 236 // number of cookies. |
229 static const int kCurrentVersionNumber = 4; | 237 static const int kCurrentVersionNumber = 5; |
230 static const int kCompatibleVersionNumber = 3; | 238 static const int kCompatibleVersionNumber = 5; |
231 | 239 |
232 namespace { | 240 namespace { |
233 | 241 |
234 // Increments a specified TimeDelta by the duration between this object's | 242 // Increments a specified TimeDelta by the duration between this object's |
235 // constructor and destructor. Not thread safe. Multiple instances may be | 243 // constructor and destructor. Not thread safe. Multiple instances may be |
236 // created with the same delta instance as long as their lifetimes are nested. | 244 // created with the same delta instance as long as their lifetimes are nested. |
237 // The shortest lived instances have no impact. | 245 // The shortest lived instances have no impact. |
238 class IncrementTimeDelta { | 246 class IncrementTimeDelta { |
239 public: | 247 public: |
240 explicit IncrementTimeDelta(base::TimeDelta* delta) : | 248 explicit IncrementTimeDelta(base::TimeDelta* delta) : |
(...skipping 15 matching lines...) Expand all Loading... | |
256 | 264 |
257 // Initializes the cookies table, returning true on success. | 265 // Initializes the cookies table, returning true on success. |
258 bool InitTable(sql::Connection* db) { | 266 bool InitTable(sql::Connection* db) { |
259 if (!db->DoesTableExist("cookies")) { | 267 if (!db->DoesTableExist("cookies")) { |
260 if (!db->Execute("CREATE TABLE cookies (" | 268 if (!db->Execute("CREATE TABLE cookies (" |
261 "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," | 269 "creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY," |
262 "host_key TEXT NOT NULL," | 270 "host_key TEXT NOT NULL," |
263 "name TEXT NOT NULL," | 271 "name TEXT NOT NULL," |
264 "value TEXT NOT NULL," | 272 "value TEXT NOT NULL," |
265 "path TEXT NOT NULL," | 273 "path TEXT NOT NULL," |
266 // We only store persistent, so we know it expires | |
267 "expires_utc INTEGER NOT NULL," | 274 "expires_utc INTEGER NOT NULL," |
268 "secure INTEGER NOT NULL," | 275 "secure INTEGER NOT NULL," |
269 "httponly INTEGER NOT NULL," | 276 "httponly INTEGER NOT NULL," |
270 "last_access_utc INTEGER NOT NULL)")) | 277 "last_access_utc INTEGER NOT NULL," |
278 "has_expires INTEGER NOT NULL," | |
279 "persistent INTEGER NOT NULL)")) | |
271 return false; | 280 return false; |
272 } | 281 } |
273 | 282 |
274 // Try to create the index every time. Older versions did not have this index, | 283 // 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. | 284 // 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" | 285 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" |
277 " (creation_utc)"); | 286 " (creation_utc)"); |
278 | 287 |
279 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); | 288 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); |
280 | 289 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 // Otherwise notify on IO thread. | 500 // Otherwise notify on IO thread. |
492 if (load_success && keys_to_load_.size() > 0) { | 501 if (load_success && keys_to_load_.size() > 0) { |
493 BrowserThread::PostTask( | 502 BrowserThread::PostTask( |
494 BrowserThread::DB, FROM_HERE, | 503 BrowserThread::DB, FROM_HERE, |
495 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); | 504 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); |
496 } else { | 505 } else { |
497 BrowserThread::PostTask( | 506 BrowserThread::PostTask( |
498 BrowserThread::IO, FROM_HERE, | 507 BrowserThread::IO, FROM_HERE, |
499 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, | 508 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, |
500 this, loaded_callback, load_success)); | 509 this, loaded_callback, load_success)); |
510 // We haven't yet had the chance to delete session cookies from the DB; do | |
511 // it now. | |
512 if (!return_session_cookies_) | |
513 DeleteSessionCookiesOnDBThread(); | |
501 } | 514 } |
502 } | 515 } |
503 | 516 |
504 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( | 517 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( |
505 const std::set<std::string>& domains) { | 518 const std::set<std::string>& domains) { |
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
507 | 520 |
508 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, | 521 const char* sql; |
509 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " | 522 if (return_session_cookies_) { |
510 "httponly, last_access_utc FROM cookies WHERE host_key = ?")); | 523 sql = |
524 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | |
525 "secure, httponly, last_access_utc, has_expires, persistent " | |
526 "FROM cookies WHERE host_key = ?"; | |
527 } else { | |
528 sql = | |
529 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | |
530 "secure, httponly, last_access_utc, has_expires, persistent " | |
531 "FROM cookies WHERE host_key = ? AND persistent == 1"; | |
532 } | |
533 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, sql)); | |
511 if (!smt) { | 534 if (!smt) { |
512 NOTREACHED() << "select statement prep failed"; | 535 NOTREACHED() << "select statement prep failed"; |
513 db_.reset(); | 536 db_.reset(); |
514 return false; | 537 return false; |
515 } | 538 } |
516 | 539 |
517 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 540 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
518 std::set<std::string>::const_iterator it = domains.begin(); | 541 std::set<std::string>::const_iterator it = domains.begin(); |
519 for (; it != domains.end(); ++it) { | 542 for (; it != domains.end(); ++it) { |
520 smt.BindString(0, *it); | 543 smt.BindString(0, *it); |
521 while (smt.Step()) { | 544 while (smt.Step()) { |
522 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 545 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( |
523 new net::CookieMonster::CanonicalCookie( | 546 new net::CookieMonster::CanonicalCookie( |
524 // The "source" URL is not used with persisted cookies. | 547 // The "source" URL is not used with persisted cookies. |
525 GURL(), // Source | 548 GURL(), // Source |
526 smt.ColumnString(2), // name | 549 smt.ColumnString(2), // name |
527 smt.ColumnString(3), // value | 550 smt.ColumnString(3), // value |
528 smt.ColumnString(1), // domain | 551 smt.ColumnString(1), // domain |
529 smt.ColumnString(4), // path | 552 smt.ColumnString(4), // path |
530 std::string(), // TODO(abarth): Persist mac_key | 553 std::string(), // TODO(abarth): Persist mac_key |
531 std::string(), // TODO(abarth): Persist mac_algorithm | 554 std::string(), // TODO(abarth): Persist mac_algorithm |
532 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | 555 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc |
533 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc | 556 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc |
534 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc | 557 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc |
535 smt.ColumnInt(6) != 0, // secure | 558 smt.ColumnInt(6) != 0, // secure |
536 smt.ColumnInt(7) != 0, // httponly | 559 smt.ColumnInt(7) != 0, // httponly |
537 true, // has_expires | 560 smt.ColumnInt(9) != 0, // has_expires |
538 true)); // is_persistent | 561 smt.ColumnInt(10) != 0)); // is_persistent |
539 DLOG_IF(WARNING, | 562 DLOG_IF(WARNING, |
540 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; | 563 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; |
541 cookies.push_back(cc.release()); | 564 cookies.push_back(cc.release()); |
542 } | 565 } |
543 smt.Reset(); | 566 smt.Reset(); |
544 } | 567 } |
545 { | 568 { |
546 base::AutoLock locked(lock_); | 569 base::AutoLock locked(lock_); |
547 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); | 570 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); |
548 } | 571 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 "SET last_access_utc = last_access_utc + 11644473600000000 " | 629 "SET last_access_utc = last_access_utc + 11644473600000000 " |
607 "WHERE rowid IN " | 630 "WHERE rowid IN " |
608 "(SELECT rowid FROM cookies WHERE " | 631 "(SELECT rowid FROM cookies WHERE " |
609 "last_access_utc > 0 AND last_access_utc < 11644473600000000)"); | 632 "last_access_utc > 0 AND last_access_utc < 11644473600000000)"); |
610 #endif | 633 #endif |
611 ++cur_version; | 634 ++cur_version; |
612 meta_table_.SetVersionNumber(cur_version); | 635 meta_table_.SetVersionNumber(cur_version); |
613 transaction.Commit(); | 636 transaction.Commit(); |
614 } | 637 } |
615 | 638 |
639 if (cur_version == 4) { | |
640 sql::Transaction transaction(db_.get()); | |
erikwright (departed)
2011/11/28 16:18:16
Please add a metric, recorded and reported here, f
marja
2011/11/29 12:56:01
Done.
| |
641 if (!transaction.Begin()) | |
642 return false; | |
643 if (!db_->Execute("ALTER TABLE cookies " | |
644 "ADD COLUMN has_expires INTEGER DEFAULT 1") || | |
erikwright (departed)
2011/11/28 16:18:16
I don't see any documentation that states that the
marja
2011/11/29 12:56:01
Done. (1 & 3)
| |
645 !db_->Execute("ALTER TABLE cookies " | |
646 "ADD COLUMN persistent INTEGER DEFAULT 1")) { | |
647 LOG(WARNING) << "Unable to update cookie database to version 5."; | |
648 return false; | |
649 } | |
650 ++cur_version; | |
651 meta_table_.SetVersionNumber(cur_version); | |
652 meta_table_.SetCompatibleVersionNumber( | |
653 std::min(cur_version, kCompatibleVersionNumber)); | |
654 transaction.Commit(); | |
655 } | |
656 | |
616 // Put future migration cases here. | 657 // Put future migration cases here. |
617 | 658 |
618 // When the version is too old, we just try to continue anyway, there should | 659 // 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. | 660 // not be a released product that makes a database too old for us to handle. |
620 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 661 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
621 "Cookie database version " << cur_version << " is too old to handle."; | 662 "Cookie database version " << cur_version << " is too old to handle."; |
622 | 663 |
623 return true; | 664 return true; |
624 } | 665 } |
625 | 666 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 pending_.swap(ops); | 720 pending_.swap(ops); |
680 num_pending_ = 0; | 721 num_pending_ = 0; |
681 } | 722 } |
682 | 723 |
683 // Maybe an old timer fired or we are already Close()'ed. | 724 // Maybe an old timer fired or we are already Close()'ed. |
684 if (!db_.get() || ops.empty()) | 725 if (!db_.get() || ops.empty()) |
685 return; | 726 return; |
686 | 727 |
687 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 728 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
688 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " | 729 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " |
689 "expires_utc, secure, httponly, last_access_utc) " | 730 "expires_utc, secure, httponly, last_access_utc, has_expires, " |
690 "VALUES (?,?,?,?,?,?,?,?,?)")); | 731 "persistent) " |
732 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); | |
691 if (!add_smt) { | 733 if (!add_smt) { |
692 NOTREACHED(); | 734 NOTREACHED(); |
693 return; | 735 return; |
694 } | 736 } |
695 | 737 |
696 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 738 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
697 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); | 739 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); |
698 if (!update_access_smt) { | 740 if (!update_access_smt) { |
699 NOTREACHED(); | 741 NOTREACHED(); |
700 return; | 742 return; |
(...skipping 20 matching lines...) Expand all Loading... | |
721 add_smt.Reset(); | 763 add_smt.Reset(); |
722 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); | 764 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); |
723 add_smt.BindString(1, po->cc().Domain()); | 765 add_smt.BindString(1, po->cc().Domain()); |
724 add_smt.BindString(2, po->cc().Name()); | 766 add_smt.BindString(2, po->cc().Name()); |
725 add_smt.BindString(3, po->cc().Value()); | 767 add_smt.BindString(3, po->cc().Value()); |
726 add_smt.BindString(4, po->cc().Path()); | 768 add_smt.BindString(4, po->cc().Path()); |
727 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); | 769 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); |
728 add_smt.BindInt(6, po->cc().IsSecure()); | 770 add_smt.BindInt(6, po->cc().IsSecure()); |
729 add_smt.BindInt(7, po->cc().IsHttpOnly()); | 771 add_smt.BindInt(7, po->cc().IsHttpOnly()); |
730 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); | 772 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); |
773 add_smt.BindInt(9, po->cc().DoesExpire()); | |
774 add_smt.BindInt(10, po->cc().IsPersistent()); | |
731 if (!add_smt.Run()) | 775 if (!add_smt.Run()) |
732 NOTREACHED() << "Could not add a cookie to the DB."; | 776 NOTREACHED() << "Could not add a cookie to the DB."; |
733 break; | 777 break; |
734 | 778 |
735 case PendingOperation::COOKIE_UPDATEACCESS: | 779 case PendingOperation::COOKIE_UPDATEACCESS: |
736 update_access_smt.Reset(); | 780 update_access_smt.Reset(); |
737 update_access_smt.BindInt64(0, | 781 update_access_smt.BindInt64(0, |
738 po->cc().LastAccessDate().ToInternalValue()); | 782 po->cc().LastAccessDate().ToInternalValue()); |
739 update_access_smt.BindInt64(1, | 783 update_access_smt.BindInt64(1, |
740 po->cc().CreationDate().ToInternalValue()); | 784 po->cc().CreationDate().ToInternalValue()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 | 838 |
795 if (clear_local_state_on_exit_) | 839 if (clear_local_state_on_exit_) |
796 file_util::Delete(path_, false); | 840 file_util::Delete(path_, false); |
797 } | 841 } |
798 | 842 |
799 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( | 843 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( |
800 bool clear_local_state) { | 844 bool clear_local_state) { |
801 base::AutoLock locked(lock_); | 845 base::AutoLock locked(lock_); |
802 clear_local_state_on_exit_ = clear_local_state; | 846 clear_local_state_on_exit_ = clear_local_state; |
803 } | 847 } |
848 | |
849 void SQLitePersistentCookieStore::Backend::DeleteSessionCookies() { | |
850 { | |
851 base::AutoLock locked(lock_); | |
852 return_session_cookies_ = false; | |
853 } | |
854 BrowserThread::PostTask( | |
855 BrowserThread::DB, FROM_HERE, | |
856 base::Bind(&Backend::DeleteSessionCookiesOnDBThread, this)); | |
857 } | |
858 | |
859 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnDBThread() { | |
860 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
861 // If the store hasn't been initialized, the session cookie deletion is done | |
862 // after all cookies have been loaded. | |
863 if (!initialized_) | |
864 return; | |
865 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0")) | |
866 LOG(WARNING) << "Unable to delete session cookies."; | |
867 } | |
868 | |
804 SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path) | 869 SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path) |
805 : backend_(new Backend(path)) { | 870 : backend_(new Backend(path)) { |
806 } | 871 } |
807 | 872 |
808 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 873 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
809 if (backend_.get()) { | 874 if (backend_.get()) { |
810 backend_->Close(); | 875 backend_->Close(); |
811 // Release our reference, it will probably still have a reference if the | 876 // Release our reference, it will probably still have a reference if the |
812 // background thread has not run Close() yet. | 877 // background thread has not run Close() yet. |
813 backend_ = NULL; | 878 backend_ = NULL; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 if (backend_.get()) | 912 if (backend_.get()) |
848 backend_->SetClearLocalStateOnExit(clear_local_state); | 913 backend_->SetClearLocalStateOnExit(clear_local_state); |
849 } | 914 } |
850 | 915 |
851 void SQLitePersistentCookieStore::Flush(Task* completion_task) { | 916 void SQLitePersistentCookieStore::Flush(Task* completion_task) { |
852 if (backend_.get()) | 917 if (backend_.get()) |
853 backend_->Flush(completion_task); | 918 backend_->Flush(completion_task); |
854 else if (completion_task) | 919 else if (completion_task) |
855 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 920 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
856 } | 921 } |
922 | |
923 void SQLitePersistentCookieStore::DeleteSessionCookies() { | |
924 if (backend_.get()) | |
925 backend_->DeleteSessionCookies(); | |
926 } | |
OLD | NEW |