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 a647429c300e82360299b743189b41c2aaa8d905..799cf71c4f9a04d22d4c50fb7cb5be8ad4021274 100644 |
--- a/chrome/browser/chromeos/policy/consumer_management_service.h |
+++ b/chrome/browser/chromeos/policy/consumer_management_service.h |
@@ -12,7 +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/chromeos/settings/device_settings_service.h" |
#include "chrome/browser/notifications/notification_delegate.h" |
#include "chromeos/dbus/dbus_method_call_status.h" |
#include "content/public/browser/notification_observer.h" |
@@ -51,23 +53,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. |
+ // Indicating if the device is enrolled, or if enrollment or unenrollment is |
bartfab (slow)
2014/08/21 11:39:35
Nit: Make this an actual sentence. As it stands, i
davidyu
2014/08/22 05:14:13
Done.
|
+ // in progress. If you want to add a value here, please also update |
+ // |kStatusString| in .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(Status status) = 0; |
}; |
// GetOwner() invokes this with an argument set to the owner user ID, |
@@ -77,18 +113,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); |
virtual ~ConsumerManagementService(); |
// Registers prefs. |
static void RegisterPrefs(PrefRegistrySimple* registry); |
- // Returns the enrollment state. |
- ConsumerEnrollmentState GetEnrollmentState() const; |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
- // Sets the enrollment state. |
- void SetEnrollmentState(ConsumerEnrollmentState state); |
+ // Returns the status. |
+ Status GetStatus() const; |
+ |
+ // Returns the string of the value. |
+ static std::string GetStatusString(Status status); |
+ |
+ // 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); |
@@ -97,15 +144,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, |
@@ -180,11 +231,11 @@ 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); |
bartfab (slow)
2014/08/21 11:39:35
Nit: One argument per line in declarations and def
davidyu
2014/08/22 05:14:13
Done.
|
// Opens the settings page. |
void OpenSettingsPage(Profile* profile) const; |
@@ -195,11 +246,15 @@ class ConsumerManagementService : public content::NotificationObserver, |
// Returns the sign-in authenticated account ID of the profile. |
bartfab (slow)
2014/08/21 11:39:35
Nit 1: "sign-in authenticated account ID" is reall
davidyu
2014/08/22 05:14:13
Done.
|
const std::string& GetAccountIdFromProfile(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); |