OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/certificate_transparency/log_dns_client.h" | 5 #include "components/certificate_transparency/log_dns_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 } | 401 } |
402 | 402 |
403 void LogDnsClient::OnDNSChanged() { | 403 void LogDnsClient::OnDNSChanged() { |
404 UpdateDnsConfig(); | 404 UpdateDnsConfig(); |
405 } | 405 } |
406 | 406 |
407 void LogDnsClient::OnInitialDNSConfigRead() { | 407 void LogDnsClient::OnInitialDNSConfigRead() { |
408 UpdateDnsConfig(); | 408 UpdateDnsConfig(); |
409 } | 409 } |
410 | 410 |
411 void LogDnsClient::NotifyWhenNotThrottled(const base::Closure& callback) { | |
412 DCHECK(HasMaxConcurrentQueriesInProgress()); | |
413 not_throttled_callbacks_.push_back(callback); | |
414 } | |
415 | |
411 net::Error LogDnsClient::QueryAuditProof(base::StringPiece domain_for_log, | 416 net::Error LogDnsClient::QueryAuditProof(base::StringPiece domain_for_log, |
412 base::StringPiece leaf_hash, | 417 base::StringPiece leaf_hash, |
413 uint64_t tree_size, | 418 uint64_t tree_size, |
414 const AuditProofCallback& callback) { | 419 const AuditProofCallback& callback) { |
415 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { | 420 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { |
416 return net::ERR_INVALID_ARGUMENT; | 421 return net::ERR_INVALID_ARGUMENT; |
417 } | 422 } |
418 | 423 |
419 if (HasMaxConcurrentQueriesInProgress()) { | 424 if (HasMaxConcurrentQueriesInProgress()) { |
420 return net::ERR_TEMPORARILY_THROTTLED; | 425 return net::ERR_TEMPORARILY_THROTTLED; |
(...skipping 25 matching lines...) Expand all Loading... | |
446 auto query_iterator = | 451 auto query_iterator = |
447 std::find_if(audit_proof_queries_.begin(), audit_proof_queries_.end(), | 452 std::find_if(audit_proof_queries_.begin(), audit_proof_queries_.end(), |
448 [query](const std::unique_ptr<AuditProofQuery>& p) { | 453 [query](const std::unique_ptr<AuditProofQuery>& p) { |
449 return p.get() == query; | 454 return p.get() == query; |
450 }); | 455 }); |
451 DCHECK(query_iterator != audit_proof_queries_.end()); | 456 DCHECK(query_iterator != audit_proof_queries_.end()); |
452 audit_proof_queries_.erase(query_iterator); | 457 audit_proof_queries_.erase(query_iterator); |
453 | 458 |
454 base::ThreadTaskRunnerHandle::Get()->PostTask( | 459 base::ThreadTaskRunnerHandle::Get()->PostTask( |
455 FROM_HERE, base::Bind(callback, result, base::Passed(&proof))); | 460 FROM_HERE, base::Bind(callback, result, base::Passed(&proof))); |
461 | |
462 for (const base::Closure& callback : not_throttled_callbacks_) { | |
463 callback.Run(); | |
464 } | |
465 not_throttled_callbacks_.clear(); | |
Ryan Sleevi
2016/10/07 15:22:55
Because the base::Callback could result in deletio
Rob Percival
2016/10/20 12:43:13
Done.
| |
456 } | 466 } |
457 | 467 |
458 bool LogDnsClient::HasMaxConcurrentQueriesInProgress() const { | 468 bool LogDnsClient::HasMaxConcurrentQueriesInProgress() const { |
459 return max_concurrent_queries_ != 0 && | 469 return max_concurrent_queries_ != 0 && |
460 audit_proof_queries_.size() >= max_concurrent_queries_; | 470 audit_proof_queries_.size() >= max_concurrent_queries_; |
461 } | 471 } |
462 | 472 |
463 void LogDnsClient::UpdateDnsConfig() { | 473 void LogDnsClient::UpdateDnsConfig() { |
464 net::DnsConfig config; | 474 net::DnsConfig config; |
465 net::NetworkChangeNotifier::GetDnsConfig(&config); | 475 net::NetworkChangeNotifier::GetDnsConfig(&config); |
466 if (config.IsValid()) | 476 if (config.IsValid()) |
467 dns_client_->SetConfig(config); | 477 dns_client_->SetConfig(config); |
468 } | 478 } |
469 | 479 |
470 } // namespace certificate_transparency | 480 } // namespace certificate_transparency |
OLD | NEW |