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 | 9 |
10 namespace net { | 10 namespace net { |
11 | 11 |
12 // static | 12 // static |
13 const size_t DefaultServerBoundCertStore::kMaxCerts = 3300; | 13 const size_t DefaultServerBoundCertStore::kMaxCerts = 3300; |
14 | 14 |
15 DefaultServerBoundCertStore::DefaultServerBoundCertStore( | 15 DefaultServerBoundCertStore::DefaultServerBoundCertStore( |
16 PersistentStore* store) | 16 PersistentStore* store) |
17 : initialized_(false), | 17 : initialized_(false), |
18 store_(store) {} | 18 store_(store) {} |
19 | 19 |
20 void DefaultServerBoundCertStore::FlushStore( | 20 void DefaultServerBoundCertStore::FlushStore( |
21 const base::Closure& completion_task) { | 21 const base::Closure& completion_task) { |
22 base::AutoLock autolock(lock_); | 22 base::AutoLock autolock(lock_); |
23 | 23 |
24 if (initialized_ && store_) | 24 if (initialized_ && store_.get()) |
25 store_->Flush(completion_task); | 25 store_->Flush(completion_task); |
26 else if (!completion_task.is_null()) | 26 else if (!completion_task.is_null()) |
27 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 27 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
28 } | 28 } |
29 | 29 |
30 bool DefaultServerBoundCertStore::GetServerBoundCert( | 30 bool DefaultServerBoundCertStore::GetServerBoundCert( |
31 const std::string& server_identifier, | 31 const std::string& server_identifier, |
32 SSLClientCertType* type, | 32 SSLClientCertType* type, |
33 base::Time* creation_time, | 33 base::Time* creation_time, |
34 base::Time* expiration_time, | 34 base::Time* expiration_time, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 base::Time delete_end) { | 82 base::Time delete_end) { |
83 base::AutoLock autolock(lock_); | 83 base::AutoLock autolock(lock_); |
84 InitIfNecessary(); | 84 InitIfNecessary(); |
85 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); | 85 for (ServerBoundCertMap::iterator it = server_bound_certs_.begin(); |
86 it != server_bound_certs_.end();) { | 86 it != server_bound_certs_.end();) { |
87 ServerBoundCertMap::iterator cur = it; | 87 ServerBoundCertMap::iterator cur = it; |
88 ++it; | 88 ++it; |
89 ServerBoundCert* cert = cur->second; | 89 ServerBoundCert* cert = cur->second; |
90 if ((delete_begin.is_null() || cert->creation_time() >= delete_begin) && | 90 if ((delete_begin.is_null() || cert->creation_time() >= delete_begin) && |
91 (delete_end.is_null() || cert->creation_time() < delete_end)) { | 91 (delete_end.is_null() || cert->creation_time() < delete_end)) { |
92 if (store_) | 92 if (store_.get()) |
93 store_->DeleteServerBoundCert(*cert); | 93 store_->DeleteServerBoundCert(*cert); |
94 delete cert; | 94 delete cert; |
95 server_bound_certs_.erase(cur); | 95 server_bound_certs_.erase(cur); |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void DefaultServerBoundCertStore::DeleteAll() { | 100 void DefaultServerBoundCertStore::DeleteAll() { |
101 DeleteAllCreatedBetween(base::Time(), base::Time()); | 101 DeleteAllCreatedBetween(base::Time(), base::Time()); |
102 } | 102 } |
(...skipping 12 matching lines...) Expand all Loading... |
115 base::AutoLock autolock(lock_); | 115 base::AutoLock autolock(lock_); |
116 InitIfNecessary(); | 116 InitIfNecessary(); |
117 | 117 |
118 return server_bound_certs_.size(); | 118 return server_bound_certs_.size(); |
119 } | 119 } |
120 | 120 |
121 void DefaultServerBoundCertStore::SetForceKeepSessionState() { | 121 void DefaultServerBoundCertStore::SetForceKeepSessionState() { |
122 base::AutoLock autolock(lock_); | 122 base::AutoLock autolock(lock_); |
123 InitIfNecessary(); | 123 InitIfNecessary(); |
124 | 124 |
125 if (store_) | 125 if (store_.get()) |
126 store_->SetForceKeepSessionState(); | 126 store_->SetForceKeepSessionState(); |
127 } | 127 } |
128 | 128 |
129 DefaultServerBoundCertStore::~DefaultServerBoundCertStore() { | 129 DefaultServerBoundCertStore::~DefaultServerBoundCertStore() { |
130 DeleteAllInMemory(); | 130 DeleteAllInMemory(); |
131 } | 131 } |
132 | 132 |
133 void DefaultServerBoundCertStore::DeleteAllInMemory() { | 133 void DefaultServerBoundCertStore::DeleteAllInMemory() { |
134 base::AutoLock autolock(lock_); | 134 base::AutoLock autolock(lock_); |
135 | 135 |
(...skipping 24 matching lines...) Expand all Loading... |
160 | 160 |
161 void DefaultServerBoundCertStore::InternalDeleteServerBoundCert( | 161 void DefaultServerBoundCertStore::InternalDeleteServerBoundCert( |
162 const std::string& server_identifier) { | 162 const std::string& server_identifier) { |
163 lock_.AssertAcquired(); | 163 lock_.AssertAcquired(); |
164 | 164 |
165 ServerBoundCertMap::iterator it = server_bound_certs_.find(server_identifier); | 165 ServerBoundCertMap::iterator it = server_bound_certs_.find(server_identifier); |
166 if (it == server_bound_certs_.end()) | 166 if (it == server_bound_certs_.end()) |
167 return; // There is nothing to delete. | 167 return; // There is nothing to delete. |
168 | 168 |
169 ServerBoundCert* cert = it->second; | 169 ServerBoundCert* cert = it->second; |
170 if (store_) | 170 if (store_.get()) |
171 store_->DeleteServerBoundCert(*cert); | 171 store_->DeleteServerBoundCert(*cert); |
172 server_bound_certs_.erase(it); | 172 server_bound_certs_.erase(it); |
173 delete cert; | 173 delete cert; |
174 } | 174 } |
175 | 175 |
176 void DefaultServerBoundCertStore::InternalInsertServerBoundCert( | 176 void DefaultServerBoundCertStore::InternalInsertServerBoundCert( |
177 const std::string& server_identifier, | 177 const std::string& server_identifier, |
178 ServerBoundCert* cert) { | 178 ServerBoundCert* cert) { |
179 lock_.AssertAcquired(); | 179 lock_.AssertAcquired(); |
180 | 180 |
181 if (store_) | 181 if (store_.get()) |
182 store_->AddServerBoundCert(*cert); | 182 store_->AddServerBoundCert(*cert); |
183 server_bound_certs_[server_identifier] = cert; | 183 server_bound_certs_[server_identifier] = cert; |
184 } | 184 } |
185 | 185 |
186 DefaultServerBoundCertStore::PersistentStore::PersistentStore() {} | 186 DefaultServerBoundCertStore::PersistentStore::PersistentStore() {} |
187 | 187 |
188 DefaultServerBoundCertStore::PersistentStore::~PersistentStore() {} | 188 DefaultServerBoundCertStore::PersistentStore::~PersistentStore() {} |
189 | 189 |
190 } // namespace net | 190 } // namespace net |
OLD | NEW |