Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Unified Diff: chrome/browser/chromeos/policy/consumer_management_service.h

Issue 493613002: Add an enrolling state for consumer management section in settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dn
Patch Set: Fixed broken browser tests. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c460658df6d1be2d6a2897e7cb2f6e5c83bef0ba 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,58 @@ 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, and |ConsumerManagementStatus| in
+ // chrome/browser/resources/options/chromeos/consumer_management_overlay.js
+ 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 +112,30 @@ 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);
+ // |client| and |device_settings_service| should outlive this object.
+ 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);
+
+ // 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 +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,
@@ -153,11 +205,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 +218,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);

Powered by Google App Engine
This is Rietveld 408576698