OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_ |
| 6 #define CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "chromeos/chromeos_export.h" |
| 12 #include "chromeos/login/login_state.h" |
| 13 #include "chromeos/network/client_cert_resolver.h" |
| 14 #include "chromeos/network/network_connection_handler.h" |
| 15 #include "chromeos/network/network_handler.h" |
| 16 #include "chromeos/network/network_policy_observer.h" |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 class CHROMEOS_EXPORT AutoConnectHandler |
| 21 : public LoginState::Observer, |
| 22 public NetworkPolicyObserver, |
| 23 public NetworkConnectionHandler::Observer, |
| 24 public ClientCertResolver::Observer { |
| 25 public: |
| 26 ~AutoConnectHandler() override; |
| 27 |
| 28 // LoginState::Observer |
| 29 void LoggedInStateChanged() override; |
| 30 |
| 31 // NetworkConnectionHandler::Observer |
| 32 void ConnectToNetworkRequested(const std::string& service_path) override; |
| 33 |
| 34 // NetworkPolicyObserver |
| 35 void PoliciesChanged(const std::string& userhash) override; |
| 36 void PoliciesApplied(const std::string& userhash) override; |
| 37 |
| 38 // ClientCertResolver::Observer |
| 39 void ResolveRequestCompleted(bool network_properties_changed) override; |
| 40 |
| 41 private: |
| 42 friend class NetworkHandler; |
| 43 friend class AutoConnectHandlerTest; |
| 44 |
| 45 AutoConnectHandler(); |
| 46 |
| 47 void Init(ClientCertResolver* client_cert_resolver, |
| 48 NetworkConnectionHandler* network_connection_handler, |
| 49 NetworkStateHandler* network_state_handler, |
| 50 ManagedNetworkConfigurationHandler* |
| 51 managed_network_configuration_handler); |
| 52 |
| 53 // If the user logged in already and the policy to prevent unmanaged & shared |
| 54 // networks to autoconnect is enabled, then disconnects all such networks |
| 55 // except wired networks. It will do this only once after the user logged in |
| 56 // and the device policy was available. |
| 57 // This is enforced once after a user logs in 1) to allow mananged networks to |
| 58 // autoconnect and 2) to prevent a previous user from foisting a network on |
| 59 // the new user. Therefore, this function is called at login and when the |
| 60 // device policy is changed. |
| 61 void DisconnectIfPolicyRequires(); |
| 62 |
| 63 // Disconnects from all unmanaged and shared WiFi networks that are currently |
| 64 // connected or connecting. |
| 65 void DisconnectFromUnmanagedSharedWiFiNetworks(); |
| 66 |
| 67 // Requests and if possible connects to the 'best' available network, see |
| 68 // CheckBestConnection(). |
| 69 void RequestBestConnection(); |
| 70 |
| 71 // If a request to connect to the best network is pending and all requirements |
| 72 // are fulfilled (like policy loaded, certificate patterns being resolved), |
| 73 // then this will call ConnectToBestWifiNetwork of |network_state_handler_|. |
| 74 void CheckBestConnection(); |
| 75 |
| 76 // Local references to the associated handler instances. |
| 77 ClientCertResolver* client_cert_resolver_; |
| 78 NetworkConnectionHandler* network_connection_handler_; |
| 79 NetworkStateHandler* network_state_handler_; |
| 80 ManagedNetworkConfigurationHandler* managed_configuration_handler_; |
| 81 |
| 82 // Whether a request to connect to the best network is pending. If true, once |
| 83 // all requirements are met (like policy loaded, certificate patterns being |
| 84 // resolved), the request is forwarded to the |network_state_handler_|. |
| 85 bool request_best_connection_pending_; |
| 86 |
| 87 // Whether the device policy, which might be empty, is already applied. |
| 88 bool device_policy_applied_; |
| 89 |
| 90 // Whether the user policy of the first user who logged in is already applied. |
| 91 // The policy might be empty. |
| 92 bool user_policy_applied_; |
| 93 |
| 94 // Whether at least once client certificate patterns were checked and if any |
| 95 // existed resolved. Even if there are no certificate patterns, this will be |
| 96 // eventually true. |
| 97 bool client_certs_resolved_; |
| 98 |
| 99 // Whether the autoconnect policy was applied already, see |
| 100 // DisconnectIfPolicyRequires(). |
| 101 bool applied_autoconnect_policy_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(AutoConnectHandler); |
| 104 }; |
| 105 |
| 106 } // namespace chromeos |
| 107 |
| 108 #endif // CHROMEOS_NETWORK_AUTO_CONNECT_HANDLER_H_ |
OLD | NEW |