Disabling flaky test ChromeRenderProcessHostTestWithCommandLine.ProcessOverflow flaky...
[chromium-blink-merge.git] / chromeos / network / auto_connect_handler.h
blob26444dc9da70cdc69564b4ef713a1dcfc79e4adb
1 // Copyright 2014 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.
5 #ifndef CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_
6 #define CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/login/login_state.h"
14 #include "chromeos/network/client_cert_resolver.h"
15 #include "chromeos/network/network_connection_observer.h"
16 #include "chromeos/network/network_handler.h"
17 #include "chromeos/network/network_policy_observer.h"
18 #include "chromeos/network/network_state_handler_observer.h"
20 namespace chromeos {
22 class CHROMEOS_EXPORT AutoConnectHandler : public LoginState::Observer,
23 public NetworkPolicyObserver,
24 public NetworkConnectionObserver,
25 public NetworkStateHandlerObserver,
26 public ClientCertResolver::Observer {
27 public:
28 ~AutoConnectHandler() override;
30 // LoginState::Observer
31 void LoggedInStateChanged() override;
33 // NetworkConnectionObserver
34 void ConnectToNetworkRequested(const std::string& service_path) override;
36 // NetworkPolicyObserver
37 void PoliciesChanged(const std::string& userhash) override;
38 void PoliciesApplied(const std::string& userhash) override;
40 // NetworkStateHandlerObserver
41 void ScanCompleted(const DeviceState* device) override;
43 // ClientCertResolver::Observer
44 void ResolveRequestCompleted(bool network_properties_changed) override;
46 private:
47 friend class NetworkHandler;
48 friend class AutoConnectHandlerTest;
50 AutoConnectHandler();
52 void Init(ClientCertResolver* client_cert_resolver,
53 NetworkConnectionHandler* network_connection_handler,
54 NetworkStateHandler* network_state_handler,
55 ManagedNetworkConfigurationHandler*
56 managed_network_configuration_handler);
58 // If the user logged in already and the policy to prevent unmanaged & shared
59 // networks to autoconnect is enabled, then disconnects all such networks
60 // except wired networks. It will do this only once after the user logged in
61 // and the device policy was available.
62 // This is enforced once after a user logs in 1) to allow mananged networks to
63 // autoconnect and 2) to prevent a previous user from foisting a network on
64 // the new user. Therefore, this function is called at login and when the
65 // device policy is changed.
66 void DisconnectIfPolicyRequires();
68 // Disconnects from all unmanaged and shared WiFi networks that are currently
69 // connected or connecting.
70 void DisconnectFromUnmanagedSharedWiFiNetworks();
72 // Requests and if possible connects to the 'best' available network, see
73 // CheckBestConnection().
74 void RequestBestConnection();
76 // If a request to connect to the best network is pending and all requirements
77 // are fulfilled (like policy loaded, certificate patterns being resolved),
78 // then this will call ConnectToBestWifiNetwork of |network_state_handler_|.
79 void CheckBestConnection();
81 // Calls Shill.Manager.ConnectToBestServices().
82 void CallShillConnectToBestServices() const;
84 // Local references to the associated handler instances.
85 ClientCertResolver* client_cert_resolver_;
86 NetworkConnectionHandler* network_connection_handler_;
87 NetworkStateHandler* network_state_handler_;
88 ManagedNetworkConfigurationHandler* managed_configuration_handler_;
90 // Whether a request to connect to the best network is pending. If true, once
91 // all requirements are met (like policy loaded, certificate patterns being
92 // resolved), a scan will be requested and ConnectToBestServices will be
93 // triggered once it completes.
94 bool request_best_connection_pending_;
96 // Whether the device policy, which might be empty, is already applied.
97 bool device_policy_applied_;
99 // Whether the user policy of the first user who logged in is already applied.
100 // The policy might be empty.
101 bool user_policy_applied_;
103 // Whether at least once client certificate patterns were checked and if any
104 // existed resolved. Even if there are no certificate patterns, this will be
105 // eventually true.
106 bool client_certs_resolved_;
108 // Whether the autoconnect policy was applied already, see
109 // DisconnectIfPolicyRequires().
110 bool applied_autoconnect_policy_;
112 // When true, trigger ConnectToBestServices after the next scan completion.
113 bool connect_to_best_services_after_scan_;
115 base::WeakPtrFactory<AutoConnectHandler> weak_ptr_factory_;
117 DISALLOW_COPY_AND_ASSIGN(AutoConnectHandler);
120 } // namespace chromeos
122 #endif // CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_