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

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

Issue 125107: * Move the global "DnsResolutionObserver" code depended on by DNS prefetcher,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address jar's comments Created 11 years, 6 months 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 | « net/base/dns_resolution_observer.h ('k') | net/base/host_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « net/base/dns_resolution_observer.h ('k') | net/base/host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698