summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfqj <fqj@chromium.org>2015-11-09 17:27:22 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-10 01:29:15 +0000
commitece043573566d4759b9c0e6756747dc4d1ecec40 (patch)
treebdd3a5931807b36eb27a31b2e726c600abb0e63d
parentaec2e4130bc2a2b8db6d6c921a05e8d18c4b80c9 (diff)
downloadchromium_src-ece043573566d4759b9c0e6756747dc4d1ecec40.zip
chromium_src-ece043573566d4759b9c0e6756747dc4d1ecec40.tar.gz
chromium_src-ece043573566d4759b9c0e6756747dc4d1ecec40.tar.bz2
Let AutoConnectHandler wait for user policy before disconnecting
AutoConnectHandler didn't wait for user policy before disconnecting from unmanaged network. This will lead to user policy not downloaded or applied. This commit make AutoConnectHandler to wait for user policy first before disconnecting from unmanaged network if device policy requires to do so. BUG=553497 Review URL: https://codereview.chromium.org/1415683013 Cr-Commit-Position: refs/heads/master@{#358730}
-rw-r--r--chromeos/network/auto_connect_handler.cc10
-rw-r--r--chromeos/network/auto_connect_handler.h4
-rw-r--r--chromeos/network/auto_connect_handler_unittest.cc6
3 files changed, 15 insertions, 5 deletions
diff --git a/chromeos/network/auto_connect_handler.cc b/chromeos/network/auto_connect_handler.cc
index edb8c6d..4665cfe 100644
--- a/chromeos/network/auto_connect_handler.cc
+++ b/chromeos/network/auto_connect_handler.cc
@@ -100,10 +100,12 @@ void AutoConnectHandler::PoliciesChanged(const std::string& userhash) {
}
void AutoConnectHandler::PoliciesApplied(const std::string& userhash) {
- if (userhash.empty())
+ if (userhash.empty()) {
device_policy_applied_ = true;
- else
+ } else {
user_policy_applied_ = true;
+ DisconnectIfPolicyRequires();
+ }
// Request to connect to the best network only if there is at least one
// managed network. Otherwise only process existing requests.
@@ -194,8 +196,10 @@ void AutoConnectHandler::CheckBestConnection() {
}
void AutoConnectHandler::DisconnectIfPolicyRequires() {
- if (applied_autoconnect_policy_ || !LoginState::Get()->IsUserLoggedIn())
+ if (applied_autoconnect_policy_ || !LoginState::Get()->IsUserLoggedIn() ||
+ !user_policy_applied_) {
return;
+ }
const base::DictionaryValue* global_network_config =
managed_configuration_handler_->GetGlobalConfigFromPolicy(
diff --git a/chromeos/network/auto_connect_handler.h b/chromeos/network/auto_connect_handler.h
index 26444dc..6d990be 100644
--- a/chromeos/network/auto_connect_handler.h
+++ b/chromeos/network/auto_connect_handler.h
@@ -58,11 +58,11 @@ class CHROMEOS_EXPORT AutoConnectHandler : public LoginState::Observer,
// If the user logged in already and the policy to prevent unmanaged & shared
// networks to autoconnect is enabled, then disconnects all such networks
// except wired networks. It will do this only once after the user logged in
- // and the device policy was available.
+ // and the device policy and user policy was available.
// This is enforced once after a user logs in 1) to allow mananged networks to
// autoconnect and 2) to prevent a previous user from foisting a network on
// the new user. Therefore, this function is called at login and when the
- // device policy is changed.
+ // device policy is changed after user policy is fetched and applied.
void DisconnectIfPolicyRequires();
// Disconnects from all unmanaged and shared WiFi networks that are currently
diff --git a/chromeos/network/auto_connect_handler_unittest.cc b/chromeos/network/auto_connect_handler_unittest.cc
index 1143108..9749ee4 100644
--- a/chromeos/network/auto_connect_handler_unittest.cc
+++ b/chromeos/network/auto_connect_handler_unittest.cc
@@ -407,6 +407,12 @@ TEST_F(AutoConnectHandlerTest, DisconnectOnPolicyLoading) {
// Because no best service is set, the fake implementation of
// ConnectToBestServices will be a no-op.
SetupPolicy(kPolicy, global_config, false /* load as device policy */);
+
+ // Should not trigger any change until user policy is loaded
+ EXPECT_EQ(shill::kStateOnline, GetServiceState("wifi0"));
+ EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1"));
+
+ SetupPolicy(std::string(), base::DictionaryValue(), true);
EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi0"));
EXPECT_EQ(shill::kStateIdle, GetServiceState("wifi1"));
}