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

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

Issue 1476263004: Remove ScopedVector from IDStores (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
18 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
19 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
20 #include "crypto/ec_private_key.h" 19 #include "crypto/ec_private_key.h"
21 #include "net/cert/asn1_util.h" 20 #include "net/cert/asn1_util.h"
22 #include "net/cert/x509_certificate.h" 21 #include "net/cert/x509_certificate.h"
23 #include "net/cookies/cookie_util.h" 22 #include "net/cookies/cookie_util.h"
24 #include "net/ssl/channel_id_service.h" 23 #include "net/ssl/channel_id_service.h"
25 #include "net/ssl/ssl_client_cert_type.h" 24 #include "net/ssl/ssl_client_cert_type.h"
26 #include "sql/error_delegate_util.h" 25 #include "sql/error_delegate_util.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 friend class base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend>; 74 friend class base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend>;
76 75
77 // You should call Close() before destructing this object. 76 // You should call Close() before destructing this object.
78 virtual ~Backend() { 77 virtual ~Backend() {
79 DCHECK(!db_.get()) << "Close should have already been called."; 78 DCHECK(!db_.get()) << "Close should have already been called.";
80 DCHECK_EQ(0u, num_pending_); 79 DCHECK_EQ(0u, num_pending_);
81 DCHECK(pending_.empty()); 80 DCHECK(pending_.empty());
82 } 81 }
83 82
84 void LoadInBackground( 83 void LoadInBackground(
85 ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids); 84 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids);
mmenke 2015/11/30 20:33:16 include vector
86 85
87 // Database upgrade statements. 86 // Database upgrade statements.
88 bool EnsureDatabaseVersion(); 87 bool EnsureDatabaseVersion();
89 88
90 class PendingOperation { 89 class PendingOperation {
91 public: 90 public:
92 enum OperationType { CHANNEL_ID_ADD, CHANNEL_ID_DELETE }; 91 enum OperationType { CHANNEL_ID_ADD, CHANNEL_ID_DELETE };
93 92
94 PendingOperation(OperationType op, 93 PendingOperation(OperationType op,
95 const DefaultChannelIDStore::ChannelID& channel_id) 94 const DefaultChannelIDStore::ChannelID& channel_id)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Indicates if the kill-database callback has been scheduled. 140 // Indicates if the kill-database callback has been scheduled.
142 bool corruption_detected_; 141 bool corruption_detected_;
143 142
144 DISALLOW_COPY_AND_ASSIGN(Backend); 143 DISALLOW_COPY_AND_ASSIGN(Backend);
145 }; 144 };
146 145
147 void SQLiteChannelIDStore::Backend::Load( 146 void SQLiteChannelIDStore::Backend::Load(
148 const LoadedCallback& loaded_callback) { 147 const LoadedCallback& loaded_callback) {
149 // This function should be called only once per instance. 148 // This function should be called only once per instance.
150 DCHECK(!db_.get()); 149 DCHECK(!db_.get());
151 scoped_ptr<ScopedVector<DefaultChannelIDStore::ChannelID> > channel_ids( 150 scoped_ptr<std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>>
152 new ScopedVector<DefaultChannelIDStore::ChannelID>()); 151 channel_ids(
153 ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids_ptr = 152 new std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>());
153 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids_ptr =
154 channel_ids.get(); 154 channel_ids.get();
155 155
156 background_task_runner_->PostTaskAndReply( 156 background_task_runner_->PostTaskAndReply(
157 FROM_HERE, 157 FROM_HERE,
158 base::Bind(&Backend::LoadInBackground, this, channel_ids_ptr), 158 base::Bind(&Backend::LoadInBackground, this, channel_ids_ptr),
159 base::Bind(loaded_callback, base::Passed(&channel_ids))); 159 base::Bind(loaded_callback, base::Passed(&channel_ids)));
160 } 160 }
161 161
162 void SQLiteChannelIDStore::Backend::LoadInBackground( 162 void SQLiteChannelIDStore::Backend::LoadInBackground(
163 ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids) { 163 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids) {
164 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); 164 DCHECK(background_task_runner_->RunsTasksOnCurrentThread());
165 165
166 // This method should be called only once per instance. 166 // This method should be called only once per instance.
167 DCHECK(!db_.get()); 167 DCHECK(!db_.get());
168 168
169 base::TimeTicks start = base::TimeTicks::Now(); 169 base::TimeTicks start = base::TimeTicks::Now();
170 170
171 // Ensure the parent directory for storing certs is created before reading 171 // Ensure the parent directory for storing certs is created before reading
172 // from it. 172 // from it.
173 const base::FilePath dir = path_.DirName(); 173 const base::FilePath dir = path_.DirName();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 scoped_ptr<crypto::ECPrivateKey> key( 223 scoped_ptr<crypto::ECPrivateKey> key(
224 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( 224 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
225 ChannelIDService::kEPKIPassword, private_key_from_db, 225 ChannelIDService::kEPKIPassword, private_key_from_db,
226 public_key_from_db)); 226 public_key_from_db));
227 if (!key) 227 if (!key)
228 continue; 228 continue;
229 scoped_ptr<DefaultChannelIDStore::ChannelID> channel_id( 229 scoped_ptr<DefaultChannelIDStore::ChannelID> channel_id(
230 new DefaultChannelIDStore::ChannelID( 230 new DefaultChannelIDStore::ChannelID(
231 smt.ColumnString(0), // host 231 smt.ColumnString(0), // host
232 base::Time::FromInternalValue(smt.ColumnInt64(3)), key.Pass())); 232 base::Time::FromInternalValue(smt.ColumnInt64(3)), key.Pass()));
233 channel_ids->push_back(channel_id.release()); 233 channel_ids->push_back(std::move(channel_id));
234 } 234 }
235 235
236 UMA_HISTOGRAM_COUNTS_10000( 236 UMA_HISTOGRAM_COUNTS_10000(
237 "DomainBoundCerts.DBLoadedCount", 237 "DomainBoundCerts.DBLoadedCount",
238 static_cast<base::HistogramBase::Sample>(channel_ids->size())); 238 static_cast<base::HistogramBase::Sample>(channel_ids->size()));
239 base::TimeDelta load_time = base::TimeTicks::Now() - start; 239 base::TimeDelta load_time = base::TimeTicks::Now() - start;
240 UMA_HISTOGRAM_CUSTOM_TIMES("DomainBoundCerts.DBLoadTime", 240 UMA_HISTOGRAM_CUSTOM_TIMES("DomainBoundCerts.DBLoadTime",
241 load_time, 241 load_time,
242 base::TimeDelta::FromMilliseconds(1), 242 base::TimeDelta::FromMilliseconds(1),
243 base::TimeDelta::FromMinutes(1), 243 base::TimeDelta::FromMinutes(1),
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 backend_->SetForceKeepSessionState(); 608 backend_->SetForceKeepSessionState();
609 } 609 }
610 610
611 SQLiteChannelIDStore::~SQLiteChannelIDStore() { 611 SQLiteChannelIDStore::~SQLiteChannelIDStore() {
612 backend_->Close(); 612 backend_->Close();
613 // We release our reference to the Backend, though it will probably still have 613 // We release our reference to the Backend, though it will probably still have
614 // a reference if the background task runner has not run Close() yet. 614 // a reference if the background task runner has not run Close() yet.
615 } 615 }
616 616
617 } // namespace net 617 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698