| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 12 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 13 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 13 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 14 #include "chrome/browser/chromeos/arc/auth/arc_active_directory_enrollment_token
_fetcher.h" | 14 #include "chrome/browser/chromeos/arc/auth/arc_active_directory_enrollment_token
_fetcher.h" |
| 15 #include "chrome/browser/chromeos/arc/auth/arc_auth_info_fetcher.h" | |
| 16 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h" | 15 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h" |
| 17 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h" | 16 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h" |
| 18 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h" | 17 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h" |
| 19 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 18 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/lifetime/application_lifetime.h" | 20 #include "chrome/browser/lifetime/application_lifetime.h" |
| 22 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 23 #include "components/arc/arc_bridge_service.h" | 22 #include "components/arc/arc_bridge_service.h" |
| 24 #include "components/arc/arc_features.h" | 23 #include "components/arc/arc_features.h" |
| 25 #include "components/arc/arc_util.h" | 24 #include "components/arc/arc_util.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // IsArcKioskMode() is true. Both cases are handled above. | 282 // IsArcKioskMode() is true. Both cases are handled above. |
| 284 fetcher_ = base::MakeUnique<ArcManualAuthCodeFetcher>( | 283 fetcher_ = base::MakeUnique<ArcManualAuthCodeFetcher>( |
| 285 ArcSessionManager::Get()->auth_context(), | 284 ArcSessionManager::Get()->auth_context(), |
| 286 ArcSessionManager::Get()->support_host()); | 285 ArcSessionManager::Get()->support_host()); |
| 287 } | 286 } |
| 288 fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched, | 287 fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched, |
| 289 weak_ptr_factory_.GetWeakPtr())); | 288 weak_ptr_factory_.GetWeakPtr())); |
| 290 } | 289 } |
| 291 | 290 |
| 292 void ArcAuthService::OnEnrollmentTokenFetched( | 291 void ArcAuthService::OnEnrollmentTokenFetched( |
| 292 ArcAuthInfoFetcher::Status status, |
| 293 const std::string& enrollment_token) { | 293 const std::string& enrollment_token) { |
| 294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 295 fetcher_.reset(); | 295 fetcher_.reset(); |
| 296 | 296 |
| 297 if (enrollment_token.empty()) { | 297 switch (status) { |
| 298 case ArcAuthInfoFetcher::Status::SUCCESS: |
| 299 notifier_->Notify(true /*is_enforced*/, enrollment_token, |
| 300 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT, |
| 301 true); |
| 302 notifier_.reset(); |
| 303 return; |
| 304 case ArcAuthInfoFetcher::Status::FAILURE: |
| 305 ArcSessionManager::Get()->OnProvisioningFinished( |
| 306 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 307 return; |
| 308 case ArcAuthInfoFetcher::Status::ARC_DISABLED: |
| 309 ArcSessionManager::Get()->OnProvisioningFinished( |
| 310 ProvisioningResult::ARC_DISABLED); |
| 311 return; |
| 312 } |
| 313 } |
| 314 |
| 315 void ArcAuthService::OnAuthCodeFetched(ArcAuthInfoFetcher::Status status, |
| 316 const std::string& auth_code) { |
| 317 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 318 fetcher_.reset(); |
| 319 |
| 320 if (status != ArcAuthInfoFetcher::Status::SUCCESS) { |
| 298 ArcSessionManager::Get()->OnProvisioningFinished( | 321 ArcSessionManager::Get()->OnProvisioningFinished( |
| 299 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 322 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 300 return; | 323 return; |
| 301 } | |
| 302 | |
| 303 notifier_->Notify(true /*is_enforced*/, enrollment_token, | |
| 304 mojom::ChromeAccountType::ACTIVE_DIRECTORY_ACCOUNT, true); | |
| 305 notifier_.reset(); | |
| 306 } | |
| 307 | |
| 308 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) { | |
| 309 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 310 fetcher_.reset(); | |
| 311 | |
| 312 if (auth_code.empty()) { | |
| 313 ArcSessionManager::Get()->OnProvisioningFinished( | |
| 314 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | |
| 315 return; | |
| 316 } | 324 } |
| 317 | 325 |
| 318 notifier_->Notify( | 326 notifier_->Notify( |
| 319 !IsArcOptInVerificationDisabled(), auth_code, GetAccountType(), | 327 !IsArcOptInVerificationDisabled(), auth_code, GetAccountType(), |
| 320 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); | 328 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); |
| 321 notifier_.reset(); | 329 notifier_.reset(); |
| 322 } | 330 } |
| 323 | 331 |
| 324 } // namespace arc | 332 } // namespace arc |
| OLD | NEW |