Add python coverage module to third_party
[chromium-blink-merge.git] / chromeos / network / auto_connect_handler.h
blob99771075fd71bdb7b5448ca16da3c6259664635e
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_handler.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
23 : public LoginState::Observer,
24 public NetworkPolicyObserver,
25 public NetworkConnectionHandler::Observer,
26 public NetworkStateHandlerObserver,
27 public ClientCertResolver::Observer {
28 public:
29 ~AutoConnectHandler() override;
31 // LoginState::Observer
32 void LoggedInStateChanged() override;
34 // NetworkConnectionHandler::Observer
35 void ConnectToNetworkRequested(const std::string& service_path) override;
37 // NetworkPolicyObserver
38 void PoliciesChanged(const std::string& userhash) override;
39 void PoliciesApplied(const std::string& userhash) override;
41 // NetworkStateHandlerObserver
42 void ScanCompleted(const DeviceState* device) override;
44 // ClientCertResolver::Observer
45 void ResolveRequestCompleted(bool network_properties_changed) override;
47 private:
48 friend class NetworkHandler;
49 friend class AutoConnectHandlerTest;
51 AutoConnectHandler();
53 void Init(ClientCertResolver* client_cert_resolver,
54 NetworkConnectionHandler* network_connection_handler,
55 NetworkStateHandler* network_state_handler,
56 ManagedNetworkConfigurationHandler*
57 managed_network_configuration_handler);
59 // If the user logged in already and the policy to prevent unmanaged & shared
60 // networks to autoconnect is enabled, then disconnects all such networks
61 // except wired networks. It will do this only once after the user logged in
62 // and the device policy was available.
63 // This is enforced once after a user logs in 1) to allow mananged networks to
64 // autoconnect and 2) to prevent a previous user from foisting a network on
65 // the new user. Therefore, this function is called at login and when the
66 // device policy is changed.
67 void DisconnectIfPolicyRequires();
69 // Disconnects from all unmanaged and shared WiFi networks that are currently
70 // connected or connecting.
71 void DisconnectFromUnmanagedSharedWiFiNetworks();
73 // Requests and if possible connects to the 'best' available network, see
74 // CheckBestConnection().
75 void RequestBestConnection();
77 // If a request to connect to the best network is pending and all requirements
78 // are fulfilled (like policy loaded, certificate patterns being resolved),
79 // then this will call ConnectToBestWifiNetwork of |network_state_handler_|.
80 void CheckBestConnection();
82 // Calls Shill.Manager.ConnectToBestServices().
83 void CallShillConnectToBestServices() const;
85 // Local references to the associated handler instances.
86 ClientCertResolver* client_cert_resolver_;
87 NetworkConnectionHandler* network_connection_handler_;
88 NetworkStateHandler* network_state_handler_;
89 ManagedNetworkConfigurationHandler* managed_configuration_handler_;
91 // Whether a request to connect to the best network is pending. If true, once
92 // all requirements are met (like policy loaded, certificate patterns being
93 // resolved), a scan will be requested and ConnectToBestServices will be
94 // triggered once it completes.
95 bool request_best_connection_pending_;
97 // Whether the device policy, which might be empty, is already applied.
98 bool device_policy_applied_;
100 // Whether the user policy of the first user who logged in is already applied.
101 // The policy might be empty.
102 bool user_policy_applied_;
104 // Whether at least once client certificate patterns were checked and if any
105 // existed resolved. Even if there are no certificate patterns, this will be
106 // eventually true.
107 bool client_certs_resolved_;
109 // Whether the autoconnect policy was applied already, see
110 // DisconnectIfPolicyRequires().
111 bool applied_autoconnect_policy_;
113 // When true, trigger ConnectToBestServices after the next scan completion.
114 bool connect_to_best_services_after_scan_;
116 base::WeakPtrFactory<AutoConnectHandler> weak_ptr_factory_;
118 DISALLOW_COPY_AND_ASSIGN(AutoConnectHandler);
121 } // namespace chromeos
123 #endif // CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_