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