| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 211 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
| 212 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 212 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 213 if (arc_sign_in_timer_.IsRunning()) | 213 if (arc_sign_in_timer_.IsRunning()) |
| 214 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 214 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 215 | 215 |
| 216 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 216 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 217 // This should be always true, but just in case as this is looked at | 217 // This should be always true, but just in case as this is looked at |
| 218 // inside RemoveArcData() at first. | 218 // inside RemoveArcData() at first. |
| 219 VLOG(1) << "ARC had previously requested to remove user data."; |
| 219 DCHECK(arc_session_runner_->IsStopped()); | 220 DCHECK(arc_session_runner_->IsStopped()); |
| 220 RemoveArcData(); | 221 RemoveArcData(); |
| 221 } else { | 222 } else { |
| 222 // To support special "Stop and enable ARC" procedure for enterprise, | 223 // To support special "Stop and enable ARC" procedure for enterprise, |
| 223 // here call MaybeReenableArc() asyncronously. | 224 // here call MaybeReenableArc() asyncronously. |
| 224 // TODO(hidehiko): Restructure the code. crbug.com/665316 | 225 // TODO(hidehiko): Restructure the code. crbug.com/665316 |
| 225 base::ThreadTaskRunnerHandle::Get()->PostTask( | 226 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 226 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, | 227 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, |
| 227 weak_ptr_factory_.GetWeakPtr())); | 228 weak_ptr_factory_.GetWeakPtr())); |
| 228 } | 229 } |
| 229 | 230 |
| 230 for (auto& observer : arc_session_observer_list_) | 231 for (auto& observer : arc_session_observer_list_) |
| 231 observer.OnSessionStopped(reason); | 232 observer.OnSessionStopped(reason); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void ArcSessionManager::RemoveArcData() { | 235 void ArcSessionManager::RemoveArcData() { |
| 235 // Ignore redundant data removal request. | 236 // Ignore redundant data removal request. |
| 236 if (state() == State::REMOVING_DATA_DIR) | 237 if (state() == State::REMOVING_DATA_DIR) |
| 237 return; | 238 return; |
| 238 | 239 |
| 239 // OnArcDataRemoved resets this flag. | 240 // OnArcDataRemoved resets this flag. |
| 240 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); | 241 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 241 | 242 |
| 242 if (!arc_session_runner_->IsStopped()) { | 243 if (!arc_session_runner_->IsStopped()) { |
| 243 // Just set a flag. On session stopped, this will be re-called, | 244 // Just set a flag. On session stopped, this will be re-called, |
| 244 // then session manager should remove the data. | 245 // then session manager should remove the data. |
| 245 return; | 246 return; |
| 246 } | 247 } |
| 247 | 248 |
| 249 VLOG(1) << "Starting ARC data removal"; |
| 248 SetState(State::REMOVING_DATA_DIR); | 250 SetState(State::REMOVING_DATA_DIR); |
| 249 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 251 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 250 cryptohome::Identification( | 252 cryptohome::Identification( |
| 251 multi_user_util::GetAccountIdFromProfile(profile_)), | 253 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 252 base::Bind(&ArcSessionManager::OnArcDataRemoved, | 254 base::Bind(&ArcSessionManager::OnArcDataRemoved, |
| 253 weak_ptr_factory_.GetWeakPtr())); | 255 weak_ptr_factory_.GetWeakPtr())); |
| 254 } | 256 } |
| 255 | 257 |
| 256 void ArcSessionManager::OnArcDataRemoved(bool success) { | 258 void ArcSessionManager::OnArcDataRemoved(bool success) { |
| 257 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; | 259 if (success) |
| 260 VLOG(1) << "ARC data removal successful"; |
| 261 else |
| 262 LOG(ERROR) << "Request for ARC user data removal failed."; |
| 258 | 263 |
| 259 // TODO(khmel): Browser tests may shutdown profile by itself. Update browser | 264 // TODO(khmel): Browser tests may shutdown profile by itself. Update browser |
| 260 // tests and remove this check. | 265 // tests and remove this check. |
| 261 if (state() == State::NOT_INITIALIZED) | 266 if (state() == State::NOT_INITIALIZED) |
| 262 return; | 267 return; |
| 263 | 268 |
| 264 for (auto& observer : observer_list_) | 269 for (auto& observer : observer_list_) |
| 265 observer.OnArcDataRemoved(); | 270 observer.OnArcDataRemoved(); |
| 266 | 271 |
| 267 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); | 272 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 playstore_launcher_.reset( | 360 playstore_launcher_.reset( |
| 356 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); | 361 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); |
| 357 } | 362 } |
| 358 | 363 |
| 359 for (auto& observer : observer_list_) | 364 for (auto& observer : observer_list_) |
| 360 observer.OnArcInitialStart(); | 365 observer.OnArcInitialStart(); |
| 361 return; | 366 return; |
| 362 } | 367 } |
| 363 | 368 |
| 364 ArcSupportHost::Error error; | 369 ArcSupportHost::Error error; |
| 370 VLOG(1) << "ARC provisioning failed: " << result << "."; |
| 365 switch (result) { | 371 switch (result) { |
| 366 case ProvisioningResult::GMS_NETWORK_ERROR: | 372 case ProvisioningResult::GMS_NETWORK_ERROR: |
| 367 error = ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR; | 373 error = ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR; |
| 368 break; | 374 break; |
| 369 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE: | 375 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE: |
| 370 case ProvisioningResult::GMS_SIGN_IN_FAILED: | 376 case ProvisioningResult::GMS_SIGN_IN_FAILED: |
| 371 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT: | 377 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT: |
| 372 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR: | 378 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR: |
| 373 error = ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR; | 379 error = ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR; |
| 374 break; | 380 break; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 404 } | 410 } |
| 405 | 411 |
| 406 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || | 412 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || |
| 407 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || | 413 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || |
| 408 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || | 414 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || |
| 409 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is | 415 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is |
| 410 // fully setup, but Chrome does not. | 416 // fully setup, but Chrome does not. |
| 411 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || | 417 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || |
| 412 // Just to be safe, remove data if we don't know the cause. | 418 // Just to be safe, remove data if we don't know the cause. |
| 413 result == ProvisioningResult::UNKNOWN_ERROR) { | 419 result == ProvisioningResult::UNKNOWN_ERROR) { |
| 420 VLOG(1) << "ARC provisioning failed permanently. Removing user data"; |
| 414 RemoveArcData(); | 421 RemoveArcData(); |
| 415 } | 422 } |
| 416 | 423 |
| 417 // We'll delay shutting down the ARC instance in this case to allow people | 424 // We'll delay shutting down the ARC instance in this case to allow people |
| 418 // to send feedback. | 425 // to send feedback. |
| 419 if (support_host_) | 426 if (support_host_) |
| 420 support_host_->ShowError(error, true /* = show send feedback button */); | 427 support_host_->ShowError(error, true /* = show send feedback button */); |
| 421 } | 428 } |
| 422 | 429 |
| 423 void ArcSessionManager::SetState(State state) { | 430 void ArcSessionManager::SetState(State state) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 pref_change_registrar_.Init(profile_->GetPrefs()); | 485 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 479 pref_change_registrar_.Add( | 486 pref_change_registrar_.Add( |
| 480 prefs::kArcEnabled, | 487 prefs::kArcEnabled, |
| 481 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | 488 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
| 482 weak_ptr_factory_.GetWeakPtr())); | 489 weak_ptr_factory_.GetWeakPtr())); |
| 483 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 490 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 484 // Don't start ARC if there is a pending request to remove the data. Restart | 491 // Don't start ARC if there is a pending request to remove the data. Restart |
| 485 // ARC once data removal finishes. | 492 // ARC once data removal finishes. |
| 486 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 493 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 487 reenable_arc_ = true; | 494 reenable_arc_ = true; |
| 495 VLOG(1) << "ARC previously requested to remove data."; |
| 488 RemoveArcData(); | 496 RemoveArcData(); |
| 489 } else { | 497 } else { |
| 490 OnOptInPreferenceChanged(); | 498 OnOptInPreferenceChanged(); |
| 491 } | 499 } |
| 492 } else { | 500 } else { |
| 501 VLOG(1) << "ARC disabled on profile. Removing data."; |
| 493 RemoveArcData(); | 502 RemoveArcData(); |
| 494 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 503 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
| 495 OnIsSyncingChanged(); | 504 OnIsSyncingChanged(); |
| 496 } | 505 } |
| 497 } | 506 } |
| 498 | 507 |
| 499 void ArcSessionManager::OnIsSyncingChanged() { | 508 void ArcSessionManager::OnIsSyncingChanged() { |
| 500 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | 509 sync_preferences::PrefServiceSyncable* const pref_service_syncable = |
| 501 PrefServiceSyncableFromProfile(profile_); | 510 PrefServiceSyncableFromProfile(profile_); |
| 502 if (!pref_service_syncable->IsSyncing()) | 511 if (!pref_service_syncable->IsSyncing()) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 observer.OnArcOptInChanged(arc_enabled); | 588 observer.OnArcOptInChanged(arc_enabled); |
| 580 | 589 |
| 581 // Hide auth notification if it was opened before and arc.enabled pref was | 590 // Hide auth notification if it was opened before and arc.enabled pref was |
| 582 // explicitly set to true or false. | 591 // explicitly set to true or false. |
| 583 if (!g_disable_ui_for_testing && | 592 if (!g_disable_ui_for_testing && |
| 584 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 593 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
| 585 ArcAuthNotification::Hide(); | 594 ArcAuthNotification::Hide(); |
| 586 } | 595 } |
| 587 | 596 |
| 588 if (!arc_enabled) { | 597 if (!arc_enabled) { |
| 589 // Reset any pending request to re-enable Arc. | 598 // Reset any pending request to re-enable ARC. |
| 599 VLOG(1) << "ARC opt-out. Removing user data."; |
| 590 reenable_arc_ = false; | 600 reenable_arc_ = false; |
| 591 StopArc(); | 601 StopArc(); |
| 592 RemoveArcData(); | 602 RemoveArcData(); |
| 593 return; | 603 return; |
| 594 } | 604 } |
| 595 | 605 |
| 596 if (state_ == State::ACTIVE) | 606 if (state_ == State::ACTIVE) |
| 597 return; | 607 return; |
| 598 | 608 |
| 599 if (state_ == State::REMOVING_DATA_DIR) { | 609 if (state_ == State::REMOVING_DATA_DIR) { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 } | 996 } |
| 987 | 997 |
| 988 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( | 998 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( |
| 989 const base::Closure& callback) { | 999 const base::Closure& callback) { |
| 990 DCHECK(!callback.is_null()); | 1000 DCHECK(!callback.is_null()); |
| 991 attempt_user_exit_callback_ = callback; | 1001 attempt_user_exit_callback_ = callback; |
| 992 } | 1002 } |
| 993 | 1003 |
| 994 std::ostream& operator<<(std::ostream& os, | 1004 std::ostream& operator<<(std::ostream& os, |
| 995 const ArcSessionManager::State& state) { | 1005 const ArcSessionManager::State& state) { |
| 1006 #define MAP_STATE(name) \ |
| 1007 case ArcSessionManager::State::name: \ |
| 1008 return os << #name |
| 1009 |
| 996 switch (state) { | 1010 switch (state) { |
| 997 case ArcSessionManager::State::NOT_INITIALIZED: | 1011 MAP_STATE(NOT_INITIALIZED); |
| 998 return os << "NOT_INITIALIZED"; | 1012 MAP_STATE(STOPPED); |
| 999 case ArcSessionManager::State::STOPPED: | 1013 MAP_STATE(SHOWING_TERMS_OF_SERVICE); |
| 1000 return os << "STOPPED"; | 1014 MAP_STATE(CHECKING_ANDROID_MANAGEMENT); |
| 1001 case ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE: | 1015 MAP_STATE(REMOVING_DATA_DIR); |
| 1002 return os << "SHOWING_TERMS_OF_SERVICE"; | 1016 MAP_STATE(ACTIVE); |
| 1003 case ArcSessionManager::State::CHECKING_ANDROID_MANAGEMENT: | |
| 1004 return os << "CHECKING_ANDROID_MANAGEMENT"; | |
| 1005 case ArcSessionManager::State::REMOVING_DATA_DIR: | |
| 1006 return os << "REMOVING_DATA_DIR"; | |
| 1007 case ArcSessionManager::State::ACTIVE: | |
| 1008 return os << "ACTIVE"; | |
| 1009 } | 1017 } |
| 1010 | 1018 |
| 1011 // Some compiler reports an error even if all values of an enum-class are | 1019 #undef MAP_STATE |
| 1012 // covered indivisually in a switch statement. | 1020 |
| 1013 NOTREACHED(); | 1021 // Some compilers report an error even if all values of an enum-class are |
| 1022 // covered exhaustively in a switch statement. |
| 1023 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 1014 return os; | 1024 return os; |
| 1015 } | 1025 } |
| 1016 | 1026 |
| 1017 } // namespace arc | 1027 } // namespace arc |
| OLD | NEW |