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

Side by Side Diff: chrome/browser/intranet_redirect_detector.h

Issue 525079: Add autodetection of "intranet" redirection, for ISPs etc. that send typos an... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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 | « chrome/browser/first_run.h ('k') | chrome/browser/intranet_redirect_detector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_
6 #define CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "chrome/browser/net/url_fetcher.h"
13 #include "chrome/common/notification_registrar.h"
14 #include "googleurl/src/gurl.h"
15 #include "net/base/host_resolver_proc.h"
16
17 class PrefService;
18
19 // This object is responsible for determining whether the user is on a network
20 // that redirects requests for intranet hostnames to another site, and if so,
21 // tracking what that site is (including across restarts via a pref). For
22 // example, the user's ISP might convert a request for "http://query/" into a
23 // 302 redirect to "http://isp.domain.com/search?q=query" in order to display
24 // custom pages on typos, nonexistent sites, etc.
25 //
26 // We use this information in the AlternateNavURLFetcher to avoid displaying
27 // infobars for these cases. Our infobars are designed to allow users to get at
28 // intranet sites when they were erroneously taken to a search result page. In
29 // these cases, however, users would be shown a confusing and useless infobar
30 // when they really did mean to do a search.
31 //
32 // Consumers should call RedirectOrigin(), which is guaranteed to synchronously
33 // return a value at all times (even during startup or in unittest mode). If no
34 // redirection is in place, the returned GURL will be empty.
35 class IntranetRedirectDetector : public URLFetcher::Delegate,
36 public NotificationObserver {
37 public:
38 // Only the main browser process loop should call this, when setting up
39 // g_browser_process->intranet_redirect_detector_. No code other than the
40 // IntranetRedirectDetector itself should actually use
41 // g_browser_process->intranet_redirect_detector() (which shouldn't be hard,
42 // since there aren't useful public functions on this object for consumers to
43 // access anyway).
44 IntranetRedirectDetector();
45 ~IntranetRedirectDetector();
46
47 // Returns the current redirect origin. This will be empty if no redirection
48 // is in place.
49 static GURL RedirectOrigin();
50
51 static void RegisterPrefs(PrefService* prefs);
52
53 // The number of characters the fetcher will use for its randomly-generated
54 // hostnames.
55 static const size_t kNumCharsInHostnames;
56
57 private:
58 typedef std::set<URLFetcher*> Fetchers;
59
60 // Called when the five second startup sleep has finished. Runs any pending
61 // fetch.
62 void FinishSleep();
63
64 // Starts the fetches to determine the redirect URL if we can currently do so.
65 void StartFetchesIfPossible();
66
67 // URLFetcher::Delegate
68 virtual void OnURLFetchComplete(const URLFetcher* source,
69 const GURL& url,
70 const URLRequestStatus& status,
71 int response_code,
72 const ResponseCookies& cookies,
73 const std::string& data);
74
75 // NotificationObserver
76 virtual void Observe(NotificationType type,
77 const NotificationSource& source,
78 const NotificationDetails& details);
79
80 NotificationRegistrar registrar_;
81 GURL redirect_origin_;
82 ScopedRunnableMethodFactory<IntranetRedirectDetector> fetcher_factory_;
83 Fetchers fetchers_;
84 std::vector<GURL> resulting_origins_;
85 bool in_startup_sleep_; // True if we're in the seven-second "no fetching"
86 // period that begins at browser start.
87 bool request_context_available_;
88 // True when the profile has been loaded and the
89 // default request context created, so we can
90 // actually do the fetch with the right data.
91
92 DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector);
93 };
94
95 // This is for use in testing, where we don't want our fetches to actually go
96 // over the network. It captures the requests and causes them to fail.
97 class IntranetRedirectHostResolverProc : public net::HostResolverProc {
98 public:
99 explicit IntranetRedirectHostResolverProc(net::HostResolverProc* previous);
100
101 virtual int Resolve(const std::string& host,
102 net::AddressFamily address_family,
103 net::AddressList* addrlist);
104 };
105
106 #endif // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/first_run.h ('k') | chrome/browser/intranet_redirect_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698