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_CHANNEL_ID_SERVICE_H_ | 5 #ifndef NET_SSL_CHANNEL_ID_SERVICE_H_ |
6 #define NET_SSL_CHANNEL_ID_SERVICE_H_ | 6 #define NET_SSL_CHANNEL_ID_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
20 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
21 #include "net/ssl/channel_id_store.h" | 21 #include "net/ssl/channel_id_store.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class TaskRunner; | 24 class TaskRunner; |
25 } // namespace base | 25 } // namespace base |
(...skipping 25 matching lines...) Expand all Loading... |
51 | 51 |
52 bool is_active() const { return !callback_.is_null(); } | 52 bool is_active() const { return !callback_.is_null(); } |
53 | 53 |
54 private: | 54 private: |
55 friend class ChannelIDService; | 55 friend class ChannelIDService; |
56 friend class ChannelIDServiceJob; | 56 friend class ChannelIDServiceJob; |
57 | 57 |
58 void RequestStarted(ChannelIDService* service, | 58 void RequestStarted(ChannelIDService* service, |
59 base::TimeTicks request_start, | 59 base::TimeTicks request_start, |
60 const CompletionCallback& callback, | 60 const CompletionCallback& callback, |
61 scoped_ptr<crypto::ECPrivateKey>* key, | 61 std::unique_ptr<crypto::ECPrivateKey>* key, |
62 ChannelIDServiceJob* job); | 62 ChannelIDServiceJob* job); |
63 | 63 |
64 void Post(int error, scoped_ptr<crypto::ECPrivateKey> key); | 64 void Post(int error, std::unique_ptr<crypto::ECPrivateKey> key); |
65 | 65 |
66 ChannelIDService* service_; | 66 ChannelIDService* service_; |
67 base::TimeTicks request_start_; | 67 base::TimeTicks request_start_; |
68 CompletionCallback callback_; | 68 CompletionCallback callback_; |
69 scoped_ptr<crypto::ECPrivateKey>* key_; | 69 std::unique_ptr<crypto::ECPrivateKey>* key_; |
70 ChannelIDServiceJob* job_; | 70 ChannelIDServiceJob* job_; |
71 }; | 71 }; |
72 | 72 |
73 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key | 73 // Password used on EncryptedPrivateKeyInfo data stored in EC private_key |
74 // values. (This is not used to provide any security, but to workaround NSS | 74 // values. (This is not used to provide any security, but to workaround NSS |
75 // being unable to import unencrypted PrivateKeyInfo for EC keys.) | 75 // being unable to import unencrypted PrivateKeyInfo for EC keys.) |
76 static const char kEPKIPassword[]; | 76 static const char kEPKIPassword[]; |
77 | 77 |
78 // This object owns |channel_id_store|. |task_runner| will | 78 // This object owns |channel_id_store|. |task_runner| will |
79 // be used to post channel ID generation worker tasks. The tasks are | 79 // be used to post channel ID generation worker tasks. The tasks are |
(...skipping 15 matching lines...) Expand all Loading... |
95 // | 95 // |
96 // On successful completion, |key| holds the ECDSA keypair used for this | 96 // On successful completion, |key| holds the ECDSA keypair used for this |
97 // channel ID. | 97 // channel ID. |
98 // | 98 // |
99 // |callback| must not be null. ERR_IO_PENDING is returned if the operation | 99 // |callback| must not be null. ERR_IO_PENDING is returned if the operation |
100 // could not be completed immediately, in which case the result code will | 100 // could not be completed immediately, in which case the result code will |
101 // be passed to the callback when available. | 101 // be passed to the callback when available. |
102 // | 102 // |
103 // |*out_req| will be initialized with a handle to the async request. | 103 // |*out_req| will be initialized with a handle to the async request. |
104 int GetOrCreateChannelID(const std::string& host, | 104 int GetOrCreateChannelID(const std::string& host, |
105 scoped_ptr<crypto::ECPrivateKey>* key, | 105 std::unique_ptr<crypto::ECPrivateKey>* key, |
106 const CompletionCallback& callback, | 106 const CompletionCallback& callback, |
107 Request* out_req); | 107 Request* out_req); |
108 | 108 |
109 // Fetches the channel ID for the specified host if one exists. | 109 // Fetches the channel ID for the specified host if one exists. |
110 // Returns OK if successful, ERR_FILE_NOT_FOUND if none exists, or an error | 110 // Returns OK if successful, ERR_FILE_NOT_FOUND if none exists, or an error |
111 // code upon failure. | 111 // code upon failure. |
112 // | 112 // |
113 // On successful completion, |key| holds the ECDSA keypair used for this | 113 // On successful completion, |key| holds the ECDSA keypair used for this |
114 // channel ID. | 114 // channel ID. |
115 // | 115 // |
116 // |callback| must not be null. ERR_IO_PENDING is returned if the operation | 116 // |callback| must not be null. ERR_IO_PENDING is returned if the operation |
117 // could not be completed immediately, in which case the result code will | 117 // could not be completed immediately, in which case the result code will |
118 // be passed to the callback when available. If an in-flight | 118 // be passed to the callback when available. If an in-flight |
119 // GetChannelID is pending, and a new GetOrCreateChannelID | 119 // GetChannelID is pending, and a new GetOrCreateChannelID |
120 // request arrives for the same domain, the GetChannelID request will | 120 // request arrives for the same domain, the GetChannelID request will |
121 // not complete until a new channel ID is created. | 121 // not complete until a new channel ID is created. |
122 // | 122 // |
123 // |*out_req| will be initialized with a handle to the async request. | 123 // |*out_req| will be initialized with a handle to the async request. |
124 int GetChannelID(const std::string& host, | 124 int GetChannelID(const std::string& host, |
125 scoped_ptr<crypto::ECPrivateKey>* key, | 125 std::unique_ptr<crypto::ECPrivateKey>* key, |
126 const CompletionCallback& callback, | 126 const CompletionCallback& callback, |
127 Request* out_req); | 127 Request* out_req); |
128 | 128 |
129 // Returns the backing ChannelIDStore. | 129 // Returns the backing ChannelIDStore. |
130 ChannelIDStore* GetChannelIDStore(); | 130 ChannelIDStore* GetChannelIDStore(); |
131 | 131 |
132 // Returns an ID that is unique across all instances of ChannelIDService in | 132 // Returns an ID that is unique across all instances of ChannelIDService in |
133 // this process. TODO(nharper): remove this once crbug.com/548423 is resolved. | 133 // this process. TODO(nharper): remove this once crbug.com/548423 is resolved. |
134 int GetUniqueID() const { return id_; } | 134 int GetUniqueID() const { return id_; } |
135 | 135 |
136 // Public only for unit testing. | 136 // Public only for unit testing. |
137 int channel_id_count(); | 137 int channel_id_count(); |
138 uint64_t requests() const { return requests_; } | 138 uint64_t requests() const { return requests_; } |
139 uint64_t key_store_hits() const { return key_store_hits_; } | 139 uint64_t key_store_hits() const { return key_store_hits_; } |
140 uint64_t inflight_joins() const { return inflight_joins_; } | 140 uint64_t inflight_joins() const { return inflight_joins_; } |
141 uint64_t workers_created() const { return workers_created_; } | 141 uint64_t workers_created() const { return workers_created_; } |
142 | 142 |
143 private: | 143 private: |
144 void GotChannelID(int err, | 144 void GotChannelID(int err, |
145 const std::string& server_identifier, | 145 const std::string& server_identifier, |
146 scoped_ptr<crypto::ECPrivateKey> key); | 146 std::unique_ptr<crypto::ECPrivateKey> key); |
147 void GeneratedChannelID( | 147 void GeneratedChannelID( |
148 const std::string& server_identifier, | 148 const std::string& server_identifier, |
149 int error, | 149 int error, |
150 scoped_ptr<ChannelIDStore::ChannelID> channel_id); | 150 std::unique_ptr<ChannelIDStore::ChannelID> channel_id); |
151 void HandleResult(int error, | 151 void HandleResult(int error, |
152 const std::string& server_identifier, | 152 const std::string& server_identifier, |
153 scoped_ptr<crypto::ECPrivateKey> key); | 153 std::unique_ptr<crypto::ECPrivateKey> key); |
154 | 154 |
155 // Searches for an in-flight request for the same domain. If found, | 155 // Searches for an in-flight request for the same domain. If found, |
156 // attaches to the request and returns true. Returns false if no in-flight | 156 // attaches to the request and returns true. Returns false if no in-flight |
157 // request is found. | 157 // request is found. |
158 bool JoinToInFlightRequest(const base::TimeTicks& request_start, | 158 bool JoinToInFlightRequest(const base::TimeTicks& request_start, |
159 const std::string& domain, | 159 const std::string& domain, |
160 scoped_ptr<crypto::ECPrivateKey>* key, | 160 std::unique_ptr<crypto::ECPrivateKey>* key, |
161 bool create_if_missing, | 161 bool create_if_missing, |
162 const CompletionCallback& callback, | 162 const CompletionCallback& callback, |
163 Request* out_req); | 163 Request* out_req); |
164 | 164 |
165 // Looks for the channel ID for |domain| in this service's store. | 165 // Looks for the channel ID for |domain| in this service's store. |
166 // Returns OK if it can be found synchronously, ERR_IO_PENDING if the | 166 // Returns OK if it can be found synchronously, ERR_IO_PENDING if the |
167 // result cannot be obtained synchronously, or a network error code on | 167 // result cannot be obtained synchronously, or a network error code on |
168 // failure (including failure to find a channel ID of |domain|). | 168 // failure (including failure to find a channel ID of |domain|). |
169 int LookupChannelID(const base::TimeTicks& request_start, | 169 int LookupChannelID(const base::TimeTicks& request_start, |
170 const std::string& domain, | 170 const std::string& domain, |
171 scoped_ptr<crypto::ECPrivateKey>* key, | 171 std::unique_ptr<crypto::ECPrivateKey>* key, |
172 bool create_if_missing, | 172 bool create_if_missing, |
173 const CompletionCallback& callback, | 173 const CompletionCallback& callback, |
174 Request* out_req); | 174 Request* out_req); |
175 | 175 |
176 scoped_ptr<ChannelIDStore> channel_id_store_; | 176 std::unique_ptr<ChannelIDStore> channel_id_store_; |
177 scoped_refptr<base::TaskRunner> task_runner_; | 177 scoped_refptr<base::TaskRunner> task_runner_; |
178 const int id_; | 178 const int id_; |
179 | 179 |
180 // inflight_ maps from a server to an active generation which is taking | 180 // inflight_ maps from a server to an active generation which is taking |
181 // place. | 181 // place. |
182 std::map<std::string, ChannelIDServiceJob*> inflight_; | 182 std::map<std::string, ChannelIDServiceJob*> inflight_; |
183 | 183 |
184 uint64_t requests_; | 184 uint64_t requests_; |
185 uint64_t key_store_hits_; | 185 uint64_t key_store_hits_; |
186 uint64_t inflight_joins_; | 186 uint64_t inflight_joins_; |
187 uint64_t workers_created_; | 187 uint64_t workers_created_; |
188 | 188 |
189 base::WeakPtrFactory<ChannelIDService> weak_ptr_factory_; | 189 base::WeakPtrFactory<ChannelIDService> weak_ptr_factory_; |
190 | 190 |
191 DISALLOW_COPY_AND_ASSIGN(ChannelIDService); | 191 DISALLOW_COPY_AND_ASSIGN(ChannelIDService); |
192 }; | 192 }; |
193 | 193 |
194 } // namespace net | 194 } // namespace net |
195 | 195 |
196 #endif // NET_SSL_CHANNEL_ID_SERVICE_H_ | 196 #endif // NET_SSL_CHANNEL_ID_SERVICE_H_ |
OLD | NEW |