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 // Ignore redundant data removal request. | |
210 if (data_removal_in_progress_) | |
hidehiko
2016/12/02 08:54:55
So this is state management. Could you add a new S
khmel
2016/12/06 03:23:57
Good idea, done.
| |
211 return; | |
212 | |
213 // OnArcDataRemoved resets this flag. | |
214 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); | |
215 | |
208 if (!arc_bridge_service()->stopped()) { | 216 if (!arc_bridge_service()->stopped()) { |
209 // Just set a flag. On bridge stopped, this will be re-called, | 217 // Just set a flag. On bridge stopped, this will be re-called, |
210 // then session manager should remove the data. | 218 // then session manager should remove the data. |
211 clear_required_ = true; | |
212 return; | 219 return; |
213 } | 220 } |
214 clear_required_ = false; | 221 |
222 data_removal_in_progress_ = true; | |
215 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 223 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
216 cryptohome::Identification( | 224 cryptohome::Identification( |
217 multi_user_util::GetAccountIdFromProfile(profile_)), | 225 multi_user_util::GetAccountIdFromProfile(profile_)), |
218 base::Bind(&ArcSessionManager::OnArcDataRemoved, | 226 base::Bind(&ArcSessionManager::OnArcDataRemoved, |
219 weak_ptr_factory_.GetWeakPtr())); | 227 weak_ptr_factory_.GetWeakPtr())); |
220 } | 228 } |
221 | 229 |
222 void ArcSessionManager::OnArcDataRemoved(bool success) { | 230 void ArcSessionManager::OnArcDataRemoved(bool success) { |
223 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; | 231 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; |
224 | 232 |
233 data_removal_in_progress_ = false; | |
234 | |
235 // In case data removal completed between shutdown and deleting this manager. | |
236 // It happens at least in browser tests. | |
237 if (IsAllowed()) | |
hidehiko
2016/12/02 08:54:55
Hmm, ok. So this check is only for browser_test, r
khmel
2016/12/06 03:23:57
Done.
| |
238 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); | |
239 | |
225 // Here check if |reenable_arc_| is marked or not. | 240 // Here check if |reenable_arc_| is marked or not. |
226 // The only case this happens should be in the special case for enterprise | 241 // The only case this happens should be in the special case for enterprise |
227 // "on managed lost" case. In that case, OnBridgeStopped() should trigger | 242 // "on managed lost" case. In that case, OnBridgeStopped() should trigger |
228 // the RemoveArcData(), then this. | 243 // the RemoveArcData(), then this. |
229 // TODO(hidehiko): Restructure the code. | 244 // TODO(hidehiko): Restructure the code. |
230 if (!reenable_arc_) | 245 if (!reenable_arc_ || !IsArcEnabled()) |
231 return; | 246 return; |
232 | 247 |
233 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 248 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
234 // the ARC user data wipe is still required or not. | 249 // the ARC user data wipe is still required or not. |
235 reenable_arc_ = false; | 250 reenable_arc_ = false; |
236 VLOG(1) << "Reenable ARC"; | 251 VLOG(1) << "Reenable ARC"; |
237 EnableArc(); | 252 EnableArc(); |
238 } | 253 } |
239 | 254 |
240 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { | 255 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { |
(...skipping 13 matching lines...) Expand all Loading... | |
254 UpdateProvisioningResultUMA(result, | 269 UpdateProvisioningResultUMA(result, |
255 policy_util::IsAccountManaged(profile_)); | 270 policy_util::IsAccountManaged(profile_)); |
256 if (result != ProvisioningResult::SUCCESS) | 271 if (result != ProvisioningResult::SUCCESS) |
257 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); | 272 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); |
258 } | 273 } |
259 | 274 |
260 if (result == ProvisioningResult::SUCCESS) { | 275 if (result == ProvisioningResult::SUCCESS) { |
261 if (support_host_) | 276 if (support_host_) |
262 support_host_->Close(); | 277 support_host_->Close(); |
263 | 278 |
279 // No data removal request is expected on Arc boot. | |
hidehiko
2016/12/02 08:54:55
It is still unclear to me why this is guaranteed.
khmel
2016/12/06 03:23:57
ReportManagementState(MANAGED_DO_LOST) calls 2 fun
hidehiko
2016/12/06 05:05:30
Oh, good catch! So, the DCHECK above is wrong...
C
khmel
2016/12/06 18:16:12
Done.
| |
280 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
281 | |
264 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | 282 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) |
265 return; | 283 return; |
266 | 284 |
267 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); | 285 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); |
268 // Don't show Play Store app for ARC Kiosk because the only one UI in kiosk | 286 // 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. | 287 // mode must be the kiosk app and device is not needed for opt-in. |
270 if (!IsOptInVerificationDisabled() && !IsArcKioskMode()) { | 288 if (!IsOptInVerificationDisabled() && !IsArcKioskMode()) { |
271 playstore_launcher_.reset( | 289 playstore_launcher_.reset( |
272 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); | 290 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); |
273 } | 291 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 494 |
477 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. | 495 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. |
478 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); | 496 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); |
479 | 497 |
480 const bool arc_enabled = IsArcEnabled(); | 498 const bool arc_enabled = IsArcEnabled(); |
481 for (auto& observer : observer_list_) | 499 for (auto& observer : observer_list_) |
482 observer.OnOptInEnabled(arc_enabled); | 500 observer.OnOptInEnabled(arc_enabled); |
483 | 501 |
484 if (!arc_enabled) { | 502 if (!arc_enabled) { |
485 StopArc(); | 503 StopArc(); |
504 // Reset any pending request to re-enable Arc. | |
505 reenable_arc_ = false; | |
486 RemoveArcData(); | 506 RemoveArcData(); |
487 return; | 507 return; |
488 } | 508 } |
489 | 509 |
490 if (state_ == State::ACTIVE) | 510 if (state_ == State::ACTIVE) |
491 return; | 511 return; |
492 | 512 |
493 if (support_host_) | 513 if (support_host_) |
494 support_host_->SetArcManaged(IsArcManaged()); | 514 support_host_->SetArcManaged(IsArcManaged()); |
495 | 515 |
516 // Don't start ARC if there is a pending request to remove the data. Restart | |
hidehiko
2016/12/02 08:54:55
I still think this is a part of OnPrimaryUserProfi
khmel
2016/12/06 03:23:57
I refactored this code based on state we introduce
hidehiko
2016/12/06 05:05:30
Nice!
khmel
2016/12/06 18:16:12
Acknowledged.
| |
517 // ARC once data removal finishes. | |
518 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | |
519 reenable_arc_ = true; | |
520 RemoveArcData(); | |
521 return; | |
522 } | |
523 | |
496 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we | 524 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we |
497 // skip ToS because it is very likely that near the device there will be | 525 // skip ToS because it is very likely that near the device there will be |
498 // no one who is eligible to accept them. We skip if Android management check | 526 // no one who is eligible to accept them. We skip if Android management check |
499 // because there are no managed human users for Kiosk exist. | 527 // because there are no managed human users for Kiosk exist. |
500 if (IsOptInVerificationDisabled() || IsArcKioskMode()) { | 528 if (IsOptInVerificationDisabled() || IsArcKioskMode()) { |
501 // Automatically accept terms in kiosk mode. This is not required for | 529 // Automatically accept terms in kiosk mode. This is not required for |
502 // IsOptInVerificationDisabled mode because in last case it may cause | 530 // IsOptInVerificationDisabled mode because in last case it may cause |
503 // a privacy issue on next run without this flag set. | 531 // a privacy issue on next run without this flag set. |
504 if (IsArcKioskMode()) | 532 if (IsArcKioskMode()) |
505 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 533 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 // TODO(hidehiko): Remove this. | 586 // TODO(hidehiko): Remove this. |
559 void ArcSessionManager::StopAndEnableArc() { | 587 void ArcSessionManager::StopAndEnableArc() { |
560 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 588 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
561 DCHECK(!arc_bridge_service()->stopped()); | 589 DCHECK(!arc_bridge_service()->stopped()); |
562 reenable_arc_ = true; | 590 reenable_arc_ = true; |
563 StopArc(); | 591 StopArc(); |
564 } | 592 } |
565 | 593 |
566 void ArcSessionManager::StartArc() { | 594 void ArcSessionManager::StartArc() { |
567 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 595 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
596 | |
597 // Arc must be started only if no pending data removal request exists. | |
598 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
599 | |
568 arc_bridge_service()->RequestStart(); | 600 arc_bridge_service()->RequestStart(); |
569 SetState(State::ACTIVE); | 601 SetState(State::ACTIVE); |
570 } | 602 } |
571 | 603 |
572 void ArcSessionManager::OnArcSignInTimeout() { | 604 void ArcSessionManager::OnArcSignInTimeout() { |
573 LOG(ERROR) << "Timed out waiting for first sign in."; | 605 LOG(ERROR) << "Timed out waiting for first sign in."; |
574 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 606 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
575 } | 607 } |
576 | 608 |
577 void ArcSessionManager::CancelAuthCode() { | 609 void ArcSessionManager::CancelAuthCode() { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 return os << "ACTIVE"; | 858 return os << "ACTIVE"; |
827 } | 859 } |
828 | 860 |
829 // Some compiler reports an error even if all values of an enum-class are | 861 // Some compiler reports an error even if all values of an enum-class are |
830 // covered indivisually in a switch statement. | 862 // covered indivisually in a switch statement. |
831 NOTREACHED(); | 863 NOTREACHED(); |
832 return os; | 864 return os; |
833 } | 865 } |
834 | 866 |
835 } // namespace arc | 867 } // namespace arc |
OLD | NEW |