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 #include "net/ssl/default_channel_id_store.h" | 5 #include "net/ssl/default_channel_id_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const GetChannelIDCallback& callback) | 54 const GetChannelIDCallback& callback) |
55 : server_identifier_(server_identifier), | 55 : server_identifier_(server_identifier), |
56 callback_(callback) { | 56 callback_(callback) { |
57 } | 57 } |
58 | 58 |
59 DefaultChannelIDStore::GetChannelIDTask::~GetChannelIDTask() { | 59 DefaultChannelIDStore::GetChannelIDTask::~GetChannelIDTask() { |
60 } | 60 } |
61 | 61 |
62 void DefaultChannelIDStore::GetChannelIDTask::Run( | 62 void DefaultChannelIDStore::GetChannelIDTask::Run( |
63 DefaultChannelIDStore* store) { | 63 DefaultChannelIDStore* store) { |
64 base::Time expiration_time; | |
65 std::string private_key_result; | 64 std::string private_key_result; |
66 std::string cert_result; | 65 std::string public_key_result; |
67 int err = store->GetChannelID( | 66 int err = store->GetChannelID(server_identifier_, &private_key_result, |
68 server_identifier_, &expiration_time, &private_key_result, | 67 &public_key_result, GetChannelIDCallback()); |
69 &cert_result, GetChannelIDCallback()); | |
70 DCHECK(err != ERR_IO_PENDING); | 68 DCHECK(err != ERR_IO_PENDING); |
71 | 69 |
72 InvokeCallback(base::Bind(callback_, err, server_identifier_, | 70 InvokeCallback(base::Bind(callback_, err, server_identifier_, |
73 expiration_time, private_key_result, cert_result)); | 71 private_key_result, public_key_result)); |
74 } | 72 } |
75 | 73 |
76 // -------------------------------------------------------------------------- | 74 // -------------------------------------------------------------------------- |
77 // SetChannelIDTask | 75 // SetChannelIDTask |
78 class DefaultChannelIDStore::SetChannelIDTask | 76 class DefaultChannelIDStore::SetChannelIDTask |
79 : public DefaultChannelIDStore::Task { | 77 : public DefaultChannelIDStore::Task { |
80 public: | 78 public: |
81 SetChannelIDTask(const std::string& server_identifier, | 79 SetChannelIDTask(const std::string& server_identifier, |
82 base::Time creation_time, | 80 base::Time creation_time, |
83 base::Time expiration_time, | |
84 const std::string& private_key, | 81 const std::string& private_key, |
85 const std::string& cert); | 82 const std::string& public_key); |
86 ~SetChannelIDTask() override; | 83 ~SetChannelIDTask() override; |
87 void Run(DefaultChannelIDStore* store) override; | 84 void Run(DefaultChannelIDStore* store) override; |
88 | 85 |
89 private: | 86 private: |
90 std::string server_identifier_; | 87 std::string server_identifier_; |
91 base::Time creation_time_; | 88 base::Time creation_time_; |
92 base::Time expiration_time_; | |
93 std::string private_key_; | 89 std::string private_key_; |
94 std::string cert_; | 90 std::string public_key_; |
95 }; | 91 }; |
96 | 92 |
97 DefaultChannelIDStore::SetChannelIDTask::SetChannelIDTask( | 93 DefaultChannelIDStore::SetChannelIDTask::SetChannelIDTask( |
98 const std::string& server_identifier, | 94 const std::string& server_identifier, |
99 base::Time creation_time, | 95 base::Time creation_time, |
100 base::Time expiration_time, | |
101 const std::string& private_key, | 96 const std::string& private_key, |
102 const std::string& cert) | 97 const std::string& public_key) |
103 : server_identifier_(server_identifier), | 98 : server_identifier_(server_identifier), |
104 creation_time_(creation_time), | 99 creation_time_(creation_time), |
105 expiration_time_(expiration_time), | |
106 private_key_(private_key), | 100 private_key_(private_key), |
107 cert_(cert) { | 101 public_key_(public_key) { |
108 } | 102 } |
109 | 103 |
110 DefaultChannelIDStore::SetChannelIDTask::~SetChannelIDTask() { | 104 DefaultChannelIDStore::SetChannelIDTask::~SetChannelIDTask() { |
111 } | 105 } |
112 | 106 |
113 void DefaultChannelIDStore::SetChannelIDTask::Run( | 107 void DefaultChannelIDStore::SetChannelIDTask::Run( |
114 DefaultChannelIDStore* store) { | 108 DefaultChannelIDStore* store) { |
115 store->SyncSetChannelID(server_identifier_, creation_time_, | 109 store->SyncSetChannelID(server_identifier_, creation_time_, private_key_, |
116 expiration_time_, private_key_, cert_); | 110 public_key_); |
117 } | 111 } |
118 | 112 |
119 // -------------------------------------------------------------------------- | 113 // -------------------------------------------------------------------------- |
120 // DeleteChannelIDTask | 114 // DeleteChannelIDTask |
121 class DefaultChannelIDStore::DeleteChannelIDTask | 115 class DefaultChannelIDStore::DeleteChannelIDTask |
122 : public DefaultChannelIDStore::Task { | 116 : public DefaultChannelIDStore::Task { |
123 public: | 117 public: |
124 DeleteChannelIDTask(const std::string& server_identifier, | 118 DeleteChannelIDTask(const std::string& server_identifier, |
125 const base::Closure& callback); | 119 const base::Closure& callback); |
126 ~DeleteChannelIDTask() override; | 120 ~DeleteChannelIDTask() override; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 GetAllChannelIDsTask(const GetChannelIDListCallback& callback) | 200 GetAllChannelIDsTask(const GetChannelIDListCallback& callback) |
207 : callback_(callback) { | 201 : callback_(callback) { |
208 } | 202 } |
209 | 203 |
210 DefaultChannelIDStore::GetAllChannelIDsTask:: | 204 DefaultChannelIDStore::GetAllChannelIDsTask:: |
211 ~GetAllChannelIDsTask() { | 205 ~GetAllChannelIDsTask() { |
212 } | 206 } |
213 | 207 |
214 void DefaultChannelIDStore::GetAllChannelIDsTask::Run( | 208 void DefaultChannelIDStore::GetAllChannelIDsTask::Run( |
215 DefaultChannelIDStore* store) { | 209 DefaultChannelIDStore* store) { |
216 ChannelIDList cert_list; | 210 ChannelIDList key_list; |
217 store->SyncGetAllChannelIDs(&cert_list); | 211 store->SyncGetAllChannelIDs(&key_list); |
218 | 212 |
219 InvokeCallback(base::Bind(callback_, cert_list)); | 213 InvokeCallback(base::Bind(callback_, key_list)); |
220 } | 214 } |
221 | 215 |
222 // -------------------------------------------------------------------------- | 216 // -------------------------------------------------------------------------- |
223 // DefaultChannelIDStore | 217 // DefaultChannelIDStore |
224 | 218 |
225 DefaultChannelIDStore::DefaultChannelIDStore( | 219 DefaultChannelIDStore::DefaultChannelIDStore( |
226 PersistentStore* store) | 220 PersistentStore* store) |
227 : initialized_(false), | 221 : initialized_(false), |
228 loaded_(false), | 222 loaded_(false), |
229 store_(store), | 223 store_(store), |
230 weak_ptr_factory_(this) {} | 224 weak_ptr_factory_(this) {} |
231 | 225 |
232 int DefaultChannelIDStore::GetChannelID( | 226 int DefaultChannelIDStore::GetChannelID(const std::string& server_identifier, |
233 const std::string& server_identifier, | 227 std::string* private_key_result, |
234 base::Time* expiration_time, | 228 std::string* public_key_result, |
235 std::string* private_key_result, | 229 const GetChannelIDCallback& callback) { |
236 std::string* cert_result, | |
237 const GetChannelIDCallback& callback) { | |
238 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
239 InitIfNecessary(); | 231 InitIfNecessary(); |
240 | 232 |
241 if (!loaded_) { | 233 if (!loaded_) { |
242 EnqueueTask(scoped_ptr<Task>( | 234 EnqueueTask(scoped_ptr<Task>( |
243 new GetChannelIDTask(server_identifier, callback))); | 235 new GetChannelIDTask(server_identifier, callback))); |
244 return ERR_IO_PENDING; | 236 return ERR_IO_PENDING; |
245 } | 237 } |
246 | 238 |
247 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); | 239 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); |
248 | 240 |
249 if (it == channel_ids_.end()) | 241 if (it == channel_ids_.end()) |
250 return ERR_FILE_NOT_FOUND; | 242 return ERR_FILE_NOT_FOUND; |
251 | 243 |
252 ChannelID* channel_id = it->second; | 244 ChannelID* channel_id = it->second; |
253 *expiration_time = channel_id->expiration_time(); | |
254 *private_key_result = channel_id->private_key(); | 245 *private_key_result = channel_id->private_key(); |
255 *cert_result = channel_id->cert(); | 246 *public_key_result = channel_id->public_key(); |
256 | 247 |
257 return OK; | 248 return OK; |
258 } | 249 } |
259 | 250 |
260 void DefaultChannelIDStore::SetChannelID( | 251 void DefaultChannelIDStore::SetChannelID(const std::string& server_identifier, |
261 const std::string& server_identifier, | 252 base::Time creation_time, |
262 base::Time creation_time, | 253 const std::string& private_key, |
263 base::Time expiration_time, | 254 const std::string& public_key) { |
264 const std::string& private_key, | |
265 const std::string& cert) { | |
266 RunOrEnqueueTask(scoped_ptr<Task>(new SetChannelIDTask( | 255 RunOrEnqueueTask(scoped_ptr<Task>(new SetChannelIDTask( |
267 server_identifier, creation_time, expiration_time, private_key, | 256 server_identifier, creation_time, private_key, public_key))); |
268 cert))); | |
269 } | 257 } |
270 | 258 |
271 void DefaultChannelIDStore::DeleteChannelID( | 259 void DefaultChannelIDStore::DeleteChannelID( |
272 const std::string& server_identifier, | 260 const std::string& server_identifier, |
273 const base::Closure& callback) { | 261 const base::Closure& callback) { |
274 RunOrEnqueueTask(scoped_ptr<Task>( | 262 RunOrEnqueueTask(scoped_ptr<Task>( |
275 new DeleteChannelIDTask(server_identifier, callback))); | 263 new DeleteChannelIDTask(server_identifier, callback))); |
276 } | 264 } |
277 | 265 |
278 void DefaultChannelIDStore::DeleteAllCreatedBetween( | 266 void DefaultChannelIDStore::DeleteAllCreatedBetween( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 347 |
360 for (ScopedVector<Task>::iterator i = waiting_tasks_.begin(); | 348 for (ScopedVector<Task>::iterator i = waiting_tasks_.begin(); |
361 i != waiting_tasks_.end(); ++i) | 349 i != waiting_tasks_.end(); ++i) |
362 (*i)->Run(this); | 350 (*i)->Run(this); |
363 waiting_tasks_.clear(); | 351 waiting_tasks_.clear(); |
364 } | 352 } |
365 | 353 |
366 void DefaultChannelIDStore::SyncSetChannelID( | 354 void DefaultChannelIDStore::SyncSetChannelID( |
367 const std::string& server_identifier, | 355 const std::string& server_identifier, |
368 base::Time creation_time, | 356 base::Time creation_time, |
369 base::Time expiration_time, | |
370 const std::string& private_key, | 357 const std::string& private_key, |
371 const std::string& cert) { | 358 const std::string& public_key) { |
372 DCHECK(CalledOnValidThread()); | 359 DCHECK(CalledOnValidThread()); |
373 DCHECK(loaded_); | 360 DCHECK(loaded_); |
374 | 361 |
375 InternalDeleteChannelID(server_identifier); | 362 InternalDeleteChannelID(server_identifier); |
376 InternalInsertChannelID( | 363 InternalInsertChannelID( |
377 server_identifier, | 364 server_identifier, |
378 new ChannelID( | 365 new ChannelID(server_identifier, creation_time, private_key, public_key)); |
379 server_identifier, creation_time, expiration_time, private_key, | |
380 cert)); | |
381 } | 366 } |
382 | 367 |
383 void DefaultChannelIDStore::SyncDeleteChannelID( | 368 void DefaultChannelIDStore::SyncDeleteChannelID( |
384 const std::string& server_identifier) { | 369 const std::string& server_identifier) { |
385 DCHECK(CalledOnValidThread()); | 370 DCHECK(CalledOnValidThread()); |
386 DCHECK(loaded_); | 371 DCHECK(loaded_); |
387 InternalDeleteChannelID(server_identifier); | 372 InternalDeleteChannelID(server_identifier); |
388 } | 373 } |
389 | 374 |
390 void DefaultChannelIDStore::SyncDeleteAllCreatedBetween( | 375 void DefaultChannelIDStore::SyncDeleteAllCreatedBetween( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 if (store_.get()) | 447 if (store_.get()) |
463 store_->AddChannelID(*channel_id); | 448 store_->AddChannelID(*channel_id); |
464 channel_ids_[server_identifier] = channel_id; | 449 channel_ids_[server_identifier] = channel_id; |
465 } | 450 } |
466 | 451 |
467 DefaultChannelIDStore::PersistentStore::PersistentStore() {} | 452 DefaultChannelIDStore::PersistentStore::PersistentStore() {} |
468 | 453 |
469 DefaultChannelIDStore::PersistentStore::~PersistentStore() {} | 454 DefaultChannelIDStore::PersistentStore::~PersistentStore() {} |
470 | 455 |
471 } // namespace net | 456 } // namespace net |
OLD | NEW |