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/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 } | 347 } |
348 | 348 |
349 void LogDnsClient::OnDNSChanged() { | 349 void LogDnsClient::OnDNSChanged() { |
350 UpdateDnsConfig(); | 350 UpdateDnsConfig(); |
351 } | 351 } |
352 | 352 |
353 void LogDnsClient::OnInitialDNSConfigRead() { | 353 void LogDnsClient::OnInitialDNSConfigRead() { |
354 UpdateDnsConfig(); | 354 UpdateDnsConfig(); |
355 } | 355 } |
356 | 356 |
357 void LogDnsClient::NotifyWhenNotThrottled( | |
358 const NotThrottledCallback& callback) { | |
359 DCHECK(HasMaxConcurrentQueriesInProgress()); | |
360 not_throttled_callbacks_.push_back(callback); | |
361 } | |
362 | |
357 net::Error LogDnsClient::QueryAuditProof(base::StringPiece domain_for_log, | 363 net::Error LogDnsClient::QueryAuditProof(base::StringPiece domain_for_log, |
358 base::StringPiece leaf_hash, | 364 base::StringPiece leaf_hash, |
359 uint64_t tree_size, | 365 uint64_t tree_size, |
360 const AuditProofCallback& callback) { | 366 const AuditProofCallback& callback) { |
361 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { | 367 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { |
362 return net::ERR_INVALID_ARGUMENT; | 368 return net::ERR_INVALID_ARGUMENT; |
363 } | 369 } |
364 | 370 |
365 if (HasMaxConcurrentQueriesInProgress()) { | 371 if (HasMaxConcurrentQueriesInProgress()) { |
366 return net::ERR_TEMPORARILY_THROTTLED; | 372 return net::ERR_TEMPORARILY_THROTTLED; |
(...skipping 27 matching lines...) Expand all Loading... | |
394 auto query_iterator = | 400 auto query_iterator = |
395 std::find_if(audit_proof_queries_.begin(), audit_proof_queries_.end(), | 401 std::find_if(audit_proof_queries_.begin(), audit_proof_queries_.end(), |
396 [query](const std::unique_ptr<AuditProofQuery>& p) { | 402 [query](const std::unique_ptr<AuditProofQuery>& p) { |
397 return p.get() == query; | 403 return p.get() == query; |
398 }); | 404 }); |
399 DCHECK(query_iterator != audit_proof_queries_.end()); | 405 DCHECK(query_iterator != audit_proof_queries_.end()); |
400 audit_proof_queries_.erase(query_iterator); | 406 audit_proof_queries_.erase(query_iterator); |
401 | 407 |
402 base::ThreadTaskRunnerHandle::Get()->PostTask( | 408 base::ThreadTaskRunnerHandle::Get()->PostTask( |
403 FROM_HERE, base::Bind(callback, result, base::Passed(&proof))); | 409 FROM_HERE, base::Bind(callback, result, base::Passed(&proof))); |
410 | |
411 for (const NotThrottledCallback& callback : not_throttled_callbacks_) { | |
412 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
413 FROM_HERE, base::Bind(callback, weak_ptr_factory_.GetWeakPtr())); | |
Ryan Sleevi
2016/10/03 23:56:04
From a design perspective: Why asynchronously? Why
Rob Percival
2016/10/04 18:53:03
An abundance of caution, but actually this can be
| |
414 } | |
415 not_throttled_callbacks_.clear(); | |
404 } | 416 } |
405 | 417 |
406 bool LogDnsClient::HasMaxConcurrentQueriesInProgress() const { | 418 bool LogDnsClient::HasMaxConcurrentQueriesInProgress() const { |
407 return max_concurrent_queries_ != 0 && | 419 return max_concurrent_queries_ != 0 && |
408 audit_proof_queries_.size() >= max_concurrent_queries_; | 420 audit_proof_queries_.size() >= max_concurrent_queries_; |
409 } | 421 } |
410 | 422 |
411 void LogDnsClient::UpdateDnsConfig() { | 423 void LogDnsClient::UpdateDnsConfig() { |
412 net::DnsConfig config; | 424 net::DnsConfig config; |
413 net::NetworkChangeNotifier::GetDnsConfig(&config); | 425 net::NetworkChangeNotifier::GetDnsConfig(&config); |
414 if (config.IsValid()) | 426 if (config.IsValid()) |
415 dns_client_->SetConfig(config); | 427 dns_client_->SetConfig(config); |
416 } | 428 } |
417 | 429 |
418 } // namespace certificate_transparency | 430 } // namespace certificate_transparency |
OLD | NEW |