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/policy/cloud/user_policy_signin_service_mobile.h" | 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_mobile.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 void UserPolicySigninService::ShutdownUserCloudPolicyManager() { | 187 void UserPolicySigninService::ShutdownUserCloudPolicyManager() { |
188 CancelPendingRegistration(); | 188 CancelPendingRegistration(); |
189 UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager(); | 189 UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager(); |
190 } | 190 } |
191 | 191 |
192 void UserPolicySigninService::RegisterCloudPolicyService() { | 192 void UserPolicySigninService::RegisterCloudPolicyService() { |
193 // If the user signed-out while this task was waiting then Shutdown() would | 193 // If the user signed-out while this task was waiting then Shutdown() would |
194 // have been called, which would have invalidated this task. Since we're here | 194 // have been called, which would have invalidated this task. Since we're here |
195 // then the user must still be signed-in. | 195 // then the user must still be signed-in. |
196 const std::string& username = signin_manager()->GetAuthenticatedUsername(); | 196 DCHECK(signin_manager()->IsAuthenticated()); |
197 DCHECK(!username.empty()); | |
198 DCHECK(!policy_manager()->IsClientRegistered()); | 197 DCHECK(!policy_manager()->IsClientRegistered()); |
199 DCHECK(policy_manager()->core()->client()); | 198 DCHECK(policy_manager()->core()->client()); |
200 | 199 |
201 // Persist the current time as the last policy registration attempt time. | 200 // Persist the current time as the last policy registration attempt time. |
202 profile_prefs_->SetInt64(prefs::kLastPolicyCheckTime, | 201 profile_prefs_->SetInt64(prefs::kLastPolicyCheckTime, |
203 base::Time::Now().ToInternalValue()); | 202 base::Time::Now().ToInternalValue()); |
204 | 203 |
205 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( | 204 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( |
206 policy_manager()->core()->client(), | 205 policy_manager()->core()->client(), |
207 GetRegistrationType())); | 206 GetRegistrationType())); |
208 registration_helper_->StartRegistration( | 207 registration_helper_->StartRegistration( |
209 oauth2_token_service_, | 208 oauth2_token_service_, |
210 username, | 209 signin_manager()->GetAuthenticatedUsername(), |
211 base::Bind(&UserPolicySigninService::OnRegistrationDone, | 210 base::Bind(&UserPolicySigninService::OnRegistrationDone, |
212 base::Unretained(this))); | 211 base::Unretained(this))); |
213 } | 212 } |
214 | 213 |
215 void UserPolicySigninService::CancelPendingRegistration() { | 214 void UserPolicySigninService::CancelPendingRegistration() { |
216 weak_factory_.InvalidateWeakPtrs(); | 215 weak_factory_.InvalidateWeakPtrs(); |
217 } | 216 } |
218 | 217 |
219 void UserPolicySigninService::OnRegistrationDone() { | 218 void UserPolicySigninService::OnRegistrationDone() { |
220 registration_helper_.reset(); | 219 registration_helper_.reset(); |
221 } | 220 } |
222 | 221 |
223 } // namespace policy | 222 } // namespace policy |
OLD | NEW |