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

Unified Diff: chrome/browser/net/sqlite_persistent_cookie_store.cc

Issue 8533013: SessionRestore: Store session cookies and restore them if chrome crashes or auto-restarts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/sqlite_persistent_cookie_store.cc
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc
index 444e1fa78fb0fdae0813e55b82440250a91e2ca4..06e2f9aee111099e5b429bcf09337f5aba5a4d98 100644
--- a/chrome/browser/net/sqlite_persistent_cookie_store.cc
+++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc
@@ -63,6 +63,7 @@ class SQLitePersistentCookieStore::Backend
db_(NULL),
num_pending_(0),
clear_local_state_on_exit_(false),
+ clear_session_state_on_exit_(true),
initialized_(false),
num_priority_waiting_(0),
total_priority_requests_(0) {
@@ -92,6 +93,7 @@ class SQLitePersistentCookieStore::Backend
void Close();
void SetClearLocalStateOnExit(bool clear_local_state);
+ void SetClearSessionStateOnExit(bool clear_session_state);
private:
friend class base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend>;
@@ -185,7 +187,10 @@ class SQLitePersistentCookieStore::Backend
PendingOperationsList::size_type num_pending_;
// True if the persistent store should be deleted upon destruction.
bool clear_local_state_on_exit_;
- // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_|
+ // True if the session cookies should be deleted upon destruction.
+ bool clear_session_state_on_exit_;
+ // Guard |cookies_|, |pending_|, |num_pending_|, |clear_local_state_on_exit_|,
+ // |clear_session_state_on_exit_|.
base::Lock lock_;
// Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce
@@ -226,8 +231,8 @@ class SQLitePersistentCookieStore::Backend
// Version 3 updated the database to include the last access time, so we can
// expire them in decreasing order of use when we've reached the maximum
// number of cookies.
-static const int kCurrentVersionNumber = 4;
-static const int kCompatibleVersionNumber = 3;
+static const int kCurrentVersionNumber = 5;
+static const int kCompatibleVersionNumber = 5;
namespace {
@@ -263,11 +268,12 @@ bool InitTable(sql::Connection* db) {
"name TEXT NOT NULL,"
"value TEXT NOT NULL,"
"path TEXT NOT NULL,"
- // We only store persistent, so we know it expires
"expires_utc INTEGER NOT NULL,"
"secure INTEGER NOT NULL,"
"httponly INTEGER NOT NULL,"
- "last_access_utc INTEGER NOT NULL)"))
+ "last_access_utc INTEGER NOT NULL,"
+ "has_expires INTEGER NOT NULL,"
+ "persistent INTEGER NOT NULL)"))
return false;
}
@@ -507,7 +513,8 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE,
"SELECT creation_utc, host_key, name, value, path, expires_utc, secure, "
- "httponly, last_access_utc FROM cookies WHERE host_key = ?"));
+ "httponly, last_access_utc, has_expires, persistent FROM cookies "
+ "WHERE host_key = ?"));
if (!smt) {
NOTREACHED() << "select statement prep failed";
db_.reset();
@@ -534,8 +541,8 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
smt.ColumnInt(6) != 0, // secure
smt.ColumnInt(7) != 0, // httponly
- true, // has_expires
- true)); // is_persistent
+ smt.ColumnInt(9) != 0, // has_expires
+ smt.ColumnInt(10) != 0)); // is_persistent
DLOG_IF(WARNING,
cc->CreationDate() > Time::Now()) << L"CreationDate too recent";
cookies.push_back(cc.release());
@@ -613,6 +620,24 @@ bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() {
transaction.Commit();
}
+ if (cur_version == 4) {
+ sql::Transaction transaction(db_.get());
+ if (!transaction.Begin())
+ return false;
+ if (!db_->Execute("ALTER TABLE cookies "
+ "ADD COLUMN has_expires INTEGER DEFAULT 1") ||
+ !db_->Execute("ALTER TABLE cookies "
+ "ADD COLUMN persistent INTEGER DEFAULT 1")) {
+ LOG(WARNING) << "Unable to update cookie database to version 5.";
+ return false;
+ }
+ ++cur_version;
+ meta_table_.SetVersionNumber(cur_version);
+ meta_table_.SetCompatibleVersionNumber(
+ std::min(cur_version, kCompatibleVersionNumber));
+ transaction.Commit();
+ }
+
// Put future migration cases here.
// When the version is too old, we just try to continue anyway, there should
@@ -686,8 +711,9 @@ void SQLitePersistentCookieStore::Backend::Commit() {
sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE,
"INSERT INTO cookies (creation_utc, host_key, name, value, path, "
- "expires_utc, secure, httponly, last_access_utc) "
- "VALUES (?,?,?,?,?,?,?,?,?)"));
+ "expires_utc, secure, httponly, last_access_utc, has_expires, "
+ "persistent) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?)"));
if (!add_smt) {
NOTREACHED();
return;
@@ -728,6 +754,8 @@ void SQLitePersistentCookieStore::Backend::Commit() {
add_smt.BindInt(6, po->cc().IsSecure());
add_smt.BindInt(7, po->cc().IsHttpOnly());
add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue());
+ add_smt.BindInt(9, po->cc().DoesExpire());
+ add_smt.BindInt(10, po->cc().IsPersistent());
if (!add_smt.Run())
NOTREACHED() << "Could not add a cookie to the DB.";
break;
@@ -790,6 +818,15 @@ void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() {
// Commit any pending operations
Commit();
+ // Delete session cookies, but only if we're not going to delete the whole DB.
+ if (!clear_local_state_on_exit_ && clear_session_state_on_exit_) {
+ if (InitializeDatabase()) {
+ DCHECK(db_.get());
+ if (!db_->Execute("DELETE FROM cookies WHERE persistent == 0"))
jochen (gone - plz use gerrit) 2011/11/25 14:45:14 maybe add a field that says "discard session cooki
marja 2011/11/28 15:22:01 In the latest version, it uses the "did chrome cra
+ LOG(WARNING) << "Unable to delete session cookies.";
+ }
+ }
+
db_.reset();
if (clear_local_state_on_exit_)
@@ -801,6 +838,13 @@ void SQLitePersistentCookieStore::Backend::SetClearLocalStateOnExit(
base::AutoLock locked(lock_);
clear_local_state_on_exit_ = clear_local_state;
}
+
+void SQLitePersistentCookieStore::Backend::SetClearSessionStateOnExit(
+ bool clear_session_state) {
+ base::AutoLock locked(lock_);
+ clear_session_state_on_exit_ = clear_session_state;
+}
+
SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path)
: backend_(new Backend(path)) {
}
@@ -848,6 +892,12 @@ void SQLitePersistentCookieStore::SetClearLocalStateOnExit(
backend_->SetClearLocalStateOnExit(clear_local_state);
}
+void SQLitePersistentCookieStore::SetClearSessionStateOnExit(
+ bool clear_session_state) {
+ if (backend_.get())
+ backend_->SetClearSessionStateOnExit(clear_session_state);
+}
+
void SQLitePersistentCookieStore::Flush(Task* completion_task) {
if (backend_.get())
backend_->Flush(completion_task);

Powered by Google App Engine
This is Rietveld 408576698