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

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: Fix 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 9
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.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"
26 #include "sql/error_delegate_util.h" 26 #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>; 75 friend class base::RefCountedThreadSafe<SQLiteChannelIDStore::Backend>;
76 76
77 // You should call Close() before destructing this object. 77 // You should call Close() before destructing this object.
78 virtual ~Backend() { 78 virtual ~Backend() {
79 DCHECK(!db_.get()) << "Close should have already been called."; 79 DCHECK(!db_.get()) << "Close should have already been called.";
80 DCHECK_EQ(0u, num_pending_); 80 DCHECK_EQ(0u, num_pending_);
81 DCHECK(pending_.empty()); 81 DCHECK(pending_.empty());
82 } 82 }
83 83
84 void LoadInBackground( 84 void LoadInBackground(
85 ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids); 85 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids);
86 86
87 // Database upgrade statements. 87 // Database upgrade statements.
88 bool EnsureDatabaseVersion(); 88 bool EnsureDatabaseVersion();
89 89
90 class PendingOperation { 90 class PendingOperation {
91 public: 91 public:
92 enum OperationType { CHANNEL_ID_ADD, CHANNEL_ID_DELETE }; 92 enum OperationType { CHANNEL_ID_ADD, CHANNEL_ID_DELETE };
93 93
94 PendingOperation(OperationType op, 94 PendingOperation(OperationType op,
95 const DefaultChannelIDStore::ChannelID& channel_id) 95 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. 141 // Indicates if the kill-database callback has been scheduled.
142 bool corruption_detected_; 142 bool corruption_detected_;
143 143
144 DISALLOW_COPY_AND_ASSIGN(Backend); 144 DISALLOW_COPY_AND_ASSIGN(Backend);
145 }; 145 };
146 146
147 void SQLiteChannelIDStore::Backend::Load( 147 void SQLiteChannelIDStore::Backend::Load(
148 const LoadedCallback& loaded_callback) { 148 const LoadedCallback& loaded_callback) {
149 // This function should be called only once per instance. 149 // This function should be called only once per instance.
150 DCHECK(!db_.get()); 150 DCHECK(!db_.get());
151 scoped_ptr<ScopedVector<DefaultChannelIDStore::ChannelID> > channel_ids( 151 scoped_ptr<std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>>
152 new ScopedVector<DefaultChannelIDStore::ChannelID>()); 152 channel_ids(
153 ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids_ptr = 153 new std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>());
154 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids_ptr =
154 channel_ids.get(); 155 channel_ids.get();
155 156
156 background_task_runner_->PostTaskAndReply( 157 background_task_runner_->PostTaskAndReply(
157 FROM_HERE, 158 FROM_HERE,
158 base::Bind(&Backend::LoadInBackground, this, channel_ids_ptr), 159 base::Bind(&Backend::LoadInBackground, this, channel_ids_ptr),
159 base::Bind(loaded_callback, base::Passed(&channel_ids))); 160 base::Bind(loaded_callback, base::Passed(&channel_ids)));
160 } 161 }
161 162
162 void SQLiteChannelIDStore::Backend::LoadInBackground( 163 void SQLiteChannelIDStore::Backend::LoadInBackground(
163 ScopedVector<DefaultChannelIDStore::ChannelID>* channel_ids) { 164 std::vector<scoped_ptr<DefaultChannelIDStore::ChannelID>>* channel_ids) {
164 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); 165 DCHECK(background_task_runner_->RunsTasksOnCurrentThread());
165 166
166 // This method should be called only once per instance. 167 // This method should be called only once per instance.
167 DCHECK(!db_.get()); 168 DCHECK(!db_.get());
168 169
169 base::TimeTicks start = base::TimeTicks::Now(); 170 base::TimeTicks start = base::TimeTicks::Now();
170 171
171 // Ensure the parent directory for storing certs is created before reading 172 // Ensure the parent directory for storing certs is created before reading
172 // from it. 173 // from it.
173 const base::FilePath dir = path_.DirName(); 174 const base::FilePath dir = path_.DirName();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 scoped_ptr<crypto::ECPrivateKey> key( 224 scoped_ptr<crypto::ECPrivateKey> key(
224 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( 225 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
225 ChannelIDService::kEPKIPassword, private_key_from_db, 226 ChannelIDService::kEPKIPassword, private_key_from_db,
226 public_key_from_db)); 227 public_key_from_db));
227 if (!key) 228 if (!key)
228 continue; 229 continue;
229 scoped_ptr<DefaultChannelIDStore::ChannelID> channel_id( 230 scoped_ptr<DefaultChannelIDStore::ChannelID> channel_id(
230 new DefaultChannelIDStore::ChannelID( 231 new DefaultChannelIDStore::ChannelID(
231 smt.ColumnString(0), // host 232 smt.ColumnString(0), // host
232 base::Time::FromInternalValue(smt.ColumnInt64(3)), key.Pass())); 233 base::Time::FromInternalValue(smt.ColumnInt64(3)), key.Pass()));
233 channel_ids->push_back(channel_id.release()); 234 channel_ids->push_back(std::move(channel_id));
234 } 235 }
235 236
236 UMA_HISTOGRAM_COUNTS_10000( 237 UMA_HISTOGRAM_COUNTS_10000(
237 "DomainBoundCerts.DBLoadedCount", 238 "DomainBoundCerts.DBLoadedCount",
238 static_cast<base::HistogramBase::Sample>(channel_ids->size())); 239 static_cast<base::HistogramBase::Sample>(channel_ids->size()));
239 base::TimeDelta load_time = base::TimeTicks::Now() - start; 240 base::TimeDelta load_time = base::TimeTicks::Now() - start;
240 UMA_HISTOGRAM_CUSTOM_TIMES("DomainBoundCerts.DBLoadTime", 241 UMA_HISTOGRAM_CUSTOM_TIMES("DomainBoundCerts.DBLoadTime",
241 load_time, 242 load_time,
242 base::TimeDelta::FromMilliseconds(1), 243 base::TimeDelta::FromMilliseconds(1),
243 base::TimeDelta::FromMinutes(1), 244 base::TimeDelta::FromMinutes(1),
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 backend_->SetForceKeepSessionState(); 609 backend_->SetForceKeepSessionState();
609 } 610 }
610 611
611 SQLiteChannelIDStore::~SQLiteChannelIDStore() { 612 SQLiteChannelIDStore::~SQLiteChannelIDStore() {
612 backend_->Close(); 613 backend_->Close();
613 // 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
614 // 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.
615 } 616 }
616 617
617 } // namespace net 618 } // namespace net
OLDNEW
« no previous file with comments | « chrome/browser/net/quota_policy_channel_id_store_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