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

Side by Side Diff: chrome/browser/net/sqlite_persistent_cookie_store.cc

Issue 10407124: Don't force non-session only cookies to be session only cookies, instead delete on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
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 "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 12 matching lines...) Expand all
23 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "base/time.h" 25 #include "base/time.h"
26 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" 26 #include "chrome/browser/diagnostics/sqlite_diagnostics.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 #include "net/base/registry_controlled_domain.h" 29 #include "net/base/registry_controlled_domain.h"
30 #include "sql/meta_table.h" 30 #include "sql/meta_table.h"
31 #include "sql/statement.h" 31 #include "sql/statement.h"
32 #include "sql/transaction.h" 32 #include "sql/transaction.h"
33 #include "webkit/quota/special_storage_policy.h"
33 34
34 using base::Time; 35 using base::Time;
35 using content::BrowserThread; 36 using content::BrowserThread;
36 37
37 // This class is designed to be shared between any calling threads and the 38 // This class is designed to be shared between any calling threads and the
38 // database thread. It batches operations and commits them on a timer. 39 // database thread. It batches operations and commits them on a timer.
39 // 40 //
40 // SQLitePersistentCookieStore::Load is called to load all cookies. It 41 // SQLitePersistentCookieStore::Load is called to load all cookies. It
41 // delegates to Backend::Load, which posts a Backend::LoadAndNotifyOnDBThread 42 // delegates to Backend::Load, which posts a Backend::LoadAndNotifyOnDBThread
42 // task to the DB thread. This task calls Backend::ChainLoadCookies(), which 43 // task to the DB thread. This task calls Backend::ChainLoadCookies(), which
43 // repeatedly posts itself to the DB thread to load each eTLD+1's cookies in 44 // repeatedly posts itself to the DB thread to load each eTLD+1's cookies in
44 // separate tasks. When this is complete, Backend::CompleteLoadOnIOThread is 45 // separate tasks. When this is complete, Backend::CompleteLoadOnIOThread is
45 // posted to the IO thread, which notifies the caller of 46 // posted to the IO thread, which notifies the caller of
46 // SQLitePersistentCookieStore::Load that the load is complete. 47 // SQLitePersistentCookieStore::Load that the load is complete.
47 // 48 //
48 // If a priority load request is invoked via SQLitePersistentCookieStore:: 49 // If a priority load request is invoked via SQLitePersistentCookieStore::
49 // LoadCookiesForKey, it is delegated to Backend::LoadCookiesForKey, which posts 50 // LoadCookiesForKey, it is delegated to Backend::LoadCookiesForKey, which posts
50 // Backend::LoadKeyAndNotifyOnDBThread to the DB thread. That routine loads just 51 // Backend::LoadKeyAndNotifyOnDBThread to the DB thread. That routine loads just
51 // that single domain key (eTLD+1)'s cookies, and posts a Backend:: 52 // that single domain key (eTLD+1)'s cookies, and posts a Backend::
52 // CompleteLoadForKeyOnIOThread to the IO thread to notify the caller of 53 // CompleteLoadForKeyOnIOThread to the IO thread to notify the caller of
53 // SQLitePersistentCookieStore::LoadCookiesForKey that that load is complete. 54 // SQLitePersistentCookieStore::LoadCookiesForKey that that load is complete.
54 // 55 //
55 // Subsequent to loading, mutations may be queued by any thread using 56 // Subsequent to loading, mutations may be queued by any thread using
56 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to 57 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to
57 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), 58 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(),
58 // whichever occurs first. 59 // whichever occurs first.
59 class SQLitePersistentCookieStore::Backend 60 class SQLitePersistentCookieStore::Backend
60 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { 61 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> {
61 public: 62 public:
62 Backend(const FilePath& path, bool restore_old_session_cookies) 63 Backend(const FilePath& path,
64 bool restore_old_session_cookies,
65 quota::SpecialStoragePolicy* special_storage_policy)
63 : path_(path), 66 : path_(path),
64 db_(NULL), 67 db_(NULL),
65 num_pending_(0), 68 num_pending_(0),
66 clear_local_state_on_exit_(false), 69 clear_local_state_on_exit_(false),
67 initialized_(false), 70 initialized_(false),
68 restore_old_session_cookies_(restore_old_session_cookies), 71 restore_old_session_cookies_(restore_old_session_cookies),
72 special_storage_policy_(special_storage_policy),
69 num_cookies_read_(0), 73 num_cookies_read_(0),
70 num_priority_waiting_(0), 74 num_priority_waiting_(0),
71 total_priority_requests_(0) { 75 total_priority_requests_(0) {
72 } 76 }
73 77
74 // Creates or loads the SQLite database. 78 // Creates or loads the SQLite database.
75 void Load(const LoadedCallback& loaded_callback); 79 void Load(const LoadedCallback& loaded_callback);
76 80
77 // Loads cookies for the domain key (eTLD+1). 81 // Loads cookies for the domain key (eTLD+1).
78 void LoadCookiesForKey(const std::string& domain, 82 void LoadCookiesForKey(const std::string& domain,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bool LoadCookiesForDomains(const std::set<std::string>& key); 178 bool LoadCookiesForDomains(const std::set<std::string>& key);
175 179
176 // Batch a cookie operation (add or delete) 180 // Batch a cookie operation (add or delete)
177 void BatchOperation(PendingOperation::OperationType op, 181 void BatchOperation(PendingOperation::OperationType op,
178 const net::CookieMonster::CanonicalCookie& cc); 182 const net::CookieMonster::CanonicalCookie& cc);
179 // Commit our pending operations to the database. 183 // Commit our pending operations to the database.
180 void Commit(); 184 void Commit();
181 // Close() executed on the background thread. 185 // Close() executed on the background thread.
182 void InternalBackgroundClose(); 186 void InternalBackgroundClose();
183 187
184 void DeleteSessionCookies(); 188 void DeleteSessionCookiesOnStartup();
189
190 void DeleteSessionCookiesOnShutdown();
185 191
186 FilePath path_; 192 FilePath path_;
187 scoped_ptr<sql::Connection> db_; 193 scoped_ptr<sql::Connection> db_;
188 sql::MetaTable meta_table_; 194 sql::MetaTable meta_table_;
189 195
190 typedef std::list<PendingOperation*> PendingOperationsList; 196 typedef std::list<PendingOperation*> PendingOperationsList;
191 PendingOperationsList pending_; 197 PendingOperationsList pending_;
192 PendingOperationsList::size_type num_pending_; 198 PendingOperationsList::size_type num_pending_;
193 // True if the persistent store should be deleted upon destruction. 199 // True if the persistent store should be deleted upon destruction.
194 bool clear_local_state_on_exit_; 200 bool clear_local_state_on_exit_;
195 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| 201 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_|,
202 // and |cookies_per_domain_|.
196 base::Lock lock_; 203 base::Lock lock_;
197 204
198 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce 205 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce
199 // the number of messages sent to the IO thread. Sent back in response to 206 // the number of messages sent to the IO thread. Sent back in response to
200 // individual load requests for domain keys or when all loading completes. 207 // individual load requests for domain keys or when all loading completes.
201 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; 208 std::vector<net::CookieMonster::CanonicalCookie*> cookies_;
202 209
203 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. 210 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB.
204 std::map<std::string, std::set<std::string> > keys_to_load_; 211 std::map<std::string, std::set<std::string> > keys_to_load_;
205 212
213 // Map of domain keys(eTLD+1) to number of cookies in the database.
214 std::map<std::string, int> cookies_per_domain_;
215
206 // Indicates if DB has been initialized. 216 // Indicates if DB has been initialized.
207 bool initialized_; 217 bool initialized_;
208 218
209 // If false, we should filter out session cookies when reading the DB. 219 // If false, we should filter out session cookies when reading the DB.
210 bool restore_old_session_cookies_; 220 bool restore_old_session_cookies_;
211 221
222 // Storage Policy defining what data is deleted on shutdown.
223 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
224
212 // The cumulative time spent loading the cookies on the DB thread. Incremented 225 // The cumulative time spent loading the cookies on the DB thread. Incremented
213 // and reported from the DB thread. 226 // and reported from the DB thread.
214 base::TimeDelta cookie_load_duration_; 227 base::TimeDelta cookie_load_duration_;
215 228
216 // The total number of cookies read. Incremented and reported on the DB 229 // The total number of cookies read. Incremented and reported on the DB
217 // thread. 230 // thread.
218 int num_cookies_read_; 231 int num_cookies_read_;
219 232
220 // Guards the following metrics-related properties (only accessed when 233 // Guards the following metrics-related properties (only accessed when
221 // starting/completing priority loads or completing the total load). 234 // starting/completing priority loads or completing the total load).
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (load_success && keys_to_load_.size() > 0) { 571 if (load_success && keys_to_load_.size() > 0) {
559 BrowserThread::PostTask( 572 BrowserThread::PostTask(
560 BrowserThread::DB, FROM_HERE, 573 BrowserThread::DB, FROM_HERE,
561 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); 574 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback));
562 } else { 575 } else {
563 BrowserThread::PostTask( 576 BrowserThread::PostTask(
564 BrowserThread::IO, FROM_HERE, 577 BrowserThread::IO, FROM_HERE,
565 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, 578 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread,
566 this, loaded_callback, load_success)); 579 this, loaded_callback, load_success));
567 if (load_success && !restore_old_session_cookies_) 580 if (load_success && !restore_old_session_cookies_)
568 DeleteSessionCookies(); 581 DeleteSessionCookiesOnStartup();
569 } 582 }
570 } 583 }
571 584
572 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( 585 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
573 const std::set<std::string>& domains) { 586 const std::set<std::string>& domains) {
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
575 588
576 sql::Statement smt; 589 sql::Statement smt;
577 if (restore_old_session_cookies_) { 590 if (restore_old_session_cookies_) {
578 smt.Assign(db_->GetCachedStatement( 591 smt.Assign(db_->GetCachedStatement(
579 SQL_FROM_HERE, 592 SQL_FROM_HERE,
580 "SELECT creation_utc, host_key, name, value, path, expires_utc, " 593 "SELECT creation_utc, host_key, name, value, path, expires_utc, "
581 "secure, httponly, last_access_utc, has_expires, persistent " 594 "secure, httponly, last_access_utc, has_expires, persistent "
582 "FROM cookies WHERE host_key = ?")); 595 "FROM cookies WHERE host_key = ?"));
583 } else { 596 } else {
584 smt.Assign(db_->GetCachedStatement( 597 smt.Assign(db_->GetCachedStatement(
585 SQL_FROM_HERE, 598 SQL_FROM_HERE,
586 "SELECT creation_utc, host_key, name, value, path, expires_utc, " 599 "SELECT creation_utc, host_key, name, value, path, expires_utc, "
587 "secure, httponly, last_access_utc, has_expires, persistent " 600 "secure, httponly, last_access_utc, has_expires, persistent "
588 "FROM cookies WHERE host_key = ? AND persistent = 1")); 601 "FROM cookies WHERE host_key = ? AND persistent = 1"));
589 } 602 }
590 if (!smt.is_valid()) { 603 if (!smt.is_valid()) {
591 smt.Clear(); // Disconnect smt_ref from db_. 604 smt.Clear(); // Disconnect smt_ref from db_.
592 db_.reset(); 605 db_.reset();
593 return false; 606 return false;
594 } 607 }
595 608
596 std::vector<net::CookieMonster::CanonicalCookie*> cookies; 609 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
597 std::set<std::string>::const_iterator it = domains.begin(); 610 std::set<std::string>::const_iterator it = domains.begin();
611 std::map<std::string, int> cookies_per_domain;
598 for (; it != domains.end(); ++it) { 612 for (; it != domains.end(); ++it) {
599 smt.BindString(0, *it); 613 smt.BindString(0, *it);
600 while (smt.Step()) { 614 while (smt.Step()) {
615 cookies_per_domain[*it]++;
601 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( 616 scoped_ptr<net::CookieMonster::CanonicalCookie> cc(
602 new net::CookieMonster::CanonicalCookie( 617 new net::CookieMonster::CanonicalCookie(
603 // The "source" URL is not used with persisted cookies. 618 // The "source" URL is not used with persisted cookies.
604 GURL(), // Source 619 GURL(), // Source
605 smt.ColumnString(2), // name 620 smt.ColumnString(2), // name
606 smt.ColumnString(3), // value 621 smt.ColumnString(3), // value
607 smt.ColumnString(1), // domain 622 smt.ColumnString(1), // domain
608 smt.ColumnString(4), // path 623 smt.ColumnString(4), // path
609 std::string(), // TODO(abarth): Persist mac_key 624 std::string(), // TODO(abarth): Persist mac_key
610 std::string(), // TODO(abarth): Persist mac_algorithm 625 std::string(), // TODO(abarth): Persist mac_algorithm
611 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc 626 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc
612 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc 627 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc
613 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc 628 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
614 smt.ColumnInt(6) != 0, // secure 629 smt.ColumnInt(6) != 0, // secure
615 smt.ColumnInt(7) != 0, // httponly 630 smt.ColumnInt(7) != 0, // httponly
616 smt.ColumnInt(9) != 0, // has_expires 631 smt.ColumnInt(9) != 0, // has_expires
617 smt.ColumnInt(10) != 0)); // is_persistent 632 smt.ColumnInt(10) != 0)); // is_persistent
618 DLOG_IF(WARNING, 633 DLOG_IF(WARNING,
619 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; 634 cc->CreationDate() > Time::Now()) << L"CreationDate too recent";
620 cookies.push_back(cc.release()); 635 cookies.push_back(cc.release());
621 ++num_cookies_read_; 636 ++num_cookies_read_;
622 } 637 }
623 smt.Reset(true); 638 smt.Reset(true);
624 } 639 }
625 { 640 {
626 base::AutoLock locked(lock_); 641 base::AutoLock locked(lock_);
627 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); 642 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end());
643 std::map<std::string, int>::iterator domain;
644 for (domain = cookies_per_domain.begin();
645 domain != cookies_per_domain.end(); ++domain) {
646 cookies_per_domain_[domain->first] += domain->second;
647 }
628 } 648 }
629 return true; 649 return true;
630 } 650 }
631 651
632 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { 652 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() {
633 // Version check. 653 // Version check.
634 if (!meta_table_.Init( 654 if (!meta_table_.Init(
635 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { 655 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) {
636 return false; 656 return false;
637 } 657 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 833
814 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, 834 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE,
815 "DELETE FROM cookies WHERE creation_utc=?")); 835 "DELETE FROM cookies WHERE creation_utc=?"));
816 if (!del_smt.is_valid()) 836 if (!del_smt.is_valid())
817 return; 837 return;
818 838
819 sql::Transaction transaction(db_.get()); 839 sql::Transaction transaction(db_.get());
820 if (!transaction.Begin()) 840 if (!transaction.Begin())
821 return; 841 return;
822 842
843 std::map<std::string, int> cookies_per_domain;
erikwright (departed) 2012/05/24 11:07:19 cookie_delta_per_domain?
jochen (gone - plz use gerrit) 2012/05/24 11:34:54 Done.
823 for (PendingOperationsList::iterator it = ops.begin(); 844 for (PendingOperationsList::iterator it = ops.begin();
824 it != ops.end(); ++it) { 845 it != ops.end(); ++it) {
825 // Free the cookies as we commit them to the database. 846 // Free the cookies as we commit them to the database.
826 scoped_ptr<PendingOperation> po(*it); 847 scoped_ptr<PendingOperation> po(*it);
827 switch (po->op()) { 848 switch (po->op()) {
828 case PendingOperation::COOKIE_ADD: 849 case PendingOperation::COOKIE_ADD:
850 cookies_per_domain[po->cc().Domain()]++;
829 add_smt.Reset(true); 851 add_smt.Reset(true);
830 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); 852 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue());
831 add_smt.BindString(1, po->cc().Domain()); 853 add_smt.BindString(1, po->cc().Domain());
832 add_smt.BindString(2, po->cc().Name()); 854 add_smt.BindString(2, po->cc().Name());
833 add_smt.BindString(3, po->cc().Value()); 855 add_smt.BindString(3, po->cc().Value());
834 add_smt.BindString(4, po->cc().Path()); 856 add_smt.BindString(4, po->cc().Path());
835 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); 857 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue());
836 add_smt.BindInt(6, po->cc().IsSecure()); 858 add_smt.BindInt(6, po->cc().IsSecure());
837 add_smt.BindInt(7, po->cc().IsHttpOnly()); 859 add_smt.BindInt(7, po->cc().IsHttpOnly());
838 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); 860 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue());
839 add_smt.BindInt(9, po->cc().DoesExpire()); 861 add_smt.BindInt(9, po->cc().DoesExpire());
840 add_smt.BindInt(10, po->cc().IsPersistent()); 862 add_smt.BindInt(10, po->cc().IsPersistent());
841 if (!add_smt.Run()) 863 if (!add_smt.Run())
842 NOTREACHED() << "Could not add a cookie to the DB."; 864 NOTREACHED() << "Could not add a cookie to the DB.";
843 break; 865 break;
844 866
845 case PendingOperation::COOKIE_UPDATEACCESS: 867 case PendingOperation::COOKIE_UPDATEACCESS:
846 update_access_smt.Reset(true); 868 update_access_smt.Reset(true);
847 update_access_smt.BindInt64(0, 869 update_access_smt.BindInt64(0,
848 po->cc().LastAccessDate().ToInternalValue()); 870 po->cc().LastAccessDate().ToInternalValue());
849 update_access_smt.BindInt64(1, 871 update_access_smt.BindInt64(1,
850 po->cc().CreationDate().ToInternalValue()); 872 po->cc().CreationDate().ToInternalValue());
851 if (!update_access_smt.Run()) 873 if (!update_access_smt.Run())
852 NOTREACHED() << "Could not update cookie last access time in the DB."; 874 NOTREACHED() << "Could not update cookie last access time in the DB.";
853 break; 875 break;
854 876
855 case PendingOperation::COOKIE_DELETE: 877 case PendingOperation::COOKIE_DELETE:
878 cookies_per_domain[po->cc().Domain()]--;
856 del_smt.Reset(true); 879 del_smt.Reset(true);
857 del_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); 880 del_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue());
858 if (!del_smt.Run()) 881 if (!del_smt.Run())
859 NOTREACHED() << "Could not delete a cookie from the DB."; 882 NOTREACHED() << "Could not delete a cookie from the DB.";
860 break; 883 break;
861 884
862 default: 885 default:
863 NOTREACHED(); 886 NOTREACHED();
864 break; 887 break;
865 } 888 }
866 } 889 }
867 bool succeeded = transaction.Commit(); 890 bool succeeded = transaction.Commit();
868 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults", 891 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults",
869 succeeded ? 0 : 1, 2); 892 succeeded ? 0 : 1, 2);
893 if (succeeded) {
894 base::AutoLock locked(lock_);
895 std::map<std::string, int>::iterator domain;
896 for (domain = cookies_per_domain.begin();
897 domain != cookies_per_domain.end(); ++domain) {
898 cookies_per_domain_[domain->first] += domain->second;
899 }
900 }
870 } 901 }
871 902
872 void SQLitePersistentCookieStore::Backend::Flush( 903 void SQLitePersistentCookieStore::Backend::Flush(
873 const base::Closure& callback) { 904 const base::Closure& callback) {
874 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); 905 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB));
875 BrowserThread::PostTask( 906 BrowserThread::PostTask(
876 BrowserThread::DB, FROM_HERE, base::Bind(&Backend::Commit, this)); 907 BrowserThread::DB, FROM_HERE, base::Bind(&Backend::Commit, this));
877 if (!callback.is_null()) { 908 if (!callback.is_null()) {
878 // We want the completion task to run immediately after Commit() returns. 909 // We want the completion task to run immediately after Commit() returns.
879 // Posting it from here means there is less chance of another task getting 910 // Posting it from here means there is less chance of another task getting
(...skipping 14 matching lines...) Expand all
894 BrowserThread::DB, FROM_HERE, 925 BrowserThread::DB, FROM_HERE,
895 base::Bind(&Backend::InternalBackgroundClose, this)); 926 base::Bind(&Backend::InternalBackgroundClose, this));
896 } 927 }
897 } 928 }
898 929
899 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() { 930 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() {
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
901 // Commit any pending operations 932 // Commit any pending operations
902 Commit(); 933 Commit();
903 934
935 if (!clear_local_state_on_exit_ && special_storage_policy_.get() &&
936 special_storage_policy_->HasSessionOnlyOrigins()) {
937 DeleteSessionCookiesOnShutdown();
938 }
939
904 db_.reset(); 940 db_.reset();
905 941
906 if (clear_local_state_on_exit_) 942 if (clear_local_state_on_exit_)
907 file_util::Delete(path_, false); 943 file_util::Delete(path_, false);
908 } 944 }
909 945
946 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnShutdown() {
947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
948
949 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE,
950 "DELETE FROM cookies WHERE host_key=?"));
951 if (!del_smt.is_valid()) {
952 LOG(WARNING) << "Unable to delete cookies on shutdown.";
953 return;
954 }
955
956 sql::Transaction transaction(db_.get());
957 if (!transaction.Begin()) {
958 LOG(WARNING) << "Unable to delete cookies on shutdown.";
959 return;
960 }
961
962 base::AutoLock locked(lock_);
963 std::map<std::string, int>::iterator domain;
964 for (domain = cookies_per_domain_.begin();
erikwright (departed) 2012/05/24 11:07:19 I'm all for putting the declaration of domain insi
jochen (gone - plz use gerrit) 2012/05/24 11:34:54 Done.
965 domain != cookies_per_domain_.end(); ++domain) {
966 if (domain->second <= 0) {
967 DCHECK_EQ(0, domain->second);
968 continue;
969 }
970
971 if (!special_storage_policy_->IsStorageSessionOnly(GURL(domain->first)))
972 continue;
973 if (special_storage_policy_->IsStorageProtected(GURL(domain->first)))
974 continue;
975
976 del_smt.Reset(true);
977 del_smt.BindString(0, domain->first);
978 if (!del_smt.Run())
979 NOTREACHED() << "Could not delete a cookie from the DB.";
980 }
981
982 if (!transaction.Commit())
983 LOG(WARNING) << "Unable to delete cookies on shutdown.";
984 }
985
910 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( 986 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit(
911 bool clear_local_state) { 987 bool clear_local_state) {
912 base::AutoLock locked(lock_); 988 base::AutoLock locked(lock_);
913 clear_local_state_on_exit_ = clear_local_state; 989 clear_local_state_on_exit_ = clear_local_state;
914 } 990 }
915 991
916 void SQLitePersistentCookieStore::Backend::DeleteSessionCookies() { 992 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnStartup() {
917 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
918 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0")) 994 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0"))
919 LOG(WARNING) << "Unable to delete session cookies."; 995 LOG(WARNING) << "Unable to delete session cookies.";
920 } 996 }
921 997
922 SQLitePersistentCookieStore::SQLitePersistentCookieStore( 998 SQLitePersistentCookieStore::SQLitePersistentCookieStore(
923 const FilePath& path, 999 const FilePath& path,
924 bool restore_old_session_cookies) 1000 bool restore_old_session_cookies,
925 : backend_(new Backend(path, restore_old_session_cookies)) { 1001 quota::SpecialStoragePolicy* storage_policy)
1002 : backend_(new Backend(path, restore_old_session_cookies, storage_policy)) {
926 } 1003 }
927 1004
928 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { 1005 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
929 backend_->Load(loaded_callback); 1006 backend_->Load(loaded_callback);
930 } 1007 }
931 1008
932 void SQLitePersistentCookieStore::LoadCookiesForKey( 1009 void SQLitePersistentCookieStore::LoadCookiesForKey(
933 const std::string& key, 1010 const std::string& key,
934 const LoadedCallback& loaded_callback) { 1011 const LoadedCallback& loaded_callback) {
935 backend_->LoadCookiesForKey(key, loaded_callback); 1012 backend_->LoadCookiesForKey(key, loaded_callback);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 } 1044 }
968 1045
969 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 1046 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
970 if (backend_.get()) { 1047 if (backend_.get()) {
971 backend_->Close(); 1048 backend_->Close();
972 // Release our reference, it will probably still have a reference if the 1049 // Release our reference, it will probably still have a reference if the
973 // background thread has not run Close() yet. 1050 // background thread has not run Close() yet.
974 backend_ = NULL; 1051 backend_ = NULL;
975 } 1052 }
976 } 1053 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698