OLD | NEW |
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 #ifndef NET_SSL_DEFAULT_CHANNEL_ID_STORE_H_ | 5 #ifndef NET_SSL_DEFAULT_CHANNEL_ID_STORE_H_ |
6 #define NET_SSL_DEFAULT_CHANNEL_ID_STORE_H_ | 6 #define NET_SSL_DEFAULT_CHANNEL_ID_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
20 #include "net/ssl/channel_id_store.h" | 20 #include "net/ssl/channel_id_store.h" |
21 | 21 |
22 namespace crypto { | 22 namespace crypto { |
23 class ECPrivateKey; | 23 class ECPrivateKey; |
24 } // namespace crypto | 24 } // namespace crypto |
25 | 25 |
26 namespace net { | 26 namespace net { |
(...skipping 15 matching lines...) Expand all Loading... |
42 // class will take care of initializing it. The backing store is NOT owned by | 42 // class will take care of initializing it. The backing store is NOT owned by |
43 // this class, but it must remain valid for the duration of the | 43 // this class, but it must remain valid for the duration of the |
44 // DefaultChannelIDStore's existence. If |store| is NULL, then no | 44 // DefaultChannelIDStore's existence. If |store| is NULL, then no |
45 // backing store will be updated. | 45 // backing store will be updated. |
46 explicit DefaultChannelIDStore(PersistentStore* store); | 46 explicit DefaultChannelIDStore(PersistentStore* store); |
47 | 47 |
48 ~DefaultChannelIDStore() override; | 48 ~DefaultChannelIDStore() override; |
49 | 49 |
50 // ChannelIDStore implementation. | 50 // ChannelIDStore implementation. |
51 int GetChannelID(const std::string& server_identifier, | 51 int GetChannelID(const std::string& server_identifier, |
52 scoped_ptr<crypto::ECPrivateKey>* key_result, | 52 std::unique_ptr<crypto::ECPrivateKey>* key_result, |
53 const GetChannelIDCallback& callback) override; | 53 const GetChannelIDCallback& callback) override; |
54 void SetChannelID(scoped_ptr<ChannelID> channel_id) override; | 54 void SetChannelID(std::unique_ptr<ChannelID> channel_id) override; |
55 void DeleteChannelID(const std::string& server_identifier, | 55 void DeleteChannelID(const std::string& server_identifier, |
56 const base::Closure& callback) override; | 56 const base::Closure& callback) override; |
57 void DeleteAllCreatedBetween(base::Time delete_begin, | 57 void DeleteAllCreatedBetween(base::Time delete_begin, |
58 base::Time delete_end, | 58 base::Time delete_end, |
59 const base::Closure& callback) override; | 59 const base::Closure& callback) override; |
60 void DeleteAll(const base::Closure& callback) override; | 60 void DeleteAll(const base::Closure& callback) override; |
61 void GetAllChannelIDs(const GetChannelIDListCallback& callback) override; | 61 void GetAllChannelIDs(const GetChannelIDListCallback& callback) override; |
62 int GetChannelIDCount() override; | 62 int GetChannelIDCount() override; |
63 void SetForceKeepSessionState() override; | 63 void SetForceKeepSessionState() override; |
64 bool IsEphemeral() override; | 64 bool IsEphemeral() override; |
(...skipping 23 matching lines...) Expand all Loading... |
88 } | 88 } |
89 initialized_ = true; | 89 initialized_ = true; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 // Initializes the backing store and reads existing certs from it. | 93 // Initializes the backing store and reads existing certs from it. |
94 // Should only be called by InitIfNecessary(). | 94 // Should only be called by InitIfNecessary(). |
95 void InitStore(); | 95 void InitStore(); |
96 | 96 |
97 // Callback for backing store loading completion. | 97 // Callback for backing store loading completion. |
98 void OnLoaded(scoped_ptr<std::vector<scoped_ptr<ChannelID>>> certs); | 98 void OnLoaded(std::unique_ptr<std::vector<std::unique_ptr<ChannelID>>> certs); |
99 | 99 |
100 // Syncronous methods which do the actual work. Can only be called after | 100 // Syncronous methods which do the actual work. Can only be called after |
101 // initialization is complete. | 101 // initialization is complete. |
102 void SyncSetChannelID(scoped_ptr<ChannelID> channel_id); | 102 void SyncSetChannelID(std::unique_ptr<ChannelID> channel_id); |
103 void SyncDeleteChannelID(const std::string& server_identifier); | 103 void SyncDeleteChannelID(const std::string& server_identifier); |
104 void SyncDeleteAllCreatedBetween(base::Time delete_begin, | 104 void SyncDeleteAllCreatedBetween(base::Time delete_begin, |
105 base::Time delete_end); | 105 base::Time delete_end); |
106 void SyncGetAllChannelIDs(ChannelIDList* channel_id_list); | 106 void SyncGetAllChannelIDs(ChannelIDList* channel_id_list); |
107 | 107 |
108 // Add |task| to |waiting_tasks_|. | 108 // Add |task| to |waiting_tasks_|. |
109 void EnqueueTask(scoped_ptr<Task> task); | 109 void EnqueueTask(std::unique_ptr<Task> task); |
110 // If already initialized, run |task| immediately. Otherwise add it to | 110 // If already initialized, run |task| immediately. Otherwise add it to |
111 // |waiting_tasks_|. | 111 // |waiting_tasks_|. |
112 void RunOrEnqueueTask(scoped_ptr<Task> task); | 112 void RunOrEnqueueTask(std::unique_ptr<Task> task); |
113 | 113 |
114 // Deletes the channel id for the specified server, if such a channel id | 114 // Deletes the channel id for the specified server, if such a channel id |
115 // exists, from the in-memory store. Deletes it from |store_| if |store_| | 115 // exists, from the in-memory store. Deletes it from |store_| if |store_| |
116 // is not NULL. | 116 // is not NULL. |
117 void InternalDeleteChannelID(const std::string& server); | 117 void InternalDeleteChannelID(const std::string& server); |
118 | 118 |
119 // Adds the channel id to the in-memory store and adds it to |store_| if | 119 // Adds the channel id to the in-memory store and adds it to |store_| if |
120 // |store_| is not NULL. | 120 // |store_| is not NULL. |
121 void InternalInsertChannelID(scoped_ptr<ChannelID> channel_id); | 121 void InternalInsertChannelID(std::unique_ptr<ChannelID> channel_id); |
122 | 122 |
123 // Indicates whether the channel id store has been initialized. This happens | 123 // Indicates whether the channel id store has been initialized. This happens |
124 // lazily in InitIfNecessary(). | 124 // lazily in InitIfNecessary(). |
125 bool initialized_; | 125 bool initialized_; |
126 | 126 |
127 // Indicates whether loading from the backend store is completed and | 127 // Indicates whether loading from the backend store is completed and |
128 // calls may be immediately processed. | 128 // calls may be immediately processed. |
129 bool loaded_; | 129 bool loaded_; |
130 | 130 |
131 // Tasks that are waiting to be run once we finish loading. | 131 // Tasks that are waiting to be run once we finish loading. |
132 std::vector<scoped_ptr<Task>> waiting_tasks_; | 132 std::vector<std::unique_ptr<Task>> waiting_tasks_; |
133 base::TimeTicks waiting_tasks_start_time_; | 133 base::TimeTicks waiting_tasks_start_time_; |
134 | 134 |
135 scoped_refptr<PersistentStore> store_; | 135 scoped_refptr<PersistentStore> store_; |
136 | 136 |
137 ChannelIDMap channel_ids_; | 137 ChannelIDMap channel_ids_; |
138 | 138 |
139 base::WeakPtrFactory<DefaultChannelIDStore> weak_ptr_factory_; | 139 base::WeakPtrFactory<DefaultChannelIDStore> weak_ptr_factory_; |
140 | 140 |
141 DISALLOW_COPY_AND_ASSIGN(DefaultChannelIDStore); | 141 DISALLOW_COPY_AND_ASSIGN(DefaultChannelIDStore); |
142 }; | 142 }; |
143 | 143 |
144 typedef base::RefCountedThreadSafe<DefaultChannelIDStore::PersistentStore> | 144 typedef base::RefCountedThreadSafe<DefaultChannelIDStore::PersistentStore> |
145 RefcountedPersistentStore; | 145 RefcountedPersistentStore; |
146 | 146 |
147 class NET_EXPORT DefaultChannelIDStore::PersistentStore | 147 class NET_EXPORT DefaultChannelIDStore::PersistentStore |
148 : public RefcountedPersistentStore { | 148 : public RefcountedPersistentStore { |
149 public: | 149 public: |
150 typedef base::Callback<void(scoped_ptr<std::vector<scoped_ptr<ChannelID>>>)> | 150 typedef base::Callback<void( |
| 151 std::unique_ptr<std::vector<std::unique_ptr<ChannelID>>>)> |
151 LoadedCallback; | 152 LoadedCallback; |
152 | 153 |
153 // Initializes the store and retrieves the existing channel_ids. This will be | 154 // Initializes the store and retrieves the existing channel_ids. This will be |
154 // called only once at startup. Note that the channel_ids are individually | 155 // called only once at startup. Note that the channel_ids are individually |
155 // allocated and that ownership is transferred to the caller upon return. | 156 // allocated and that ownership is transferred to the caller upon return. |
156 // The |loaded_callback| must not be called synchronously. | 157 // The |loaded_callback| must not be called synchronously. |
157 virtual void Load(const LoadedCallback& loaded_callback) = 0; | 158 virtual void Load(const LoadedCallback& loaded_callback) = 0; |
158 | 159 |
159 virtual void AddChannelID(const ChannelID& channel_id) = 0; | 160 virtual void AddChannelID(const ChannelID& channel_id) = 0; |
160 | 161 |
161 virtual void DeleteChannelID(const ChannelID& channel_id) = 0; | 162 virtual void DeleteChannelID(const ChannelID& channel_id) = 0; |
162 | 163 |
163 // When invoked, instructs the store to keep session related data on | 164 // When invoked, instructs the store to keep session related data on |
164 // destruction. | 165 // destruction. |
165 virtual void SetForceKeepSessionState() = 0; | 166 virtual void SetForceKeepSessionState() = 0; |
166 | 167 |
167 protected: | 168 protected: |
168 friend class base::RefCountedThreadSafe<PersistentStore>; | 169 friend class base::RefCountedThreadSafe<PersistentStore>; |
169 | 170 |
170 PersistentStore(); | 171 PersistentStore(); |
171 virtual ~PersistentStore(); | 172 virtual ~PersistentStore(); |
172 | 173 |
173 private: | 174 private: |
174 DISALLOW_COPY_AND_ASSIGN(PersistentStore); | 175 DISALLOW_COPY_AND_ASSIGN(PersistentStore); |
175 }; | 176 }; |
176 | 177 |
177 } // namespace net | 178 } // namespace net |
178 | 179 |
179 #endif // NET_SSL_DEFAULT_CHANNEL_ID_STORE_H_ | 180 #endif // NET_SSL_DEFAULT_CHANNEL_ID_STORE_H_ |
OLD | NEW |