| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 manager_->GetDeviceRequisition(), | 128 manager_->GetDeviceRequisition(), |
| 129 allowed_device_modes, | 129 allowed_device_modes, |
| 130 management_mode, | 130 management_mode, |
| 131 base::Bind(&DeviceCloudPolicyInitializer::EnrollmentCompleted, | 131 base::Bind(&DeviceCloudPolicyInitializer::EnrollmentCompleted, |
| 132 base::Unretained(this), | 132 base::Unretained(this), |
| 133 enrollment_callback))); | 133 enrollment_callback))); |
| 134 enrollment_handler_->StartEnrollment(); | 134 enrollment_handler_->StartEnrollment(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool DeviceCloudPolicyInitializer::ShouldAutoStartEnrollment() const { | 137 bool DeviceCloudPolicyInitializer::ShouldAutoStartEnrollment() const { |
| 138 std::string restore_mode = GetRestoreMode(); | 138 const RestoreMode restore_mode = GetRestoreMode(); |
| 139 if (restore_mode == kDeviceStateRestoreModeReEnrollmentRequested || | 139 if (restore_mode == RESTORE_MODE_REENROLLMENT_REQUESTED || |
| 140 restore_mode == kDeviceStateRestoreModeReEnrollmentEnforced) { | 140 restore_mode == RESTORE_MODE_REENROLLMENT_ENFORCED) { |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) | 144 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) |
| 145 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); | 145 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); |
| 146 | 146 |
| 147 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); | 147 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); |
| 148 } | 148 } |
| 149 | 149 |
| 150 bool DeviceCloudPolicyInitializer::ShouldRecoverEnrollment() const { | 150 bool DeviceCloudPolicyInitializer::ShouldRecoverEnrollment() const { |
| 151 if (install_attributes_->IsEnterpriseDevice() && | 151 if (install_attributes_->IsEnterpriseDevice() && |
| 152 chromeos::StartupUtils::IsEnrollmentRecoveryRequired()) { | 152 chromeos::StartupUtils::IsEnrollmentRecoveryRequired()) { |
| 153 LOG(WARNING) << "Enrollment recovery required according to pref."; | 153 LOG(WARNING) << "Enrollment recovery required according to pref."; |
| 154 if (!DeviceCloudPolicyManagerChromeOS::GetMachineID().empty()) | 154 if (!DeviceCloudPolicyManagerChromeOS::GetMachineID().empty()) |
| 155 return true; | 155 return true; |
| 156 LOG(WARNING) << "Postponing recovery because machine id is missing."; | 156 LOG(WARNING) << "Postponing recovery because machine id is missing."; |
| 157 } | 157 } |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 | 160 |
| 161 std::string DeviceCloudPolicyInitializer::GetEnrollmentRecoveryDomain() const { | 161 std::string DeviceCloudPolicyInitializer::GetEnrollmentRecoveryDomain() const { |
| 162 return install_attributes_->GetDomain(); | 162 return install_attributes_->GetDomain(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool DeviceCloudPolicyInitializer::CanExitEnrollment() const { | 165 bool DeviceCloudPolicyInitializer::CanExitEnrollment() const { |
| 166 if (GetRestoreMode() == kDeviceStateRestoreModeReEnrollmentEnforced) | 166 if (GetRestoreMode() == RESTORE_MODE_REENROLLMENT_ENFORCED) |
| 167 return false; | 167 return false; |
| 168 | 168 |
| 169 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentCanExit)) | 169 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentCanExit)) |
| 170 return local_state_->GetBoolean(prefs::kDeviceEnrollmentCanExit); | 170 return local_state_->GetBoolean(prefs::kDeviceEnrollmentCanExit); |
| 171 | 171 |
| 172 return GetMachineFlag(chromeos::system::kOemCanExitEnterpriseEnrollmentKey, | 172 return GetMachineFlag(chromeos::system::kOemCanExitEnterpriseEnrollmentKey, |
| 173 true); | 173 true); |
| 174 } | 174 } |
| 175 | 175 |
| 176 std::string | 176 std::string |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 scoped_ptr<CloudPolicyClient> client) { | 247 scoped_ptr<CloudPolicyClient> client) { |
| 248 if (!manager_->core()->service()) | 248 if (!manager_->core()->service()) |
| 249 manager_->StartConnection(client.Pass(), device_status_provider_.Pass()); | 249 manager_->StartConnection(client.Pass(), device_status_provider_.Pass()); |
| 250 | 250 |
| 251 if (!on_connected_callback_.is_null()) { | 251 if (!on_connected_callback_.is_null()) { |
| 252 on_connected_callback_.Run(); | 252 on_connected_callback_.Run(); |
| 253 on_connected_callback_.Reset(); | 253 on_connected_callback_.Reset(); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 std::string DeviceCloudPolicyInitializer::GetRestoreMode() const { | |
| 258 const base::DictionaryValue* device_state_dict = | |
| 259 local_state_->GetDictionary(prefs::kServerBackedDeviceState); | |
| 260 std::string restore_mode; | |
| 261 device_state_dict->GetString(kDeviceStateRestoreMode, &restore_mode); | |
| 262 return restore_mode; | |
| 263 } | |
| 264 | |
| 265 } // namespace policy | 257 } // namespace policy |
| OLD | NEW |