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

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: Merge to head 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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"));
262 sql::Statement update_expires_smt(db_->GetUniqueStatement( 261 sql::Statement update_expires_smt(db_->GetUniqueStatement(
263 "UPDATE origin_bound_certs SET expiration_time = ? WHERE origin = ?")); 262 "UPDATE origin_bound_certs SET expiration_time = ? WHERE origin = ?"));
264 sql::Statement update_creation_smt(db_->GetUniqueStatement( 263 sql::Statement update_creation_smt(db_->GetUniqueStatement(
265 "UPDATE origin_bound_certs SET creation_time = ? WHERE origin = ?")); 264 "UPDATE origin_bound_certs SET creation_time = ? WHERE origin = ?"));
266 if (!smt || !update_expires_smt || !update_creation_smt) { 265 if (!smt.is_valid() ||
266 !update_expires_smt.is_valid() ||
267 !update_creation_smt.is_valid()) {
267 LOG(WARNING) << "Unable to update origin bound cert database to " 268 LOG(WARNING) << "Unable to update origin bound cert database to "
268 << "version 4."; 269 << "version 4.";
269 return false; 270 return false;
270 } 271 }
272
271 while (smt.Step()) { 273 while (smt.Step()) {
272 std::string origin = smt.ColumnString(0); 274 std::string origin = smt.ColumnString(0);
273 std::string cert_from_db; 275 std::string cert_from_db;
274 smt.ColumnBlobAsString(1, &cert_from_db); 276 smt.ColumnBlobAsString(1, &cert_from_db);
275 // Parse the cert and extract the real value and then update the DB. 277 // Parse the cert and extract the real value and then update the DB.
276 scoped_refptr<net::X509Certificate> cert( 278 scoped_refptr<net::X509Certificate> cert(
277 net::X509Certificate::CreateFromBytes( 279 net::X509Certificate::CreateFromBytes(
278 cert_from_db.data(), cert_from_db.size())); 280 cert_from_db.data(), cert_from_db.size()));
279 if (cert) { 281 if (cert) {
280 if (cur_version == 2) { 282 if (cur_version == 2) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 num_pending_ = 0; 377 num_pending_ = 0;
376 } 378 }
377 379
378 // Maybe an old timer fired or we are already Close()'ed. 380 // Maybe an old timer fired or we are already Close()'ed.
379 if (!db_.get() || ops.empty()) 381 if (!db_.get() || ops.empty())
380 return; 382 return;
381 383
382 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, 384 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE,
383 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, " 385 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, "
384 "expiration_time, creation_time) VALUES (?,?,?,?,?,?)")); 386 "expiration_time, creation_time) VALUES (?,?,?,?,?,?)"));
385 if (!add_smt) { 387 if (!add_smt.is_valid())
386 NOTREACHED();
387 return; 388 return;
388 }
389 389
390 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, 390 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE,
391 "DELETE FROM origin_bound_certs WHERE origin=?")); 391 "DELETE FROM origin_bound_certs WHERE origin=?"));
392 if (!del_smt) { 392 if (!del_smt.is_valid())
393 NOTREACHED();
394 return; 393 return;
395 }
396 394
397 sql::Transaction transaction(db_.get()); 395 sql::Transaction transaction(db_.get());
398 if (!transaction.Begin()) { 396 if (!transaction.Begin())
399 NOTREACHED();
400 return; 397 return;
401 } 398
402 for (PendingOperationsList::iterator it = ops.begin(); 399 for (PendingOperationsList::iterator it = ops.begin();
403 it != ops.end(); ++it) { 400 it != ops.end(); ++it) {
404 // Free the certs as we commit them to the database. 401 // Free the certs as we commit them to the database.
405 scoped_ptr<PendingOperation> po(*it); 402 scoped_ptr<PendingOperation> po(*it);
406 switch (po->op()) { 403 switch (po->op()) {
407 case PendingOperation::CERT_ADD: { 404 case PendingOperation::CERT_ADD: {
408 add_smt.Reset(); 405 add_smt.Reset();
409 add_smt.BindString(0, po->cert().origin()); 406 add_smt.BindString(0, po->cert().origin());
410 const std::string& private_key = po->cert().private_key(); 407 const std::string& private_key = po->cert().private_key();
411 add_smt.BindBlob(1, private_key.data(), private_key.size()); 408 add_smt.BindBlob(1, private_key.data(), private_key.size());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 if (backend_.get()) 506 if (backend_.get())
510 backend_->SetClearLocalStateOnExit(clear_local_state); 507 backend_->SetClearLocalStateOnExit(clear_local_state);
511 } 508 }
512 509
513 void SQLiteOriginBoundCertStore::Flush(const base::Closure& completion_task) { 510 void SQLiteOriginBoundCertStore::Flush(const base::Closure& completion_task) {
514 if (backend_.get()) 511 if (backend_.get())
515 backend_->Flush(completion_task); 512 backend_->Flush(completion_task);
516 else if (!completion_task.is_null()) 513 else if (!completion_task.is_null())
517 MessageLoop::current()->PostTask(FROM_HERE, completion_task); 514 MessageLoop::current()->PostTask(FROM_HERE, completion_task);
518 } 515 }
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