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

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

Issue 10447117: Unwire the clear on exit preference from the storage systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 years, 6 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // whichever occurs first. 59 // whichever occurs first.
60 class SQLitePersistentCookieStore::Backend 60 class SQLitePersistentCookieStore::Backend
61 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { 61 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> {
62 public: 62 public:
63 Backend(const FilePath& path, 63 Backend(const FilePath& path,
64 bool restore_old_session_cookies, 64 bool restore_old_session_cookies,
65 ClearOnExitPolicy* clear_on_exit_policy) 65 ClearOnExitPolicy* clear_on_exit_policy)
66 : path_(path), 66 : path_(path),
67 db_(NULL), 67 db_(NULL),
68 num_pending_(0), 68 num_pending_(0),
69 clear_local_state_on_exit_(false), 69 force_keep_session_state_(false),
70 initialized_(false), 70 initialized_(false),
71 restore_old_session_cookies_(restore_old_session_cookies), 71 restore_old_session_cookies_(restore_old_session_cookies),
72 clear_on_exit_policy_(clear_on_exit_policy), 72 clear_on_exit_policy_(clear_on_exit_policy),
73 num_cookies_read_(0), 73 num_cookies_read_(0),
74 num_priority_waiting_(0), 74 num_priority_waiting_(0),
75 total_priority_requests_(0) { 75 total_priority_requests_(0) {
76 } 76 }
77 77
78 // Creates or loads the SQLite database. 78 // Creates or loads the SQLite database.
79 void Load(const LoadedCallback& loaded_callback); 79 void Load(const LoadedCallback& loaded_callback);
(...skipping 11 matching lines...) Expand all
91 // Batch a cookie deletion. 91 // Batch a cookie deletion.
92 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); 92 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc);
93 93
94 // Commit pending operations as soon as possible. 94 // Commit pending operations as soon as possible.
95 void Flush(const base::Closure& callback); 95 void Flush(const base::Closure& callback);
96 96
97 // Commit any pending operations and close the database. This must be called 97 // Commit any pending operations and close the database. This must be called
98 // before the object is destructed. 98 // before the object is destructed.
99 void Close(); 99 void Close();
100 100
101 void SetClearLocalStateOnExit(bool clear_local_state); 101 void SetForceKeepSessionState();
102 102
103 private: 103 private:
104 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>; 104 friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>;
105 105
106 // You should call Close() before destructing this object. 106 // You should call Close() before destructing this object.
107 ~Backend() { 107 ~Backend() {
108 DCHECK(!db_.get()) << "Close should have already been called."; 108 DCHECK(!db_.get()) << "Close should have already been called.";
109 DCHECK(num_pending_ == 0 && pending_.empty()); 109 DCHECK(num_pending_ == 0 && pending_.empty());
110 } 110 }
111 111
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 void DeleteSessionCookiesOnShutdown(); 190 void DeleteSessionCookiesOnShutdown();
191 191
192 FilePath path_; 192 FilePath path_;
193 scoped_ptr<sql::Connection> db_; 193 scoped_ptr<sql::Connection> db_;
194 sql::MetaTable meta_table_; 194 sql::MetaTable meta_table_;
195 195
196 typedef std::list<PendingOperation*> PendingOperationsList; 196 typedef std::list<PendingOperation*> PendingOperationsList;
197 PendingOperationsList pending_; 197 PendingOperationsList pending_;
198 PendingOperationsList::size_type num_pending_; 198 PendingOperationsList::size_type num_pending_;
199 // True if the persistent store should be deleted upon destruction. 199 // True if the persistent store should skip delete on exit rules.
200 bool clear_local_state_on_exit_; 200 bool force_keep_session_state_;
201 // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_| 201 // Guard |cookies_|, |pending_|, |num_pending_|, |force_keep_session_state_|
202 base::Lock lock_; 202 base::Lock lock_;
203 203
204 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce 204 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce
205 // the number of messages sent to the IO thread. Sent back in response to 205 // the number of messages sent to the IO thread. Sent back in response to
206 // individual load requests for domain keys or when all loading completes. 206 // individual load requests for domain keys or when all loading completes.
207 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; 207 std::vector<net::CookieMonster::CanonicalCookie*> cookies_;
208 208
209 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. 209 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB.
210 std::map<std::string, std::set<std::string> > keys_to_load_; 210 std::map<std::string, std::set<std::string> > keys_to_load_;
211 211
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 BrowserThread::DB, FROM_HERE, 914 BrowserThread::DB, FROM_HERE,
915 base::Bind(&Backend::InternalBackgroundClose, this)); 915 base::Bind(&Backend::InternalBackgroundClose, this));
916 } 916 }
917 } 917 }
918 918
919 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() { 919 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() {
920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
921 // Commit any pending operations 921 // Commit any pending operations
922 Commit(); 922 Commit();
923 923
924 if (!clear_local_state_on_exit_ && clear_on_exit_policy_.get() && 924 if (!force_keep_session_state_ && clear_on_exit_policy_.get() &&
925 clear_on_exit_policy_->HasClearOnExitOrigins()) { 925 clear_on_exit_policy_->HasClearOnExitOrigins()) {
926 DeleteSessionCookiesOnShutdown(); 926 DeleteSessionCookiesOnShutdown();
927 } 927 }
928 928
929 db_.reset(); 929 db_.reset();
930
931 if (clear_local_state_on_exit_)
932 file_util::Delete(path_, false);
933 } 930 }
934 931
935 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnShutdown() { 932 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnShutdown() {
936 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
937 934
938 if (!db_.get()) 935 if (!db_.get())
939 return; 936 return;
940 937
941 sql::Statement del_smt(db_->GetCachedStatement( 938 sql::Statement del_smt(db_->GetCachedStatement(
942 SQL_FROM_HERE, "DELETE FROM cookies WHERE host_key=? AND secure=?")); 939 SQL_FROM_HERE, "DELETE FROM cookies WHERE host_key=? AND secure=?"));
(...skipping 23 matching lines...) Expand all
966 del_smt.BindString(0, it->first.first); 963 del_smt.BindString(0, it->first.first);
967 del_smt.BindInt(1, it->first.second); 964 del_smt.BindInt(1, it->first.second);
968 if (!del_smt.Run()) 965 if (!del_smt.Run())
969 NOTREACHED() << "Could not delete a cookie from the DB."; 966 NOTREACHED() << "Could not delete a cookie from the DB.";
970 } 967 }
971 968
972 if (!transaction.Commit()) 969 if (!transaction.Commit())
973 LOG(WARNING) << "Unable to delete cookies on shutdown."; 970 LOG(WARNING) << "Unable to delete cookies on shutdown.";
974 } 971 }
975 972
976 void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit( 973 void SQLitePersistentCookieStore::Backend::SetForceKeepSessionState() {
977 bool clear_local_state) {
978 base::AutoLock locked(lock_); 974 base::AutoLock locked(lock_);
979 clear_local_state_on_exit_ = clear_local_state; 975 force_keep_session_state_ = true;
980 } 976 }
981 977
982 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnStartup() { 978 void SQLitePersistentCookieStore::Backend::DeleteSessionCookiesOnStartup() {
983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
984 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0")) 980 if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0"))
985 LOG(WARNING) << "Unable to delete session cookies."; 981 LOG(WARNING) << "Unable to delete session cookies.";
986 } 982 }
987 983
988 SQLitePersistentCookieStore::SQLitePersistentCookieStore( 984 SQLitePersistentCookieStore::SQLitePersistentCookieStore(
989 const FilePath& path, 985 const FilePath& path,
(...skipping 24 matching lines...) Expand all
1014 if (backend_.get()) 1010 if (backend_.get())
1015 backend_->UpdateCookieAccessTime(cc); 1011 backend_->UpdateCookieAccessTime(cc);
1016 } 1012 }
1017 1013
1018 void SQLitePersistentCookieStore::DeleteCookie( 1014 void SQLitePersistentCookieStore::DeleteCookie(
1019 const net::CookieMonster::CanonicalCookie& cc) { 1015 const net::CookieMonster::CanonicalCookie& cc) {
1020 if (backend_.get()) 1016 if (backend_.get())
1021 backend_->DeleteCookie(cc); 1017 backend_->DeleteCookie(cc);
1022 } 1018 }
1023 1019
1024 void SQLitePersistentCookieStore::SetClearLocalStateOnExit( 1020 void SQLitePersistentCookieStore::SetForceKeepSessionState() {
erikwright (departed) 2012/06/01 15:17:18 I gather that, by design, one would never _un_set
1025 bool clear_local_state) {
1026 if (backend_.get()) 1021 if (backend_.get())
1027 backend_->SetClearLocalStateOnExit(clear_local_state); 1022 backend_->SetForceKeepSessionState();
1028 } 1023 }
1029 1024
1030 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { 1025 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) {
1031 if (backend_.get()) 1026 if (backend_.get())
1032 backend_->Flush(callback); 1027 backend_->Flush(callback);
1033 else if (!callback.is_null()) 1028 else if (!callback.is_null())
1034 MessageLoop::current()->PostTask(FROM_HERE, callback); 1029 MessageLoop::current()->PostTask(FROM_HERE, callback);
1035 } 1030 }
1036 1031
1037 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { 1032 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
1038 if (backend_.get()) { 1033 if (backend_.get()) {
1039 backend_->Close(); 1034 backend_->Close();
1040 // Release our reference, it will probably still have a reference if the 1035 // Release our reference, it will probably still have a reference if the
1041 // background thread has not run Close() yet. 1036 // background thread has not run Close() yet.
1042 backend_ = NULL; 1037 backend_ = NULL;
1043 } 1038 }
1044 } 1039 }
OLDNEW
« no previous file with comments | « chrome/browser/net/sqlite_persistent_cookie_store.h ('k') | chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698