| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_origin_bound_cert_store.h" | 5 #include "net/base/default_origin_bound_cert_store.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 if (it == origin_bound_certs_.end()) | 37 if (it == origin_bound_certs_.end()) |
| 38 return false; | 38 return false; |
| 39 | 39 |
| 40 OriginBoundCert* cert = it->second; | 40 OriginBoundCert* cert = it->second; |
| 41 *private_key_result = cert->private_key(); | 41 *private_key_result = cert->private_key(); |
| 42 *cert_result = cert->cert(); | 42 *cert_result = cert->cert(); |
| 43 | 43 |
| 44 return true; | 44 return true; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool DefaultOriginBoundCertStore::SetOriginBoundCert( | 47 void DefaultOriginBoundCertStore::SetOriginBoundCert( |
| 48 const std::string& origin, | 48 const std::string& origin, |
| 49 const std::string& private_key, | 49 const std::string& private_key, |
| 50 const std::string& cert) { | 50 const std::string& cert) { |
| 51 base::AutoLock autolock(lock_); | 51 base::AutoLock autolock(lock_); |
| 52 InitIfNecessary(); | 52 InitIfNecessary(); |
| 53 | 53 |
| 54 InternalDeleteOriginBoundCert(origin); | 54 InternalDeleteOriginBoundCert(origin); |
| 55 InternalInsertOriginBoundCert(origin, | 55 InternalInsertOriginBoundCert(origin, |
| 56 new OriginBoundCert(origin, private_key, cert)); | 56 new OriginBoundCert(origin, private_key, cert)); |
| 57 } |
| 57 | 58 |
| 58 return true; | 59 void DefaultOriginBoundCertStore::DeleteOriginBoundCert( |
| 60 const std::string& origin) { |
| 61 base::AutoLock autolock(lock_); |
| 62 InitIfNecessary(); |
| 63 InternalDeleteOriginBoundCert(origin); |
| 64 } |
| 65 |
| 66 void DefaultOriginBoundCertStore::DeleteAll() { |
| 67 base::AutoLock autolock(lock_); |
| 68 InitIfNecessary(); |
| 69 for (OriginBoundCertMap::iterator it = origin_bound_certs_.begin(); |
| 70 it != origin_bound_certs_.end(); ++it) { |
| 71 OriginBoundCert* cert = it->second; |
| 72 if (store_) |
| 73 store_->DeleteOriginBoundCert(*cert); |
| 74 delete cert; |
| 75 } |
| 76 origin_bound_certs_.clear(); |
| 77 } |
| 78 |
| 79 void DefaultOriginBoundCertStore::GetAllOriginBoundCerts( |
| 80 std::vector<OriginBoundCertInfo>* origin_bound_certs) { |
| 81 base::AutoLock autolock(lock_); |
| 82 InitIfNecessary(); |
| 83 for (OriginBoundCertMap::iterator it = origin_bound_certs_.begin(); |
| 84 it != origin_bound_certs_.end(); ++it) { |
| 85 OriginBoundCertInfo cert_info = { |
| 86 it->second->origin(), |
| 87 it->second->private_key(), |
| 88 it->second->cert() |
| 89 }; |
| 90 // TODO(rkn): Make changes so we can simply write |
| 91 // origin_bound_certs->push_back(*it->second). This is probably best done |
| 92 // by unnesting the OriginBoundCert class. |
| 93 origin_bound_certs->push_back(cert_info); |
| 94 } |
| 59 } | 95 } |
| 60 | 96 |
| 61 int DefaultOriginBoundCertStore::GetCertCount() { | 97 int DefaultOriginBoundCertStore::GetCertCount() { |
| 62 base::AutoLock autolock(lock_); | 98 base::AutoLock autolock(lock_); |
| 63 InitIfNecessary(); | 99 InitIfNecessary(); |
| 64 | 100 |
| 65 return origin_bound_certs_.size(); | 101 return origin_bound_certs_.size(); |
| 66 } | 102 } |
| 67 | 103 |
| 68 DefaultOriginBoundCertStore::~DefaultOriginBoundCertStore() { | 104 DefaultOriginBoundCertStore::~DefaultOriginBoundCertStore() { |
| 69 DeleteAll(); | 105 DeleteAllInMemory(); |
| 70 } | 106 } |
| 71 | 107 |
| 72 void DefaultOriginBoundCertStore::DeleteAll() { | 108 void DefaultOriginBoundCertStore::DeleteAllInMemory() { |
| 73 base::AutoLock autolock(lock_); | 109 base::AutoLock autolock(lock_); |
| 74 | 110 |
| 75 for (OriginBoundCertMap::iterator it = origin_bound_certs_.begin(); | 111 for (OriginBoundCertMap::iterator it = origin_bound_certs_.begin(); |
| 76 it != origin_bound_certs_.end(); it++) { | 112 it != origin_bound_certs_.end(); ++it) { |
| 77 delete it->second; | 113 delete it->second; |
| 78 } | 114 } |
| 79 origin_bound_certs_.clear(); | 115 origin_bound_certs_.clear(); |
| 80 } | 116 } |
| 81 | 117 |
| 82 void DefaultOriginBoundCertStore::InitStore() { | 118 void DefaultOriginBoundCertStore::InitStore() { |
| 83 lock_.AssertAcquired(); | 119 lock_.AssertAcquired(); |
| 84 | 120 |
| 85 DCHECK(store_) << "Store must exist to initialize"; | 121 DCHECK(store_) << "Store must exist to initialize"; |
| 86 | 122 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 const std::string& origin, | 164 const std::string& origin, |
| 129 const std::string& private_key, | 165 const std::string& private_key, |
| 130 const std::string& cert) | 166 const std::string& cert) |
| 131 : origin_(origin), | 167 : origin_(origin), |
| 132 private_key_(private_key), | 168 private_key_(private_key), |
| 133 cert_(cert) {} | 169 cert_(cert) {} |
| 134 | 170 |
| 135 DefaultOriginBoundCertStore::PersistentStore::PersistentStore() {} | 171 DefaultOriginBoundCertStore::PersistentStore::PersistentStore() {} |
| 136 | 172 |
| 137 } // namespace net | 173 } // namespace net |
| OLD | NEW |