| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/dnsrr_resolver.h" | 5 #include "net/base/dnsrr_resolver.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <resolv.h> | 9 #include <resolv.h> |
| 10 #endif | 10 #endif |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 502 |
| 503 // An RRResolverJob is a one-to-one counterpart of an RRResolverWorker. It | 503 // An RRResolverJob is a one-to-one counterpart of an RRResolverWorker. It |
| 504 // lives only on the DnsRRResolver's origin message loop. | 504 // lives only on the DnsRRResolver's origin message loop. |
| 505 class RRResolverJob { | 505 class RRResolverJob { |
| 506 public: | 506 public: |
| 507 explicit RRResolverJob(RRResolverWorker* worker) | 507 explicit RRResolverJob(RRResolverWorker* worker) |
| 508 : worker_(worker) { | 508 : worker_(worker) { |
| 509 } | 509 } |
| 510 | 510 |
| 511 ~RRResolverJob() { | 511 ~RRResolverJob() { |
| 512 if (worker_) { | 512 Cancel(ERR_ABORTED); |
| 513 worker_->Cancel(); | |
| 514 worker_ = NULL; | |
| 515 PostAll(ERR_ABORTED, NULL); | |
| 516 } | |
| 517 } | 513 } |
| 518 | 514 |
| 519 void AddHandle(RRResolverHandle* handle) { | 515 void AddHandle(RRResolverHandle* handle) { |
| 520 handles_.push_back(handle); | 516 handles_.push_back(handle); |
| 521 } | 517 } |
| 522 | 518 |
| 523 void HandleResult(int result, const RRResponse& response) { | 519 void HandleResult(int result, const RRResponse& response) { |
| 524 worker_ = NULL; | 520 worker_ = NULL; |
| 525 PostAll(result, &response); | 521 PostAll(result, &response); |
| 526 } | 522 } |
| 527 | 523 |
| 524 void Cancel(int result) { |
| 525 if (worker_) { |
| 526 worker_->Cancel(); |
| 527 worker_ = NULL; |
| 528 PostAll(result, NULL); |
| 529 } |
| 530 } |
| 531 |
| 528 private: | 532 private: |
| 529 void PostAll(int result, const RRResponse* response) { | 533 void PostAll(int result, const RRResponse* response) { |
| 530 std::vector<RRResolverHandle*> handles; | 534 std::vector<RRResolverHandle*> handles; |
| 531 handles_.swap(handles); | 535 handles_.swap(handles); |
| 532 | 536 |
| 533 for (std::vector<RRResolverHandle*>::iterator | 537 for (std::vector<RRResolverHandle*>::iterator |
| 534 i = handles.begin(); i != handles.end(); i++) { | 538 i = handles.begin(); i != handles.end(); i++) { |
| 535 (*i)->Post(result, response); | 539 (*i)->Post(result, response); |
| 536 // Post() causes the RRResolverHandle to delete itself. | 540 // Post() causes the RRResolverHandle to delete itself. |
| 537 } | 541 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 640 } |
| 637 | 641 |
| 638 void DnsRRResolver::OnIPAddressChanged() { | 642 void DnsRRResolver::OnIPAddressChanged() { |
| 639 DCHECK(CalledOnValidThread()); | 643 DCHECK(CalledOnValidThread()); |
| 640 DCHECK(!in_destructor_); | 644 DCHECK(!in_destructor_); |
| 641 | 645 |
| 642 std::map<std::pair<std::string, uint16>, RRResolverJob*> inflight; | 646 std::map<std::pair<std::string, uint16>, RRResolverJob*> inflight; |
| 643 inflight.swap(inflight_); | 647 inflight.swap(inflight_); |
| 644 cache_.clear(); | 648 cache_.clear(); |
| 645 | 649 |
| 650 std::map<std::pair<std::string, uint16>, RRResolverJob*>::iterator it; |
| 651 for (it = inflight.begin(); it != inflight.end(); ++it) |
| 652 it->second->Cancel(ERR_NETWORK_CHANGED); |
| 646 STLDeleteValues(&inflight); | 653 STLDeleteValues(&inflight); |
| 647 } | 654 } |
| 648 | 655 |
| 649 // HandleResult is called on the origin message loop. | 656 // HandleResult is called on the origin message loop. |
| 650 void DnsRRResolver::HandleResult(const std::string& name, uint16 rrtype, | 657 void DnsRRResolver::HandleResult(const std::string& name, uint16 rrtype, |
| 651 int result, const RRResponse& response) { | 658 int result, const RRResponse& response) { |
| 652 DCHECK(CalledOnValidThread()); | 659 DCHECK(CalledOnValidThread()); |
| 653 | 660 |
| 654 const std::pair<std::string, uint16> key(std::make_pair(name, rrtype)); | 661 const std::pair<std::string, uint16> key(std::make_pair(name, rrtype)); |
| 655 | 662 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 680 return; | 687 return; |
| 681 } | 688 } |
| 682 RRResolverJob* job = j->second; | 689 RRResolverJob* job = j->second; |
| 683 inflight_.erase(j); | 690 inflight_.erase(j); |
| 684 | 691 |
| 685 job->HandleResult(result, response); | 692 job->HandleResult(result, response); |
| 686 delete job; | 693 delete job; |
| 687 } | 694 } |
| 688 | 695 |
| 689 } // namespace net | 696 } // namespace net |
| OLD | NEW |