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 |
| 128 void DeviceCloudPolicyManagerChromeOS::InitalizeRequisition() { | |
| 129 if (chromeos::StartupUtils::IsOobeCompleted()) | |
| 130 return; | |
| 131 | |
| 132 const PrefService::Preference* pref = local_state_->FindPreference( | |
| 133 prefs::kDeviceEnrollmentRequisition); | |
| 134 if (pref->IsDefaultValue()) { | |
| 135 // OEM statistics are only loaded when OOBE is not completed. | |
|
xiyuan
2014/03/01 04:38:58
nit: Move to the comment to above line 129? It fee
zel
2014/03/01 21:30:27
Done.
| |
| 136 std::string requisition = | |
| 137 GetMachineStatistic(chromeos::system::kOemDeviceRequisitionKey); | |
| 138 if (!requisition.empty()) | |
| 139 SetDeviceRequisition(requisition); | |
| 140 } | |
| 141 } | |
| 142 | |
| 124 void DeviceCloudPolicyManagerChromeOS::StartEnrollment( | 143 void DeviceCloudPolicyManagerChromeOS::StartEnrollment( |
| 125 const std::string& auth_token, | 144 const std::string& auth_token, |
| 126 bool is_auto_enrollment, | 145 bool is_auto_enrollment, |
| 127 const AllowedDeviceModes& allowed_device_modes, | 146 const AllowedDeviceModes& allowed_device_modes, |
| 128 const EnrollmentCallback& callback) { | 147 const EnrollmentCallback& callback) { |
| 129 CHECK(device_management_service_); | 148 CHECK(device_management_service_); |
| 130 core()->Disconnect(); | 149 core()->Disconnect(); |
| 131 | 150 |
| 132 enrollment_handler_.reset( | 151 enrollment_handler_.reset( |
| 133 new EnrollmentHandlerChromeOS( | 152 new EnrollmentHandlerChromeOS( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 144 if (enrollment_handler_.get()) { | 163 if (enrollment_handler_.get()) { |
| 145 enrollment_handler_.reset(); | 164 enrollment_handler_.reset(); |
| 146 StartIfManaged(); | 165 StartIfManaged(); |
| 147 } | 166 } |
| 148 } | 167 } |
| 149 | 168 |
| 150 std::string DeviceCloudPolicyManagerChromeOS::GetDeviceRequisition() const { | 169 std::string DeviceCloudPolicyManagerChromeOS::GetDeviceRequisition() const { |
| 151 std::string requisition; | 170 std::string requisition; |
| 152 const PrefService::Preference* pref = local_state_->FindPreference( | 171 const PrefService::Preference* pref = local_state_->FindPreference( |
| 153 prefs::kDeviceEnrollmentRequisition); | 172 prefs::kDeviceEnrollmentRequisition); |
| 154 if (pref->IsDefaultValue() && !chromeos::StartupUtils::IsOobeCompleted()) { | 173 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); | 174 pref->GetValue()->GetAsString(&requisition); |
| 160 } | 175 |
| 176 if (requisition == kNoRequisition) | |
| 177 requisition.clear(); | |
| 161 | 178 |
| 162 return requisition; | 179 return requisition; |
| 163 } | 180 } |
| 164 | 181 |
| 165 void DeviceCloudPolicyManagerChromeOS::SetDeviceRequisition( | 182 void DeviceCloudPolicyManagerChromeOS::SetDeviceRequisition( |
| 166 const std::string& requisition) { | 183 const std::string& requisition) { |
| 167 if (local_state_) { | 184 if (local_state_) { |
| 168 if (requisition.empty()) { | 185 if (requisition.empty()) { |
| 169 local_state_->ClearPref(prefs::kDeviceEnrollmentRequisition); | 186 local_state_->ClearPref(prefs::kDeviceEnrollmentRequisition); |
| 170 local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart); | 187 local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart); |
| 171 local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit); | 188 local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit); |
| 172 } else { | 189 } else { |
| 173 local_state_->SetString(prefs::kDeviceEnrollmentRequisition, requisition); | 190 local_state_->SetString(prefs::kDeviceEnrollmentRequisition, requisition); |
| 174 local_state_->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | 191 if (requisition == kNoRequisition) { |
| 175 local_state_->SetBoolean(prefs::kDeviceEnrollmentCanExit, false); | 192 local_state_->ClearPref(prefs::kDeviceEnrollmentAutoStart); |
| 193 local_state_->ClearPref(prefs::kDeviceEnrollmentCanExit); | |
| 194 } else { | |
| 195 local_state_->SetBoolean(prefs::kDeviceEnrollmentAutoStart, true); | |
| 196 local_state_->SetBoolean(prefs::kDeviceEnrollmentCanExit, false); | |
| 197 } | |
| 176 } | 198 } |
| 177 } | 199 } |
| 178 } | 200 } |
| 179 | 201 |
| 180 bool DeviceCloudPolicyManagerChromeOS::ShouldAutoStartEnrollment() const { | 202 bool DeviceCloudPolicyManagerChromeOS::ShouldAutoStartEnrollment() const { |
| 181 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) | 203 if (local_state_->HasPrefPath(prefs::kDeviceEnrollmentAutoStart)) |
| 182 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); | 204 return local_state_->GetBoolean(prefs::kDeviceEnrollmentAutoStart); |
| 183 | 205 |
| 184 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); | 206 return GetMachineFlag(chromeos::system::kOemIsEnterpriseManagedKey, false); |
| 185 } | 207 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 core()->Connect(CreateClient()); | 303 core()->Connect(CreateClient()); |
| 282 core()->StartRefreshScheduler(); | 304 core()->StartRefreshScheduler(); |
| 283 core()->TrackRefreshDelayPref(local_state_, | 305 core()->TrackRefreshDelayPref(local_state_, |
| 284 prefs::kDevicePolicyRefreshRate); | 306 prefs::kDevicePolicyRefreshRate); |
| 285 attestation_policy_observer_.reset( | 307 attestation_policy_observer_.reset( |
| 286 new chromeos::attestation::AttestationPolicyObserver(client())); | 308 new chromeos::attestation::AttestationPolicyObserver(client())); |
| 287 } | 309 } |
| 288 } | 310 } |
| 289 | 311 |
| 290 } // namespace policy | 312 } // namespace policy |
| OLD | NEW |