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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_
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"
19 class PrefRegistrySimple
;
22 class CryptohomeClient
;
25 namespace cryptohome
{
31 // The consumer management service handles several things:
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.
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.
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
50 class ConsumerManagementService
51 : public chromeos::DeviceSettingsService::Observer
{
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
58 // The status is currently unavailable.
66 // This should always be the last one.
72 // Called when the status changes.
73 virtual void OnConsumerManagementStatusChanged() = 0;
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
;
80 // SetOwner() invokes this with an argument indicating success or failure.
81 typedef base::Callback
<void(bool)> SetOwnerCallback
;
83 // |client| and |device_settings_service| should outlive this object.
84 ConsumerManagementService(
85 chromeos::CryptohomeClient
* client
,
86 chromeos::DeviceSettingsService
* device_settings_service
);
88 ~ConsumerManagementService() override
;
91 static void RegisterPrefs(PrefRegistrySimple
* registry
);
93 void AddObserver(Observer
* observer
);
94 void RemoveObserver(Observer
* observer
);
96 // Returns the status.
97 virtual Status
GetStatus() const;
99 // Returns the string value of the status.
100 std::string
GetStatusString() const;
102 // Returns the stage.
103 virtual ConsumerManagementStage
GetStage() const;
106 virtual void SetStage(const ConsumerManagementStage
& stage
);
108 // Returns the device owner stored in the boot lockbox via |callback|.
109 void GetOwner(const GetOwnerCallback
& callback
);
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
);
115 // chromeos::DeviceSettingsService::Observer:
116 void OwnershipStatusChanged() override
;
117 void DeviceSettingsUpdated() override
;
118 void OnDeviceSettingsServiceShutdown() override
;
121 void NotifyStatusChanged();
124 void OnGetBootAttributeDone(
125 const GetOwnerCallback
& callback
,
126 chromeos::DBusMethodCallStatus call_status
,
128 const cryptohome::BaseReply
& reply
);
130 void OnSetBootAttributeDone(const SetOwnerCallback
& callback
,
131 chromeos::DBusMethodCallStatus call_status
,
133 const cryptohome::BaseReply
& reply
);
135 void OnFlushAndSignBootAttributesDone(
136 const SetOwnerCallback
& callback
,
137 chromeos::DBusMethodCallStatus call_status
,
139 const cryptohome::BaseReply
& reply
);
141 chromeos::CryptohomeClient
* client_
;
142 chromeos::DeviceSettingsService
* device_settings_service_
;
144 ObserverList
<Observer
, true> observers_
;
145 base::WeakPtrFactory
<ConsumerManagementService
> weak_ptr_factory_
;
147 DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService
);
150 } // namespace policy
152 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_