Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/policy/consumer_unenrollment_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
|
bartfab (slow)
2014/11/28 13:25:17
Nit: Not used.
davidyu
2014/12/01 17:05:22
Done.
| |
| 10 #include "chrome/browser/browser_process_platform_part.h" | |
|
bartfab (slow)
2014/11/28 13:25:17
Nit: Not used.
davidyu
2014/12/01 17:05:22
Done.
| |
| 11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
|
bartfab (slow)
2014/11/28 13:25:17
Nit: Not used.
davidyu
2014/12/01 17:05:21
Done.
| |
| 12 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 13 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | |
| 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | |
| 15 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 16 #include "policy/proto/device_management_backend.pb.h" | |
| 17 | |
| 18 namespace em = enterprise_management; | |
| 19 | |
| 20 namespace policy { | |
| 21 | |
| 22 ConsumerUnenrollmentHandler::ConsumerUnenrollmentHandler( | |
| 23 chromeos::DeviceSettingsService* device_settings_service, | |
| 24 ConsumerManagementService* consumer_management_service, | |
| 25 DeviceCloudPolicyManagerChromeOS* device_cloud_policy_manager) | |
| 26 : device_settings_service_(device_settings_service), | |
| 27 consumer_management_service_(consumer_management_service), | |
| 28 device_cloud_policy_manager_(device_cloud_policy_manager), | |
| 29 weak_factory_(this) { | |
| 30 } | |
| 31 | |
| 32 ConsumerUnenrollmentHandler::~ConsumerUnenrollmentHandler() { | |
| 33 } | |
| 34 | |
| 35 void ConsumerUnenrollmentHandler::Shutdown() { | |
| 36 } | |
| 37 | |
| 38 void ConsumerUnenrollmentHandler::Start() { | |
| 39 device_cloud_policy_manager_->Unregister( | |
|
bartfab (slow)
2014/11/28 13:25:18
What if the user clicks the "unenroll" button agai
davidyu
2014/12/01 17:05:21
When the user clicks the unenroll button, it immed
| |
| 40 base::Bind(&ConsumerUnenrollmentHandler::OnUnregistered, | |
| 41 weak_factory_.GetWeakPtr())); | |
| 42 } | |
| 43 | |
| 44 void ConsumerUnenrollmentHandler::OnUnregistered(bool success) { | |
| 45 if (!success) { | |
| 46 consumer_management_service_->SetStage(ConsumerManagementStage( | |
| 47 ConsumerManagementStage::UNENROLLMENT_DM_SERVER_FAILED)); | |
| 48 LOG(ERROR) << "Failed to unregister and disconnect device cloud policy " | |
| 49 << "manager."; | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 device_settings_service_->SetManagementSettings( | |
| 54 em::PolicyData::LOCAL_OWNER, | |
| 55 "", // request token | |
| 56 "", // device ID | |
| 57 base::Bind(&ConsumerUnenrollmentHandler::OnManagementSettingsSet, | |
| 58 weak_factory_.GetWeakPtr())); | |
| 59 } | |
| 60 | |
| 61 void ConsumerUnenrollmentHandler::OnManagementSettingsSet() { | |
| 62 if (device_settings_service_->status() != | |
| 63 chromeos::DeviceSettingsService::STORE_SUCCESS) { | |
| 64 consumer_management_service_->SetStage(ConsumerManagementStage( | |
| 65 ConsumerManagementStage::UNENROLLMENT_UPDATE_DEVICE_SETTINGS_FAILED)); | |
| 66 LOG(ERROR) << "Failed to unset request token and device ID."; | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 consumer_management_service_->SetStage(ConsumerManagementStage( | |
| 71 ConsumerManagementStage::UNENROLLMENT_SUCCESS)); | |
| 72 | |
| 73 // Disconnecting the device cloud policy manager will restart the device | |
| 74 // cloud policy initializer. So this must be done after the management | |
| 75 // settings are updated, so that the initializer won't reconnect the manager. | |
| 76 device_cloud_policy_manager_->Disconnect(); | |
| 77 } | |
| 78 | |
| 79 } // namespace policy | |
| OLD | NEW |