OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 // This file supports network stack independent notification of progress | 5 // This file supports network stack independent notification of progress |
6 // towards resolving a hostname. | 6 // towards resolving a hostname. |
7 | 7 |
8 // The observer class supports exactly one active (Add'ed) instance, and in | 8 // The observer class supports exactly one active (Add'ed) instance, and in |
9 // typical usage, that observer will be Add'ed during process startup, and | 9 // typical usage, that observer will be Add'ed during process startup, and |
10 // Remove'd during process termination. | 10 // Remove'd during process termination. |
11 | 11 |
12 | 12 |
13 #ifndef NET_BASE_DNS_RESOLUTION_OBSERVER_H_ | 13 #ifndef NET_BASE_DNS_RESOLUTION_OBSERVER_H_ |
14 #define NET_BASE_DNS_RESOLUTION_OBSERVER_H_ | 14 #define NET_BASE_DNS_RESOLUTION_OBSERVER_H_ |
15 | 15 |
16 #include <string> | 16 #include <string> |
17 | 17 |
| 18 #include "net/base/host_resolver.h" |
| 19 |
18 class GURL; | 20 class GURL; |
19 | 21 |
20 namespace net { | 22 namespace net { |
21 | 23 |
| 24 // TODO(eroman): Move this interface to HostResolver::Observer. |
22 class DnsResolutionObserver { | 25 class DnsResolutionObserver { |
23 public: | 26 public: |
24 virtual ~DnsResolutionObserver() {} | 27 virtual ~DnsResolutionObserver() {} |
25 | 28 |
26 // For each OnStartResolution() notification, there should be a later | 29 // For each OnStartResolution() notification, there should be a later |
27 // OnFinishResolutionWithStatus() indicating completion of the resolution | 30 // OnFinishResolutionWithStatus() indicating completion of the resolution |
28 // activity. | 31 // activity. |
29 // Related pairs of notification will arrive with matching context values. | 32 // Related pairs of notification will arrive with matching id values. |
30 // A caller may use the context values to match up these asynchronous calls | 33 // A caller may use the id values to match up these asynchronous calls |
31 // from among a larger call stream. | 34 // from among a larger call stream. |
32 // Once a matching pair of notifications has been provided (i.e., a pair with | 35 virtual void OnStartResolution(int id, |
33 // identical context values), and the notification methods (below) have | 36 const HostResolver::RequestInfo& info) = 0; |
34 // returned, the context values *might* be reused. | 37 virtual void OnFinishResolutionWithStatus( |
35 virtual void OnStartResolution(const std::string& host_name, | 38 int id, |
36 void* context) = 0; | 39 bool was_resolved, |
37 virtual void OnFinishResolutionWithStatus(bool was_resolved, | 40 const HostResolver::RequestInfo& info) = 0; |
38 const GURL& referrer, | |
39 void* context) = 0; | |
40 }; | 41 }; |
41 | 42 |
42 | |
43 // Note that *exactly* one observer is currently supported, and any attempt to | |
44 // add a second observer via AddDnsResolutionObserver() before removing the | |
45 // first DnsResolutionObserver will induce a DCHECK() assertion. | |
46 void AddDnsResolutionObserver(DnsResolutionObserver* new_observer); | |
47 | |
48 // Note that the RemoveDnsResolutionObserver() will NOT perform any delete | |
49 // operations, and it is the responsibility of the code that called | |
50 // AddDnsResolutionObserver() to make a corresponding call to | |
51 // RemoveDnsResolutionObserver() and then delete the returned | |
52 // DnsResolutionObserver instance. | |
53 DnsResolutionObserver* RemoveDnsResolutionObserver(); | |
54 | |
55 // The following functions are expected to be called only by network stack | |
56 // implementations. This above observer class will relay the notifications | |
57 // to any registered observer. | |
58 void DidStartDnsResolution(const std::string& name, | |
59 void* context); | |
60 void DidFinishDnsResolutionWithStatus(bool was_resolved, | |
61 const GURL& url, | |
62 void* context); | |
63 } // namspace net | 43 } // namspace net |
64 | 44 |
65 #endif // NET_BASE_DNS_RESOLUTION_OBSERVER_H_ | 45 #endif // NET_BASE_DNS_RESOLUTION_OBSERVER_H_ |
OLD | NEW |