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 #ifndef CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ | 5 #ifndef CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ |
6 #define CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ | 6 #define CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/common/url_fetcher_delegate.h" | |
17 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
18 #include "net/base/host_resolver_proc.h" | 17 #include "net/base/host_resolver_proc.h" |
19 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
| 19 #include "net/url_request/url_fetcher_delegate.h" |
20 | 20 |
21 class PrefService; | 21 class PrefService; |
22 | 22 |
23 // This object is responsible for determining whether the user is on a network | 23 // This object is responsible for determining whether the user is on a network |
24 // that redirects requests for intranet hostnames to another site, and if so, | 24 // that redirects requests for intranet hostnames to another site, and if so, |
25 // tracking what that site is (including across restarts via a pref). For | 25 // tracking what that site is (including across restarts via a pref). For |
26 // example, the user's ISP might convert a request for "http://query/" into a | 26 // example, the user's ISP might convert a request for "http://query/" into a |
27 // 302 redirect to "http://isp.domain.com/search?q=query" in order to display | 27 // 302 redirect to "http://isp.domain.com/search?q=query" in order to display |
28 // custom pages on typos, nonexistent sites, etc. | 28 // custom pages on typos, nonexistent sites, etc. |
29 // | 29 // |
30 // We use this information in the AlternateNavURLFetcher to avoid displaying | 30 // We use this information in the AlternateNavURLFetcher to avoid displaying |
31 // infobars for these cases. Our infobars are designed to allow users to get at | 31 // infobars for these cases. Our infobars are designed to allow users to get at |
32 // intranet sites when they were erroneously taken to a search result page. In | 32 // intranet sites when they were erroneously taken to a search result page. In |
33 // these cases, however, users would be shown a confusing and useless infobar | 33 // these cases, however, users would be shown a confusing and useless infobar |
34 // when they really did mean to do a search. | 34 // when they really did mean to do a search. |
35 // | 35 // |
36 // Consumers should call RedirectOrigin(), which is guaranteed to synchronously | 36 // Consumers should call RedirectOrigin(), which is guaranteed to synchronously |
37 // return a value at all times (even during startup or in unittest mode). If no | 37 // return a value at all times (even during startup or in unittest mode). If no |
38 // redirection is in place, the returned GURL will be empty. | 38 // redirection is in place, the returned GURL will be empty. |
39 class IntranetRedirectDetector | 39 class IntranetRedirectDetector |
40 : public content::URLFetcherDelegate, | 40 : public net::URLFetcherDelegate, |
41 public net::NetworkChangeNotifier::IPAddressObserver { | 41 public net::NetworkChangeNotifier::IPAddressObserver { |
42 public: | 42 public: |
43 // Only the main browser process loop should call this, when setting up | 43 // Only the main browser process loop should call this, when setting up |
44 // g_browser_process->intranet_redirect_detector_. No code other than the | 44 // g_browser_process->intranet_redirect_detector_. No code other than the |
45 // IntranetRedirectDetector itself should actually use | 45 // IntranetRedirectDetector itself should actually use |
46 // g_browser_process->intranet_redirect_detector() (which shouldn't be hard, | 46 // g_browser_process->intranet_redirect_detector() (which shouldn't be hard, |
47 // since there aren't useful public functions on this object for consumers to | 47 // since there aren't useful public functions on this object for consumers to |
48 // access anyway). | 48 // access anyway). |
49 IntranetRedirectDetector(); | 49 IntranetRedirectDetector(); |
50 virtual ~IntranetRedirectDetector(); | 50 virtual ~IntranetRedirectDetector(); |
51 | 51 |
52 // Returns the current redirect origin. This will be empty if no redirection | 52 // Returns the current redirect origin. This will be empty if no redirection |
53 // is in place. | 53 // is in place. |
54 static GURL RedirectOrigin(); | 54 static GURL RedirectOrigin(); |
55 | 55 |
56 static void RegisterPrefs(PrefService* prefs); | 56 static void RegisterPrefs(PrefService* prefs); |
57 | 57 |
58 // The number of characters the fetcher will use for its randomly-generated | 58 // The number of characters the fetcher will use for its randomly-generated |
59 // hostnames. | 59 // hostnames. |
60 static const size_t kNumCharsInHostnames; | 60 static const size_t kNumCharsInHostnames; |
61 | 61 |
62 private: | 62 private: |
63 typedef std::set<net::URLFetcher*> Fetchers; | 63 typedef std::set<net::URLFetcher*> Fetchers; |
64 | 64 |
65 // Called when the seven second startup sleep or the one second network | 65 // Called when the seven second startup sleep or the one second network |
66 // switch sleep has finished. Runs any pending fetch. | 66 // switch sleep has finished. Runs any pending fetch. |
67 void FinishSleep(); | 67 void FinishSleep(); |
68 | 68 |
69 // content::URLFetcherDelegate | 69 // net::URLFetcherDelegate |
70 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 70 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
71 | 71 |
72 // NetworkChangeNotifier::IPAddressObserver | 72 // NetworkChangeNotifier::IPAddressObserver |
73 virtual void OnIPAddressChanged() OVERRIDE; | 73 virtual void OnIPAddressChanged() OVERRIDE; |
74 | 74 |
75 GURL redirect_origin_; | 75 GURL redirect_origin_; |
76 base::WeakPtrFactory<IntranetRedirectDetector> weak_factory_; | 76 base::WeakPtrFactory<IntranetRedirectDetector> weak_factory_; |
77 Fetchers fetchers_; | 77 Fetchers fetchers_; |
78 std::vector<GURL> resulting_origins_; | 78 std::vector<GURL> resulting_origins_; |
79 bool in_sleep_; // True if we're in the seven-second "no fetching" period | 79 bool in_sleep_; // True if we're in the seven-second "no fetching" period |
(...skipping 13 matching lines...) Expand all Loading... |
93 net::AddressFamily address_family, | 93 net::AddressFamily address_family, |
94 net::HostResolverFlags host_resolver_flags, | 94 net::HostResolverFlags host_resolver_flags, |
95 net::AddressList* addrlist, | 95 net::AddressList* addrlist, |
96 int* os_error) OVERRIDE; | 96 int* os_error) OVERRIDE; |
97 | 97 |
98 private: | 98 private: |
99 virtual ~IntranetRedirectHostResolverProc() {} | 99 virtual ~IntranetRedirectHostResolverProc() {} |
100 }; | 100 }; |
101 | 101 |
102 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ | 102 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ |
OLD | NEW |