Chromium Code Reviews| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && | 410 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && |
| 411 !IsArcKioskMode()) { | 411 !IsArcKioskMode()) { |
| 412 DCHECK(!support_host_); | 412 DCHECK(!support_host_); |
| 413 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); | 413 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); |
| 414 support_host_->AddObserver(this); | 414 support_host_->AddObserver(this); |
| 415 } | 415 } |
| 416 | 416 |
| 417 DCHECK_EQ(State::NOT_INITIALIZED, state_); | 417 DCHECK_EQ(State::NOT_INITIALIZED, state_); |
| 418 SetState(State::STOPPED); | 418 SetState(State::STOPPED); |
| 419 | 419 |
| 420 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | |
| 421 prefs::kArcEnabled, this); | |
| 422 | |
| 423 context_.reset(new ArcAuthContext(profile_)); | 420 context_.reset(new ArcAuthContext(profile_)); |
| 424 | 421 |
| 425 if (!g_disable_ui_for_testing || | 422 if (!g_disable_ui_for_testing || |
| 426 g_enable_check_android_management_for_testing) { | 423 g_enable_check_android_management_for_testing) { |
| 427 ArcAndroidManagementChecker::StartClient(); | 424 ArcAndroidManagementChecker::StartClient(); |
| 428 } | 425 } |
| 429 pref_change_registrar_.Init(profile_->GetPrefs()); | 426 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 430 pref_change_registrar_.Add( | 427 pref_change_registrar_.Add( |
| 431 prefs::kArcEnabled, | 428 prefs::kArcEnabled, |
| 432 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | 429 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 447 } | 444 } |
| 448 } | 445 } |
| 449 | 446 |
| 450 void ArcSessionManager::OnIsSyncingChanged() { | 447 void ArcSessionManager::OnIsSyncingChanged() { |
| 451 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | 448 sync_preferences::PrefServiceSyncable* const pref_service_syncable = |
| 452 PrefServiceSyncableFromProfile(profile_); | 449 PrefServiceSyncableFromProfile(profile_); |
| 453 if (!pref_service_syncable->IsSyncing()) | 450 if (!pref_service_syncable->IsSyncing()) |
| 454 return; | 451 return; |
| 455 | 452 |
| 456 pref_service_syncable->RemoveObserver(this); | 453 pref_service_syncable->RemoveObserver(this); |
| 457 | |
| 458 if (IsArcEnabled()) | |
|
hidehiko
2017/02/07 14:05:37
Note: according to https://codereview.chromium.org
| |
| 459 OnOptInPreferenceChanged(); | |
| 460 | |
| 461 if (!g_disable_ui_for_testing && | 454 if (!g_disable_ui_for_testing && |
| 462 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 455 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 463 chromeos::switches::kEnableArcOOBEOptIn) && | 456 chromeos::switches::kEnableArcOOBEOptIn) && |
| 464 profile_->IsNewProfile() && | 457 profile_->IsNewProfile() && |
| 465 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 458 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
| 466 ArcAuthNotification::Show(profile_); | 459 ArcAuthNotification::Show(profile_); |
| 467 } | 460 } |
| 468 } | 461 } |
| 469 | 462 |
| 470 void ArcSessionManager::Shutdown() { | 463 void ArcSessionManager::Shutdown() { |
| 471 if (!g_disable_ui_for_testing) | 464 if (!g_disable_ui_for_testing) |
| 472 ArcAuthNotification::Hide(); | 465 ArcAuthNotification::Hide(); |
| 473 | 466 |
| 474 ShutdownSession(); | 467 ShutdownSession(); |
| 475 if (support_host_) { | 468 if (support_host_) { |
| 476 support_host_->Close(); | 469 support_host_->Close(); |
| 477 support_host_->RemoveObserver(this); | 470 support_host_->RemoveObserver(this); |
| 478 support_host_.reset(); | 471 support_host_.reset(); |
| 479 } | 472 } |
| 480 if (profile_) { | 473 if (profile_) { |
| 481 sync_preferences::PrefServiceSyncable* pref_service_syncable = | 474 sync_preferences::PrefServiceSyncable* pref_service_syncable = |
| 482 PrefServiceSyncableFromProfile(profile_); | 475 PrefServiceSyncableFromProfile(profile_); |
| 483 pref_service_syncable->RemoveObserver(this); | 476 pref_service_syncable->RemoveObserver(this); |
| 484 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); | |
| 485 } | 477 } |
| 486 pref_change_registrar_.RemoveAll(); | 478 pref_change_registrar_.RemoveAll(); |
| 487 context_.reset(); | 479 context_.reset(); |
| 488 profile_ = nullptr; | 480 profile_ = nullptr; |
| 489 SetState(State::NOT_INITIALIZED); | 481 SetState(State::NOT_INITIALIZED); |
| 490 } | 482 } |
| 491 | 483 |
| 492 void ArcSessionManager::OnSyncedPrefChanged(const std::string& path, | |
| 493 bool from_sync) { | |
| 494 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 495 | |
| 496 // Update UMA only for local changes | |
| 497 if (!from_sync) { | |
| 498 const bool arc_enabled = | |
| 499 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | |
| 500 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | |
| 501 : OptInActionType::OPTED_OUT); | |
| 502 | |
| 503 if (!arc_enabled && !IsArcManaged()) { | |
| 504 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | |
| 505 if (shelf_delegate) | |
| 506 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 507 } | |
| 508 } | |
| 509 } | |
| 510 | |
| 511 void ArcSessionManager::StopArc() { | 484 void ArcSessionManager::StopArc() { |
| 512 if (state_ != State::STOPPED) { | 485 if (state_ != State::STOPPED) { |
| 513 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 486 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 514 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); | 487 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); |
| 515 } | 488 } |
| 516 ShutdownSession(); | 489 ShutdownSession(); |
| 517 if (support_host_) | 490 if (support_host_) |
| 518 support_host_->Close(); | 491 support_host_->Close(); |
| 519 } | 492 } |
| 520 | 493 |
| 521 void ArcSessionManager::OnOptInPreferenceChanged() { | 494 void ArcSessionManager::OnOptInPreferenceChanged() { |
| 522 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 495 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 523 DCHECK(profile_); | 496 DCHECK(profile_); |
| 524 | 497 |
| 525 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. | 498 const bool arc_enabled = IsArcEnabled(); |
| 526 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); | 499 if (!IsArcManaged()) { |
| 500 // Update UMA only for non-Managed cases. | |
| 501 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | |
| 502 : OptInActionType::OPTED_OUT); | |
| 527 | 503 |
| 528 const bool arc_enabled = IsArcEnabled(); | 504 if (!arc_enabled) { |
| 505 // Remove the pinned Play Store icon launcher in Shelf. | |
| 506 // This is only for non-Managed cases. In managed cases, it is expected | |
| 507 // to be "disabled" rather than "removed", so keep it here. | |
| 508 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | |
| 509 if (shelf_delegate) | |
| 510 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 511 } | |
| 512 } | |
| 513 | |
| 529 for (auto& observer : observer_list_) | 514 for (auto& observer : observer_list_) |
| 530 observer.OnArcOptInChanged(arc_enabled); | 515 observer.OnArcOptInChanged(arc_enabled); |
| 531 | 516 |
| 532 // Hide auth notification if it was opened before and arc.enabled pref was | 517 // Hide auth notification if it was opened before and arc.enabled pref was |
| 533 // explicitly set to true or false. | 518 // explicitly set to true or false. |
| 534 if (!g_disable_ui_for_testing && | 519 if (!g_disable_ui_for_testing && |
| 535 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 520 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
| 536 ArcAuthNotification::Hide(); | 521 ArcAuthNotification::Hide(); |
| 537 } | 522 } |
| 538 | 523 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 978 return os << "ACTIVE"; | 963 return os << "ACTIVE"; |
| 979 } | 964 } |
| 980 | 965 |
| 981 // Some compiler reports an error even if all values of an enum-class are | 966 // Some compiler reports an error even if all values of an enum-class are |
| 982 // covered indivisually in a switch statement. | 967 // covered indivisually in a switch statement. |
| 983 NOTREACHED(); | 968 NOTREACHED(); |
| 984 return os; | 969 return os; |
| 985 } | 970 } |
| 986 | 971 |
| 987 } // namespace arc | 972 } // namespace arc |
| OLD | NEW |