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

Side by Side Diff: chrome/browser/supervised_user/legacy/supervised_user_registration_utility.cc

Issue 1878143002: Convert //chrome/browser/supervised_user from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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 <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/base64.h" 10 #include "base/base64.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/rand_util.h" 15 #include "base/rand_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/signin/chrome_signin_client_factory.h" 19 #include "chrome/browser/signin/chrome_signin_client_factory.h"
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fe tcher.h" 22 #include "chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fe tcher.h"
22 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service.h" 23 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service.h"
23 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service_factory.h" 24 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_ service_factory.h"
(...skipping 18 matching lines...) Expand all
42 43
43 SupervisedUserRegistrationUtility* g_instance_for_tests = NULL; 44 SupervisedUserRegistrationUtility* g_instance_for_tests = NULL;
44 45
45 // Actual implementation of SupervisedUserRegistrationUtility. 46 // Actual implementation of SupervisedUserRegistrationUtility.
46 class SupervisedUserRegistrationUtilityImpl 47 class SupervisedUserRegistrationUtilityImpl
47 : public SupervisedUserRegistrationUtility, 48 : public SupervisedUserRegistrationUtility,
48 public SupervisedUserSyncServiceObserver { 49 public SupervisedUserSyncServiceObserver {
49 public: 50 public:
50 SupervisedUserRegistrationUtilityImpl( 51 SupervisedUserRegistrationUtilityImpl(
51 PrefService* prefs, 52 PrefService* prefs,
52 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, 53 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher,
53 SupervisedUserSyncService* service, 54 SupervisedUserSyncService* service,
54 SupervisedUserSharedSettingsService* shared_settings_service); 55 SupervisedUserSharedSettingsService* shared_settings_service);
55 56
56 ~SupervisedUserRegistrationUtilityImpl() override; 57 ~SupervisedUserRegistrationUtilityImpl() override;
57 58
58 // Registers a new supervised user with the server. |supervised_user_id| is a 59 // Registers a new supervised user with the server. |supervised_user_id| is a
59 // new unique ID for the new supervised user. If its value is the same as that 60 // new unique ID for the new supervised user. If its value is the same as that
60 // of one of the existing supervised users, then the same user will be created 61 // of one of the existing supervised users, then the same user will be created
61 // on this machine (and if he has no avatar in sync, his avatar will be 62 // on this machine (and if he has no avatar in sync, his avatar will be
62 // updated). |info| contains necessary information like the display name of 63 // updated). |info| contains necessary information like the display name of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 // Cancels any registration currently in progress, without calling the 99 // Cancels any registration currently in progress, without calling the
99 // callback or reporting an error. 100 // callback or reporting an error.
100 void CancelPendingRegistration(); 101 void CancelPendingRegistration();
101 102
102 // SupervisedUserSharedSettingsUpdate acknowledgment callback for password 103 // SupervisedUserSharedSettingsUpdate acknowledgment callback for password
103 // data in shared settings. 104 // data in shared settings.
104 void OnPasswordChangeAcknowledged(bool success); 105 void OnPasswordChangeAcknowledged(bool success);
105 106
106 PrefService* prefs_; 107 PrefService* prefs_;
107 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher_; 108 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher_;
108 109
109 // A |KeyedService| owned by the custodian profile. 110 // A |KeyedService| owned by the custodian profile.
110 SupervisedUserSyncService* supervised_user_sync_service_; 111 SupervisedUserSyncService* supervised_user_sync_service_;
111 112
112 // A |KeyedService| owned by the custodian profile. 113 // A |KeyedService| owned by the custodian profile.
113 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service_; 114 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service_;
114 115
115 std::string pending_supervised_user_id_; 116 std::string pending_supervised_user_id_;
116 std::string pending_supervised_user_token_; 117 std::string pending_supervised_user_token_;
117 bool pending_supervised_user_acknowledged_; 118 bool pending_supervised_user_acknowledged_;
118 bool is_existing_supervised_user_; 119 bool is_existing_supervised_user_;
119 bool avatar_updated_; 120 bool avatar_updated_;
120 RegistrationCallback callback_; 121 RegistrationCallback callback_;
121 scoped_ptr<SupervisedUserSharedSettingsUpdate> password_update_; 122 std::unique_ptr<SupervisedUserSharedSettingsUpdate> password_update_;
122 123
123 base::WeakPtrFactory<SupervisedUserRegistrationUtilityImpl> weak_ptr_factory_; 124 base::WeakPtrFactory<SupervisedUserRegistrationUtilityImpl> weak_ptr_factory_;
124 125
125 DISALLOW_COPY_AND_ASSIGN(SupervisedUserRegistrationUtilityImpl); 126 DISALLOW_COPY_AND_ASSIGN(SupervisedUserRegistrationUtilityImpl);
126 }; 127 };
127 128
128 } // namespace 129 } // namespace
129 130
130 SupervisedUserRegistrationInfo::SupervisedUserRegistrationInfo( 131 SupervisedUserRegistrationInfo::SupervisedUserRegistrationInfo(
131 const base::string16& name, 132 const base::string16& name,
132 int avatar_index) 133 int avatar_index)
133 : avatar_index(avatar_index), 134 : avatar_index(avatar_index),
134 name(name) { 135 name(name) {
135 } 136 }
136 137
137 SupervisedUserRegistrationInfo::~SupervisedUserRegistrationInfo() {} 138 SupervisedUserRegistrationInfo::~SupervisedUserRegistrationInfo() {}
138 139
139 ScopedTestingSupervisedUserRegistrationUtility:: 140 ScopedTestingSupervisedUserRegistrationUtility::
140 ScopedTestingSupervisedUserRegistrationUtility( 141 ScopedTestingSupervisedUserRegistrationUtility(
141 SupervisedUserRegistrationUtility* instance) { 142 SupervisedUserRegistrationUtility* instance) {
142 SupervisedUserRegistrationUtility::SetUtilityForTests(instance); 143 SupervisedUserRegistrationUtility::SetUtilityForTests(instance);
143 } 144 }
144 145
145 ScopedTestingSupervisedUserRegistrationUtility:: 146 ScopedTestingSupervisedUserRegistrationUtility::
146 ~ScopedTestingSupervisedUserRegistrationUtility() { 147 ~ScopedTestingSupervisedUserRegistrationUtility() {
147 SupervisedUserRegistrationUtility::SetUtilityForTests(NULL); 148 SupervisedUserRegistrationUtility::SetUtilityForTests(NULL);
148 } 149 }
149 150
150 // static 151 // static
151 scoped_ptr<SupervisedUserRegistrationUtility> 152 std::unique_ptr<SupervisedUserRegistrationUtility>
152 SupervisedUserRegistrationUtility::Create(Profile* profile) { 153 SupervisedUserRegistrationUtility::Create(Profile* profile) {
153 if (g_instance_for_tests) { 154 if (g_instance_for_tests) {
154 SupervisedUserRegistrationUtility* result = g_instance_for_tests; 155 SupervisedUserRegistrationUtility* result = g_instance_for_tests;
155 g_instance_for_tests = NULL; 156 g_instance_for_tests = NULL;
156 return make_scoped_ptr(result); 157 return base::WrapUnique(result);
157 } 158 }
158 159
159 ProfileOAuth2TokenService* token_service = 160 ProfileOAuth2TokenService* token_service =
160 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 161 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
161 SigninManagerBase* signin_manager = 162 SigninManagerBase* signin_manager =
162 SigninManagerFactory::GetForProfile(profile); 163 SigninManagerFactory::GetForProfile(profile);
163 SigninClient* signin_client = 164 SigninClient* signin_client =
164 ChromeSigninClientFactory::GetForProfile(profile); 165 ChromeSigninClientFactory::GetForProfile(profile);
165 std::string signin_scoped_device_id = 166 std::string signin_scoped_device_id =
166 signin_client->GetSigninScopedDeviceId(); 167 signin_client->GetSigninScopedDeviceId();
167 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher = 168 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher =
168 SupervisedUserRefreshTokenFetcher::Create( 169 SupervisedUserRefreshTokenFetcher::Create(
169 token_service, 170 token_service, signin_manager->GetAuthenticatedAccountId(),
170 signin_manager->GetAuthenticatedAccountId(), 171 signin_scoped_device_id, profile->GetRequestContext());
171 signin_scoped_device_id,
172 profile->GetRequestContext());
173 SupervisedUserSyncService* supervised_user_sync_service = 172 SupervisedUserSyncService* supervised_user_sync_service =
174 SupervisedUserSyncServiceFactory::GetForProfile(profile); 173 SupervisedUserSyncServiceFactory::GetForProfile(profile);
175 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service = 174 SupervisedUserSharedSettingsService* supervised_user_shared_settings_service =
176 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); 175 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile);
177 return make_scoped_ptr(SupervisedUserRegistrationUtility::CreateImpl( 176 return base::WrapUnique(SupervisedUserRegistrationUtility::CreateImpl(
178 profile->GetPrefs(), std::move(token_fetcher), 177 profile->GetPrefs(), std::move(token_fetcher),
179 supervised_user_sync_service, supervised_user_shared_settings_service)); 178 supervised_user_sync_service, supervised_user_shared_settings_service));
180 } 179 }
181 180
182 // static 181 // static
183 std::string SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId() { 182 std::string SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId() {
184 std::string new_supervised_user_id; 183 std::string new_supervised_user_id;
185 base::Base64Encode(base::RandBytesAsString(8), &new_supervised_user_id); 184 base::Base64Encode(base::RandBytesAsString(8), &new_supervised_user_id);
186 return new_supervised_user_id; 185 return new_supervised_user_id;
187 } 186 }
188 187
189 // static 188 // static
190 void SupervisedUserRegistrationUtility::SetUtilityForTests( 189 void SupervisedUserRegistrationUtility::SetUtilityForTests(
191 SupervisedUserRegistrationUtility* utility) { 190 SupervisedUserRegistrationUtility* utility) {
192 if (g_instance_for_tests) 191 if (g_instance_for_tests)
193 delete g_instance_for_tests; 192 delete g_instance_for_tests;
194 g_instance_for_tests = utility; 193 g_instance_for_tests = utility;
195 } 194 }
196 195
197 // static 196 // static
198 SupervisedUserRegistrationUtility* 197 SupervisedUserRegistrationUtility*
199 SupervisedUserRegistrationUtility::CreateImpl( 198 SupervisedUserRegistrationUtility::CreateImpl(
200 PrefService* prefs, 199 PrefService* prefs,
201 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, 200 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher,
202 SupervisedUserSyncService* service, 201 SupervisedUserSyncService* service,
203 SupervisedUserSharedSettingsService* shared_settings_service) { 202 SupervisedUserSharedSettingsService* shared_settings_service) {
204 return new SupervisedUserRegistrationUtilityImpl( 203 return new SupervisedUserRegistrationUtilityImpl(
205 prefs, std::move(token_fetcher), service, shared_settings_service); 204 prefs, std::move(token_fetcher), service, shared_settings_service);
206 } 205 }
207 206
208 namespace { 207 namespace {
209 208
210 SupervisedUserRegistrationUtilityImpl::SupervisedUserRegistrationUtilityImpl( 209 SupervisedUserRegistrationUtilityImpl::SupervisedUserRegistrationUtilityImpl(
211 PrefService* prefs, 210 PrefService* prefs,
212 scoped_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher, 211 std::unique_ptr<SupervisedUserRefreshTokenFetcher> token_fetcher,
213 SupervisedUserSyncService* service, 212 SupervisedUserSyncService* service,
214 SupervisedUserSharedSettingsService* shared_settings_service) 213 SupervisedUserSharedSettingsService* shared_settings_service)
215 : prefs_(prefs), 214 : prefs_(prefs),
216 token_fetcher_(std::move(token_fetcher)), 215 token_fetcher_(std::move(token_fetcher)),
217 supervised_user_sync_service_(service), 216 supervised_user_sync_service_(service),
218 supervised_user_shared_settings_service_(shared_settings_service), 217 supervised_user_shared_settings_service_(shared_settings_service),
219 pending_supervised_user_acknowledged_(false), 218 pending_supervised_user_acknowledged_(false),
220 is_existing_supervised_user_(false), 219 is_existing_supervised_user_(false),
221 avatar_updated_(false), 220 avatar_updated_(false),
222 weak_ptr_factory_(this) { 221 weak_ptr_factory_(this) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 #if defined(OS_CHROMEOS) 287 #if defined(OS_CHROMEOS)
289 const char* kAvatarKey = supervised_users::kChromeOSAvatarIndex; 288 const char* kAvatarKey = supervised_users::kChromeOSAvatarIndex;
290 #else 289 #else
291 const char* kAvatarKey = supervised_users::kChromeAvatarIndex; 290 const char* kAvatarKey = supervised_users::kChromeAvatarIndex;
292 #endif 291 #endif
293 supervised_user_shared_settings_service_->SetValue( 292 supervised_user_shared_settings_service_->SetValue(
294 pending_supervised_user_id_, kAvatarKey, 293 pending_supervised_user_id_, kAvatarKey,
295 base::FundamentalValue(info.avatar_index)); 294 base::FundamentalValue(info.avatar_index));
296 if (need_password_update) { 295 if (need_password_update) {
297 password_update_.reset(new SupervisedUserSharedSettingsUpdate( 296 password_update_.reset(new SupervisedUserSharedSettingsUpdate(
298 supervised_user_shared_settings_service_, 297 supervised_user_shared_settings_service_, pending_supervised_user_id_,
299 pending_supervised_user_id_,
300 supervised_users::kChromeOSPasswordData, 298 supervised_users::kChromeOSPasswordData,
301 scoped_ptr<base::Value>(info.password_data.DeepCopy()), 299 std::unique_ptr<base::Value>(info.password_data.DeepCopy()),
302 base::Bind( 300 base::Bind(&SupervisedUserRegistrationUtilityImpl::
303 &SupervisedUserRegistrationUtilityImpl:: 301 OnPasswordChangeAcknowledged,
304 OnPasswordChangeAcknowledged, 302 weak_ptr_factory_.GetWeakPtr())));
305 weak_ptr_factory_.GetWeakPtr())));
306 } 303 }
307 304
308 syncer::GetSessionName( 305 syncer::GetSessionName(
309 content::BrowserThread::GetBlockingPool() 306 content::BrowserThread::GetBlockingPool()
310 ->GetTaskRunnerWithShutdownBehavior( 307 ->GetTaskRunnerWithShutdownBehavior(
311 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN).get(), 308 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN).get(),
312 base::Bind(&SupervisedUserRegistrationUtilityImpl::FetchToken, 309 base::Bind(&SupervisedUserRegistrationUtilityImpl::FetchToken,
313 weak_ptr_factory_.GetWeakPtr())); 310 weak_ptr_factory_.GetWeakPtr()));
314 } 311 }
315 312
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 pending_supervised_user_id_); 407 pending_supervised_user_id_);
411 } 408 }
412 } 409 }
413 410
414 if (run_callback) 411 if (run_callback)
415 callback_.Run(error, pending_supervised_user_token_); 412 callback_.Run(error, pending_supervised_user_token_);
416 callback_.Reset(); 413 callback_.Reset();
417 } 414 }
418 415
419 } // namespace 416 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698