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 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" | 5 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti
lity.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/base64.h" | 9 #include "base/base64.h" |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
13 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 SupervisedUserRefreshTokenFetcher::Create( | 168 SupervisedUserRefreshTokenFetcher::Create( |
167 token_service, | 169 token_service, |
168 signin_manager->GetAuthenticatedAccountId(), | 170 signin_manager->GetAuthenticatedAccountId(), |
169 signin_scoped_device_id, | 171 signin_scoped_device_id, |
170 profile->GetRequestContext()); | 172 profile->GetRequestContext()); |
171 SupervisedUserSyncService* supervised_user_sync_service = | 173 SupervisedUserSyncService* supervised_user_sync_service = |
172 SupervisedUserSyncServiceFactory::GetForProfile(profile); | 174 SupervisedUserSyncServiceFactory::GetForProfile(profile); |
173 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service = | 175 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service = |
174 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); | 176 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); |
175 return make_scoped_ptr(SupervisedUserRegistrationUtility::CreateImpl( | 177 return make_scoped_ptr(SupervisedUserRegistrationUtility::CreateImpl( |
176 profile->GetPrefs(), | 178 profile->GetPrefs(), std::move(token_fetcher), |
177 token_fetcher.Pass(), | 179 supervised_user_sync_service, supervised_user_shared_settings_service)); |
178 supervised_user_sync_service, | |
179 supervised_user_shared_settings_service)); | |
180 } | 180 } |
181 | 181 |
182 // static | 182 // static |
183 std::string SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId() { | 183 std::string SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId() { |
184 std::string new_supervised_user_id; | 184 std::string new_supervised_user_id; |
185 base::Base64Encode(base::RandBytesAsString(8), &new_supervised_user_id); | 185 base::Base64Encode(base::RandBytesAsString(8), &new_supervised_user_id); |
186 return new_supervised_user_id; | 186 return new_supervised_user_id; |
187 } | 187 } |
188 | 188 |
189 // static | 189 // static |
190 void SupervisedUserRegistrationUtility::SetUtilityForTests( | 190 void SupervisedUserRegistrationUtility::SetUtilityForTests( |
191 SupervisedUserRegistrationUtility* utility) { | 191 SupervisedUserRegistrationUtility* utility) { |
192 if (g_instance_for_tests) | 192 if (g_instance_for_tests) |
193 delete g_instance_for_tests; | 193 delete g_instance_for_tests; |
194 g_instance_for_tests = utility; | 194 g_instance_for_tests = utility; |
195 } | 195 } |
196 | 196 |
197 // static | 197 // static |
198 SupervisedUserRegistrationUtility* | 198 SupervisedUserRegistrationUtility* |
199 SupervisedUserRegistrationUtility::CreateImpl( | 199 SupervisedUserRegistrationUtility::CreateImpl( |
200 PrefService* prefs, | 200 PrefService* prefs, |
201 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, | 201 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, |
202 SupervisedUserSyncService* service, | 202 SupervisedUserSyncService* service, |
203 SupervisedUserSharedSettingsService* shared_settings_service) { | 203 SupervisedUserSharedSettingsService* shared_settings_service) { |
204 return new SupervisedUserRegistrationUtilityImpl(prefs, | 204 return new SupervisedUserRegistrationUtilityImpl( |
205 token_fetcher.Pass(), | 205 prefs, std::move(token_fetcher), service, shared_settings_service); |
206 service, | |
207 shared_settings_service); | |
208 } | 206 } |
209 | 207 |
210 namespace { | 208 namespace { |
211 | 209 |
212 SupervisedUserRegistrationUtilityImpl::SupervisedUserRegistrationUtilityImpl( | 210 SupervisedUserRegistrationUtilityImpl::SupervisedUserRegistrationUtilityImpl( |
213 PrefService* prefs, | 211 PrefService* prefs, |
214 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, | 212 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, |
215 SupervisedUserSyncService* service, | 213 SupervisedUserSyncService* service, |
216 SupervisedUserSharedSettingsService* shared_settings_service) | 214 SupervisedUserSharedSettingsService* shared_settings_service) |
217 : prefs_(prefs), | 215 : prefs_(prefs), |
218 token_fetcher_(token_fetcher.Pass()), | 216 token_fetcher_(std::move(token_fetcher)), |
219 supervised_user_sync_service_(service), | 217 supervised_user_sync_service_(service), |
220 supervised_user_shared_settings_service_(shared_settings_service), | 218 supervised_user_shared_settings_service_(shared_settings_service), |
221 pending_supervised_user_acknowledged_(false), | 219 pending_supervised_user_acknowledged_(false), |
222 is_existing_supervised_user_(false), | 220 is_existing_supervised_user_(false), |
223 avatar_updated_(false), | 221 avatar_updated_(false), |
224 weak_ptr_factory_(this) { | 222 weak_ptr_factory_(this) { |
225 supervised_user_sync_service_->AddObserver(this); | 223 supervised_user_sync_service_->AddObserver(this); |
226 } | 224 } |
227 | 225 |
228 SupervisedUserRegistrationUtilityImpl:: | 226 SupervisedUserRegistrationUtilityImpl:: |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 pending_supervised_user_id_); | 410 pending_supervised_user_id_); |
413 } | 411 } |
414 } | 412 } |
415 | 413 |
416 if (run_callback) | 414 if (run_callback) |
417 callback_.Run(error, pending_supervised_user_token_); | 415 callback_.Run(error, pending_supervised_user_token_); |
418 callback_.Reset(); | 416 callback_.Reset(); |
419 } | 417 } |
420 | 418 |
421 } // namespace | 419 } // namespace |
OLD | NEW |