OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/arc/arc_auth_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback) | 83 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback) |
84 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT), | 84 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT), |
85 auth_account_callback_(auth_account_callback) {} | 85 auth_account_callback_(auth_account_callback) {} |
86 | 86 |
87 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback) | 87 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback) |
88 : callback_type_(CallbackType::ACCOUNT_INFO), | 88 : callback_type_(CallbackType::ACCOUNT_INFO), |
89 account_info_callback_(account_info_callback) {} | 89 account_info_callback_(account_info_callback) {} |
90 | 90 |
91 void Notify(bool is_enforced, | 91 void Notify(bool is_enforced, |
92 const std::string& auth_info, | 92 const std::string& auth_info, |
93 const std::string& account_name, | |
93 mojom::ChromeAccountType account_type, | 94 mojom::ChromeAccountType account_type, |
94 bool is_managed) { | 95 bool is_managed) { |
95 switch (callback_type_) { | 96 switch (callback_type_) { |
96 case CallbackType::AUTH_CODE: | 97 case CallbackType::AUTH_CODE: |
97 DCHECK(!auth_callback_.is_null()); | 98 DCHECK(!auth_callback_.is_null()); |
98 auth_callback_.Run(auth_info, is_enforced); | 99 auth_callback_.Run(auth_info, is_enforced); |
99 break; | 100 break; |
100 case CallbackType::AUTH_CODE_AND_ACCOUNT: | 101 case CallbackType::AUTH_CODE_AND_ACCOUNT: |
101 DCHECK(!auth_account_callback_.is_null()); | 102 DCHECK(!auth_account_callback_.is_null()); |
102 auth_account_callback_.Run(auth_info, is_enforced, account_type); | 103 auth_account_callback_.Run(auth_info, is_enforced, account_type); |
103 break; | 104 break; |
104 case CallbackType::ACCOUNT_INFO: | 105 case CallbackType::ACCOUNT_INFO: |
105 DCHECK(!account_info_callback_.is_null()); | 106 DCHECK(!account_info_callback_.is_null()); |
106 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New(); | 107 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New(); |
108 account_info->account_name = account_name; | |
107 if (account_type == | 109 if (account_type == |
108 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT) { | 110 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT) { |
109 account_info->enrollment_token = auth_info; | 111 account_info->enrollment_token = auth_info; |
110 } else { | 112 } else { |
111 if (!is_enforced) | 113 if (!is_enforced) |
112 account_info->auth_code = base::nullopt; | 114 account_info->auth_code = base::nullopt; |
113 else | 115 else |
114 account_info->auth_code = auth_info; | 116 account_info->auth_code = auth_info; |
115 } | 117 } |
116 account_info->account_type = account_type; | 118 account_info->account_type = account_type; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 UpdateAuthCheckinAttempts(value); | 190 UpdateAuthCheckinAttempts(value); |
189 break; | 191 break; |
190 case mojom::MetricsType::CHECKIN_TIME_MILLISECONDS: | 192 case mojom::MetricsType::CHECKIN_TIME_MILLISECONDS: |
191 UpdateAuthTiming("ArcAuth.CheckinTime", | 193 UpdateAuthTiming("ArcAuth.CheckinTime", |
192 base::TimeDelta::FromMilliseconds(value)); | 194 base::TimeDelta::FromMilliseconds(value)); |
193 break; | 195 break; |
194 case mojom::MetricsType::SIGNIN_TIME_MILLISECONDS: | 196 case mojom::MetricsType::SIGNIN_TIME_MILLISECONDS: |
195 UpdateAuthTiming("ArcAuth.SignInTime", | 197 UpdateAuthTiming("ArcAuth.SignInTime", |
196 base::TimeDelta::FromMilliseconds(value)); | 198 base::TimeDelta::FromMilliseconds(value)); |
197 break; | 199 break; |
200 case mojom::MetricsType::ACCOUNT_CHECK_MILLISECONDS: | |
201 UpdateAuthTiming("ArcAuth.AccountCheckTime", | |
202 base::TimeDelta::FromMilliseconds(value)); | |
203 break; | |
198 } | 204 } |
199 } | 205 } |
200 | 206 |
207 void ArcAuthService::ReportAccountCheckStatus( | |
208 mojom::AccountCheckStatus status) { | |
209 switch (status) { | |
210 case mojom::AccountCheckStatus::UP_TO_DATE: | |
211 UpdateAuthAccountCheckStatus(AccountCheckStatus::UP_TO_DATE); | |
212 break; | |
213 case mojom::AccountCheckStatus::NEW: | |
214 UpdateAuthAccountCheckStatus(AccountCheckStatus::NEW); | |
215 break; | |
216 case mojom::AccountCheckStatus::NEED_REAUTH: | |
217 UpdateAuthAccountCheckStatus(AccountCheckStatus::NEED_REAUTH); | |
218 break; | |
219 case mojom::AccountCheckStatus::UNKNOWN: | |
220 UpdateAuthAccountCheckStatus(AccountCheckStatus::UNKNOWN); | |
221 break; | |
222 case mojom::AccountCheckStatus::CHECK_FAILED: | |
223 UpdateAuthAccountCheckStatus(AccountCheckStatus::CHECK_FAILED); | |
224 break; | |
225 default: | |
226 NOTREACHED() << "Unknown account check status"; | |
dcheng
2017/03/25 00:55:04
Please typemap this enum instead =)
(Or just use
khmel
2017/03/25 01:24:14
Not sure if I got you correctly. I added << status
| |
227 } | |
228 } | |
229 | |
201 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { | 230 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { |
202 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 231 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
203 auto* instance = ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->auth(), | 232 auto* instance = ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->auth(), |
204 OnAccountInfoReady); | 233 OnAccountInfoReady); |
205 DCHECK(instance); | 234 DCHECK(instance); |
206 instance->OnAccountInfoReady(std::move(account_info)); | 235 instance->OnAccountInfoReady(std::move(account_info)); |
207 } | 236 } |
208 | 237 |
209 void ArcAuthService::GetAuthCodeDeprecated0( | 238 void ArcAuthService::GetAuthCodeDeprecated0( |
210 const GetAuthCodeDeprecated0Callback& callback) { | 239 const GetAuthCodeDeprecated0Callback& callback) { |
(...skipping 25 matching lines...) Expand all Loading... | |
236 | 265 |
237 void ArcAuthService::RequestAccountInfoInternal( | 266 void ArcAuthService::RequestAccountInfoInternal( |
238 std::unique_ptr<AccountInfoNotifier> notifier) { | 267 std::unique_ptr<AccountInfoNotifier> notifier) { |
239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 268 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
240 // No other auth code-related operation may be in progress. | 269 // No other auth code-related operation may be in progress. |
241 DCHECK(!notifier_); | 270 DCHECK(!notifier_); |
242 DCHECK(!fetcher_); | 271 DCHECK(!fetcher_); |
243 | 272 |
244 if (IsArcOptInVerificationDisabled()) { | 273 if (IsArcOptInVerificationDisabled()) { |
245 notifier->Notify( | 274 notifier->Notify( |
246 false /* = is_enforced */, std::string(), GetAccountType(), | 275 false /* = is_enforced */, std::string() /* auth_info */, |
276 std::string() /* auth_name */, GetAccountType(), | |
247 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); | 277 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); |
248 return; | 278 return; |
249 } | 279 } |
250 | 280 |
251 // Hereafter asynchronous operation. Remember the notifier. | 281 // Hereafter asynchronous operation. Remember the notifier. |
252 notifier_ = std::move(notifier); | 282 notifier_ = std::move(notifier); |
253 | 283 |
254 Profile* profile = ArcSessionManager::Get()->profile(); | 284 Profile* profile = ArcSessionManager::Get()->profile(); |
255 const user_manager::User* user = nullptr; | 285 const user_manager::User* user = nullptr; |
256 if (profile) | 286 if (profile) |
257 user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 287 user = chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
288 | |
258 if (user && user->IsActiveDirectoryUser()) { | 289 if (user && user->IsActiveDirectoryUser()) { |
259 // For Active Directory enrolled devices, we get an enrollment token for a | 290 // For Active Directory enrolled devices, we get an enrollment token for a |
260 // managed Google Play account from DMServer. | 291 // managed Google Play account from DMServer. |
261 fetcher_ = base::MakeUnique<ArcActiveDirectoryEnrollmentTokenFetcher>(); | 292 fetcher_ = base::MakeUnique<ArcActiveDirectoryEnrollmentTokenFetcher>(); |
262 fetcher_->Fetch(base::Bind(&ArcAuthService::OnEnrollmentTokenFetched, | 293 fetcher_->Fetch(base::Bind(&ArcAuthService::OnEnrollmentTokenFetched, |
263 weak_ptr_factory_.GetWeakPtr())); | 294 weak_ptr_factory_.GetWeakPtr())); |
264 return; | 295 return; |
265 } | 296 } |
266 // For non-AD enrolled devices an auth code is fetched. | 297 // For non-AD enrolled devices an auth code is fetched. |
267 if (IsArcKioskMode()) { | 298 if (IsArcKioskMode()) { |
(...skipping 22 matching lines...) Expand all Loading... | |
290 | 321 |
291 void ArcAuthService::OnEnrollmentTokenFetched( | 322 void ArcAuthService::OnEnrollmentTokenFetched( |
292 ArcAuthInfoFetcher::Status status, | 323 ArcAuthInfoFetcher::Status status, |
293 const std::string& enrollment_token) { | 324 const std::string& enrollment_token) { |
294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 325 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
295 fetcher_.reset(); | 326 fetcher_.reset(); |
296 | 327 |
297 switch (status) { | 328 switch (status) { |
298 case ArcAuthInfoFetcher::Status::SUCCESS: | 329 case ArcAuthInfoFetcher::Status::SUCCESS: |
299 notifier_->Notify(true /*is_enforced*/, enrollment_token, | 330 notifier_->Notify(true /*is_enforced*/, enrollment_token, |
331 std::string() /* account_name */, | |
300 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT, | 332 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT, |
301 true); | 333 true); |
302 notifier_.reset(); | 334 notifier_.reset(); |
303 return; | 335 return; |
304 case ArcAuthInfoFetcher::Status::FAILURE: | 336 case ArcAuthInfoFetcher::Status::FAILURE: |
305 ArcSessionManager::Get()->OnProvisioningFinished( | 337 ArcSessionManager::Get()->OnProvisioningFinished( |
306 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 338 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
307 return; | 339 return; |
308 case ArcAuthInfoFetcher::Status::ARC_DISABLED: | 340 case ArcAuthInfoFetcher::Status::ARC_DISABLED: |
309 ArcSessionManager::Get()->OnProvisioningFinished( | 341 ArcSessionManager::Get()->OnProvisioningFinished( |
310 ProvisioningResult::ARC_DISABLED); | 342 ProvisioningResult::ARC_DISABLED); |
311 return; | 343 return; |
312 } | 344 } |
313 } | 345 } |
314 | 346 |
315 void ArcAuthService::OnAuthCodeFetched(ArcAuthInfoFetcher::Status status, | 347 void ArcAuthService::OnAuthCodeFetched(ArcAuthInfoFetcher::Status status, |
316 const std::string& auth_code) { | 348 const std::string& auth_code) { |
317 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 349 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
318 fetcher_.reset(); | 350 fetcher_.reset(); |
319 | 351 |
320 if (status != ArcAuthInfoFetcher::Status::SUCCESS) { | 352 if (status != ArcAuthInfoFetcher::Status::SUCCESS) { |
321 ArcSessionManager::Get()->OnProvisioningFinished( | 353 ArcSessionManager::Get()->OnProvisioningFinished( |
322 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 354 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
323 return; | 355 return; |
324 } | 356 } |
325 | 357 |
326 notifier_->Notify( | 358 notifier_->Notify( |
327 !IsArcOptInVerificationDisabled(), auth_code, GetAccountType(), | 359 !IsArcOptInVerificationDisabled(), auth_code, |
360 ArcSessionManager::Get()->auth_context()->full_account_id(), | |
361 GetAccountType(), | |
328 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); | 362 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); |
329 notifier_.reset(); | 363 notifier_.reset(); |
330 } | 364 } |
331 | 365 |
332 } // namespace arc | 366 } // namespace arc |
OLD | NEW |