| 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 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...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 net::URLFetcherDelegate, | 39 : public net::URLFetcherDelegate, |
| 40 public net::NetworkChangeNotifier::IPAddressObserver { | 40 public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 41 public: | 41 public: |
| 42 // 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 |
| 43 // g_browser_process->intranet_redirect_detector_. No code other than the | 43 // g_browser_process->intranet_redirect_detector_. No code other than the |
| 44 // IntranetRedirectDetector itself should actually use | 44 // IntranetRedirectDetector itself should actually use |
| 45 // g_browser_process->intranet_redirect_detector() (which shouldn't be hard, | 45 // g_browser_process->intranet_redirect_detector() (which shouldn't be hard, |
| 46 // 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 |
| 47 // access anyway). | 47 // access anyway). |
| 48 IntranetRedirectDetector(); | 48 IntranetRedirectDetector(); |
| 49 virtual ~IntranetRedirectDetector(); | 49 virtual ~IntranetRedirectDetector(); |
| 50 | 50 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 private: | 61 private: |
| 62 typedef std::set<net::URLFetcher*> Fetchers; | 62 typedef std::set<net::URLFetcher*> Fetchers; |
| 63 | 63 |
| 64 // 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 |
| 65 // switch sleep has finished. Runs any pending fetch. | 65 // switch sleep has finished. Runs any pending fetch. |
| 66 void FinishSleep(); | 66 void FinishSleep(); |
| 67 | 67 |
| 68 // net::URLFetcherDelegate | 68 // net::URLFetcherDelegate |
| 69 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 69 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 70 | 70 |
| 71 // NetworkChangeNotifier::IPAddressObserver | 71 // NetworkChangeNotifier::NetworkChangeObserver |
| 72 virtual void OnIPAddressChanged() OVERRIDE; | 72 virtual void OnNetworkChanged( |
| 73 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 73 | 74 |
| 74 GURL redirect_origin_; | 75 GURL redirect_origin_; |
| 75 base::WeakPtrFactory<IntranetRedirectDetector> weak_factory_; | 76 base::WeakPtrFactory<IntranetRedirectDetector> weak_factory_; |
| 76 Fetchers fetchers_; | 77 Fetchers fetchers_; |
| 77 std::vector<GURL> resulting_origins_; | 78 std::vector<GURL> resulting_origins_; |
| 78 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 |
| 79 // that begins at browser start, or the one-second "no | 80 // that begins at browser start, or the one-second "no |
| 80 // fetching" period that begins after network switches. | 81 // fetching" period that begins after network switches. |
| 81 | 82 |
| 82 DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector); | 83 DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector); |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 // This is for use in testing, where we don't want our fetches to actually go | 86 // This is for use in testing, where we don't want our fetches to actually go |
| 86 // over the network. It captures the requests and causes them to fail. | 87 // over the network. It captures the requests and causes them to fail. |
| 87 class IntranetRedirectHostResolverProc : public net::HostResolverProc { | 88 class IntranetRedirectHostResolverProc : public net::HostResolverProc { |
| 88 public: | 89 public: |
| 89 explicit IntranetRedirectHostResolverProc(net::HostResolverProc* previous); | 90 explicit IntranetRedirectHostResolverProc(net::HostResolverProc* previous); |
| 90 | 91 |
| 91 virtual int Resolve(const std::string& host, | 92 virtual int Resolve(const std::string& host, |
| 92 net::AddressFamily address_family, | 93 net::AddressFamily address_family, |
| 93 net::HostResolverFlags host_resolver_flags, | 94 net::HostResolverFlags host_resolver_flags, |
| 94 net::AddressList* addrlist, | 95 net::AddressList* addrlist, |
| 95 int* os_error) OVERRIDE; | 96 int* os_error) OVERRIDE; |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 virtual ~IntranetRedirectHostResolverProc() {} | 99 virtual ~IntranetRedirectHostResolverProc() {} |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ | 102 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_ |
| OLD | NEW |