OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | 5 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/managed_mode/managed_user_constants.h" | |
15 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" | |
16 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" | |
17 #include "chrome/browser/managed_mode/managed_user_shared_settings_service_facto
ry.h" | |
18 #include "chrome/browser/managed_mode/managed_user_shared_settings_update.h" | |
19 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | |
20 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | |
21 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
23 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 18 #include "chrome/browser/supervised_user/supervised_user_refresh_token_fetcher.h
" |
| 19 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_shared_settings_update.
h" |
| 22 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
| 23 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" |
24 #include "chrome/browser/sync/glue/device_info.h" | 24 #include "chrome/browser/sync/glue/device_info.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 27 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
28 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
29 #include "google_apis/gaia/gaia_urls.h" | 29 #include "google_apis/gaia/gaia_urls.h" |
30 #include "google_apis/gaia/google_service_auth_error.h" | 30 #include "google_apis/gaia/google_service_auth_error.h" |
31 | 31 |
32 using base::DictionaryValue; | 32 using base::DictionaryValue; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 ManagedUserRegistrationUtility* g_instance_for_tests = NULL; | 36 SupervisedUserRegistrationUtility* g_instance_for_tests = NULL; |
37 | 37 |
38 // Actual implementation of ManagedUserRegistrationUtility. | 38 // Actual implementation of SupervisedUserRegistrationUtility. |
39 class ManagedUserRegistrationUtilityImpl | 39 class SupervisedUserRegistrationUtilityImpl |
40 : public ManagedUserRegistrationUtility, | 40 : public SupervisedUserRegistrationUtility, |
41 public ManagedUserSyncServiceObserver { | 41 public SupervisedUserSyncServiceObserver { |
42 public: | 42 public: |
43 ManagedUserRegistrationUtilityImpl( | 43 SupervisedUserRegistrationUtilityImpl( |
44 PrefService* prefs, | 44 PrefService* prefs, |
45 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher, | 45 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, |
46 ManagedUserSyncService* service, | 46 SupervisedUserSyncService* service, |
47 ManagedUserSharedSettingsService* shared_settings_service); | 47 SupervisedUserSharedSettingsService* shared_settings_service); |
48 | 48 |
49 virtual ~ManagedUserRegistrationUtilityImpl(); | 49 virtual ~SupervisedUserRegistrationUtilityImpl(); |
50 | 50 |
51 // Registers a new managed user with the server. |managed_user_id| is a new | 51 // Registers a new supervised user with the server. |supervised_user_id| is a |
52 // unique ID for the new managed user. If its value is the same as that of | 52 // new unique ID for the new supervised user. If its value is the same as that |
53 // of one of the existing managed users, then the same user will be created | 53 // of one of the existing supervised users, then the same user will be created |
54 // on this machine (and if he has no avatar in sync, his avatar will | 54 // on this machine (and if he has no avatar in sync, his avatar will be |
55 // be updated). |info| contains necessary information like | 55 // updated). |info| contains necessary information like the display name of |
56 // the display name of the user and his avatar. |callback| is called | 56 // the user and his avatar. |callback| is called with the result of the |
57 // with the result of the registration. We use the info here and not the | 57 // registration. We use the info here and not the profile, because on Chrome |
58 // profile, because on Chrome OS the profile of the managed user does not | 58 // OS the profile of the supervised user does not yet exist. |
59 // yet exist. | 59 virtual void Register(const std::string& supervised_user_id, |
60 virtual void Register(const std::string& managed_user_id, | 60 const SupervisedUserRegistrationInfo& info, |
61 const ManagedUserRegistrationInfo& info, | |
62 const RegistrationCallback& callback) OVERRIDE; | 61 const RegistrationCallback& callback) OVERRIDE; |
63 | 62 |
64 // ManagedUserSyncServiceObserver: | 63 // SupervisedUserSyncServiceObserver: |
65 virtual void OnManagedUserAcknowledged(const std::string& managed_user_id) | 64 virtual void OnSupervisedUserAcknowledged( |
66 OVERRIDE; | 65 const std::string& supervised_user_id) OVERRIDE; |
67 virtual void OnManagedUsersSyncingStopped() OVERRIDE; | 66 virtual void OnSupervisedUsersSyncingStopped() OVERRIDE; |
68 virtual void OnManagedUsersChanged() OVERRIDE; | 67 virtual void OnSupervisedUsersChanged() OVERRIDE; |
69 | 68 |
70 private: | 69 private: |
71 // Fetches the managed user token when we have the device name. | 70 // Fetches the supervised user token when we have the device name. |
72 void FetchToken(const std::string& client_name); | 71 void FetchToken(const std::string& client_name); |
73 | 72 |
74 // Called when we have received a token for the managed user. | 73 // Called when we have received a token for the supervised user. |
75 void OnReceivedToken(const GoogleServiceAuthError& error, | 74 void OnReceivedToken(const GoogleServiceAuthError& error, |
76 const std::string& token); | 75 const std::string& token); |
77 | 76 |
78 // Dispatches the callback and cleans up if all the conditions have been met. | 77 // Dispatches the callback and cleans up if all the conditions have been met. |
79 void CompleteRegistrationIfReady(); | 78 void CompleteRegistrationIfReady(); |
80 | 79 |
81 // Aborts any registration currently in progress. If |run_callback| is true, | 80 // Aborts any registration currently in progress. If |run_callback| is true, |
82 // calls the callback specified in Register() with the given |error|. | 81 // calls the callback specified in Register() with the given |error|. |
83 void AbortPendingRegistration(bool run_callback, | 82 void AbortPendingRegistration(bool run_callback, |
84 const GoogleServiceAuthError& error); | 83 const GoogleServiceAuthError& error); |
85 | 84 |
86 // If |run_callback| is true, dispatches the callback with the saved token | 85 // If |run_callback| is true, dispatches the callback with the saved token |
87 // (which may be empty) and the given |error|. In any case, resets internal | 86 // (which may be empty) and the given |error|. In any case, resets internal |
88 // variables to be ready for the next registration. | 87 // variables to be ready for the next registration. |
89 void CompleteRegistration(bool run_callback, | 88 void CompleteRegistration(bool run_callback, |
90 const GoogleServiceAuthError& error); | 89 const GoogleServiceAuthError& error); |
91 | 90 |
92 // Cancels any registration currently in progress, without calling the | 91 // Cancels any registration currently in progress, without calling the |
93 // callback or reporting an error. | 92 // callback or reporting an error. |
94 void CancelPendingRegistration(); | 93 void CancelPendingRegistration(); |
95 | 94 |
96 // ManagedUserSharedSettingsUpdate acknowledgment callback for password data | 95 // SupervisedUserSharedSettingsUpdate acknowledgment callback for password |
97 // in shared settings. | 96 // data in shared settings. |
98 void OnPasswordChangeAcknowledged(bool success); | 97 void OnPasswordChangeAcknowledged(bool success); |
99 | 98 |
100 PrefService* prefs_; | 99 PrefService* prefs_; |
101 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; | 100 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher_; |
102 | 101 |
103 // A |KeyedService| owned by the custodian profile. | 102 // A |KeyedService| owned by the custodian profile. |
104 ManagedUserSyncService* managed_user_sync_service_; | 103 SupervisedUserSyncService* supervised_user_sync_service_; |
105 | 104 |
106 // A |KeyedService| owned by the custodian profile. | 105 // A |KeyedService| owned by the custodian profile. |
107 ManagedUserSharedSettingsService* managed_user_shared_settings_service_; | 106 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service_; |
108 | 107 |
109 std::string pending_managed_user_id_; | 108 std::string pending_supervised_user_id_; |
110 std::string pending_managed_user_token_; | 109 std::string pending_supervised_user_token_; |
111 bool pending_managed_user_acknowledged_; | 110 bool pending_supervised_user_acknowledged_; |
112 bool is_existing_managed_user_; | 111 bool is_existing_supervised_user_; |
113 bool avatar_updated_; | 112 bool avatar_updated_; |
114 RegistrationCallback callback_; | 113 RegistrationCallback callback_; |
115 scoped_ptr<ManagedUserSharedSettingsUpdate> password_update_; | 114 scoped_ptr<SupervisedUserSharedSettingsUpdate> password_update_; |
116 | 115 |
117 base::WeakPtrFactory<ManagedUserRegistrationUtilityImpl> weak_ptr_factory_; | 116 base::WeakPtrFactory<SupervisedUserRegistrationUtilityImpl> weak_ptr_factory_; |
118 | 117 |
119 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationUtilityImpl); | 118 DISALLOW_COPY_AND_ASSIGN(SupervisedUserRegistrationUtilityImpl); |
120 }; | 119 }; |
121 | 120 |
122 } // namespace | 121 } // namespace |
123 | 122 |
124 ManagedUserRegistrationInfo::ManagedUserRegistrationInfo( | 123 SupervisedUserRegistrationInfo::SupervisedUserRegistrationInfo( |
125 const base::string16& name, | 124 const base::string16& name, |
126 int avatar_index) | 125 int avatar_index) |
127 : avatar_index(avatar_index), | 126 : avatar_index(avatar_index), |
128 name(name) { | 127 name(name) { |
129 } | 128 } |
130 | 129 |
131 ManagedUserRegistrationInfo::~ManagedUserRegistrationInfo() {} | 130 SupervisedUserRegistrationInfo::~SupervisedUserRegistrationInfo() {} |
132 | 131 |
133 ScopedTestingManagedUserRegistrationUtility:: | 132 ScopedTestingSupervisedUserRegistrationUtility:: |
134 ScopedTestingManagedUserRegistrationUtility( | 133 ScopedTestingSupervisedUserRegistrationUtility( |
135 ManagedUserRegistrationUtility* instance) { | 134 SupervisedUserRegistrationUtility* instance) { |
136 ManagedUserRegistrationUtility::SetUtilityForTests(instance); | 135 SupervisedUserRegistrationUtility::SetUtilityForTests(instance); |
137 } | 136 } |
138 | 137 |
139 ScopedTestingManagedUserRegistrationUtility:: | 138 ScopedTestingSupervisedUserRegistrationUtility:: |
140 ~ScopedTestingManagedUserRegistrationUtility() { | 139 ~ScopedTestingSupervisedUserRegistrationUtility() { |
141 ManagedUserRegistrationUtility::SetUtilityForTests(NULL); | 140 SupervisedUserRegistrationUtility::SetUtilityForTests(NULL); |
142 } | 141 } |
143 | 142 |
144 // static | 143 // static |
145 scoped_ptr<ManagedUserRegistrationUtility> | 144 scoped_ptr<SupervisedUserRegistrationUtility> |
146 ManagedUserRegistrationUtility::Create(Profile* profile) { | 145 SupervisedUserRegistrationUtility::Create(Profile* profile) { |
147 if (g_instance_for_tests) { | 146 if (g_instance_for_tests) { |
148 ManagedUserRegistrationUtility* result = g_instance_for_tests; | 147 SupervisedUserRegistrationUtility* result = g_instance_for_tests; |
149 g_instance_for_tests = NULL; | 148 g_instance_for_tests = NULL; |
150 return make_scoped_ptr(result); | 149 return make_scoped_ptr(result); |
151 } | 150 } |
152 | 151 |
153 ProfileOAuth2TokenService* token_service = | 152 ProfileOAuth2TokenService* token_service = |
154 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 153 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
155 SigninManagerBase* signin_manager = | 154 SigninManagerBase* signin_manager = |
156 SigninManagerFactory::GetForProfile(profile); | 155 SigninManagerFactory::GetForProfile(profile); |
157 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher = | 156 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher = |
158 ManagedUserRefreshTokenFetcher::Create( | 157 SupervisedUserRefreshTokenFetcher::Create( |
159 token_service, | 158 token_service, |
160 signin_manager->GetAuthenticatedAccountId(), | 159 signin_manager->GetAuthenticatedAccountId(), |
161 profile->GetRequestContext()); | 160 profile->GetRequestContext()); |
162 ManagedUserSyncService* managed_user_sync_service = | 161 SupervisedUserSyncService* supervised_user_sync_service = |
163 ManagedUserSyncServiceFactory::GetForProfile(profile); | 162 SupervisedUserSyncServiceFactory::GetForProfile(profile); |
164 ManagedUserSharedSettingsService* managed_user_shared_settings_service = | 163 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service = |
165 ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); | 164 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); |
166 return make_scoped_ptr(ManagedUserRegistrationUtility::CreateImpl( | 165 return make_scoped_ptr(SupervisedUserRegistrationUtility::CreateImpl( |
167 profile->GetPrefs(), | 166 profile->GetPrefs(), |
168 token_fetcher.Pass(), | 167 token_fetcher.Pass(), |
169 managed_user_sync_service, | 168 supervised_user_sync_service, |
170 managed_user_shared_settings_service)); | 169 supervised_user_shared_settings_service)); |
171 } | 170 } |
172 | 171 |
173 // static | 172 // static |
174 std::string ManagedUserRegistrationUtility::GenerateNewManagedUserId() { | 173 std::string SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId() { |
175 std::string new_managed_user_id; | 174 std::string new_supervised_user_id; |
176 base::Base64Encode(base::RandBytesAsString(8), &new_managed_user_id); | 175 base::Base64Encode(base::RandBytesAsString(8), &new_supervised_user_id); |
177 return new_managed_user_id; | 176 return new_supervised_user_id; |
178 } | 177 } |
179 | 178 |
180 // static | 179 // static |
181 void ManagedUserRegistrationUtility::SetUtilityForTests( | 180 void SupervisedUserRegistrationUtility::SetUtilityForTests( |
182 ManagedUserRegistrationUtility* utility) { | 181 SupervisedUserRegistrationUtility* utility) { |
183 if (g_instance_for_tests) | 182 if (g_instance_for_tests) |
184 delete g_instance_for_tests; | 183 delete g_instance_for_tests; |
185 g_instance_for_tests = utility; | 184 g_instance_for_tests = utility; |
186 } | 185 } |
187 | 186 |
188 // static | 187 // static |
189 ManagedUserRegistrationUtility* ManagedUserRegistrationUtility::CreateImpl( | 188 SupervisedUserRegistrationUtility* |
| 189 SupervisedUserRegistrationUtility::CreateImpl( |
190 PrefService* prefs, | 190 PrefService* prefs, |
191 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher, | 191 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, |
192 ManagedUserSyncService* service, | 192 SupervisedUserSyncService* service, |
193 ManagedUserSharedSettingsService* shared_settings_service) { | 193 SupervisedUserSharedSettingsService* shared_settings_service) { |
194 return new ManagedUserRegistrationUtilityImpl(prefs, | 194 return new SupervisedUserRegistrationUtilityImpl(prefs, |
195 token_fetcher.Pass(), | 195 token_fetcher.Pass(), |
196 service, | 196 service, |
197 shared_settings_service); | 197 shared_settings_service); |
198 } | 198 } |
199 | 199 |
200 namespace { | 200 namespace { |
201 | 201 |
202 ManagedUserRegistrationUtilityImpl::ManagedUserRegistrationUtilityImpl( | 202 SupervisedUserRegistrationUtilityImpl::SupervisedUserRegistrationUtilityImpl( |
203 PrefService* prefs, | 203 PrefService* prefs, |
204 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher, | 204 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, |
205 ManagedUserSyncService* service, | 205 SupervisedUserSyncService* service, |
206 ManagedUserSharedSettingsService* shared_settings_service) | 206 SupervisedUserSharedSettingsService* shared_settings_service) |
207 : prefs_(prefs), | 207 : prefs_(prefs), |
208 token_fetcher_(token_fetcher.Pass()), | 208 token_fetcher_(token_fetcher.Pass()), |
209 managed_user_sync_service_(service), | 209 supervised_user_sync_service_(service), |
210 managed_user_shared_settings_service_(shared_settings_service), | 210 supervised_user_shared_settings_service_(shared_settings_service), |
211 pending_managed_user_acknowledged_(false), | 211 pending_supervised_user_acknowledged_(false), |
212 is_existing_managed_user_(false), | 212 is_existing_supervised_user_(false), |
213 avatar_updated_(false), | 213 avatar_updated_(false), |
214 weak_ptr_factory_(this) { | 214 weak_ptr_factory_(this) { |
215 managed_user_sync_service_->AddObserver(this); | 215 supervised_user_sync_service_->AddObserver(this); |
216 } | 216 } |
217 | 217 |
218 ManagedUserRegistrationUtilityImpl::~ManagedUserRegistrationUtilityImpl() { | 218 SupervisedUserRegistrationUtilityImpl:: |
219 managed_user_sync_service_->RemoveObserver(this); | 219 ~SupervisedUserRegistrationUtilityImpl() { |
| 220 supervised_user_sync_service_->RemoveObserver(this); |
220 CancelPendingRegistration(); | 221 CancelPendingRegistration(); |
221 } | 222 } |
222 | 223 |
223 void ManagedUserRegistrationUtilityImpl::Register( | 224 void SupervisedUserRegistrationUtilityImpl::Register( |
224 const std::string& managed_user_id, | 225 const std::string& supervised_user_id, |
225 const ManagedUserRegistrationInfo& info, | 226 const SupervisedUserRegistrationInfo& info, |
226 const RegistrationCallback& callback) { | 227 const RegistrationCallback& callback) { |
227 DCHECK(pending_managed_user_id_.empty()); | 228 DCHECK(pending_supervised_user_id_.empty()); |
228 callback_ = callback; | 229 callback_ = callback; |
229 pending_managed_user_id_ = managed_user_id; | 230 pending_supervised_user_id_ = supervised_user_id; |
230 | 231 |
231 bool need_password_update = !info.password_data.empty(); | 232 bool need_password_update = !info.password_data.empty(); |
232 const base::DictionaryValue* dict = | 233 const base::DictionaryValue* dict = |
233 prefs_->GetDictionary(prefs::kSupervisedUsers); | 234 prefs_->GetDictionary(prefs::kSupervisedUsers); |
234 is_existing_managed_user_ = dict->HasKey(managed_user_id); | 235 is_existing_supervised_user_ = dict->HasKey(supervised_user_id); |
235 if (!is_existing_managed_user_) { | 236 if (!is_existing_supervised_user_) { |
236 managed_user_sync_service_->AddManagedUser(pending_managed_user_id_, | 237 supervised_user_sync_service_->AddSupervisedUser( |
237 base::UTF16ToUTF8(info.name), | 238 pending_supervised_user_id_, |
238 info.master_key, | 239 base::UTF16ToUTF8(info.name), |
239 info.password_signature_key, | 240 info.master_key, |
240 info.password_encryption_key, | 241 info.password_signature_key, |
241 info.avatar_index); | 242 info.password_encryption_key, |
| 243 info.avatar_index); |
242 } else { | 244 } else { |
243 const base::DictionaryValue* value = NULL; | 245 const base::DictionaryValue* value = NULL; |
244 bool success = | 246 bool success = |
245 dict->GetDictionaryWithoutPathExpansion(managed_user_id, &value); | 247 dict->GetDictionaryWithoutPathExpansion(supervised_user_id, &value); |
246 DCHECK(success); | 248 DCHECK(success); |
247 std::string key; | 249 std::string key; |
248 bool need_keys = !info.password_signature_key.empty() || | 250 bool need_keys = !info.password_signature_key.empty() || |
249 !info.password_encryption_key.empty(); | 251 !info.password_encryption_key.empty(); |
250 bool have_keys = | 252 bool have_keys = |
251 value->GetString(ManagedUserSyncService::kPasswordSignatureKey, &key) && | 253 value->GetString(SupervisedUserSyncService::kPasswordSignatureKey, |
| 254 &key) && |
252 !key.empty() && | 255 !key.empty() && |
253 value->GetString(ManagedUserSyncService::kPasswordEncryptionKey, | 256 value->GetString(SupervisedUserSyncService::kPasswordEncryptionKey, |
254 &key) && | 257 &key) && |
255 !key.empty(); | 258 !key.empty(); |
256 | 259 |
257 bool keys_need_update = need_keys && !have_keys; | 260 bool keys_need_update = need_keys && !have_keys; |
258 | 261 |
259 if (keys_need_update) { | 262 if (keys_need_update) { |
260 managed_user_sync_service_->UpdateManagedUser( | 263 supervised_user_sync_service_->UpdateSupervisedUser( |
261 pending_managed_user_id_, | 264 pending_supervised_user_id_, |
262 base::UTF16ToUTF8(info.name), | 265 base::UTF16ToUTF8(info.name), |
263 info.master_key, | 266 info.master_key, |
264 info.password_signature_key, | 267 info.password_signature_key, |
265 info.password_encryption_key, | 268 info.password_encryption_key, |
266 info.avatar_index); | 269 info.avatar_index); |
267 } else { | 270 } else { |
268 // The user already exists and does not need to be updated. | 271 // The user already exists and does not need to be updated. |
269 need_password_update = false; | 272 need_password_update = false; |
270 OnManagedUserAcknowledged(managed_user_id); | 273 OnSupervisedUserAcknowledged(supervised_user_id); |
271 } | 274 } |
272 avatar_updated_ = | 275 avatar_updated_ = |
273 managed_user_sync_service_->UpdateManagedUserAvatarIfNeeded( | 276 supervised_user_sync_service_->UpdateSupervisedUserAvatarIfNeeded( |
274 managed_user_id, | 277 supervised_user_id, |
275 info.avatar_index); | 278 info.avatar_index); |
276 } | 279 } |
277 #if defined(OS_CHROMEOS) | 280 #if defined(OS_CHROMEOS) |
278 const char* kAvatarKey = managed_users::kChromeOSAvatarIndex; | 281 const char* kAvatarKey = supervised_users::kChromeOSAvatarIndex; |
279 #else | 282 #else |
280 const char* kAvatarKey = managed_users::kChromeAvatarIndex; | 283 const char* kAvatarKey = supervised_users::kChromeAvatarIndex; |
281 #endif | 284 #endif |
282 managed_user_shared_settings_service_->SetValue( | 285 supervised_user_shared_settings_service_->SetValue( |
283 pending_managed_user_id_, kAvatarKey, | 286 pending_supervised_user_id_, kAvatarKey, |
284 base::FundamentalValue(info.avatar_index)); | 287 base::FundamentalValue(info.avatar_index)); |
285 if (need_password_update) { | 288 if (need_password_update) { |
286 password_update_.reset(new ManagedUserSharedSettingsUpdate( | 289 password_update_.reset(new SupervisedUserSharedSettingsUpdate( |
287 managed_user_shared_settings_service_, | 290 supervised_user_shared_settings_service_, |
288 pending_managed_user_id_, | 291 pending_supervised_user_id_, |
289 managed_users::kChromeOSPasswordData, | 292 supervised_users::kChromeOSPasswordData, |
290 scoped_ptr<base::Value>(info.password_data.DeepCopy()), | 293 scoped_ptr<base::Value>(info.password_data.DeepCopy()), |
291 base::Bind( | 294 base::Bind( |
292 &ManagedUserRegistrationUtilityImpl::OnPasswordChangeAcknowledged, | 295 &SupervisedUserRegistrationUtilityImpl:: |
| 296 OnPasswordChangeAcknowledged, |
293 weak_ptr_factory_.GetWeakPtr()))); | 297 weak_ptr_factory_.GetWeakPtr()))); |
294 } | 298 } |
295 | 299 |
296 browser_sync::DeviceInfo::GetClientName( | 300 browser_sync::DeviceInfo::GetClientName( |
297 base::Bind(&ManagedUserRegistrationUtilityImpl::FetchToken, | 301 base::Bind(&SupervisedUserRegistrationUtilityImpl::FetchToken, |
298 weak_ptr_factory_.GetWeakPtr())); | 302 weak_ptr_factory_.GetWeakPtr())); |
299 } | 303 } |
300 | 304 |
301 void ManagedUserRegistrationUtilityImpl::CancelPendingRegistration() { | 305 void SupervisedUserRegistrationUtilityImpl::CancelPendingRegistration() { |
302 AbortPendingRegistration( | 306 AbortPendingRegistration( |
303 false, // Don't run the callback. The error will be ignored. | 307 false, // Don't run the callback. The error will be ignored. |
304 GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | 308 GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
305 } | 309 } |
306 | 310 |
307 void ManagedUserRegistrationUtilityImpl::OnManagedUserAcknowledged( | 311 void SupervisedUserRegistrationUtilityImpl::OnSupervisedUserAcknowledged( |
308 const std::string& managed_user_id) { | 312 const std::string& supervised_user_id) { |
309 DCHECK_EQ(pending_managed_user_id_, managed_user_id); | 313 DCHECK_EQ(pending_supervised_user_id_, supervised_user_id); |
310 DCHECK(!pending_managed_user_acknowledged_); | 314 DCHECK(!pending_supervised_user_acknowledged_); |
311 pending_managed_user_acknowledged_ = true; | 315 pending_supervised_user_acknowledged_ = true; |
312 CompleteRegistrationIfReady(); | 316 CompleteRegistrationIfReady(); |
313 } | 317 } |
314 | 318 |
315 void ManagedUserRegistrationUtilityImpl::OnPasswordChangeAcknowledged( | 319 void SupervisedUserRegistrationUtilityImpl::OnPasswordChangeAcknowledged( |
316 bool success) { | 320 bool success) { |
317 DCHECK(password_update_); | 321 DCHECK(password_update_); |
318 DCHECK(success); | 322 DCHECK(success); |
319 password_update_.reset(); | 323 password_update_.reset(); |
320 CompleteRegistrationIfReady(); | 324 CompleteRegistrationIfReady(); |
321 } | 325 } |
322 | 326 |
323 void ManagedUserRegistrationUtilityImpl::OnManagedUsersSyncingStopped() { | 327 void SupervisedUserRegistrationUtilityImpl::OnSupervisedUsersSyncingStopped() { |
324 AbortPendingRegistration( | 328 AbortPendingRegistration( |
325 true, // Run the callback. | 329 true, // Run the callback. |
326 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); | 330 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); |
327 } | 331 } |
328 | 332 |
329 void ManagedUserRegistrationUtilityImpl::OnManagedUsersChanged() {} | 333 void SupervisedUserRegistrationUtilityImpl::OnSupervisedUsersChanged() {} |
330 | 334 |
331 void ManagedUserRegistrationUtilityImpl::FetchToken( | 335 void SupervisedUserRegistrationUtilityImpl::FetchToken( |
332 const std::string& client_name) { | 336 const std::string& client_name) { |
333 token_fetcher_->Start( | 337 token_fetcher_->Start( |
334 pending_managed_user_id_, client_name, | 338 pending_supervised_user_id_, client_name, |
335 base::Bind(&ManagedUserRegistrationUtilityImpl::OnReceivedToken, | 339 base::Bind(&SupervisedUserRegistrationUtilityImpl::OnReceivedToken, |
336 weak_ptr_factory_.GetWeakPtr())); | 340 weak_ptr_factory_.GetWeakPtr())); |
337 } | 341 } |
338 | 342 |
339 void ManagedUserRegistrationUtilityImpl::OnReceivedToken( | 343 void SupervisedUserRegistrationUtilityImpl::OnReceivedToken( |
340 const GoogleServiceAuthError& error, | 344 const GoogleServiceAuthError& error, |
341 const std::string& token) { | 345 const std::string& token) { |
342 if (error.state() != GoogleServiceAuthError::NONE) { | 346 if (error.state() != GoogleServiceAuthError::NONE) { |
343 CompleteRegistration(true, error); | 347 CompleteRegistration(true, error); |
344 return; | 348 return; |
345 } | 349 } |
346 | 350 |
347 DCHECK(!token.empty()); | 351 DCHECK(!token.empty()); |
348 pending_managed_user_token_ = token; | 352 pending_supervised_user_token_ = token; |
349 CompleteRegistrationIfReady(); | 353 CompleteRegistrationIfReady(); |
350 } | 354 } |
351 | 355 |
352 void ManagedUserRegistrationUtilityImpl::CompleteRegistrationIfReady() { | 356 void SupervisedUserRegistrationUtilityImpl::CompleteRegistrationIfReady() { |
353 bool skip_check = CommandLine::ForCurrentProcess()->HasSwitch( | 357 bool skip_check = CommandLine::ForCurrentProcess()->HasSwitch( |
354 switches::kNoSupervisedUserAcknowledgmentCheck); | 358 switches::kNoSupervisedUserAcknowledgmentCheck); |
355 | 359 |
356 if (!pending_managed_user_acknowledged_ && !skip_check) | 360 if (!pending_supervised_user_acknowledged_ && !skip_check) |
357 return; | 361 return; |
358 if (password_update_ && !skip_check) | 362 if (password_update_ && !skip_check) |
359 return; | 363 return; |
360 if (pending_managed_user_token_.empty()) | 364 if (pending_supervised_user_token_.empty()) |
361 return; | 365 return; |
362 | 366 |
363 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | 367 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
364 CompleteRegistration(true, error); | 368 CompleteRegistration(true, error); |
365 } | 369 } |
366 | 370 |
367 void ManagedUserRegistrationUtilityImpl::AbortPendingRegistration( | 371 void SupervisedUserRegistrationUtilityImpl::AbortPendingRegistration( |
368 bool run_callback, | 372 bool run_callback, |
369 const GoogleServiceAuthError& error) { | 373 const GoogleServiceAuthError& error) { |
370 pending_managed_user_token_.clear(); | 374 pending_supervised_user_token_.clear(); |
371 CompleteRegistration(run_callback, error); | 375 CompleteRegistration(run_callback, error); |
372 } | 376 } |
373 | 377 |
374 void ManagedUserRegistrationUtilityImpl::CompleteRegistration( | 378 void SupervisedUserRegistrationUtilityImpl::CompleteRegistration( |
375 bool run_callback, | 379 bool run_callback, |
376 const GoogleServiceAuthError& error) { | 380 const GoogleServiceAuthError& error) { |
377 if (callback_.is_null()) | 381 if (callback_.is_null()) |
378 return; | 382 return; |
379 | 383 |
380 if (pending_managed_user_token_.empty()) { | 384 if (pending_supervised_user_token_.empty()) { |
381 DCHECK(!pending_managed_user_id_.empty()); | 385 DCHECK(!pending_supervised_user_id_.empty()); |
382 | 386 |
383 if (!is_existing_managed_user_) { | 387 if (!is_existing_supervised_user_) { |
384 // Remove the pending managed user if we weren't successful. | 388 // Remove the pending supervised user if we weren't successful. |
385 // However, check that we are not importing a managed user | 389 // However, check that we are not importing a supervised user |
386 // before deleting it from sync to avoid accidental deletion of | 390 // before deleting it from sync to avoid accidental deletion of |
387 // existing managed users by just canceling the registration for example. | 391 // existing supervised users by just canceling the registration for |
388 managed_user_sync_service_->DeleteManagedUser(pending_managed_user_id_); | 392 // example. |
| 393 supervised_user_sync_service_->DeleteSupervisedUser( |
| 394 pending_supervised_user_id_); |
389 } else if (avatar_updated_) { | 395 } else if (avatar_updated_) { |
390 // Canceling (or failing) a managed user import that did set the avatar | 396 // Canceling (or failing) a supervised user import that did set the avatar |
391 // should undo this change. | 397 // should undo this change. |
392 managed_user_sync_service_->ClearManagedUserAvatar( | 398 supervised_user_sync_service_->ClearSupervisedUserAvatar( |
393 pending_managed_user_id_); | 399 pending_supervised_user_id_); |
394 } | 400 } |
395 } | 401 } |
396 | 402 |
397 if (run_callback) | 403 if (run_callback) |
398 callback_.Run(error, pending_managed_user_token_); | 404 callback_.Run(error, pending_supervised_user_token_); |
399 callback_.Reset(); | 405 callback_.Reset(); |
400 } | 406 } |
401 | 407 |
402 } // namespace | 408 } // namespace |
OLD | NEW |