Index: chrome/browser/chromeos/policy/consumer_management_service.h |
diff --git a/chrome/browser/chromeos/policy/consumer_management_service.h b/chrome/browser/chromeos/policy/consumer_management_service.h |
index 92e3418203d77dd432cde449ea220ff5bd9175da..f7bfad17745e31f23be442c9072d21d747c88bec 100644 |
--- a/chrome/browser/chromeos/policy/consumer_management_service.h |
+++ b/chrome/browser/chromeos/policy/consumer_management_service.h |
@@ -12,8 +12,9 @@ |
#include "base/macros.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
+#include "base/observer_list.h" |
#include "base/strings/string16.h" |
-#include "chrome/browser/notifications/notification_delegate.h" |
+#include "chrome/browser/chromeos/settings/device_settings_service.h" |
#include "chromeos/dbus/dbus_method_call_status.h" |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_registrar.h" |
@@ -50,23 +51,57 @@ class EnrollmentStatus; |
// 3. Consumer management enrollment process: The service kicks off the last |
// part of the consumer management enrollment process after the owner ID is |
// stored in the boot lockbox and the owner signs in. |
-class ConsumerManagementService : public content::NotificationObserver, |
- public OAuth2TokenService::Consumer, |
- public OAuth2TokenService::Observer { |
+class ConsumerManagementService |
+ : public chromeos::DeviceSettingsService::Observer, |
+ public content::NotificationObserver, |
+ public OAuth2TokenService::Consumer, |
+ public OAuth2TokenService::Observer { |
public: |
- enum ConsumerEnrollmentState { |
- ENROLLMENT_NONE = 0, // Not enrolled, or enrollment is completed. |
- ENROLLMENT_REQUESTED, // Enrollment is requested by the owner. |
- ENROLLMENT_OWNER_STORED, // The owner ID is stored in the boot lockbox. |
- ENROLLMENT_SUCCESS, // Success. The notification is not sent yet. |
- |
- // Error states. |
- ENROLLMENT_CANCELED, // Canceled by the user. |
- ENROLLMENT_BOOT_LOCKBOX_FAILED, // Failed to write to the boot lockbox. |
- ENROLLMENT_GET_TOKEN_FAILED, // Failed to get the access token. |
- ENROLLMENT_DM_SERVER_FAILED, // Failed to register the device. |
- |
- ENROLLMENT_LAST, // This should always be the last one. |
+ // The status indicates if the device is enrolled, or if enrollment or |
+ // unenrollment is in progress. If you want to add a value here, please also |
+ // update |kStatusString| in the .cc file. |
+ enum Status { |
+ // The status is currently unavailable. |
+ STATUS_UNKNOWN = 0, |
+ |
+ STATUS_ENROLLED, |
+ STATUS_ENROLLING, |
+ STATUS_UNENROLLED, |
+ STATUS_UNENROLLING, |
+ |
+ // This should always be the last one. |
+ STATUS_LAST, |
+ }; |
+ |
+ // Indicating which stage the enrollment process is in. |
+ enum EnrollmentStage { |
+ // Not enrolled, or enrollment is completed. |
+ ENROLLMENT_STAGE_NONE = 0, |
+ // Enrollment is requested by the owner. |
+ ENROLLMENT_STAGE_REQUESTED, |
+ // The owner ID is stored in the boot lockbox. |
+ ENROLLMENT_STAGE_OWNER_STORED, |
+ // Success. The notification is not sent yet. |
+ ENROLLMENT_STAGE_SUCCESS, |
+ |
+ // Error stages. |
+ // Canceled by the user. |
+ ENROLLMENT_STAGE_CANCELED, |
+ // Failed to write to the boot lockbox. |
+ ENROLLMENT_STAGE_BOOT_LOCKBOX_FAILED, |
+ // Failed to get the access token. |
+ ENROLLMENT_STAGE_GET_TOKEN_FAILED, |
+ // Failed to register the device. |
+ ENROLLMENT_STAGE_DM_SERVER_FAILED, |
+ |
+ // This should always be the last one. |
+ ENROLLMENT_STAGE_LAST, |
+ }; |
+ |
+ class Observer { |
+ public: |
+ // Called when the status changes. |
+ virtual void OnConsumerManagementStatusChanged() = 0; |
}; |
// GetOwner() invokes this with an argument set to the owner user ID, |
@@ -76,18 +111,29 @@ class ConsumerManagementService : public content::NotificationObserver, |
// SetOwner() invokes this with an argument indicating success or failure. |
typedef base::Callback<void(bool)> SetOwnerCallback; |
- explicit ConsumerManagementService(chromeos::CryptohomeClient* client); |
+ ConsumerManagementService( |
+ chromeos::CryptohomeClient* client, |
+ chromeos::DeviceSettingsService* device_settings_service); |
stevenjb
2014/09/02 17:06:39
nit: We should at least comment that device_settin
davidyu
2014/09/03 06:29:18
Done.
|
virtual ~ConsumerManagementService(); |
// Registers prefs. |
static void RegisterPrefs(PrefRegistrySimple* registry); |
- // Returns the enrollment state. |
- ConsumerEnrollmentState GetEnrollmentState() const; |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
+ // Returns the status. |
+ Status GetStatus() const; |
- // Sets the enrollment state. |
- void SetEnrollmentState(ConsumerEnrollmentState state); |
+ // Returns the string value of the status. |
+ std::string GetStatusString() const; |
+ |
+ // Returns the enrollment stage. |
+ EnrollmentStage GetEnrollmentStage() const; |
+ |
+ // Sets the enrollment stage. |
+ void SetEnrollmentStage(EnrollmentStage stage); |
// Returns the device owner stored in the boot lockbox via |callback|. |
void GetOwner(const GetOwnerCallback& callback); |
@@ -96,15 +142,19 @@ class ConsumerManagementService : public content::NotificationObserver, |
// |callback| is invoked with an agument indicating success or failure. |
void SetOwner(const std::string& user_id, const SetOwnerCallback& callback); |
+ // chromeos::DeviceSettingsService::Observer: |
+ virtual void OwnershipStatusChanged() OVERRIDE; |
+ virtual void DeviceSettingsUpdated() OVERRIDE; |
+ |
// content::NotificationObserver implmentation. |
virtual void Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) OVERRIDE; |
- // OAuth2TokenService::Observer implementation. |
+ // OAuth2TokenService::Observer: |
virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
- // OAuth2TokenService::Consumer implementation. |
+ // OAuth2TokenService::Consumer: |
virtual void OnGetTokenSuccess( |
const OAuth2TokenService::Request* request, |
const std::string& access_token, |
@@ -153,11 +203,12 @@ class ConsumerManagementService : public content::NotificationObserver, |
// Ends the enrollment process and shows a desktop notification if the |
// current user is the owner. |
- void EndEnrollment(ConsumerEnrollmentState state); |
+ void EndEnrollment(EnrollmentStage stage); |
- // Shows a desktop notification and resets the enrollment state. |
- void ShowDesktopNotificationAndResetState(ConsumerEnrollmentState state, |
- Profile* profile); |
+ // Shows a desktop notification and resets the enrollment stage. |
+ void ShowDesktopNotificationAndResetStage( |
+ EnrollmentStage stage, |
+ Profile* profile); |
// Opens the settings page. |
void OpenSettingsPage(Profile* profile) const; |
@@ -165,11 +216,15 @@ class ConsumerManagementService : public content::NotificationObserver, |
// Opens the enrollment confirmation dialog in the settings page. |
void TryEnrollmentAgain(Profile* profile) const; |
+ void NotifyStatusChanged(); |
+ |
chromeos::CryptohomeClient* client_; |
+ chromeos::DeviceSettingsService* device_settings_service_; |
Profile* enrolling_profile_; |
scoped_ptr<OAuth2TokenService::Request> token_request_; |
content::NotificationRegistrar registrar_; |
+ ObserverList<Observer, true> observers_; |
base::WeakPtrFactory<ConsumerManagementService> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService); |