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

Side by Side Diff: net/extras/sqlite/sqlite_channel_id_store.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/extras/sqlite/sqlite_channel_id_store.h" 5 #include "net/extras/sqlite/sqlite_channel_id_store.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h"
11 #include "base/bind.h" 10 #include "base/bind.h"
12 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
14 #include "base/location.h" 13 #include "base/location.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "crypto/ec_private_key.h" 20 #include "crypto/ec_private_key.h"
21 #include "net/cert/asn1_util.h" 21 #include "net/cert/asn1_util.h"
22 #include "net/cert/x509_certificate.h" 22 #include "net/cert/x509_certificate.h"
23 #include "net/cookies/cookie_util.h" 23 #include "net/cookies/cookie_util.h"
24 #include "net/ssl/channel_id_service.h" 24 #include "net/ssl/channel_id_service.h"
25 #include "net/ssl/ssl_client_cert_type.h" 25 #include "net/ssl/ssl_client_cert_type.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 DCHECK(!db_.get()); 168 DCHECK(!db_.get());
169 169
170 base::TimeTicks start = base::TimeTicks::Now(); 170 base::TimeTicks start = base::TimeTicks::Now();
171 171
172 // Ensure the parent directory for storing certs is created before reading 172 // Ensure the parent directory for storing certs is created before reading
173 // from it. 173 // from it.
174 const base::FilePath dir = path_.DirName(); 174 const base::FilePath dir = path_.DirName();
175 if (!base::PathExists(dir) && !base::CreateDirectory(dir)) 175 if (!base::PathExists(dir) && !base::CreateDirectory(dir))
176 return; 176 return;
177 177
178 int64 db_size = 0; 178 int64_t db_size = 0;
179 if (base::GetFileSize(path_, &db_size)) 179 if (base::GetFileSize(path_, &db_size))
180 UMA_HISTOGRAM_COUNTS("DomainBoundCerts.DBSizeInKB", db_size / 1024); 180 UMA_HISTOGRAM_COUNTS("DomainBoundCerts.DBSizeInKB", db_size / 1024);
181 181
182 db_.reset(new sql::Connection); 182 db_.reset(new sql::Connection);
183 db_->set_histogram_tag("DomainBoundCerts"); 183 db_->set_histogram_tag("DomainBoundCerts");
184 184
185 // Unretained to avoid a ref loop with db_. 185 // Unretained to avoid a ref loop with db_.
186 db_->set_error_callback( 186 db_->set_error_callback(
187 base::Bind(&SQLiteChannelIDStore::Backend::DatabaseErrorCallback, 187 base::Bind(&SQLiteChannelIDStore::Backend::DatabaseErrorCallback,
188 base::Unretained(this))); 188 base::Unretained(this)));
(...skipping 22 matching lines...) Expand all
211 "SELECT host, private_key, public_key, creation_time FROM channel_id")); 211 "SELECT host, private_key, public_key, creation_time FROM channel_id"));
212 if (!smt.is_valid()) { 212 if (!smt.is_valid()) {
213 if (corruption_detected_) 213 if (corruption_detected_)
214 KillDatabase(); 214 KillDatabase();
215 meta_table_.Reset(); 215 meta_table_.Reset();
216 db_.reset(); 216 db_.reset();
217 return; 217 return;
218 } 218 }
219 219
220 while (smt.Step()) { 220 while (smt.Step()) {
221 std::vector<uint8> private_key_from_db, public_key_from_db; 221 std::vector<uint8_t> private_key_from_db, public_key_from_db;
222 smt.ColumnBlobAsVector(1, &private_key_from_db); 222 smt.ColumnBlobAsVector(1, &private_key_from_db);
223 smt.ColumnBlobAsVector(2, &public_key_from_db); 223 smt.ColumnBlobAsVector(2, &public_key_from_db);
224 scoped_ptr<crypto::ECPrivateKey> key( 224 scoped_ptr<crypto::ECPrivateKey> key(
225 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( 225 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
226 ChannelIDService::kEPKIPassword, private_key_from_db, 226 ChannelIDService::kEPKIPassword, private_key_from_db,
227 public_key_from_db)); 227 public_key_from_db));
228 if (!key) 228 if (!key)
229 continue; 229 continue;
230 scoped_ptr<DefaultChannelIDStore::ChannelID> channel_id( 230 scoped_ptr<DefaultChannelIDStore::ChannelID> channel_id(
231 new DefaultChannelIDStore::ChannelID( 231 new DefaultChannelIDStore::ChannelID(
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 return; 486 return;
487 487
488 for (PendingOperationsList::iterator it = ops.begin(); it != ops.end(); 488 for (PendingOperationsList::iterator it = ops.begin(); it != ops.end();
489 ++it) { 489 ++it) {
490 // Free the certs as we commit them to the database. 490 // Free the certs as we commit them to the database.
491 scoped_ptr<PendingOperation> po(*it); 491 scoped_ptr<PendingOperation> po(*it);
492 switch (po->op()) { 492 switch (po->op()) {
493 case PendingOperation::CHANNEL_ID_ADD: { 493 case PendingOperation::CHANNEL_ID_ADD: {
494 add_statement.Reset(true); 494 add_statement.Reset(true);
495 add_statement.BindString(0, po->channel_id().server_identifier()); 495 add_statement.BindString(0, po->channel_id().server_identifier());
496 std::vector<uint8> private_key, public_key; 496 std::vector<uint8_t> private_key, public_key;
497 if (!po->channel_id().key()->ExportEncryptedPrivateKey( 497 if (!po->channel_id().key()->ExportEncryptedPrivateKey(
498 ChannelIDService::kEPKIPassword, 1, &private_key)) 498 ChannelIDService::kEPKIPassword, 1, &private_key))
499 continue; 499 continue;
500 if (!po->channel_id().key()->ExportPublicKey(&public_key)) 500 if (!po->channel_id().key()->ExportPublicKey(&public_key))
501 continue; 501 continue;
502 add_statement.BindBlob( 502 add_statement.BindBlob(
503 1, private_key.data(), static_cast<int>(private_key.size())); 503 1, private_key.data(), static_cast<int>(private_key.size()));
504 add_statement.BindBlob(2, public_key.data(), 504 add_statement.BindBlob(2, public_key.data(),
505 static_cast<int>(public_key.size())); 505 static_cast<int>(public_key.size()));
506 add_statement.BindInt64( 506 add_statement.BindInt64(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 backend_->SetForceKeepSessionState(); 609 backend_->SetForceKeepSessionState();
610 } 610 }
611 611
612 SQLiteChannelIDStore::~SQLiteChannelIDStore() { 612 SQLiteChannelIDStore::~SQLiteChannelIDStore() {
613 backend_->Close(); 613 backend_->Close();
614 // We release our reference to the Backend, though it will probably still have 614 // We release our reference to the Backend, though it will probably still have
615 // a reference if the background task runner has not run Close() yet. 615 // a reference if the background task runner has not run Close() yet.
616 } 616 }
617 617
618 } // namespace net 618 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/single_request_host_resolver_unittest.cc ('k') | net/extras/sqlite/sqlite_channel_id_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698