| 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback_forward.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/observer_list.h" | |
| 15 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | |
| 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 17 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 18 | |
| 19 class PrefRegistrySimple; | |
| 20 | |
| 21 namespace chromeos { | |
| 22 class CryptohomeClient; | |
| 23 } | |
| 24 | |
| 25 namespace cryptohome { | |
| 26 class BaseReply; | |
| 27 } | |
| 28 | |
| 29 namespace policy { | |
| 30 | |
| 31 // The consumer management service handles several things: | |
| 32 // | |
| 33 // 1. The consumer management status: The consumer management status is an enum | |
| 34 // indicating if the device is consumer-managed and if enrollment or un- | |
| 35 // enrollment is in progress. The service can be observed and the observers | |
| 36 // will be notified when the status is changed. Note that the observers may | |
| 37 // be notified even when the status is NOT changed. The observers need to | |
| 38 // check the status upon receiving the notification. | |
| 39 // | |
| 40 // 2. The consumer management stage: The consumer management stage is a value | |
| 41 // indicating the enrollment or the unenrollment process, stored in local | |
| 42 // state to pass the information across reboots and between components, | |
| 43 // including settings page, sign-in screen, and user notification. | |
| 44 // | |
| 45 // 3. Boot lockbox owner ID: Unlike the owner ID in CrosSettings, the owner ID | |
| 46 // stored in the boot lockbox can only be modified after reboot and before | |
| 47 // the first session starts. It is guaranteed that if the device is consumer | |
| 48 // managed, the owner ID in the boot lockbox will be available, but not the | |
| 49 // other way. | |
| 50 class ConsumerManagementService | |
| 51 : public chromeos::DeviceSettingsService::Observer { | |
| 52 public: | |
| 53 // The status indicates if the device is enrolled, or if enrollment or | |
| 54 // unenrollment is in progress. If you want to add a value here, please also | |
| 55 // update |kStatusString| in the .cc file, and |ConsumerManagementStatus| in | |
| 56 // chrome/browser/resources/options/chromeos/consumer_management_overlay.js | |
| 57 enum Status { | |
| 58 // The status is currently unavailable. | |
| 59 STATUS_UNKNOWN = 0, | |
| 60 | |
| 61 STATUS_ENROLLED, | |
| 62 STATUS_ENROLLING, | |
| 63 STATUS_UNENROLLED, | |
| 64 STATUS_UNENROLLING, | |
| 65 | |
| 66 // This should always be the last one. | |
| 67 STATUS_LAST, | |
| 68 }; | |
| 69 | |
| 70 class Observer { | |
| 71 public: | |
| 72 // Called when the status changes. | |
| 73 virtual void OnConsumerManagementStatusChanged() = 0; | |
| 74 }; | |
| 75 | |
| 76 // GetOwner() invokes this with an argument set to the owner user ID, | |
| 77 // or an empty string on failure. | |
| 78 typedef base::Callback<void(const std::string&)> GetOwnerCallback; | |
| 79 | |
| 80 // SetOwner() invokes this with an argument indicating success or failure. | |
| 81 typedef base::Callback<void(bool)> SetOwnerCallback; | |
| 82 | |
| 83 // |client| and |device_settings_service| should outlive this object. | |
| 84 ConsumerManagementService( | |
| 85 chromeos::CryptohomeClient* client, | |
| 86 chromeos::DeviceSettingsService* device_settings_service); | |
| 87 | |
| 88 ~ConsumerManagementService() override; | |
| 89 | |
| 90 // Registers prefs. | |
| 91 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 92 | |
| 93 void AddObserver(Observer* observer); | |
| 94 void RemoveObserver(Observer* observer); | |
| 95 | |
| 96 // Returns the status. | |
| 97 virtual Status GetStatus() const; | |
| 98 | |
| 99 // Returns the string value of the status. | |
| 100 std::string GetStatusString() const; | |
| 101 | |
| 102 // Returns the stage. | |
| 103 virtual ConsumerManagementStage GetStage() const; | |
| 104 | |
| 105 // Sets the stage. | |
| 106 virtual void SetStage(const ConsumerManagementStage& stage); | |
| 107 | |
| 108 // Returns the device owner stored in the boot lockbox via |callback|. | |
| 109 void GetOwner(const GetOwnerCallback& callback); | |
| 110 | |
| 111 // Stores the device owner user ID into the boot lockbox and signs it. | |
| 112 // |callback| is invoked with an agument indicating success or failure. | |
| 113 void SetOwner(const std::string& user_id, const SetOwnerCallback& callback); | |
| 114 | |
| 115 // chromeos::DeviceSettingsService::Observer: | |
| 116 void OwnershipStatusChanged() override; | |
| 117 void DeviceSettingsUpdated() override; | |
| 118 void OnDeviceSettingsServiceShutdown() override; | |
| 119 | |
| 120 protected: | |
| 121 void NotifyStatusChanged(); | |
| 122 | |
| 123 private: | |
| 124 void OnGetBootAttributeDone( | |
| 125 const GetOwnerCallback& callback, | |
| 126 chromeos::DBusMethodCallStatus call_status, | |
| 127 bool dbus_success, | |
| 128 const cryptohome::BaseReply& reply); | |
| 129 | |
| 130 void OnSetBootAttributeDone(const SetOwnerCallback& callback, | |
| 131 chromeos::DBusMethodCallStatus call_status, | |
| 132 bool dbus_success, | |
| 133 const cryptohome::BaseReply& reply); | |
| 134 | |
| 135 void OnFlushAndSignBootAttributesDone( | |
| 136 const SetOwnerCallback& callback, | |
| 137 chromeos::DBusMethodCallStatus call_status, | |
| 138 bool dbus_success, | |
| 139 const cryptohome::BaseReply& reply); | |
| 140 | |
| 141 chromeos::CryptohomeClient* client_; | |
| 142 chromeos::DeviceSettingsService* device_settings_service_; | |
| 143 | |
| 144 base::ObserverList<Observer, true> observers_; | |
| 145 base::WeakPtrFactory<ConsumerManagementService> weak_ptr_factory_; | |
| 146 | |
| 147 DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService); | |
| 148 }; | |
| 149 | |
| 150 } // namespace policy | |
| 151 | |
| 152 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | |
| OLD | NEW |