OLD | NEW |
---|---|
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 "net/base/default_server_bound_cert_store.h" | 5 #include "net/base/default_server_bound_cert_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | |
9 | 10 |
10 namespace net { | 11 namespace net { |
11 | 12 |
13 // -------------------------------------------------------------------------- | |
14 // Task | |
15 class DefaultServerBoundCertStore::Task { | |
16 public: | |
17 virtual ~Task(); | |
18 | |
19 // Runs the task and invokes the client callback on the thread that | |
20 // originally constructed the task. | |
21 virtual void Run(DefaultServerBoundCertStore* store) = 0; | |
22 | |
23 protected: | |
24 void InvokeCallback(base::Closure callback) const; | |
25 }; | |
26 | |
27 DefaultServerBoundCertStore::Task::~Task() { | |
28 } | |
29 | |
30 void DefaultServerBoundCertStore::Task::InvokeCallback( | |
31 base::Closure callback) const { | |
32 if (!callback.is_null()) | |
33 callback.Run(); | |
34 } | |
35 | |
36 // -------------------------------------------------------------------------- | |
37 // GetServerBoundCertTask | |
38 class DefaultServerBoundCertStore::GetServerBoundCertTask | |
39 : public DefaultServerBoundCertStore::Task { | |
40 public: | |
41 GetServerBoundCertTask(const std::string& server_identifier, | |
42 const GetCertCallback& callback); | |
43 virtual ~GetServerBoundCertTask(); | |
44 virtual void Run(DefaultServerBoundCertStore* store) OVERRIDE; | |
45 | |
46 private: | |
47 std::string server_identifier_; | |
48 GetCertCallback callback_; | |
49 }; | |
50 | |
51 DefaultServerBoundCertStore::GetServerBoundCertTask::GetServerBoundCertTask( | |
52 const std::string& server_identifier, | |
53 const GetCertCallback& callback) | |
54 : server_identifier_(server_identifier), | |
55 callback_(callback) { | |
56 } | |
57 | |
58 DefaultServerBoundCertStore::GetServerBoundCertTask::~GetServerBoundCertTask() { | |
59 } | |
60 | |
61 void DefaultServerBoundCertStore::GetServerBoundCertTask::Run( | |
62 DefaultServerBoundCertStore* store) { | |
63 SSLClientCertType type = CLIENT_CERT_INVALID_TYPE; | |
64 base::Time expiration_time; | |
65 std::string private_key_result; | |
66 std::string cert_result; | |
67 bool was_sync = store->GetServerBoundCert( | |
68 server_identifier_, &type, &expiration_time, &private_key_result, | |
69 &cert_result, GetCertCallback()); | |
70 DCHECK(was_sync); | |
71 | |
72 InvokeCallback(base::Bind(callback_, server_identifier_, type, | |
73 expiration_time, private_key_result, cert_result)); | |
74 } | |
75 | |
76 // -------------------------------------------------------------------------- | |
77 // SetServerBoundCertTask | |
78 class DefaultServerBoundCertStore::SetServerBoundCertTask | |
79 : public DefaultServerBoundCertStore::Task { | |
80 public: | |
81 SetServerBoundCertTask(const std::string& server_identifier, | |
82 SSLClientCertType type, | |
83 base::Time creation_time, | |
84 base::Time expiration_time, | |
85 const std::string& private_key, | |
86 const std::string& cert); | |
87 virtual ~SetServerBoundCertTask(); | |
88 virtual void Run(DefaultServerBoundCertStore* store) OVERRIDE; | |
89 | |
90 private: | |
91 std::string server_identifier_; | |
92 SSLClientCertType type_; | |
93 base::Time creation_time_; | |
94 base::Time expiration_time_; | |
95 std::string private_key_; | |
96 std::string cert_; | |
97 }; | |
98 | |
99 DefaultServerBoundCertStore::SetServerBoundCertTask::SetServerBoundCertTask( | |
100 const std::string& server_identifier, | |
101 SSLClientCertType type, | |
102 base::Time creation_time, | |
103 base::Time expiration_time, | |
104 const std::string& private_key, | |
105 const std::string& cert) | |
106 : server_identifier_(server_identifier), | |
107 type_(type), | |
108 creation_time_(creation_time), | |
109 expiration_time_(expiration_time), | |
110 private_key_(private_key), | |
111 cert_(cert) { | |
112 } | |
113 | |
114 DefaultServerBoundCertStore::SetServerBoundCertTask::~SetServerBoundCertTask() { | |
115 } | |
116 | |
117 void DefaultServerBoundCertStore::SetServerBoundCertTask::Run( | |
118 DefaultServerBoundCertStore* store) { | |
119 store->SyncSetServerBoundCert(server_identifier_, type_, creation_time_, | |
120 expiration_time_, private_key_, cert_); | |
erikwright (departed)
2013/01/04 19:20:10
indent
mattm
2013/01/08 04:53:21
Done.
| |
121 } | |
122 | |
123 // -------------------------------------------------------------------------- | |
124 // DeleteServerBoundCertTask | |
125 class DefaultServerBoundCertStore::DeleteServerBoundCertTask | |
126 : public DefaultServerBoundCertStore::Task { | |
127 public: | |
128 DeleteServerBoundCertTask(const std::string& server_identifier, | |
129 const base::Closure& callback); | |
130 virtual ~DeleteServerBoundCertTask(); | |
131 virtual void Run(DefaultServerBoundCertStore* store) OVERRIDE; | |
132 | |
133 private: | |
134 std::string server_identifier_; | |
135 base::Closure callback_; | |
136 }; | |
137 | |
138 DefaultServerBoundCertStore::DeleteServerBoundCertTask:: | |
139 DeleteServerBoundCertTask( | |
140 const std::string& server_identifier, | |
141 const base::Closure& callback) | |
142 : server_identifier_(server_identifier), | |
143 callback_(callback) { | |
144 } | |
145 | |
146 DefaultServerBoundCertStore::DeleteServerBoundCertTask:: | |
147 ~DeleteServerBoundCertTask() { | |
148 } | |
149 | |
150 void DefaultServerBoundCertStore::DeleteServerBoundCertTask::Run( | |
151 DefaultServerBoundCertStore* store) { | |
152 store->SyncDeleteServerBoundCert(server_identifier_); | |
153 | |
154 InvokeCallback(callback_); | |
155 } | |
156 | |
157 // -------------------------------------------------------------------------- | |
158 // DeleteAllCreatedBetweenTask | |
159 class DefaultServerBoundCertStore::DeleteAllCreatedBetweenTask | |
160 : public DefaultServerBoundCertStore::Task { | |
161 public: | |
162 DeleteAllCreatedBetweenTask(base::Time delete_begin, | |
163 base::Time delete_end, | |
164 const base::Closure& callback); | |
165 virtual ~DeleteAllCreatedBetweenTask(); | |
166 virtual void Run(DefaultServerBoundCertStore* store) OVERRIDE; | |
167 | |
168 private: | |
169 base::Time delete_begin_; | |
170 base::Time delete_end_; | |
171 base::Closure callback_; | |
172 }; | |
173 | |
174 DefaultServerBoundCertStore::DeleteAllCreatedBetweenTask:: | |
175 DeleteAllCreatedBetweenTask( | |
176 base::Time delete_begin, | |
177 base::Time delete_end, | |
178 const base::Closure& callback) | |
179 : delete_begin_(delete_begin), | |
180 delete_end_(delete_end), | |
181 callback_(callback) { | |
182 } | |
183 | |
184 DefaultServerBoundCertStore::DeleteAllCreatedBetweenTask:: | |
185 ~DeleteAllCreatedBetweenTask() { | |
186 } | |
187 | |
188 void DefaultServerBoundCertStore::DeleteAllCreatedBetweenTask::Run( | |
189 DefaultServerBoundCertStore* store) { | |
190 store->SyncDeleteAllCreatedBetween(delete_begin_, delete_end_); | |
191 | |
192 InvokeCallback(callback_); | |
193 } | |
194 | |
195 // -------------------------------------------------------------------------- | |
196 // GetAllServerBoundCertsTask | |
197 class DefaultServerBoundCertStore::GetAllServerBoundCertsTask | |
198 : public DefaultServerBoundCertStore::Task { | |
199 public: | |
200 explicit GetAllServerBoundCertsTask(const GetCertListCallback& callback); | |
201 virtual ~GetAllServerBoundCertsTask(); | |
202 virtual void Run(DefaultServerBoundCertStore* store) OVERRIDE; | |
203 | |
204 private: | |
205 std::string server_identifier_; | |
206 GetCertListCallback callback_; | |
207 }; | |
208 | |
209 DefaultServerBoundCertStore::GetAllServerBoundCertsTask:: | |
210 GetAllServerBoundCertsTask(const GetCertListCallback& callback) | |
211 : callback_(callback) { | |
212 } | |
213 | |
214 DefaultServerBoundCertStore::GetAllServerBoundCertsTask:: | |
215 ~GetAllServerBoundCertsTask() { | |
216 } | |
217 | |
218 void DefaultServerBoundCertStore::GetAllServerBoundCertsTask::Run( | |
219 DefaultServerBoundCertStore* store) { | |
220 ServerBoundCertList cert_list; | |
221 store->SyncGetAllServerBoundCerts(&cert_list); | |
222 | |
223 InvokeCallback(base::Bind(callback_, cert_list)); | |
224 } | |
225 | |
226 // -------------------------------------------------------------------------- | |
227 // DefaultServerBoundCertStore | |
228 | |
12 // static | 229 // static |
13 const size_t DefaultServerBoundCertStore::kMaxCerts = 3300; | 230 const size_t DefaultServerBoundCertStore::kMaxCerts = 3300; |
14 | 231 |
15 DefaultServerBoundCertStore::DefaultServerBoundCertStore( | 232 DefaultServerBoundCertStore::DefaultServerBoundCertStore( |
16 PersistentStore* store) | 233 PersistentStore* store) |
17 : initialized_(false), | 234 : initialized_(false), |
18 store_(store) {} | 235 loaded_(false), |
236 store_(store), | |
237 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {} | |
19 | 238 |
20 void DefaultServerBoundCertStore::FlushStore( | 239 void DefaultServerBoundCertStore::FlushStore( |
21 const base::Closure& completion_task) { | 240 const base::Closure& completion_task) { |
22 DCHECK(CalledOnValidThread()); | 241 DCHECK(CalledOnValidThread()); |
23 | 242 |
24 if (initialized_ && store_) | 243 if (initialized_ && store_) |
25 store_->Flush(completion_task); | 244 store_->Flush(completion_task); |
26 else if (!completion_task.is_null()) | 245 else if (!completion_task.is_null()) |
27 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 246 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
28 } | 247 } |
29 | 248 |
30 bool DefaultServerBoundCertStore::GetServerBoundCert( | 249 bool DefaultServerBoundCertStore::GetServerBoundCert( |
31 const std::string& server_identifier, | 250 const std::string& server_identifier, |
32 SSLClientCertType* type, | 251 SSLClientCertType* type, |
33 base::Time* creation_time, | |
34 base::Time* expiration_time, | 252 base::Time* expiration_time, |
35 std::string* private_key_result, | 253 std::string* private_key_result, |
36 std::string* cert_result) { | 254 std::string* cert_result, |
255 const GetCertCallback& callback) { | |
37 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
38 InitIfNecessary(); | 257 InitIfNecessary(); |
39 | 258 |
259 if (!loaded_) { | |
260 EnqueueTask(new GetServerBoundCertTask(server_identifier, callback)); | |
261 return false; | |
262 } | |
263 | |
40 ServerBoundCertMap::iterator it = server_bound_certs_.find(server_identifier); | 264 ServerBoundCertMap::iterator it = server_bound_certs_.find(server_identifier); |
41 | 265 |
42 if (it == server_bound_certs_.end()) | 266 if (it == server_bound_certs_.end()) { |
43 return false; | 267 *type = CLIENT_CERT_INVALID_TYPE; |
268 return true; | |
269 } | |
44 | 270 |
45 ServerBoundCert* cert = it->second; | 271 ServerBoundCert* cert = it->second; |
46 *type = cert->type(); | 272 *type = cert->type(); |
47 *creation_time = cert->creation_time(); | |
48 *expiration_time = cert->expiration_time(); | 273 *expiration_time = cert->expiration_time(); |
49 *private_key_result = cert->private_key(); | 274 *private_key_result = cert->private_key(); |
50 *cert_result = cert->cert(); | 275 *cert_result = cert->cert(); |
51 | 276 |
52 return true; | 277 return true; |
53 } | 278 } |
54 | 279 |
55 void DefaultServerBoundCertStore::SetServerBoundCert( | 280 void DefaultServerBoundCertStore::SetServerBoundCert( |
56 const std::string& server_identifier, | 281 const std::string& server_identifier, |
57 SSLClientCertType type, | 282 SSLClientCertType type, |
58 base::Time creation_time, | 283 base::Time creation_time, |
59 base::Time expiration_time, | 284 base::Time expiration_time, |
60 const std::string& private_key, | 285 const std::string& private_key, |
61 const std::string& cert) { | 286 const std::string& cert) { |
62 DCHECK(CalledOnValidThread()); | 287 RunOrEnqueueTask(new SetServerBoundCertTask( |
63 InitIfNecessary(); | 288 server_identifier, type, creation_time, expiration_time, private_key, |
64 | 289 cert)); |
65 InternalDeleteServerBoundCert(server_identifier); | |
66 InternalInsertServerBoundCert( | |
67 server_identifier, | |
68 new ServerBoundCert( | |
69 server_identifier, type, creation_time, expiration_time, private_key, | |
70 cert)); | |
71 } | 290 } |
72 | 291 |
73 void DefaultServerBoundCertStore::DeleteServerBoundCert( | 292 void DefaultServerBoundCertStore::DeleteServerBoundCert( |
74 const std::string& server_identifier) { | 293 const std::string& server_identifier, |
75 DCHECK(CalledOnValidThread()); | 294 const base::Closure& callback) { |
76 InitIfNecessary(); | 295 RunOrEnqueueTask(new DeleteServerBoundCertTask(server_identifier, callback)); |
77 InternalDeleteServerBoundCert(server_identifier); | |
78 } | 296 } |
79 | 297 |
80 void DefaultServerBoundCertStore::DeleteAllCreatedBetween( | 298 void DefaultServerBoundCertStore::DeleteAllCreatedBetween( |
81 base::Time delete_begin, | 299 base::Time delete_begin, |
82 base::Time delete_end) { | 300 base::Time delete_end, |
83 DCHECK(CalledOnValidThread()); | 301 const base::Closure& callback) { |
84 InitIfNecessary(); | 302 RunOrEnqueueTask(new DeleteAllCreatedBetweenTask(delete_begin, delete_end, |
85 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); | 303 callback)); |
86 it != server_bound_certs_.end();) { | |
87 ServerBoundCertMap::iterator cur = it; | |
88 ++it; | |
89 ServerBoundCert* cert = cur->second; | |
90 if ((delete_begin.is_null() || cert->creation_time() >= delete_begin) && | |
91 (delete_end.is_null() || cert->creation_time() < delete_end)) { | |
92 if (store_) | |
93 store_->DeleteServerBoundCert(*cert); | |
94 delete cert; | |
95 server_bound_certs_.erase(cur); | |
96 } | |
97 } | |
98 } | 304 } |
99 | 305 |
100 void DefaultServerBoundCertStore::DeleteAll() { | 306 void DefaultServerBoundCertStore::DeleteAll( |
101 DeleteAllCreatedBetween(base::Time(), base::Time()); | 307 const base::Closure& callback) { |
308 DeleteAllCreatedBetween(base::Time(), base::Time(), callback); | |
102 } | 309 } |
103 | 310 |
104 void DefaultServerBoundCertStore::GetAllServerBoundCerts( | 311 void DefaultServerBoundCertStore::GetAllServerBoundCerts( |
105 ServerBoundCertList* server_bound_certs) { | 312 const GetCertListCallback& callback) { |
106 DCHECK(CalledOnValidThread()); | 313 RunOrEnqueueTask(new GetAllServerBoundCertsTask(callback)); |
107 InitIfNecessary(); | |
108 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); | |
109 it != server_bound_certs_.end(); ++it) { | |
110 server_bound_certs->push_back(*it->second); | |
111 } | |
112 } | 314 } |
113 | 315 |
114 int DefaultServerBoundCertStore::GetCertCount() { | 316 int DefaultServerBoundCertStore::GetCertCount() { |
115 DCHECK(CalledOnValidThread()); | 317 DCHECK(CalledOnValidThread()); |
116 InitIfNecessary(); | |
117 | 318 |
118 return server_bound_certs_.size(); | 319 return server_bound_certs_.size(); |
119 } | 320 } |
120 | 321 |
121 void DefaultServerBoundCertStore::SetForceKeepSessionState() { | 322 void DefaultServerBoundCertStore::SetForceKeepSessionState() { |
122 DCHECK(CalledOnValidThread()); | 323 DCHECK(CalledOnValidThread()); |
123 InitIfNecessary(); | 324 InitIfNecessary(); |
124 | 325 |
125 if (store_) | 326 if (store_) |
126 store_->SetForceKeepSessionState(); | 327 store_->SetForceKeepSessionState(); |
127 } | 328 } |
128 | 329 |
129 DefaultServerBoundCertStore::~DefaultServerBoundCertStore() { | 330 DefaultServerBoundCertStore::~DefaultServerBoundCertStore() { |
130 DeleteAllInMemory(); | 331 DeleteAllInMemory(); |
131 } | 332 } |
132 | 333 |
133 void DefaultServerBoundCertStore::DeleteAllInMemory() { | 334 void DefaultServerBoundCertStore::DeleteAllInMemory() { |
134 DCHECK(CalledOnValidThread()); | 335 DCHECK(CalledOnValidThread()); |
135 | 336 |
136 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); | 337 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); |
137 it != server_bound_certs_.end(); ++it) { | 338 it != server_bound_certs_.end(); ++it) { |
138 delete it->second; | 339 delete it->second; |
139 } | 340 } |
140 server_bound_certs_.clear(); | 341 server_bound_certs_.clear(); |
141 } | 342 } |
142 | 343 |
143 void DefaultServerBoundCertStore::InitStore() { | 344 void DefaultServerBoundCertStore::InitStore() { |
144 DCHECK(CalledOnValidThread()); | 345 DCHECK(CalledOnValidThread()); |
145 DCHECK(store_) << "Store must exist to initialize"; | 346 DCHECK(store_) << "Store must exist to initialize"; |
347 DCHECK(!loaded_); | |
146 | 348 |
147 // Initialize the store and sync in any saved persistent certs. | 349 store_->Load(base::Bind(&DefaultServerBoundCertStore::OnLoaded, |
148 std::vector<ServerBoundCert*> certs; | 350 weak_ptr_factory_.GetWeakPtr())); |
149 // Reserve space for the maximum amount of certs a database should have. | 351 } |
150 // This prevents multiple vector growth / copies as we append certs. | |
151 certs.reserve(kMaxCerts); | |
152 store_->Load(&certs); | |
153 | 352 |
154 for (std::vector<ServerBoundCert*>::const_iterator it = certs.begin(); | 353 void DefaultServerBoundCertStore::OnLoaded( |
155 it != certs.end(); ++it) { | 354 scoped_ptr<ScopedVector<ServerBoundCert> > certs) { |
355 DCHECK(CalledOnValidThread()); | |
356 | |
357 for (std::vector<ServerBoundCert*>::const_iterator it = certs->begin(); | |
358 it != certs->end(); ++it) { | |
359 DCHECK(server_bound_certs_.find((*it)->server_identifier()) == | |
360 server_bound_certs_.end()); | |
156 server_bound_certs_[(*it)->server_identifier()] = *it; | 361 server_bound_certs_[(*it)->server_identifier()] = *it; |
157 } | 362 } |
363 certs->weak_clear(); | |
364 | |
365 loaded_ = true; | |
366 | |
367 base::TimeDelta wait_time; | |
368 if (!waiting_tasks_.empty()) | |
369 wait_time = base::TimeTicks::Now() - waiting_tasks_start_time_; | |
370 DVLOG(1) << "Task delay " << wait_time.InMilliseconds(); | |
371 UMA_HISTOGRAM_CUSTOM_TIMES("DomainBoundCerts.TaskMaxWaitTime", | |
372 wait_time, | |
373 base::TimeDelta::FromMilliseconds(1), | |
374 base::TimeDelta::FromMinutes(1), | |
375 50); | |
376 UMA_HISTOGRAM_COUNTS_100("DomainBoundCerts.TaskWaitCount", | |
377 waiting_tasks_.size()); | |
378 | |
379 | |
380 for (ScopedVector<Task>::iterator i = waiting_tasks_.begin(); | |
381 i != waiting_tasks_.end(); ++i) | |
382 (*i)->Run(this); | |
383 waiting_tasks_.clear(); | |
384 } | |
385 | |
386 void DefaultServerBoundCertStore::SyncSetServerBoundCert( | |
387 const std::string& server_identifier, | |
388 SSLClientCertType type, | |
389 base::Time creation_time, | |
390 base::Time expiration_time, | |
391 const std::string& private_key, | |
392 const std::string& cert) { | |
393 DCHECK(CalledOnValidThread()); | |
394 DCHECK(loaded_); | |
395 | |
396 InternalDeleteServerBoundCert(server_identifier); | |
397 InternalInsertServerBoundCert( | |
398 server_identifier, | |
399 new ServerBoundCert( | |
400 server_identifier, type, creation_time, expiration_time, private_key, | |
401 cert)); | |
402 } | |
403 | |
404 void DefaultServerBoundCertStore::SyncDeleteServerBoundCert( | |
405 const std::string& server_identifier) { | |
406 DCHECK(CalledOnValidThread()); | |
407 DCHECK(loaded_); | |
408 InternalDeleteServerBoundCert(server_identifier); | |
409 } | |
410 | |
411 void DefaultServerBoundCertStore::SyncDeleteAllCreatedBetween( | |
412 base::Time delete_begin, | |
413 base::Time delete_end) { | |
414 DCHECK(CalledOnValidThread()); | |
415 DCHECK(loaded_); | |
416 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); | |
417 it != server_bound_certs_.end();) { | |
418 ServerBoundCertMap::iterator cur = it; | |
419 ++it; | |
420 ServerBoundCert* cert = cur->second; | |
421 if ((delete_begin.is_null() || cert->creation_time() >= delete_begin) && | |
422 (delete_end.is_null() || cert->creation_time() < delete_end)) { | |
423 if (store_) | |
424 store_->DeleteServerBoundCert(*cert); | |
425 delete cert; | |
426 server_bound_certs_.erase(cur); | |
427 } | |
428 } | |
429 } | |
430 | |
431 void DefaultServerBoundCertStore::SyncGetAllServerBoundCerts( | |
432 ServerBoundCertList* cert_list) { | |
433 DCHECK(CalledOnValidThread()); | |
434 DCHECK(loaded_); | |
435 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); | |
436 it != server_bound_certs_.end(); ++it) | |
437 cert_list->push_back(*it->second); | |
438 } | |
439 | |
440 void DefaultServerBoundCertStore::EnqueueTask(Task* task) { | |
441 DCHECK(CalledOnValidThread()); | |
442 DCHECK(!loaded_); | |
443 if (waiting_tasks_.empty()) | |
444 waiting_tasks_start_time_ = base::TimeTicks::Now(); | |
445 waiting_tasks_.push_back(task); | |
446 } | |
447 | |
448 void DefaultServerBoundCertStore::RunOrEnqueueTask(Task* task) { | |
449 DCHECK(CalledOnValidThread()); | |
450 InitIfNecessary(); | |
451 | |
452 if (!loaded_) { | |
453 EnqueueTask(task); | |
454 return; | |
455 } | |
456 | |
457 task->Run(this); | |
458 delete task; | |
158 } | 459 } |
159 | 460 |
160 void DefaultServerBoundCertStore::InternalDeleteServerBoundCert( | 461 void DefaultServerBoundCertStore::InternalDeleteServerBoundCert( |
161 const std::string& server_identifier) { | 462 const std::string& server_identifier) { |
162 DCHECK(CalledOnValidThread()); | 463 DCHECK(CalledOnValidThread()); |
464 DCHECK(loaded_); | |
163 | 465 |
164 ServerBoundCertMap::iterator it = server_bound_certs_.find(server_identifier); | 466 ServerBoundCertMap::iterator it = server_bound_certs_.find(server_identifier); |
165 if (it == server_bound_certs_.end()) | 467 if (it == server_bound_certs_.end()) |
166 return; // There is nothing to delete. | 468 return; // There is nothing to delete. |
167 | 469 |
168 ServerBoundCert* cert = it->second; | 470 ServerBoundCert* cert = it->second; |
169 if (store_) | 471 if (store_) |
170 store_->DeleteServerBoundCert(*cert); | 472 store_->DeleteServerBoundCert(*cert); |
171 server_bound_certs_.erase(it); | 473 server_bound_certs_.erase(it); |
172 delete cert; | 474 delete cert; |
173 } | 475 } |
174 | 476 |
175 void DefaultServerBoundCertStore::InternalInsertServerBoundCert( | 477 void DefaultServerBoundCertStore::InternalInsertServerBoundCert( |
176 const std::string& server_identifier, | 478 const std::string& server_identifier, |
177 ServerBoundCert* cert) { | 479 ServerBoundCert* cert) { |
178 DCHECK(CalledOnValidThread()); | 480 DCHECK(CalledOnValidThread()); |
481 DCHECK(loaded_); | |
179 | 482 |
180 if (store_) | 483 if (store_) |
181 store_->AddServerBoundCert(*cert); | 484 store_->AddServerBoundCert(*cert); |
182 server_bound_certs_[server_identifier] = cert; | 485 server_bound_certs_[server_identifier] = cert; |
183 } | 486 } |
184 | 487 |
185 DefaultServerBoundCertStore::PersistentStore::PersistentStore() {} | 488 DefaultServerBoundCertStore::PersistentStore::PersistentStore() {} |
186 | 489 |
187 DefaultServerBoundCertStore::PersistentStore::~PersistentStore() {} | 490 DefaultServerBoundCertStore::PersistentStore::~PersistentStore() {} |
188 | 491 |
189 } // namespace net | 492 } // namespace net |
OLD | NEW |