| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This file supports network stack independent notification of progress | |
| 6 // towards resolving a hostname. | |
| 7 | |
| 8 #include "net/base/dns_resolution_observer.h" | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/logging.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 static DnsResolutionObserver* dns_resolution_observer; | |
| 17 | |
| 18 void AddDnsResolutionObserver(DnsResolutionObserver* new_observer) { | |
| 19 if (new_observer == dns_resolution_observer) | |
| 20 return; // Facilitate unit tests that init/teardown repeatedly. | |
| 21 DCHECK(!dns_resolution_observer); | |
| 22 dns_resolution_observer = new_observer; | |
| 23 } | |
| 24 | |
| 25 DnsResolutionObserver* RemoveDnsResolutionObserver() { | |
| 26 // We really need to check that the entire network subsystem is shutting down, | |
| 27 // and hence no additional calls can even *possibly* still be lingering in the | |
| 28 // notification path that includes our observer. Until we have a way to | |
| 29 // really assert that fact, we will outlaw the calling of this function. | |
| 30 // Darin suggested that the caller use a static initializer for the observer, | |
| 31 // so that it can safely be destroyed after process termination, and without | |
| 32 // inducing a memory leak. | |
| 33 // Bottom line: Don't call this function! You will crash for now. | |
| 34 CHECK(0); | |
| 35 DnsResolutionObserver* old_observer = dns_resolution_observer; | |
| 36 dns_resolution_observer = NULL; | |
| 37 return old_observer; | |
| 38 } | |
| 39 | |
| 40 // Locking access to dns_resolution_observer is not really critical... but we | |
| 41 // should test the value of dns_resolution_observer that we use. | |
| 42 // Worst case, we'll get an "out of date" value... which is no big deal for the | |
| 43 // DNS prefetching system (the most common (only?) observer). | |
| 44 void DidStartDnsResolution(const std::string& name, void* context) { | |
| 45 DnsResolutionObserver* current_observer = dns_resolution_observer; | |
| 46 if (current_observer) | |
| 47 current_observer->OnStartResolution(name, context); | |
| 48 } | |
| 49 | |
| 50 void DidFinishDnsResolutionWithStatus(bool was_resolved, | |
| 51 const GURL& referrer, | |
| 52 void* context) { | |
| 53 DnsResolutionObserver* current_observer = dns_resolution_observer; | |
| 54 if (current_observer) { | |
| 55 current_observer->OnFinishResolutionWithStatus(was_resolved, referrer, | |
| 56 context); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 } // namspace net | |
| OLD | NEW |