| 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" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 16 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 16 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 17 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
| 17 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 19 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 19 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" | 20 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" |
| 20 #include "chrome/common/chrome_content_client.h" | 21 #include "chrome/common/chrome_content_client.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chromeos/system/statistics_provider.h" | 23 #include "chromeos/system/statistics_provider.h" |
| 23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 24 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 restore_mode == kDeviceStateRestoreModeReEnrollmentEnforced) { | 122 restore_mode == kDeviceStateRestoreModeReEnrollmentEnforced) { |
| 122 return true; | 123 return true; |
| 123 } | 124 } |
| 124 | 125 |
| 125 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) | 126 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) |
| 126 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); | 127 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); |
| 127 | 128 |
| 128 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); | 129 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); |
| 129 } | 130 } |
| 130 | 131 |
| 132 bool DeviceCloudPolicyInitializer::ShouldRecoverEnrollment() const { |
| 133 if (install_attributes_->IsEnterpriseDevice() && |
| 134 chromeos::StartupUtils::IsEnrollmentRecoveryRequired()) { |
| 135 LOG(WARNING) << "Enrollment recovery required according to pref."; |
| 136 std::string machine_id; |
| 137 bool machine_id_success = |
| 138 chromeos::system::StatisticsProvider::GetInstance() |
| 139 ->GetMachineStatistic(chromeos::system::kHardwareClassKey, |
| 140 &machine_id); |
| 141 if (machine_id_success && machine_id != "") |
| 142 return true; |
| 143 LOG(WARNING) << "Postponing recovery because machine id is missing."; |
| 144 } |
| 145 return false; |
| 146 } |
| 147 |
| 131 bool DeviceCloudPolicyInitializer::CanExitEnrollment() const { | 148 bool DeviceCloudPolicyInitializer::CanExitEnrollment() const { |
| 132 if (GetRestoreMode() == kDeviceStateRestoreModeReEnrollmentEnforced) | 149 if (GetRestoreMode() == kDeviceStateRestoreModeReEnrollmentEnforced) |
| 133 return false; | 150 return false; |
| 134 | 151 |
| 135 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentCanExit)) | 152 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentCanExit)) |
| 136 return local_state_->GetBoolean(prefs::kDeviceEnrollmentCanExit); | 153 return local_state_->GetBoolean(prefs::kDeviceEnrollmentCanExit); |
| 137 | 154 |
| 138 return GetMachineFlag(chromeos::system::kOemCanExitEnterpriseEnrollmentKey, | 155 return GetMachineFlag(chromeos::system::kOemCanExitEnterpriseEnrollmentKey, |
| 139 true); | 156 true); |
| 140 } | 157 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 kPolicyVerificationKeyHash, | 204 kPolicyVerificationKeyHash, |
| 188 USER_AFFILIATION_NONE, | 205 USER_AFFILIATION_NONE, |
| 189 device_status_provider_.get(), | 206 device_status_provider_.get(), |
| 190 device_management_service, | 207 device_management_service, |
| 191 request_context)); | 208 request_context)); |
| 192 } | 209 } |
| 193 | 210 |
| 194 void DeviceCloudPolicyInitializer::TryToCreateClient() { | 211 void DeviceCloudPolicyInitializer::TryToCreateClient() { |
| 195 if (device_store_->is_initialized() && | 212 if (device_store_->is_initialized() && |
| 196 device_store_->has_policy() && | 213 device_store_->has_policy() && |
| 214 !device_store_->policy()->request_token().empty() && |
| 197 !state_keys_broker_->pending() && | 215 !state_keys_broker_->pending() && |
| 198 !enrollment_handler_) { | 216 !enrollment_handler_) { |
| 199 DeviceManagementService* service; | 217 DeviceManagementService* service; |
| 200 if (device_store_->policy()->management_mode() == | 218 if (device_store_->policy()->management_mode() == |
| 201 em::PolicyData::CONSUMER_MANAGED) { | 219 em::PolicyData::CONSUMER_MANAGED) { |
| 202 service = consumer_service_; | 220 service = consumer_service_; |
| 203 } else { | 221 } else { |
| 204 service = enterprise_service_; | 222 service = enterprise_service_; |
| 205 } | 223 } |
| 206 StartConnection(CreateClient(service)); | 224 StartConnection(CreateClient(service)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 220 | 238 |
| 221 std::string DeviceCloudPolicyInitializer::GetRestoreMode() const { | 239 std::string DeviceCloudPolicyInitializer::GetRestoreMode() const { |
| 222 const base::DictionaryValue* device_state_dict = | 240 const base::DictionaryValue* device_state_dict = |
| 223 local_state_->GetDictionary(prefs::kServerBackedDeviceState); | 241 local_state_->GetDictionary(prefs::kServerBackedDeviceState); |
| 224 std::string restore_mode; | 242 std::string restore_mode; |
| 225 device_state_dict->GetString(kDeviceStateRestoreMode, &restore_mode); | 243 device_state_dict->GetString(kDeviceStateRestoreMode, &restore_mode); |
| 226 return restore_mode; | 244 return restore_mode; |
| 227 } | 245 } |
| 228 | 246 |
| 229 } // namespace policy | 247 } // namespace policy |
| OLD | NEW |