Chromium Code Reviews| Index: chrome/browser/net/sqlite_origin_bound_cert_store.cc |
| diff --git a/chrome/browser/net/sqlite_origin_bound_cert_store.cc b/chrome/browser/net/sqlite_origin_bound_cert_store.cc |
| index 83d07bd335db5fa1ae5e705682d3eeed7093ec74..9bbeac92bbbfbdf12754351328c8c6622cc00c58 100644 |
| --- a/chrome/browser/net/sqlite_origin_bound_cert_store.cc |
| +++ b/chrome/browser/net/sqlite_origin_bound_cert_store.cc |
| @@ -16,6 +16,7 @@ |
| #include "base/threading/thread_restrictions.h" |
| #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "net/base/origin_bound_cert_type.h" |
| #include "sql/meta_table.h" |
| #include "sql/statement.h" |
| #include "sql/transaction.h" |
| @@ -115,7 +116,7 @@ class SQLiteOriginBoundCertStore::Backend |
| }; |
| // Version number of the database. |
| -static const int kCurrentVersionNumber = 1; |
| +static const int kCurrentVersionNumber = 2; |
| static const int kCompatibleVersionNumber = 1; |
| namespace { |
| @@ -126,7 +127,8 @@ bool InitTable(sql::Connection* db) { |
| if (!db->Execute("CREATE TABLE origin_bound_certs (" |
| "origin TEXT NOT NULL UNIQUE PRIMARY KEY," |
| "private_key BLOB NOT NULL," |
| - "cert BLOB NOT NULL)")) |
| + "cert BLOB NOT NULL," |
| + "cert_type INTEGER DEFAULT 1)")) |
|
wtc
2011/11/30 23:23:40
Nit: it seems better to put cert_type before priva
mattm
2011/12/02 01:55:59
Could probably do that since the selects and such
wtc
2011/12/02 22:06:59
I didn't realize an upgraded db has to add a new c
|
| return false; |
| } |
| @@ -168,7 +170,7 @@ bool SQLiteOriginBoundCertStore::Backend::Load( |
| // Slurp all the certs into the out-vector. |
| sql::Statement smt(db_->GetUniqueStatement( |
| - "SELECT origin, private_key, cert FROM origin_bound_certs")); |
| + "SELECT origin, private_key, cert, cert_type FROM origin_bound_certs")); |
| if (!smt) { |
| NOTREACHED() << "select statement prep failed"; |
| db_.reset(); |
| @@ -182,6 +184,7 @@ bool SQLiteOriginBoundCertStore::Backend::Load( |
| scoped_ptr<net::DefaultOriginBoundCertStore::OriginBoundCert> cert( |
| new net::DefaultOriginBoundCertStore::OriginBoundCert( |
| smt.ColumnString(0), // origin |
| + static_cast<net::OriginBoundCertType>(smt.ColumnInt(3)), |
| private_key_from_db, |
| cert_from_db)); |
| certs->push_back(cert.release()); |
| @@ -203,6 +206,22 @@ bool SQLiteOriginBoundCertStore::Backend::EnsureDatabaseVersion() { |
| } |
| int cur_version = meta_table_.GetVersionNumber(); |
| + if (cur_version == 1) { |
| + sql::Transaction transaction(db_.get()); |
| + if (!transaction.Begin()) |
| + return false; |
| + if (!db_->Execute("ALTER TABLE origin_bound_certs ADD COLUMN cert_type " |
| + "INTEGER DEFAULT 1")) { |
| + LOG(WARNING) << "Unable to update origin bound cert database to " |
| + << "version 2."; |
| + return false; |
| + } |
| + ++cur_version; |
| + meta_table_.SetVersionNumber(cur_version); |
| + meta_table_.SetCompatibleVersionNumber( |
| + std::min(cur_version, kCompatibleVersionNumber)); |
| + transaction.Commit(); |
| + } |
| // Put future migration cases here. |
| @@ -272,8 +291,8 @@ void SQLiteOriginBoundCertStore::Backend::Commit() { |
| return; |
| sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
| - "INSERT INTO origin_bound_certs (origin, private_key, cert) " |
| - "VALUES (?,?,?)")); |
| + "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type) " |
| + "VALUES (?,?,?,?)")); |
| if (!add_smt) { |
| NOTREACHED(); |
| return; |
| @@ -303,6 +322,7 @@ void SQLiteOriginBoundCertStore::Backend::Commit() { |
| add_smt.BindBlob(1, private_key.data(), private_key.size()); |
| const std::string& cert = po->cert().cert(); |
| add_smt.BindBlob(2, cert.data(), cert.size()); |
| + add_smt.BindInt(3, po->cert().type()); |
| if (!add_smt.Run()) |
| NOTREACHED() << "Could not add an origin bound cert to the DB."; |
| break; |