Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "chrome/browser/notifications/notification_delegate.h" | 17 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 17 #include "chromeos/dbus/dbus_method_call_status.h" | 18 #include "chromeos/dbus/dbus_method_call_status.h" |
| 18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 20 #include "google_apis/gaia/oauth2_token_service.h" | 21 #include "google_apis/gaia/oauth2_token_service.h" |
| 21 | 22 |
| 22 class PrefRegistrySimple; | 23 class PrefRegistrySimple; |
| 23 class Profile; | 24 class Profile; |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 class CryptohomeClient; | 27 class CryptohomeClient; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 43 // | 44 // |
| 44 // 2. Boot lockbox owner ID: Unlike the owner ID in CrosSettings, the owner ID | 45 // 2. Boot lockbox owner ID: Unlike the owner ID in CrosSettings, the owner ID |
| 45 // stored in the boot lockbox can only be modified after reboot and before | 46 // stored in the boot lockbox can only be modified after reboot and before |
| 46 // the first session starts. It is guaranteed that if the device is consumer | 47 // the first session starts. It is guaranteed that if the device is consumer |
| 47 // managed, the owner ID in the boot lockbox will be available, but not the | 48 // managed, the owner ID in the boot lockbox will be available, but not the |
| 48 // other way. | 49 // other way. |
| 49 // | 50 // |
| 50 // 3. Consumer management enrollment process: The service kicks off the last | 51 // 3. Consumer management enrollment process: The service kicks off the last |
| 51 // part of the consumer management enrollment process after the owner ID is | 52 // part of the consumer management enrollment process after the owner ID is |
| 52 // stored in the boot lockbox and the owner signs in. | 53 // stored in the boot lockbox and the owner signs in. |
| 53 class ConsumerManagementService : public content::NotificationObserver, | 54 class ConsumerManagementService |
| 54 public OAuth2TokenService::Consumer, | 55 : public chromeos::DeviceSettingsService::Observer, |
| 55 public OAuth2TokenService::Observer { | 56 public content::NotificationObserver, |
| 57 public OAuth2TokenService::Consumer, | |
| 58 public OAuth2TokenService::Observer { | |
| 56 public: | 59 public: |
| 57 enum ConsumerEnrollmentState { | 60 // The status indicates if the device is enrolled, or if enrollment or |
| 58 ENROLLMENT_NONE = 0, // Not enrolled, or enrollment is completed. | 61 // unenrollment is in progress. If you want to add a value here, please also |
| 59 ENROLLMENT_REQUESTED, // Enrollment is requested by the owner. | 62 // update |kStatusString| in the .cc file. |
| 60 ENROLLMENT_OWNER_STORED, // The owner ID is stored in the boot lockbox. | 63 enum Status { |
| 61 ENROLLMENT_SUCCESS, // Success. The notification is not sent yet. | 64 // The status is currently unavailable. |
| 65 STATUS_UNKNOWN = 0, | |
| 62 | 66 |
| 63 // Error states. | 67 STATUS_ENROLLED, |
| 64 ENROLLMENT_CANCELED, // Canceled by the user. | 68 STATUS_ENROLLING, |
| 65 ENROLLMENT_BOOT_LOCKBOX_FAILED, // Failed to write to the boot lockbox. | 69 STATUS_UNENROLLED, |
| 66 ENROLLMENT_GET_TOKEN_FAILED, // Failed to get the access token. | 70 STATUS_UNENROLLING, |
| 67 ENROLLMENT_DM_SERVER_FAILED, // Failed to register the device. | |
| 68 | 71 |
| 69 ENROLLMENT_LAST, // This should always be the last one. | 72 // This should always be the last one. |
| 73 STATUS_LAST, | |
| 74 }; | |
| 75 | |
| 76 // Indicating which stage the enrollment process is in. | |
| 77 enum EnrollmentStage { | |
| 78 // Not enrolled, or enrollment is completed. | |
| 79 ENROLLMENT_STAGE_NONE = 0, | |
| 80 // Enrollment is requested by the owner. | |
| 81 ENROLLMENT_STAGE_REQUESTED, | |
| 82 // The owner ID is stored in the boot lockbox. | |
| 83 ENROLLMENT_STAGE_OWNER_STORED, | |
| 84 // Success. The notification is not sent yet. | |
| 85 ENROLLMENT_STAGE_SUCCESS, | |
| 86 | |
| 87 // Error stages. | |
| 88 // Canceled by the user. | |
| 89 ENROLLMENT_STAGE_CANCELED, | |
| 90 // Failed to write to the boot lockbox. | |
| 91 ENROLLMENT_STAGE_BOOT_LOCKBOX_FAILED, | |
| 92 // Failed to get the access token. | |
| 93 ENROLLMENT_STAGE_GET_TOKEN_FAILED, | |
| 94 // Failed to register the device. | |
| 95 ENROLLMENT_STAGE_DM_SERVER_FAILED, | |
| 96 | |
| 97 // This should always be the last one. | |
| 98 ENROLLMENT_STAGE_LAST, | |
| 99 }; | |
| 100 | |
| 101 class Observer { | |
| 102 public: | |
| 103 // Called when the status changes. | |
| 104 virtual void OnConsumerManagementStatusChanged() = 0; | |
| 70 }; | 105 }; |
| 71 | 106 |
| 72 // GetOwner() invokes this with an argument set to the owner user ID, | 107 // GetOwner() invokes this with an argument set to the owner user ID, |
| 73 // or an empty string on failure. | 108 // or an empty string on failure. |
| 74 typedef base::Callback<void(const std::string&)> GetOwnerCallback; | 109 typedef base::Callback<void(const std::string&)> GetOwnerCallback; |
| 75 | 110 |
| 76 // SetOwner() invokes this with an argument indicating success or failure. | 111 // SetOwner() invokes this with an argument indicating success or failure. |
| 77 typedef base::Callback<void(bool)> SetOwnerCallback; | 112 typedef base::Callback<void(bool)> SetOwnerCallback; |
| 78 | 113 |
| 79 explicit ConsumerManagementService(chromeos::CryptohomeClient* client); | 114 ConsumerManagementService( |
| 115 chromeos::CryptohomeClient* client, | |
| 116 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.
| |
| 80 | 117 |
| 81 virtual ~ConsumerManagementService(); | 118 virtual ~ConsumerManagementService(); |
| 82 | 119 |
| 83 // Registers prefs. | 120 // Registers prefs. |
| 84 static void RegisterPrefs(PrefRegistrySimple* registry); | 121 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 85 | 122 |
| 86 // Returns the enrollment state. | 123 void AddObserver(Observer* observer); |
| 87 ConsumerEnrollmentState GetEnrollmentState() const; | 124 void RemoveObserver(Observer* observer); |
| 88 | 125 |
| 89 // Sets the enrollment state. | 126 // Returns the status. |
| 90 void SetEnrollmentState(ConsumerEnrollmentState state); | 127 Status GetStatus() const; |
| 128 | |
| 129 // Returns the string value of the status. | |
| 130 std::string GetStatusString() const; | |
| 131 | |
| 132 // Returns the enrollment stage. | |
| 133 EnrollmentStage GetEnrollmentStage() const; | |
| 134 | |
| 135 // Sets the enrollment stage. | |
| 136 void SetEnrollmentStage(EnrollmentStage stage); | |
| 91 | 137 |
| 92 // Returns the device owner stored in the boot lockbox via |callback|. | 138 // Returns the device owner stored in the boot lockbox via |callback|. |
| 93 void GetOwner(const GetOwnerCallback& callback); | 139 void GetOwner(const GetOwnerCallback& callback); |
| 94 | 140 |
| 95 // Stores the device owner user ID into the boot lockbox and signs it. | 141 // Stores the device owner user ID into the boot lockbox and signs it. |
| 96 // |callback| is invoked with an agument indicating success or failure. | 142 // |callback| is invoked with an agument indicating success or failure. |
| 97 void SetOwner(const std::string& user_id, const SetOwnerCallback& callback); | 143 void SetOwner(const std::string& user_id, const SetOwnerCallback& callback); |
| 98 | 144 |
| 145 // chromeos::DeviceSettingsService::Observer: | |
| 146 virtual void OwnershipStatusChanged() OVERRIDE; | |
| 147 virtual void DeviceSettingsUpdated() OVERRIDE; | |
| 148 | |
| 99 // content::NotificationObserver implmentation. | 149 // content::NotificationObserver implmentation. |
| 100 virtual void Observe(int type, | 150 virtual void Observe(int type, |
| 101 const content::NotificationSource& source, | 151 const content::NotificationSource& source, |
| 102 const content::NotificationDetails& details) OVERRIDE; | 152 const content::NotificationDetails& details) OVERRIDE; |
| 103 | 153 |
| 104 // OAuth2TokenService::Observer implementation. | 154 // OAuth2TokenService::Observer: |
| 105 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 155 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 106 | 156 |
| 107 // OAuth2TokenService::Consumer implementation. | 157 // OAuth2TokenService::Consumer: |
| 108 virtual void OnGetTokenSuccess( | 158 virtual void OnGetTokenSuccess( |
| 109 const OAuth2TokenService::Request* request, | 159 const OAuth2TokenService::Request* request, |
| 110 const std::string& access_token, | 160 const std::string& access_token, |
| 111 const base::Time& expiration_time) OVERRIDE; | 161 const base::Time& expiration_time) OVERRIDE; |
| 112 virtual void OnGetTokenFailure( | 162 virtual void OnGetTokenFailure( |
| 113 const OAuth2TokenService::Request* request, | 163 const OAuth2TokenService::Request* request, |
| 114 const GoogleServiceAuthError& error) OVERRIDE; | 164 const GoogleServiceAuthError& error) OVERRIDE; |
| 115 | 165 |
| 116 OAuth2TokenService::Request* GetTokenRequestForTesting() { | 166 OAuth2TokenService::Request* GetTokenRequestForTesting() { |
| 117 return token_request_.get(); | 167 return token_request_.get(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 146 void OnOwnerRefreshTokenAvailable(); | 196 void OnOwnerRefreshTokenAvailable(); |
| 147 | 197 |
| 148 // Called when the owner's access token for device management is available. | 198 // Called when the owner's access token for device management is available. |
| 149 void OnOwnerAccessTokenAvailable(const std::string& access_token); | 199 void OnOwnerAccessTokenAvailable(const std::string& access_token); |
| 150 | 200 |
| 151 // Called upon the completion of the enrollment process. | 201 // Called upon the completion of the enrollment process. |
| 152 void OnEnrollmentCompleted(EnrollmentStatus status); | 202 void OnEnrollmentCompleted(EnrollmentStatus status); |
| 153 | 203 |
| 154 // Ends the enrollment process and shows a desktop notification if the | 204 // Ends the enrollment process and shows a desktop notification if the |
| 155 // current user is the owner. | 205 // current user is the owner. |
| 156 void EndEnrollment(ConsumerEnrollmentState state); | 206 void EndEnrollment(EnrollmentStage stage); |
| 157 | 207 |
| 158 // Shows a desktop notification and resets the enrollment state. | 208 // Shows a desktop notification and resets the enrollment stage. |
| 159 void ShowDesktopNotificationAndResetState(ConsumerEnrollmentState state, | 209 void ShowDesktopNotificationAndResetStage( |
| 160 Profile* profile); | 210 EnrollmentStage stage, |
| 211 Profile* profile); | |
| 161 | 212 |
| 162 // Opens the settings page. | 213 // Opens the settings page. |
| 163 void OpenSettingsPage(Profile* profile) const; | 214 void OpenSettingsPage(Profile* profile) const; |
| 164 | 215 |
| 165 // Opens the enrollment confirmation dialog in the settings page. | 216 // Opens the enrollment confirmation dialog in the settings page. |
| 166 void TryEnrollmentAgain(Profile* profile) const; | 217 void TryEnrollmentAgain(Profile* profile) const; |
| 167 | 218 |
| 219 void NotifyStatusChanged(); | |
| 220 | |
| 168 chromeos::CryptohomeClient* client_; | 221 chromeos::CryptohomeClient* client_; |
| 222 chromeos::DeviceSettingsService* device_settings_service_; | |
| 169 | 223 |
| 170 Profile* enrolling_profile_; | 224 Profile* enrolling_profile_; |
| 171 scoped_ptr<OAuth2TokenService::Request> token_request_; | 225 scoped_ptr<OAuth2TokenService::Request> token_request_; |
| 172 content::NotificationRegistrar registrar_; | 226 content::NotificationRegistrar registrar_; |
| 227 ObserverList<Observer, true> observers_; | |
| 173 base::WeakPtrFactory<ConsumerManagementService> weak_ptr_factory_; | 228 base::WeakPtrFactory<ConsumerManagementService> weak_ptr_factory_; |
| 174 | 229 |
| 175 DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService); | 230 DISALLOW_COPY_AND_ASSIGN(ConsumerManagementService); |
| 176 }; | 231 }; |
| 177 | 232 |
| 178 } // namespace policy | 233 } // namespace policy |
| 179 | 234 |
| 180 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ | 235 #endif // CHROME_BROWSER_CHROMEOS_POLICY_CONSUMER_MANAGEMENT_SERVICE_H_ |
| OLD | NEW |