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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 new GetChannelIDTask(server_identifier, callback))); | 235 new GetChannelIDTask(server_identifier, callback))); |
236 return ERR_IO_PENDING; | 236 return ERR_IO_PENDING; |
237 } | 237 } |
238 | 238 |
239 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); | 239 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); |
240 | 240 |
241 if (it == channel_ids_.end()) | 241 if (it == channel_ids_.end()) |
242 return ERR_FILE_NOT_FOUND; | 242 return ERR_FILE_NOT_FOUND; |
243 | 243 |
244 ChannelID* channel_id = it->second; | 244 ChannelID* channel_id = it->second; |
245 key_result->reset(channel_id->key()->Copy()); | 245 *key_result = channel_id->key()->Copy(); |
246 | 246 |
247 return OK; | 247 return OK; |
248 } | 248 } |
249 | 249 |
250 void DefaultChannelIDStore::SetChannelID( | 250 void DefaultChannelIDStore::SetChannelID( |
251 std::unique_ptr<ChannelID> channel_id) { | 251 std::unique_ptr<ChannelID> channel_id) { |
252 auto task = new SetChannelIDTask(std::move(channel_id)); | 252 auto task = new SetChannelIDTask(std::move(channel_id)); |
253 RunOrEnqueueTask(std::unique_ptr<Task>(task)); | 253 RunOrEnqueueTask(std::unique_ptr<Task>(task)); |
254 } | 254 } |
255 | 255 |
(...skipping 27 matching lines...) Expand all Loading... |
283 int DefaultChannelIDStore::GetChannelIDCount() { | 283 int DefaultChannelIDStore::GetChannelIDCount() { |
284 DCHECK(CalledOnValidThread()); | 284 DCHECK(CalledOnValidThread()); |
285 | 285 |
286 return channel_ids_.size(); | 286 return channel_ids_.size(); |
287 } | 287 } |
288 | 288 |
289 void DefaultChannelIDStore::SetForceKeepSessionState() { | 289 void DefaultChannelIDStore::SetForceKeepSessionState() { |
290 DCHECK(CalledOnValidThread()); | 290 DCHECK(CalledOnValidThread()); |
291 InitIfNecessary(); | 291 InitIfNecessary(); |
292 | 292 |
293 if (store_.get()) | 293 if (store_) |
294 store_->SetForceKeepSessionState(); | 294 store_->SetForceKeepSessionState(); |
295 } | 295 } |
296 | 296 |
297 DefaultChannelIDStore::~DefaultChannelIDStore() { | 297 DefaultChannelIDStore::~DefaultChannelIDStore() { |
298 DeleteAllInMemory(); | 298 DeleteAllInMemory(); |
299 } | 299 } |
300 | 300 |
301 void DefaultChannelIDStore::DeleteAllInMemory() { | 301 void DefaultChannelIDStore::DeleteAllInMemory() { |
302 DCHECK(CalledOnValidThread()); | 302 DCHECK(CalledOnValidThread()); |
303 | 303 |
304 for (ChannelIDMap::iterator it = channel_ids_.begin(); | 304 for (ChannelIDMap::iterator it = channel_ids_.begin(); |
305 it != channel_ids_.end(); ++it) { | 305 it != channel_ids_.end(); ++it) { |
306 delete it->second; | 306 delete it->second; |
307 } | 307 } |
308 channel_ids_.clear(); | 308 channel_ids_.clear(); |
309 } | 309 } |
310 | 310 |
311 void DefaultChannelIDStore::InitStore() { | 311 void DefaultChannelIDStore::InitStore() { |
312 DCHECK(CalledOnValidThread()); | 312 DCHECK(CalledOnValidThread()); |
313 DCHECK(store_.get()) << "Store must exist to initialize"; | 313 DCHECK(store_) << "Store must exist to initialize"; |
314 DCHECK(!loaded_); | 314 DCHECK(!loaded_); |
315 | 315 |
316 store_->Load(base::Bind(&DefaultChannelIDStore::OnLoaded, | 316 store_->Load(base::Bind(&DefaultChannelIDStore::OnLoaded, |
317 weak_ptr_factory_.GetWeakPtr())); | 317 weak_ptr_factory_.GetWeakPtr())); |
318 } | 318 } |
319 | 319 |
320 void DefaultChannelIDStore::OnLoaded( | 320 void DefaultChannelIDStore::OnLoaded( |
321 std::unique_ptr<std::vector<std::unique_ptr<ChannelID>>> channel_ids) { | 321 std::unique_ptr<std::vector<std::unique_ptr<ChannelID>>> channel_ids) { |
322 DCHECK(CalledOnValidThread()); | 322 DCHECK(CalledOnValidThread()); |
323 for (std::vector<std::unique_ptr<ChannelID>>::iterator it = | 323 for (std::vector<std::unique_ptr<ChannelID>>::iterator it = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 for (ChannelIDMap::iterator it = channel_ids_.begin(); | 374 for (ChannelIDMap::iterator it = channel_ids_.begin(); |
375 it != channel_ids_.end();) { | 375 it != channel_ids_.end();) { |
376 ChannelIDMap::iterator cur = it; | 376 ChannelIDMap::iterator cur = it; |
377 ++it; | 377 ++it; |
378 ChannelID* channel_id = cur->second; | 378 ChannelID* channel_id = cur->second; |
379 | 379 |
380 if ((delete_begin.is_null() || | 380 if ((delete_begin.is_null() || |
381 channel_id->creation_time() >= delete_begin) && | 381 channel_id->creation_time() >= delete_begin) && |
382 (delete_end.is_null() || channel_id->creation_time() < delete_end) && | 382 (delete_end.is_null() || channel_id->creation_time() < delete_end) && |
383 domain_predicate.Run(channel_id->server_identifier())) { | 383 domain_predicate.Run(channel_id->server_identifier())) { |
384 if (store_.get()) | 384 if (store_) |
385 store_->DeleteChannelID(*channel_id); | 385 store_->DeleteChannelID(*channel_id); |
386 delete channel_id; | 386 delete channel_id; |
387 channel_ids_.erase(cur); | 387 channel_ids_.erase(cur); |
388 } | 388 } |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 void DefaultChannelIDStore::SyncGetAllChannelIDs( | 392 void DefaultChannelIDStore::SyncGetAllChannelIDs( |
393 ChannelIDList* channel_id_list) { | 393 ChannelIDList* channel_id_list) { |
394 DCHECK(CalledOnValidThread()); | 394 DCHECK(CalledOnValidThread()); |
(...skipping 26 matching lines...) Expand all Loading... |
421 void DefaultChannelIDStore::InternalDeleteChannelID( | 421 void DefaultChannelIDStore::InternalDeleteChannelID( |
422 const std::string& server_identifier) { | 422 const std::string& server_identifier) { |
423 DCHECK(CalledOnValidThread()); | 423 DCHECK(CalledOnValidThread()); |
424 DCHECK(loaded_); | 424 DCHECK(loaded_); |
425 | 425 |
426 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); | 426 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); |
427 if (it == channel_ids_.end()) | 427 if (it == channel_ids_.end()) |
428 return; // There is nothing to delete. | 428 return; // There is nothing to delete. |
429 | 429 |
430 ChannelID* channel_id = it->second; | 430 ChannelID* channel_id = it->second; |
431 if (store_.get()) | 431 if (store_) |
432 store_->DeleteChannelID(*channel_id); | 432 store_->DeleteChannelID(*channel_id); |
433 channel_ids_.erase(it); | 433 channel_ids_.erase(it); |
434 delete channel_id; | 434 delete channel_id; |
435 } | 435 } |
436 | 436 |
437 void DefaultChannelIDStore::InternalInsertChannelID( | 437 void DefaultChannelIDStore::InternalInsertChannelID( |
438 std::unique_ptr<ChannelID> channel_id) { | 438 std::unique_ptr<ChannelID> channel_id) { |
439 DCHECK(CalledOnValidThread()); | 439 DCHECK(CalledOnValidThread()); |
440 DCHECK(loaded_); | 440 DCHECK(loaded_); |
441 | 441 |
442 if (store_.get()) | 442 if (store_) |
443 store_->AddChannelID(*(channel_id.get())); | 443 store_->AddChannelID(*channel_id); |
444 const std::string& server_identifier = channel_id->server_identifier(); | 444 const std::string& server_identifier = channel_id->server_identifier(); |
445 channel_ids_[server_identifier] = channel_id.release(); | 445 channel_ids_[server_identifier] = channel_id.release(); |
446 } | 446 } |
447 | 447 |
448 bool DefaultChannelIDStore::IsEphemeral() { | 448 bool DefaultChannelIDStore::IsEphemeral() { |
449 return store_.get() == nullptr; | 449 return !store_; |
450 } | 450 } |
451 | 451 |
452 DefaultChannelIDStore::PersistentStore::PersistentStore() {} | 452 DefaultChannelIDStore::PersistentStore::PersistentStore() {} |
453 | 453 |
454 DefaultChannelIDStore::PersistentStore::~PersistentStore() {} | 454 DefaultChannelIDStore::PersistentStore::~PersistentStore() {} |
455 | 455 |
456 } // namespace net | 456 } // namespace net |
OLD | NEW |