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/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/port.h" | 12 #include "base/port.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" | 17 #include "chrome/browser/chromeos/attestation/attestation_policy_observer.h" |
18 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" | 18 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" |
19 #include "chrome/browser/chromeos/login/startup_utils.h" | 19 #include "chrome/browser/chromeos/login/startup_utils.h" |
20 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
21 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 21 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 22 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
23 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" | 23 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" |
| 24 #include "chrome/browser/chromeos/policy/status_uploader.h" |
24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
25 #include "chromeos/chromeos_constants.h" | 26 #include "chromeos/chromeos_constants.h" |
26 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
27 #include "chromeos/system/statistics_provider.h" | 28 #include "chromeos/system/statistics_provider.h" |
28 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 29 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
29 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 30 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
30 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 31 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "crypto/sha2.h" | 33 #include "crypto/sha2.h" |
33 #include "policy/proto/device_management_backend.pb.h" | 34 #include "policy/proto/device_management_backend.pb.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 ServerBackedStateKeysBroker* state_keys_broker) | 107 ServerBackedStateKeysBroker* state_keys_broker) |
107 : CloudPolicyManager( | 108 : CloudPolicyManager( |
108 dm_protocol::kChromeDevicePolicyType, | 109 dm_protocol::kChromeDevicePolicyType, |
109 std::string(), | 110 std::string(), |
110 store.get(), | 111 store.get(), |
111 task_runner, | 112 task_runner, |
112 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)), | 114 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)), |
114 device_store_(store.Pass()), | 115 device_store_(store.Pass()), |
115 state_keys_broker_(state_keys_broker), | 116 state_keys_broker_(state_keys_broker), |
| 117 task_runner_(task_runner), |
116 local_state_(nullptr) { | 118 local_state_(nullptr) { |
117 } | 119 } |
118 | 120 |
119 DeviceCloudPolicyManagerChromeOS::~DeviceCloudPolicyManagerChromeOS() {} | 121 DeviceCloudPolicyManagerChromeOS::~DeviceCloudPolicyManagerChromeOS() {} |
120 | 122 |
121 void DeviceCloudPolicyManagerChromeOS::Initialize(PrefService* local_state) { | 123 void DeviceCloudPolicyManagerChromeOS::Initialize(PrefService* local_state) { |
122 CHECK(local_state); | 124 CHECK(local_state); |
123 | 125 |
124 local_state_ = local_state; | 126 local_state_ = local_state; |
125 | 127 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 178 |
177 bool DeviceCloudPolicyManagerChromeOS::IsRemoraRequisition() const { | 179 bool DeviceCloudPolicyManagerChromeOS::IsRemoraRequisition() const { |
178 return GetDeviceRequisition() == kRemoraRequisition; | 180 return GetDeviceRequisition() == kRemoraRequisition; |
179 } | 181 } |
180 | 182 |
181 bool DeviceCloudPolicyManagerChromeOS::IsSharkRequisition() const { | 183 bool DeviceCloudPolicyManagerChromeOS::IsSharkRequisition() const { |
182 return GetDeviceRequisition() == kSharkRequisition; | 184 return GetDeviceRequisition() == kSharkRequisition; |
183 } | 185 } |
184 | 186 |
185 void DeviceCloudPolicyManagerChromeOS::Shutdown() { | 187 void DeviceCloudPolicyManagerChromeOS::Shutdown() { |
| 188 status_uploader_.reset(); |
186 state_keys_update_subscription_.reset(); | 189 state_keys_update_subscription_.reset(); |
187 CloudPolicyManager::Shutdown(); | 190 CloudPolicyManager::Shutdown(); |
188 } | 191 } |
189 | 192 |
190 // static | 193 // static |
191 void DeviceCloudPolicyManagerChromeOS::RegisterPrefs( | 194 void DeviceCloudPolicyManagerChromeOS::RegisterPrefs( |
192 PrefRegistrySimple* registry) { | 195 PrefRegistrySimple* registry) { |
193 registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition, | 196 registry->RegisterStringPref(prefs::kDeviceEnrollmentRequisition, |
194 std::string()); | 197 std::string()); |
195 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false); | 198 registry->RegisterBooleanPref(prefs::kDeviceEnrollmentAutoStart, false); |
(...skipping 22 matching lines...) Expand all Loading... |
218 | 221 |
219 // static | 222 // static |
220 std::string DeviceCloudPolicyManagerChromeOS::GetMachineModel() { | 223 std::string DeviceCloudPolicyManagerChromeOS::GetMachineModel() { |
221 return GetMachineStatistic(chromeos::system::kHardwareClassKey); | 224 return GetMachineStatistic(chromeos::system::kHardwareClassKey); |
222 } | 225 } |
223 | 226 |
224 void DeviceCloudPolicyManagerChromeOS::StartConnection( | 227 void DeviceCloudPolicyManagerChromeOS::StartConnection( |
225 scoped_ptr<CloudPolicyClient> client_to_connect, | 228 scoped_ptr<CloudPolicyClient> client_to_connect, |
226 EnterpriseInstallAttributes* install_attributes) { | 229 EnterpriseInstallAttributes* install_attributes) { |
227 CHECK(!service()); | 230 CHECK(!service()); |
228 // Enable device reporting for enterprise enrolled devices. We want to do this | |
229 // even if management is currently inactive, in case management is turned | |
230 // back on in a future policy fetch. | |
231 if (install_attributes->IsEnterpriseDevice()) { | |
232 client_to_connect->SetStatusProvider( | |
233 scoped_ptr<CloudPolicyClient::StatusProvider>( | |
234 new DeviceStatusCollector( | |
235 local_state_, | |
236 chromeos::system::StatisticsProvider::GetInstance(), | |
237 DeviceStatusCollector::LocationUpdateRequester(), | |
238 DeviceStatusCollector::VolumeInfoFetcher()))); | |
239 } | |
240 | 231 |
241 // Set state keys here so the first policy fetch submits them to the server. | 232 // Set state keys here so the first policy fetch submits them to the server. |
242 if (ForcedReEnrollmentEnabled()) | 233 if (ForcedReEnrollmentEnabled()) |
243 client_to_connect->SetStateKeysToUpload(state_keys_broker_->state_keys()); | 234 client_to_connect->SetStateKeysToUpload(state_keys_broker_->state_keys()); |
244 | 235 |
245 core()->Connect(client_to_connect.Pass()); | 236 core()->Connect(client_to_connect.Pass()); |
246 core()->StartRefreshScheduler(); | 237 core()->StartRefreshScheduler(); |
247 core()->TrackRefreshDelayPref(local_state_, | 238 core()->TrackRefreshDelayPref(local_state_, |
248 prefs::kDevicePolicyRefreshRate); | 239 prefs::kDevicePolicyRefreshRate); |
249 attestation_policy_observer_.reset( | 240 attestation_policy_observer_.reset( |
250 new chromeos::attestation::AttestationPolicyObserver(client())); | 241 new chromeos::attestation::AttestationPolicyObserver(client())); |
251 | 242 |
| 243 // Enable device reporting for enterprise enrolled devices. We want to do this |
| 244 // even if management is currently inactive, in case management is turned |
| 245 // back on in a future policy fetch. |
| 246 if (install_attributes->IsEnterpriseDevice()) |
| 247 CreateStatusUploader(); |
| 248 |
252 NotifyConnected(); | 249 NotifyConnected(); |
253 } | 250 } |
254 | 251 |
255 void DeviceCloudPolicyManagerChromeOS::Unregister( | 252 void DeviceCloudPolicyManagerChromeOS::Unregister( |
256 const UnregisterCallback& callback) { | 253 const UnregisterCallback& callback) { |
257 if (!service()) { | 254 if (!service()) { |
258 LOG(ERROR) << "Tried to unregister but DeviceCloudPolicyManagerChromeOS is " | 255 LOG(ERROR) << "Tried to unregister but DeviceCloudPolicyManagerChromeOS is " |
259 << "not connected."; | 256 << "not connected."; |
260 callback.Run(false); | 257 callback.Run(false); |
261 return; | 258 return; |
262 } | 259 } |
263 | 260 |
264 service()->Unregister(callback); | 261 service()->Unregister(callback); |
265 } | 262 } |
266 | 263 |
267 void DeviceCloudPolicyManagerChromeOS::Disconnect() { | 264 void DeviceCloudPolicyManagerChromeOS::Disconnect() { |
| 265 status_uploader_.reset(); |
268 core()->Disconnect(); | 266 core()->Disconnect(); |
269 | 267 |
270 NotifyDisconnected(); | 268 NotifyDisconnected(); |
271 } | 269 } |
272 | 270 |
273 void DeviceCloudPolicyManagerChromeOS::OnStateKeysUpdated() { | 271 void DeviceCloudPolicyManagerChromeOS::OnStateKeysUpdated() { |
274 if (client() && ForcedReEnrollmentEnabled()) | 272 if (client() && ForcedReEnrollmentEnabled()) |
275 client()->SetStateKeysToUpload(state_keys_broker_->state_keys()); | 273 client()->SetStateKeysToUpload(state_keys_broker_->state_keys()); |
276 } | 274 } |
277 | 275 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 void DeviceCloudPolicyManagerChromeOS::NotifyConnected() { | 308 void DeviceCloudPolicyManagerChromeOS::NotifyConnected() { |
311 FOR_EACH_OBSERVER( | 309 FOR_EACH_OBSERVER( |
312 Observer, observers_, OnDeviceCloudPolicyManagerConnected()); | 310 Observer, observers_, OnDeviceCloudPolicyManagerConnected()); |
313 } | 311 } |
314 | 312 |
315 void DeviceCloudPolicyManagerChromeOS::NotifyDisconnected() { | 313 void DeviceCloudPolicyManagerChromeOS::NotifyDisconnected() { |
316 FOR_EACH_OBSERVER( | 314 FOR_EACH_OBSERVER( |
317 Observer, observers_, OnDeviceCloudPolicyManagerDisconnected()); | 315 Observer, observers_, OnDeviceCloudPolicyManagerDisconnected()); |
318 } | 316 } |
319 | 317 |
| 318 void DeviceCloudPolicyManagerChromeOS::CreateStatusUploader() { |
| 319 status_uploader_.reset( |
| 320 new StatusUploader( |
| 321 local_state_, |
| 322 client(), |
| 323 make_scoped_ptr(new DeviceStatusCollector( |
| 324 local_state_, |
| 325 chromeos::system::StatisticsProvider::GetInstance(), |
| 326 DeviceStatusCollector::LocationUpdateRequester(), |
| 327 DeviceStatusCollector::VolumeInfoFetcher())), |
| 328 task_runner_)); |
| 329 } |
| 330 |
320 } // namespace policy | 331 } // namespace policy |
OLD | NEW |