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

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

Issue 9365030: More SQL statement usage regularization. Back-touch some (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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_origin_bound_cert_store.h" 5 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 db_.reset(); 169 db_.reset();
170 return false; 170 return false;
171 } 171 }
172 172
173 db_->Preload(); 173 db_->Preload();
174 174
175 // Slurp all the certs into the out-vector. 175 // Slurp all the certs into the out-vector.
176 sql::Statement smt(db_->GetUniqueStatement( 176 sql::Statement smt(db_->GetUniqueStatement(
177 "SELECT origin, private_key, cert, cert_type, expiration_time, " 177 "SELECT origin, private_key, cert, cert_type, expiration_time, "
178 "creation_time FROM origin_bound_certs")); 178 "creation_time FROM origin_bound_certs"));
179 if (!smt) { 179 if (!smt.is_valid()) {
180 NOTREACHED() << "select statement prep failed";
181 db_.reset(); 180 db_.reset();
182 return false; 181 return false;
183 } 182 }
184 183
185 while (smt.Step()) { 184 while (smt.Step()) {
186 std::string private_key_from_db, cert_from_db; 185 std::string private_key_from_db, cert_from_db;
187 smt.ColumnBlobAsString(1, &private_key_from_db); 186 smt.ColumnBlobAsString(1, &private_key_from_db);
188 smt.ColumnBlobAsString(2, &cert_from_db); 187 smt.ColumnBlobAsString(2, &cert_from_db);
189 scoped_ptr<net::DefaultOriginBoundCertStore::OriginBoundCert> cert( 188 scoped_ptr<net::DefaultOriginBoundCertStore::OriginBoundCert> cert(
190 new net::DefaultOriginBoundCertStore::OriginBoundCert( 189 new net::DefaultOriginBoundCertStore::OriginBoundCert(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 251
253 if (!db_->Execute("ALTER TABLE origin_bound_certs ADD COLUMN " 252 if (!db_->Execute("ALTER TABLE origin_bound_certs ADD COLUMN "
254 "creation_time INTEGER")) { 253 "creation_time INTEGER")) {
255 LOG(WARNING) << "Unable to update origin bound cert database to " 254 LOG(WARNING) << "Unable to update origin bound cert database to "
256 << "version 4."; 255 << "version 4.";
257 return false; 256 return false;
258 } 257 }
259 258
260 sql::Statement smt(db_->GetUniqueStatement( 259 sql::Statement smt(db_->GetUniqueStatement(
261 "SELECT origin, cert FROM origin_bound_certs")); 260 "SELECT origin, cert FROM origin_bound_certs"));
261 if (!smt.is_valid()) {
262 LOG(WARNING) << "Unable to update origin bound cert database to "
263 << "version 3.";
wtc 2012/02/10 18:30:53 All the warning log messages should in this functi
Greg Billock 2012/02/10 23:54:54 Done.
Scott Hess - ex-Googler 2012/02/13 22:07:16 Hmm, just saw this WRT my review. Note that _this
264 return false;
265 }
266
262 sql::Statement update_expires_smt(db_->GetUniqueStatement( 267 sql::Statement update_expires_smt(db_->GetUniqueStatement(
263 "UPDATE origin_bound_certs SET expiration_time = ? WHERE origin = ?")); 268 "UPDATE origin_bound_certs SET expiration_time = ? WHERE origin = ?"));
264 sql::Statement update_creation_smt(db_->GetUniqueStatement( 269 if (!update_expires_smt.is_valid()) {
265 "UPDATE origin_bound_certs SET creation_time = ? WHERE origin = ?"));
266 if (!smt || !update_expires_smt || !update_creation_smt) {
267 LOG(WARNING) << "Unable to update origin bound cert database to " 270 LOG(WARNING) << "Unable to update origin bound cert database to "
268 << "version 4."; 271 << "version 4.";
269 return false; 272 return false;
270 } 273 }
274
275 sql::Statement update_creation_smt(db_->GetUniqueStatement(
276 "UPDATE origin_bound_certs SET creation_time = ? WHERE origin = ?"));
277 if (!update_creation_smt.is_valid()) {
278 LOG(WARNING) << "Unable to create origin bound cert database.";
279 return false;
280 }
281
271 while (smt.Step()) { 282 while (smt.Step()) {
272 std::string origin = smt.ColumnString(0); 283 std::string origin = smt.ColumnString(0);
273 std::string cert_from_db; 284 std::string cert_from_db;
274 smt.ColumnBlobAsString(1, &cert_from_db); 285 smt.ColumnBlobAsString(1, &cert_from_db);
275 // Parse the cert and extract the real value and then update the DB. 286 // Parse the cert and extract the real value and then update the DB.
276 scoped_refptr<net::X509Certificate> cert( 287 scoped_refptr<net::X509Certificate> cert(
277 net::X509Certificate::CreateFromBytes( 288 net::X509Certificate::CreateFromBytes(
278 cert_from_db.data(), cert_from_db.size())); 289 cert_from_db.data(), cert_from_db.size()));
279 if (cert) { 290 if (cert) {
280 if (cur_version == 2) { 291 if (cur_version == 2) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 num_pending_ = 0; 386 num_pending_ = 0;
376 } 387 }
377 388
378 // Maybe an old timer fired or we are already Close()'ed. 389 // Maybe an old timer fired or we are already Close()'ed.
379 if (!db_.get() || ops.empty()) 390 if (!db_.get() || ops.empty())
380 return; 391 return;
381 392
382 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, 393 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE,
383 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, " 394 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, "
384 "expiration_time) VALUES (?,?,?,?,?)")); 395 "expiration_time) VALUES (?,?,?,?,?)"));
385 if (!add_smt) { 396 if (!add_smt.is_valid())
386 NOTREACHED();
387 return; 397 return;
388 }
389 398
390 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, 399 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE,
391 "DELETE FROM origin_bound_certs WHERE origin=?")); 400 "DELETE FROM origin_bound_certs WHERE origin=?"));
392 if (!del_smt) { 401 if (!del_smt.is_valid())
393 NOTREACHED();
394 return; 402 return;
395 }
396 403
397 sql::Transaction transaction(db_.get()); 404 sql::Transaction transaction(db_.get());
398 if (!transaction.Begin()) { 405 if (!transaction.Begin())
399 NOTREACHED();
400 return; 406 return;
401 } 407
402 for (PendingOperationsList::iterator it = ops.begin(); 408 for (PendingOperationsList::iterator it = ops.begin();
403 it != ops.end(); ++it) { 409 it != ops.end(); ++it) {
404 // Free the certs as we commit them to the database. 410 // Free the certs as we commit them to the database.
405 scoped_ptr<PendingOperation> po(*it); 411 scoped_ptr<PendingOperation> po(*it);
406 switch (po->op()) { 412 switch (po->op()) {
407 case PendingOperation::CERT_ADD: { 413 case PendingOperation::CERT_ADD: {
408 add_smt.Reset(); 414 add_smt.Reset();
409 add_smt.BindString(0, po->cert().origin()); 415 add_smt.BindString(0, po->cert().origin());
410 const std::string& private_key = po->cert().private_key(); 416 const std::string& private_key = po->cert().private_key();
411 add_smt.BindBlob(1, private_key.data(), private_key.size()); 417 add_smt.BindBlob(1, private_key.data(), private_key.size());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if (backend_.get()) 514 if (backend_.get())
509 backend_->SetClearLocalStateOnExit(clear_local_state); 515 backend_->SetClearLocalStateOnExit(clear_local_state);
510 } 516 }
511 517
512 void SQLiteOriginBoundCertStore::Flush(const base::Closure& completion_task) { 518 void SQLiteOriginBoundCertStore::Flush(const base::Closure& completion_task) {
513 if (backend_.get()) 519 if (backend_.get())
514 backend_->Flush(completion_task); 520 backend_->Flush(completion_task);
515 else if (!completion_task.is_null()) 521 else if (!completion_task.is_null())
516 MessageLoop::current()->PostTask(FROM_HERE, completion_task); 522 MessageLoop::current()->PostTask(FROM_HERE, completion_task);
517 } 523 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/safari_importer.mm ('k') | chrome/browser/net/sqlite_persistent_cookie_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698