| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // infobars for these cases. Our infobars are designed to allow users to get at | 30 // infobars for these cases. Our infobars are designed to allow users to get at |
| 31 // intranet sites when they were erroneously taken to a search result page. In | 31 // intranet sites when they were erroneously taken to a search result page. In |
| 32 // these cases, however, users would be shown a confusing and useless infobar | 32 // these cases, however, users would be shown a confusing and useless infobar |
| 33 // when they really did mean to do a search. | 33 // when they really did mean to do a search. |
| 34 // | 34 // |
| 35 // Consumers should call RedirectOrigin(), which is guaranteed to synchronously | 35 // Consumers should call RedirectOrigin(), which is guaranteed to synchronously |
| 36 // return a value at all times (even during startup or in unittest mode). If no | 36 // return a value at all times (even during startup or in unittest mode). If no |
| 37 // redirection is in place, the returned GURL will be empty. | 37 // redirection is in place, the returned GURL will be empty. |
| 38 class IntranetRedirectDetector | 38 class IntranetRedirectDetector |
| 39 : public URLFetcher::Delegate, | 39 : public URLFetcher::Delegate, |
| 40 public NotificationObserver, | |
| 41 public net::NetworkChangeNotifier::IPAddressObserver { | 40 public net::NetworkChangeNotifier::IPAddressObserver { |
| 42 public: | 41 public: |
| 43 // Only the main browser process loop should call this, when setting up | 42 // Only the main browser process loop should call this, when setting up |
| 44 // g_browser_process->intranet_redirect_detector_. No code other than the | 43 // g_browser_process->intranet_redirect_detector_. No code other than the |
| 45 // IntranetRedirectDetector itself should actually use | 44 // IntranetRedirectDetector itself should actually use |
| 46 // g_browser_process->intranet_redirect_detector() (which shouldn't be hard, | 45 // 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 | 46 // since there aren't useful public functions on this object for consumers to |
| 48 // access anyway). | 47 // access anyway). |
| 49 IntranetRedirectDetector(); | 48 IntranetRedirectDetector(); |
| 50 ~IntranetRedirectDetector(); | 49 ~IntranetRedirectDetector(); |
| 51 | 50 |
| 52 // Returns the current redirect origin. This will be empty if no redirection | 51 // Returns the current redirect origin. This will be empty if no redirection |
| 53 // is in place. | 52 // is in place. |
| 54 static GURL RedirectOrigin(); | 53 static GURL RedirectOrigin(); |
| 55 | 54 |
| 56 static void RegisterPrefs(PrefService* prefs); | 55 static void RegisterPrefs(PrefService* prefs); |
| 57 | 56 |
| 58 // The number of characters the fetcher will use for its randomly-generated | 57 // The number of characters the fetcher will use for its randomly-generated |
| 59 // hostnames. | 58 // hostnames. |
| 60 static const size_t kNumCharsInHostnames; | 59 static const size_t kNumCharsInHostnames; |
| 61 | 60 |
| 62 private: | 61 private: |
| 63 typedef std::set<URLFetcher*> Fetchers; | 62 typedef std::set<URLFetcher*> Fetchers; |
| 64 | 63 |
| 65 // Called when the seven second startup sleep or the one second network | 64 // Called when the seven second startup sleep or the one second network |
| 66 // switch sleep has finished. Runs any pending fetch. | 65 // switch sleep has finished. Runs any pending fetch. |
| 67 void FinishSleep(); | 66 void FinishSleep(); |
| 68 | 67 |
| 69 // Starts the fetches to determine the redirect URL if we can currently do so. | |
| 70 void StartFetchesIfPossible(); | |
| 71 | |
| 72 // URLFetcher::Delegate | 68 // URLFetcher::Delegate |
| 73 virtual void OnURLFetchComplete(const URLFetcher* source, | 69 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 74 const GURL& url, | 70 const GURL& url, |
| 75 const net::URLRequestStatus& status, | 71 const net::URLRequestStatus& status, |
| 76 int response_code, | 72 int response_code, |
| 77 const ResponseCookies& cookies, | 73 const ResponseCookies& cookies, |
| 78 const std::string& data); | 74 const std::string& data); |
| 79 | 75 |
| 80 // NotificationObserver | |
| 81 virtual void Observe(NotificationType type, | |
| 82 const NotificationSource& source, | |
| 83 const NotificationDetails& details); | |
| 84 | |
| 85 // NetworkChangeNotifier::IPAddressObserver | 76 // NetworkChangeNotifier::IPAddressObserver |
| 86 virtual void OnIPAddressChanged(); | 77 virtual void OnIPAddressChanged(); |
| 87 | 78 |
| 88 NotificationRegistrar registrar_; | |
| 89 GURL redirect_origin_; | 79 GURL redirect_origin_; |
| 90 ScopedRunnableMethodFactory<IntranetRedirectDetector> fetcher_factory_; | 80 ScopedRunnableMethodFactory<IntranetRedirectDetector> fetcher_factory_; |
| 91 Fetchers fetchers_; | 81 Fetchers fetchers_; |
| 92 std::vector<GURL> resulting_origins_; | 82 std::vector<GURL> resulting_origins_; |
| 93 bool in_sleep_; // True if we're in the seven-second "no fetching" period | 83 bool in_sleep_; // True if we're in the seven-second "no fetching" period |
| 94 // that begins at browser start, or the one-second "no | 84 // that begins at browser start, or the one-second "no |
| 95 // fetching" period that begins after network switches. | 85 // fetching" period that begins after network switches. |
| 96 bool request_context_available_; | |
| 97 // True when the profile has been loaded and the | |
| 98 // default request context created, so we can | |
| 99 // actually do the fetch with the right data. | |
| 100 | 86 |
| 101 DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector); | 87 DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector); |
| 102 }; | 88 }; |
| 103 | 89 |
| 104 // This is for use in testing, where we don't want our fetches to actually go | 90 // This is for use in testing, where we don't want our fetches to actually go |
| 105 // over the network. It captures the requests and causes them to fail. | 91 // over the network. It captures the requests and causes them to fail. |
| 106 class IntranetRedirectHostResolverProc : public net::HostResolverProc { | 92 class IntranetRedirectHostResolverProc : public net::HostResolverProc { |
| 107 public: | 93 public: |
| 108 explicit IntranetRedirectHostResolverProc(net::HostResolverProc* previous); | 94 explicit IntranetRedirectHostResolverProc(net::HostResolverProc* previous); |
| 109 | 95 |
| 110 virtual int Resolve(const std::string& host, | 96 virtual int Resolve(const std::string& host, |
| 111 net::AddressFamily address_family, | 97 net::AddressFamily address_family, |
| 112 net::HostResolverFlags host_resolver_flags, | 98 net::HostResolverFlags host_resolver_flags, |
| 113 net::AddressList* addrlist, | 99 net::AddressList* addrlist, |
| 114 int* os_error); | 100 int* os_error); |
| 115 }; | 101 }; |
| 116 | 102 |
| 117 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ | 103 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ |
| OLD | NEW |