| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_session_manager.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 ArcSessionManager* ArcSessionManager::Get() { | 103 ArcSessionManager* ArcSessionManager::Get() { |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 105 return g_arc_session_manager; | 105 return g_arc_session_manager; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // static | 108 // static |
| 109 void ArcSessionManager::RegisterProfilePrefs( | 109 void ArcSessionManager::RegisterProfilePrefs( |
| 110 user_prefs::PrefRegistrySyncable* registry) { | 110 user_prefs::PrefRegistrySyncable* registry) { |
| 111 // TODO(dspaid): Implement a mechanism to allow this to sync on first boot | 111 // TODO(dspaid): Implement a mechanism to allow this to sync on first boot |
| 112 // only. | 112 // only. |
| 113 registry->RegisterBooleanPref(prefs::kArcDataRemoveRequested, false); |
| 113 registry->RegisterBooleanPref(prefs::kArcEnabled, false); | 114 registry->RegisterBooleanPref(prefs::kArcEnabled, false); |
| 114 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); | 115 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); |
| 115 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); | 116 registry->RegisterBooleanPref(prefs::kArcTermsAccepted, false); |
| 116 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); | 117 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); |
| 117 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); | 118 registry->RegisterBooleanPref(prefs::kArcLocationServiceEnabled, true); |
| 118 } | 119 } |
| 119 | 120 |
| 120 // static | 121 // static |
| 121 void ArcSessionManager::DisableUIForTesting() { | 122 void ArcSessionManager::DisableUIForTesting() { |
| 122 g_disable_ui_for_testing = true; | 123 g_disable_ui_for_testing = true; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 bool ArcSessionManager::IsArcKioskMode() { | 182 bool ArcSessionManager::IsArcKioskMode() { |
| 182 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); | 183 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void ArcSessionManager::OnBridgeStopped(ArcBridgeService::StopReason reason) { | 186 void ArcSessionManager::OnBridgeStopped(ArcBridgeService::StopReason reason) { |
| 186 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 187 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 187 if (arc_sign_in_timer_.IsRunning()) { | 188 if (arc_sign_in_timer_.IsRunning()) { |
| 188 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 189 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 189 } | 190 } |
| 190 | 191 |
| 191 if (clear_required_) { | 192 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 192 // This should be always true, but just in case as this is looked at | 193 // This should be always true, but just in case as this is looked at |
| 193 // inside RemoveArcData() at first. | 194 // inside RemoveArcData() at first. |
| 194 DCHECK(arc_bridge_service()->stopped()); | 195 DCHECK(arc_bridge_service()->stopped()); |
| 195 RemoveArcData(); | 196 RemoveArcData(); |
| 196 } else { | 197 } else { |
| 197 // To support special "Stop and enable ARC" procedure for enterprise, | 198 // To support special "Stop and enable ARC" procedure for enterprise, |
| 198 // here call OnArcDataRemoved(true) as if the data removal is successfully | 199 // here call OnArcDataRemoved(true) as if the data removal is successfully |
| 199 // done. | 200 // done. |
| 200 // TODO(hidehiko): Restructure the code. crbug.com/665316 | 201 // TODO(hidehiko): Restructure the code. crbug.com/665316 |
| 201 base::ThreadTaskRunnerHandle::Get()->PostTask( | 202 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 202 FROM_HERE, base::Bind(&ArcSessionManager::OnArcDataRemoved, | 203 FROM_HERE, base::Bind(&ArcSessionManager::OnArcDataRemoved, |
| 203 weak_ptr_factory_.GetWeakPtr(), true)); | 204 weak_ptr_factory_.GetWeakPtr(), true)); |
| 204 } | 205 } |
| 205 } | 206 } |
| 206 | 207 |
| 207 void ArcSessionManager::RemoveArcData() { | 208 void ArcSessionManager::RemoveArcData() { |
| 209 // OnArcDataRemoved resets this flag. |
| 210 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 211 |
| 208 if (!arc_bridge_service()->stopped()) { | 212 if (!arc_bridge_service()->stopped()) { |
| 209 // Just set a flag. On bridge stopped, this will be re-called, | 213 // Just set a flag. On bridge stopped, this will be re-called, |
| 210 // then session manager should remove the data. | 214 // then session manager should remove the data. |
| 211 clear_required_ = true; | |
| 212 return; | 215 return; |
| 213 } | 216 } |
| 214 clear_required_ = false; | 217 |
| 215 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 218 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 216 cryptohome::Identification( | 219 cryptohome::Identification( |
| 217 multi_user_util::GetAccountIdFromProfile(profile_)), | 220 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 218 base::Bind(&ArcSessionManager::OnArcDataRemoved, | 221 base::Bind(&ArcSessionManager::OnArcDataRemoved, |
| 219 weak_ptr_factory_.GetWeakPtr())); | 222 weak_ptr_factory_.GetWeakPtr())); |
| 220 } | 223 } |
| 221 | 224 |
| 222 void ArcSessionManager::OnArcDataRemoved(bool success) { | 225 void ArcSessionManager::OnArcDataRemoved(bool success) { |
| 223 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; | 226 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; |
| 224 | 227 |
| 228 // In case data removal completed between shutdown and deleting this manager. |
| 229 // It happens at least in browser tests. |
| 230 if (!IsAllowed()) |
| 231 return; |
| 232 |
| 233 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); |
| 234 |
| 225 // Here check if |reenable_arc_| is marked or not. | 235 // Here check if |reenable_arc_| is marked or not. |
| 226 // The only case this happens should be in the special case for enterprise | 236 // The only case this happens should be in the special case for enterprise |
| 227 // "on managed lost" case. In that case, OnBridgeStopped() should trigger | 237 // "on managed lost" case. In that case, OnBridgeStopped() should trigger |
| 228 // the RemoveArcData(), then this. | 238 // the RemoveArcData(), then this. |
| 229 // TODO(hidehiko): Restructure the code. | 239 // TODO(hidehiko): Restructure the code. |
| 230 if (!reenable_arc_) | 240 if (!reenable_arc_) |
| 231 return; | 241 return; |
| 232 | 242 |
| 233 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 243 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 234 // the ARC user data wipe is still required or not. | 244 // the ARC user data wipe is still required or not. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 254 UpdateProvisioningResultUMA(result, | 264 UpdateProvisioningResultUMA(result, |
| 255 policy_util::IsAccountManaged(profile_)); | 265 policy_util::IsAccountManaged(profile_)); |
| 256 if (result != ProvisioningResult::SUCCESS) | 266 if (result != ProvisioningResult::SUCCESS) |
| 257 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); | 267 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); |
| 258 } | 268 } |
| 259 | 269 |
| 260 if (result == ProvisioningResult::SUCCESS) { | 270 if (result == ProvisioningResult::SUCCESS) { |
| 261 if (support_host_) | 271 if (support_host_) |
| 262 support_host_->Close(); | 272 support_host_->Close(); |
| 263 | 273 |
| 274 // Make sure request to remove data folder is off. |
| 275 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); |
| 276 |
| 264 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | 277 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) |
| 265 return; | 278 return; |
| 266 | 279 |
| 267 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); | 280 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); |
| 268 // Don't show Play Store app for ARC Kiosk because the only one UI in kiosk | 281 // Don't show Play Store app for ARC Kiosk because the only one UI in kiosk |
| 269 // mode must be the kiosk app and device is not needed for opt-in. | 282 // mode must be the kiosk app and device is not needed for opt-in. |
| 270 if (!IsOptInVerificationDisabled() && !IsArcKioskMode()) { | 283 if (!IsOptInVerificationDisabled() && !IsArcKioskMode()) { |
| 271 playstore_launcher_.reset( | 284 playstore_launcher_.reset( |
| 272 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); | 285 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); |
| 273 } | 286 } |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // TODO(hidehiko): Remove this. | 571 // TODO(hidehiko): Remove this. |
| 559 void ArcSessionManager::StopAndEnableArc() { | 572 void ArcSessionManager::StopAndEnableArc() { |
| 560 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 573 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 561 DCHECK(!arc_bridge_service()->stopped()); | 574 DCHECK(!arc_bridge_service()->stopped()); |
| 562 reenable_arc_ = true; | 575 reenable_arc_ = true; |
| 563 StopArc(); | 576 StopArc(); |
| 564 } | 577 } |
| 565 | 578 |
| 566 void ArcSessionManager::StartArc() { | 579 void ArcSessionManager::StartArc() { |
| 567 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 580 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 581 |
| 582 // Don't start ARC if there is a pending request to remove the data. Restart |
| 583 // ARC once data removal finishes. |
| 584 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 585 reenable_arc_ = true; |
| 586 RemoveArcData(); |
| 587 return; |
| 588 } |
| 589 |
| 568 arc_bridge_service()->RequestStart(); | 590 arc_bridge_service()->RequestStart(); |
| 569 SetState(State::ACTIVE); | 591 SetState(State::ACTIVE); |
| 570 } | 592 } |
| 571 | 593 |
| 572 void ArcSessionManager::OnArcSignInTimeout() { | 594 void ArcSessionManager::OnArcSignInTimeout() { |
| 573 LOG(ERROR) << "Timed out waiting for first sign in."; | 595 LOG(ERROR) << "Timed out waiting for first sign in."; |
| 574 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 596 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
| 575 } | 597 } |
| 576 | 598 |
| 577 void ArcSessionManager::CancelAuthCode() { | 599 void ArcSessionManager::CancelAuthCode() { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 return os << "ACTIVE"; | 848 return os << "ACTIVE"; |
| 827 } | 849 } |
| 828 | 850 |
| 829 // Some compiler reports an error even if all values of an enum-class are | 851 // Some compiler reports an error even if all values of an enum-class are |
| 830 // covered indivisually in a switch statement. | 852 // covered indivisually in a switch statement. |
| 831 NOTREACHED(); | 853 NOTREACHED(); |
| 832 return os; | 854 return os; |
| 833 } | 855 } |
| 834 | 856 |
| 835 } // namespace arc | 857 } // namespace arc |
| OLD | NEW |