| 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 // |leaf_hash| is not a const-ref to allow callers to std::move that string into | 416 // |leaf_hash| is not a const-ref to allow callers to std::move that string into |
| 412 // the method, avoiding LogDnsClient::AuditProofQuery having to make a copy. | 417 // the method, avoiding LogDnsClient::AuditProofQuery having to make a copy. |
| 413 net::Error LogDnsClient::QueryAuditProof( | 418 net::Error LogDnsClient::QueryAuditProof( |
| 414 base::StringPiece domain_for_log, | 419 base::StringPiece domain_for_log, |
| 415 std::string leaf_hash, | 420 std::string leaf_hash, |
| 416 uint64_t tree_size, | 421 uint64_t tree_size, |
| 417 net::ct::MerkleAuditProof* proof, | 422 net::ct::MerkleAuditProof* proof, |
| 418 const net::CompletionCallback& callback) { | 423 const net::CompletionCallback& callback) { |
| 419 DCHECK(proof); | 424 DCHECK(proof); |
| 420 | 425 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 447 // Finished with the query - destroy it. | 452 // Finished with the query - destroy it. |
| 448 auto query_iterator = | 453 auto query_iterator = |
| 449 std::find_if(audit_proof_queries_.begin(), audit_proof_queries_.end(), | 454 std::find_if(audit_proof_queries_.begin(), audit_proof_queries_.end(), |
| 450 [query](const std::unique_ptr<AuditProofQuery>& p) { | 455 [query](const std::unique_ptr<AuditProofQuery>& p) { |
| 451 return p.get() == query; | 456 return p.get() == query; |
| 452 }); | 457 }); |
| 453 DCHECK(query_iterator != audit_proof_queries_.end()); | 458 DCHECK(query_iterator != audit_proof_queries_.end()); |
| 454 audit_proof_queries_.erase(query_iterator); | 459 audit_proof_queries_.erase(query_iterator); |
| 455 | 460 |
| 456 callback.Run(net_error); | 461 callback.Run(net_error); |
| 462 |
| 463 // Notify interested parties that the next query will not be throttled. |
| 464 std::list<base::Closure> callbacks = std::move(not_throttled_callbacks_); |
| 465 for (const base::Closure& callback : callbacks) { |
| 466 callback.Run(); |
| 467 } |
| 457 } | 468 } |
| 458 | 469 |
| 459 bool LogDnsClient::HasMaxConcurrentQueriesInProgress() const { | 470 bool LogDnsClient::HasMaxConcurrentQueriesInProgress() const { |
| 460 return max_concurrent_queries_ != 0 && | 471 return max_concurrent_queries_ != 0 && |
| 461 audit_proof_queries_.size() >= max_concurrent_queries_; | 472 audit_proof_queries_.size() >= max_concurrent_queries_; |
| 462 } | 473 } |
| 463 | 474 |
| 464 void LogDnsClient::UpdateDnsConfig() { | 475 void LogDnsClient::UpdateDnsConfig() { |
| 465 net::DnsConfig config; | 476 net::DnsConfig config; |
| 466 net::NetworkChangeNotifier::GetDnsConfig(&config); | 477 net::NetworkChangeNotifier::GetDnsConfig(&config); |
| 467 if (config.IsValid()) | 478 if (config.IsValid()) |
| 468 dns_client_->SetConfig(config); | 479 dns_client_->SetConfig(config); |
| 469 } | 480 } |
| 470 | 481 |
| 471 } // namespace certificate_transparency | 482 } // namespace certificate_transparency |
| OLD | NEW |