[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / chrome / browser / intranet_redirect_detector.h
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
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 <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/pref_registry/pref_registry_syncable.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "mojo/public/cpp/bindings/receiver.h"
19 #include "services/network/public/cpp/network_connection_tracker.h"
20 #include "services/network/public/mojom/host_resolver.mojom.h"
21 #include "url/gurl.h"
22
23 namespace network {
24 class SimpleURLLoader;
25 }
26
27 class PrefRegistrySimple;
28
29 // This object is responsible for determining whether the user is on a network
30 // that redirects requests for intranet hostnames to another site, and if so,
31 // tracking what that site is (including across restarts via a pref).  For
32 // example, the user's ISP might convert a request for "http://query/" into a
33 // 302 redirect to "http://isp.domain.com/search?q=query" in order to display
34 // custom pages on typos, nonexistent sites, etc.
35 //
36 // We use this information in the OmniboxNavigationObserver to avoid displaying
37 // infobars for these cases.  Our infobars are designed to allow users to get at
38 // intranet sites when they were erroneously taken to a search result page.  In
39 // these cases, however, users would be shown a confusing and useless infobar
40 // when they really did mean to do a search.
41 //
42 // Consumers should call RedirectOrigin(), which is guaranteed to synchronously
43 // return a value at all times (even during startup or in unittest mode).  If no
44 // redirection is in place, the returned GURL will be empty.
45 class IntranetRedirectDetector
46     : public network::NetworkConnectionTracker::NetworkConnectionObserver,
47       public network::mojom::DnsConfigChangeManagerClient {
48  public:
49   // Only the main browser process loop should call this, when setting up
50   // g_browser_process->intranet_redirect_detector_.  No code other than the
51   // IntranetRedirectDetector itself should actually use
52   // g_browser_process->intranet_redirect_detector() (which shouldn't be hard,
53   // since there aren't useful public functions on this object for consumers to
54   // access anyway).
55   IntranetRedirectDetector();
56   ~IntranetRedirectDetector() override;
57
58   // Returns the current redirect origin.  This will be empty if no redirection
59   // is in place.
60   static GURL RedirectOrigin();
61
62   static void RegisterPrefs(PrefRegistrySimple* registry);
63
64  private:
65   // Called on connection or config change to ensure detector runs again (after
66   // a delay).
67   void Restart();
68
69   // Called when the startup or restart sleep has finished.  Runs any pending
70   // fetch.
71   void FinishSleep();
72
73   // Invoked from SimpleURLLoader after download is complete.
74   void OnSimpleLoaderComplete(network::SimpleURLLoader* source,
75                               std::unique_ptr<std::string> response_body);
76
77   // NetworkConnectionTracker::NetworkConnectionObserver
78   void OnConnectionChanged(network::mojom::ConnectionType type) override;
79
80   // network::mojom::DnsConfigChangeManagerClient
81   void OnDnsConfigChanged() override;
82
83   void SetupDnsConfigClient();
84   void OnDnsConfigClientConnectionError();
85
86   // Whether the IntranetRedirectDetector is enabled, or, through policy,
87   // disabled.
88   bool IsEnabledByPolicy();
89
90   GURL redirect_origin_;
91   std::map<network::SimpleURLLoader*, std::unique_ptr<network::SimpleURLLoader>>
92       simple_loaders_;
93   std::vector<GURL> resulting_origins_;
94   bool in_sleep_ = true;  // True if we're in the seven-second "no fetching"
95                           // period that begins at browser start, or the
96                           // one-second "no fetching" period that begins after
97                           // network switches.
98   mojo::Receiver<network::mojom::DnsConfigChangeManagerClient>
99       dns_config_client_receiver_{this};
100   base::WeakPtrFactory<IntranetRedirectDetector> weak_ptr_factory_{this};
101
102   DISALLOW_COPY_AND_ASSIGN(IntranetRedirectDetector);
103 };
104
105 #endif  // CHROME_BROWSER_INTRANET_REDIRECT_DETECTOR_H_