Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.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/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 | 30 |
| 31 namespace em = enterprise_management; | 31 namespace em = enterprise_management; |
| 32 | 32 |
| 33 namespace policy { | 33 namespace policy { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // Overridden no requisition value. | |
| 38 const char kNoRequisition[] = "none"; | |
| 39 | |
| 37 // MachineInfo key names. | 40 // MachineInfo key names. |
| 38 const char kMachineInfoSystemHwqual[] = "hardware_class"; | 41 const char kMachineInfoSystemHwqual[] = "hardware_class"; |
| 39 | 42 |
| 40 // These are the machine serial number keys that we check in order until we | 43 // These are the machine serial number keys that we check in order until we |
| 41 // find a non-empty serial number. The VPD spec says the serial number should be | 44 // find a non-empty serial number. The VPD spec says the serial number should be |
| 42 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a | 45 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a |
| 43 // different keys to report their serial number, which we fall back to if | 46 // different keys to report their serial number, which we fall back to if |
| 44 // "serial_number" is not present. | 47 // "serial_number" is not present. |
| 45 // | 48 // |
| 46 // Product_S/N is still special-cased due to inconsistencies with serial | 49 // Product_S/N is still special-cased due to inconsistencies with serial |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 DeviceManagementService* device_management_service, | 114 DeviceManagementService* device_management_service, |
| 112 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider) { | 115 scoped_ptr<CloudPolicyClient::StatusProvider> device_status_provider) { |
| 113 CHECK(!device_management_service_); | 116 CHECK(!device_management_service_); |
| 114 CHECK(device_management_service); | 117 CHECK(device_management_service); |
| 115 CHECK(local_state); | 118 CHECK(local_state); |
| 116 | 119 |
| 117 local_state_ = local_state; | 120 local_state_ = local_state; |
| 118 device_management_service_ = device_management_service; | 121 device_management_service_ = device_management_service; |
| 119 device_status_provider_ = device_status_provider.Pass(); | 122 device_status_provider_ = device_status_provider.Pass(); |
| 120 | 123 |
| 124 InitalizeRequisition(); | |
| 121 StartIfManaged(); | 125 StartIfManaged(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void DeviceCloudPolicyManagerChromeOS::StartEnrollment( | 128 void DeviceCloudPolicyManagerChromeOS::StartEnrollment( |
| 125 const std::string& auth_token, | 129 const std::string& auth_token, |
| 126 bool is_auto_enrollment, | 130 bool is_auto_enrollment, |
| 127 const AllowedDeviceModes& allowed_device_modes, | 131 const AllowedDeviceModes& allowed_device_modes, |
| 128 const EnrollmentCallback& callback) { | 132 const EnrollmentCallback& callback) { |
| 129 CHECK(device_management_service_); | 133 CHECK(device_management_service_); |
| 130 core()->Disconnect(); | 134 core()->Disconnect(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 144 if (enrollment_handler_.get()) { | 148 if (enrollment_handler_.get()) { |
| 145 enrollment_handler_.reset(); | 149 enrollment_handler_.reset(); |
| 146 StartIfManaged(); | 150 StartIfManaged(); |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 std::string DeviceCloudPolicyManagerChromeOS::GetDeviceRequisition() const { | 154 std::string DeviceCloudPolicyManagerChromeOS::GetDeviceRequisition() const { |
| 151 std::string requisition; | 155 std::string requisition; |
| 152 const PrefService::Preference* pref = local_state_->FindPreference( | 156 const PrefService::Preference* pref = local_state_->FindPreference( |
| 153 prefs::kDeviceEnrollmentRequisition); | 157 prefs::kDeviceEnrollmentRequisition); |
| 154 if (pref->IsDefaultValue() && !chromeos::StartupUtils::IsOobeCompleted()) { | 158 if (!pref->IsDefaultValue()) |
| 155 // OEM statistics are only loaded when OOBE is not completed. | |
| 156 requisition = | |
| 157 GetMachineStatistic(chromeos::system::kOemDeviceRequisitionKey); | |
| 158 } else { | |
| 159 pref->GetValue()->GetAsString(&requisition); | 159 pref->GetValue()->GetAsString(&requisition); |
| 160 } | 160 |
| 161 if (requisition == kNoRequisition) | |
| 162 requisition.clear(); | |
| 161 | 163 |
| 162 return requisition; | 164 return requisition; |
| 163 } | 165 } |
| 164 | 166 |
| 165 void DeviceCloudPolicyManagerChromeOS::SetDeviceRequisition( | 167 void DeviceCloudPolicyManagerChromeOS::SetDeviceRequisition( |
| 166 const std::string& requisition) { | 168 const std::string& requisition) { |
| 167 if (local_state_) { | 169 if (local_state_) { |
| 168 if (requisition.empty()) { | 170 if (requisition.empty()) { |
| 169 local_state_->ClearPref(prefs::kDeviceEnrollmentRequisition); | 171 local_state_->ClearPref(prefs::kDeviceEnrollmentRequisition); |
| 170 local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart); | 172 local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart); |
| 171 local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit); | 173 local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit); |
| 172 } else { | 174 } else { |
| 173 local_state_->SetString(prefs::kDeviceEnrollmentRequisition, requisition); | 175 local_state_->SetString(prefs::kDeviceEnrollmentRequisition, requisition); |
| 174 local_state_->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | 176 if (requisition == kNoRequisition) { |
| 175 local_state_->SetBoolean(prefs::kDeviceEnrollmentCanExit, false); | 177 local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart); |
| 178 local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit); | |
| 179 } else { | |
| 180 local_state_->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | |
| 181 local_state_->SetBoolean(prefs::kDeviceEnrollmentCanExit, false); | |
|
Mattias Nissler (ping if slow)
2014/03/02 08:35:08
This will become problematic once we're starting t
zel
2014/03/03 19:43:39
This should stay the way it is since it's only cal
| |
| 182 } | |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 | 186 |
| 180 bool DeviceCloudPolicyManagerChromeOS::ShouldAutoStartEnrollment() const { | 187 bool DeviceCloudPolicyManagerChromeOS::ShouldAutoStartEnrollment() const { |
| 181 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) | 188 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) |
| 182 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); | 189 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); |
| 183 | 190 |
| 184 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); | 191 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); |
| 185 } | 192 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 !service()) { | 287 !service()) { |
| 281 core()->Connect(CreateClient()); | 288 core()->Connect(CreateClient()); |
| 282 core()->StartRefreshScheduler(); | 289 core()->StartRefreshScheduler(); |
| 283 core()->TrackRefreshDelayPref(local_state_, | 290 core()->TrackRefreshDelayPref(local_state_, |
| 284 prefs::kDevicePolicyRefreshRate); | 291 prefs::kDevicePolicyRefreshRate); |
| 285 attestation_policy_observer_.reset( | 292 attestation_policy_observer_.reset( |
| 286 new chromeos::attestation::AttestationPolicyObserver(client())); | 293 new chromeos::attestation::AttestationPolicyObserver(client())); |
| 287 } | 294 } |
| 288 } | 295 } |
| 289 | 296 |
| 297 void DeviceCloudPolicyManagerChromeOS::InitalizeRequisition() { | |
| 298 // OEM statistics are only loaded when OOBE is not completed. | |
| 299 if (chromeos::StartupUtils::IsOobeCompleted()) | |
| 300 return; | |
| 301 | |
| 302 const PrefService::Preference* pref = local_state_->FindPreference( | |
| 303 prefs::kDeviceEnrollmentRequisition); | |
| 304 if (pref->IsDefaultValue()) { | |
| 305 std::string requisition = | |
| 306 GetMachineStatistic(chromeos::system::kOemDeviceRequisitionKey); | |
| 307 if (!requisition.empty()) | |
| 308 SetDeviceRequisition(requisition); | |
| 309 } | |
| 310 } | |
| 311 | |
| 290 } // namespace policy | 312 } // namespace policy |
| OLD | NEW |