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/enrollment_handler_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" | 12 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" |
13 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | |
13 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
15 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" | 16 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" |
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
16 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | 19 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " |
18 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 20 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
21 #include "chrome/browser/profiles/profile.h" | |
19 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
20 #include "google_apis/gaia/gaia_urls.h" | 23 #include "google_apis/gaia/gaia_urls.h" |
21 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
22 | 25 |
23 namespace em = enterprise_management; | 26 namespace em = enterprise_management; |
24 | 27 |
25 namespace policy { | 28 namespace policy { |
26 | 29 |
27 namespace { | 30 namespace { |
28 | 31 |
29 // Retry for InstallAttrs initialization every 500ms. | 32 // Retry for InstallAttrs initialization every 500ms. |
30 const int kLockRetryIntervalMs = 500; | 33 const int kLockRetryIntervalMs = 500; |
31 // Maximum time to retry InstallAttrs initialization before we give up. | 34 // Maximum time to retry InstallAttrs initialization before we give up. |
32 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes. | 35 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes. |
33 | 36 |
34 // Testing token used when the enrollment-skip-robot-auth is set to skip talking | 37 // Testing token used when the enrollment-skip-robot-auth is set to skip talking |
35 // to GAIA for an actual token. This is needed to be able to run against the | 38 // to GAIA for an actual token. This is needed to be able to run against the |
36 // testing DMServer implementations. | 39 // testing DMServer implementations. |
37 const char kTestingRobotToken[] = "test-token"; | 40 const char kTestingRobotToken[] = "test-token"; |
38 | 41 |
39 } // namespace | 42 } // namespace |
40 | 43 |
41 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS( | 44 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS( |
42 DeviceCloudPolicyStoreChromeOS* store, | 45 DeviceCloudPolicyStoreChromeOS* store, |
43 EnterpriseInstallAttributes* install_attributes, | 46 EnterpriseInstallAttributes* install_attributes, |
44 ServerBackedStateKeysBroker* state_keys_broker, | 47 ServerBackedStateKeysBroker* state_keys_broker, |
45 chromeos::DeviceSettingsService* device_settings_service, | 48 chromeos::DeviceSettingsService* device_settings_service, |
49 chromeos::OwnerSettingsServiceChromeOS* owner_settings_service, | |
46 scoped_ptr<CloudPolicyClient> client, | 50 scoped_ptr<CloudPolicyClient> client, |
47 scoped_refptr<base::SequencedTaskRunner> background_task_runner, | 51 scoped_refptr<base::SequencedTaskRunner> background_task_runner, |
48 const std::string& auth_token, | 52 const std::string& auth_token, |
49 const std::string& client_id, | 53 const std::string& client_id, |
50 bool is_auto_enrollment, | 54 bool is_auto_enrollment, |
51 const std::string& requisition, | 55 const std::string& requisition, |
52 const AllowedDeviceModes& allowed_device_modes, | 56 const AllowedDeviceModes& allowed_device_modes, |
53 ManagementMode management_mode, | 57 ManagementMode management_mode, |
54 const EnrollmentCallback& completion_callback) | 58 const EnrollmentCallback& completion_callback) |
55 : store_(store), | 59 : store_(store), |
56 install_attributes_(install_attributes), | 60 install_attributes_(install_attributes), |
57 state_keys_broker_(state_keys_broker), | 61 state_keys_broker_(state_keys_broker), |
58 device_settings_service_(device_settings_service), | 62 device_settings_service_(device_settings_service), |
63 owner_settings_service_(owner_settings_service), | |
59 client_(client.Pass()), | 64 client_(client.Pass()), |
60 background_task_runner_(background_task_runner), | 65 background_task_runner_(background_task_runner), |
61 auth_token_(auth_token), | 66 auth_token_(auth_token), |
62 client_id_(client_id), | 67 client_id_(client_id), |
63 is_auto_enrollment_(is_auto_enrollment), | 68 is_auto_enrollment_(is_auto_enrollment), |
64 requisition_(requisition), | 69 requisition_(requisition), |
65 allowed_device_modes_(allowed_device_modes), | 70 allowed_device_modes_(allowed_device_modes), |
66 management_mode_(management_mode), | 71 management_mode_(management_mode), |
67 completion_callback_(completion_callback), | 72 completion_callback_(completion_callback), |
68 device_mode_(DEVICE_MODE_NOT_SET), | 73 device_mode_(DEVICE_MODE_NOT_SET), |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 // again after the store finishes loading. | 204 // again after the store finishes loading. |
200 StartRegistration(); | 205 StartRegistration(); |
201 } else if (enrollment_step_ == STEP_STORE_POLICY) { | 206 } else if (enrollment_step_ == STEP_STORE_POLICY) { |
202 ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)); | 207 ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)); |
203 } | 208 } |
204 } | 209 } |
205 | 210 |
206 void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) { | 211 void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) { |
207 DCHECK_EQ(store_, store); | 212 DCHECK_EQ(store_, store); |
208 if (enrollment_step_ == STEP_STORE_TOKEN_AND_ID) { | 213 if (enrollment_step_ == STEP_STORE_TOKEN_AND_ID) { |
209 // Calling DeviceSettingsService::SetManagementSettings() on a non- | 214 // Calling OwnerSettingsServiceChromeOS::SetManagementSettings() |
210 // enterprise-managed device will trigger OnStoreError(), as | 215 // on a non- enterprise-managed device will fail as |
211 // DeviceCloudPolicyStore listens to all changes on DeviceSettingsService, | 216 // DeviceCloudPolicyStore listens to all changes on device |
212 // and it calls OnStoreError() when the device is not enterprise-managed. | 217 // settings, and it calls OnStoreError() when the device is not |
218 // enterprise-managed. | |
213 return; | 219 return; |
214 } | 220 } |
215 ReportResult(EnrollmentStatus::ForStoreError(store_->status(), | 221 ReportResult(EnrollmentStatus::ForStoreError(store_->status(), |
216 store_->validation_status())); | 222 store_->validation_status())); |
217 } | 223 } |
218 | 224 |
219 void EnrollmentHandlerChromeOS::HandleStateKeysResult( | 225 void EnrollmentHandlerChromeOS::HandleStateKeysResult( |
220 const std::vector<std::string>& state_keys) { | 226 const std::vector<std::string>& state_keys) { |
221 CHECK_EQ(STEP_STATE_KEYS, enrollment_step_); | 227 CHECK_EQ(STEP_STATE_KEYS, enrollment_step_); |
222 | 228 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 } | 344 } |
339 | 345 |
340 void EnrollmentHandlerChromeOS::StartLockDevice() { | 346 void EnrollmentHandlerChromeOS::StartLockDevice() { |
341 CHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_); | 347 CHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_); |
342 // Since this method is also called directly. | 348 // Since this method is also called directly. |
343 weak_ptr_factory_.InvalidateWeakPtrs(); | 349 weak_ptr_factory_.InvalidateWeakPtrs(); |
344 | 350 |
345 if (management_mode_ == MANAGEMENT_MODE_CONSUMER_MANAGED) { | 351 if (management_mode_ == MANAGEMENT_MODE_CONSUMER_MANAGED) { |
346 // Consumer device enrollment doesn't use install attributes. Instead, | 352 // Consumer device enrollment doesn't use install attributes. Instead, |
347 // we put the information in the owners settings. | 353 // we put the information in the owners settings. |
348 enrollment_step_ = STEP_STORE_TOKEN_AND_ID; | 354 enrollment_step_ = STEP_STORE_TOKEN_AND_ID; |
davidyu
2014/12/03 16:06:04
CHECK(owner_settings_service_);
ygorshenin1
2014/12/04 10:27:23
Done.
| |
349 device_settings_service_->SetManagementSettings( | 355 chromeos::OwnerSettingsServiceChromeOS::ManagementSettings settings; |
350 em::PolicyData::CONSUMER_MANAGED, request_token_, device_id_, | 356 settings.management_mode = management_mode_; |
357 settings.request_token = request_token_; | |
358 settings.device_id = device_id_; | |
359 owner_settings_service_->SetManagementSettings( | |
360 settings, | |
351 base::Bind(&EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone, | 361 base::Bind(&EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone, |
352 weak_ptr_factory_.GetWeakPtr())); | 362 weak_ptr_factory_.GetWeakPtr())); |
353 } else { | 363 } else { |
354 install_attributes_->LockDevice( | 364 install_attributes_->LockDevice( |
355 username_, device_mode_, device_id_, | 365 username_, device_mode_, device_id_, |
356 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult, | 366 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult, |
357 weak_ptr_factory_.GetWeakPtr())); | 367 weak_ptr_factory_.GetWeakPtr())); |
358 } | 368 } |
359 } | 369 } |
360 | 370 |
361 void EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone() { | 371 void EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone(bool success) { |
362 CHECK_EQ(STEP_STORE_TOKEN_AND_ID, enrollment_step_); | 372 CHECK_EQ(STEP_STORE_TOKEN_AND_ID, enrollment_step_); |
363 if (device_settings_service_->status() != | 373 if (!success) { |
364 chromeos::DeviceSettingsService::STORE_SUCCESS) { | |
365 ReportResult(EnrollmentStatus::ForStatus( | 374 ReportResult(EnrollmentStatus::ForStatus( |
366 EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED)); | 375 EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED)); |
367 return; | 376 return; |
368 } | 377 } |
369 | 378 |
370 StartStoreRobotAuth(); | 379 StartStoreRobotAuth(); |
371 } | 380 } |
372 | 381 |
373 void EnrollmentHandlerChromeOS::HandleLockDeviceResult( | 382 void EnrollmentHandlerChromeOS::HandleLockDeviceResult( |
374 EnterpriseInstallAttributes::LockResult lock_result) { | 383 EnterpriseInstallAttributes::LockResult lock_result) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 << ", validation: " << status.validation_status() | 462 << ", validation: " << status.validation_status() |
454 << ", store: " << status.store_status() | 463 << ", store: " << status.store_status() |
455 << ", lock: " << status.lock_status(); | 464 << ", lock: " << status.lock_status(); |
456 } | 465 } |
457 | 466 |
458 if (!callback.is_null()) | 467 if (!callback.is_null()) |
459 callback.Run(status); | 468 callback.Run(status); |
460 } | 469 } |
461 | 470 |
462 } // namespace policy | 471 } // namespace policy |
OLD | NEW |