Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: net/base/dnsrr_resolver.cc

Issue 11464028: Introduce ERR_NETWORK_CHANGED and allow URLFetcher to automatically retry on that error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed nits Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/gaia/gaia_oauth_client.cc ('k') | net/base/dnsrr_resolver_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_oauth_client.cc ('k') | net/base/dnsrr_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698