| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 namespace arc { | 53 namespace arc { |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 // Weak pointer. This class is owned by ArcServiceManager. | 57 // Weak pointer. This class is owned by ArcServiceManager. |
| 58 ArcSessionManager* g_arc_session_manager = nullptr; | 58 ArcSessionManager* g_arc_session_manager = nullptr; |
| 59 | 59 |
| 60 // Skip creating UI in unit tests | 60 // Skip creating UI in unit tests |
| 61 bool g_disable_ui_for_testing = false; | 61 bool g_disable_ui_for_testing = false; |
| 62 | 62 |
| 63 // Use specified ash::ShelfDelegate for unit tests. | |
| 64 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; | |
| 65 | |
| 66 // The Android management check is disabled by default, it's used only for | 63 // The Android management check is disabled by default, it's used only for |
| 67 // testing. | 64 // testing. |
| 68 bool g_enable_check_android_management_for_testing = false; | 65 bool g_enable_check_android_management_for_testing = false; |
| 69 | 66 |
| 70 // Maximum amount of time we'll wait for ARC to finish booting up. Once this | 67 // Maximum amount of time we'll wait for ARC to finish booting up. Once this |
| 71 // timeout expires, keep ARC running in case the user wants to file feedback, | 68 // timeout expires, keep ARC running in case the user wants to file feedback, |
| 72 // but present the UI to try again. | 69 // but present the UI to try again. |
| 73 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); | 70 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); |
| 74 | 71 |
| 75 ash::ShelfDelegate* GetShelfDelegate() { | |
| 76 if (g_shelf_delegate_for_testing) | |
| 77 return g_shelf_delegate_for_testing; | |
| 78 if (ash::WmShell::HasInstance()) | |
| 79 return ash::WmShell::Get()->shelf_delegate(); | |
| 80 return nullptr; | |
| 81 } | |
| 82 | |
| 83 } // namespace | 72 } // namespace |
| 84 | 73 |
| 85 ArcSessionManager::ArcSessionManager( | 74 ArcSessionManager::ArcSessionManager( |
| 86 std::unique_ptr<ArcSessionRunner> arc_session_runner) | 75 std::unique_ptr<ArcSessionRunner> arc_session_runner) |
| 87 : arc_session_runner_(std::move(arc_session_runner)), | 76 : arc_session_runner_(std::move(arc_session_runner)), |
| 88 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), | 77 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), |
| 89 weak_ptr_factory_(this) { | 78 weak_ptr_factory_(this) { |
| 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 91 DCHECK(!g_arc_session_manager); | 80 DCHECK(!g_arc_session_manager); |
| 92 g_arc_session_manager = this; | 81 g_arc_session_manager = this; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return false; | 128 return false; |
| 140 return true; | 129 return true; |
| 141 } | 130 } |
| 142 | 131 |
| 143 // static | 132 // static |
| 144 void ArcSessionManager::DisableUIForTesting() { | 133 void ArcSessionManager::DisableUIForTesting() { |
| 145 g_disable_ui_for_testing = true; | 134 g_disable_ui_for_testing = true; |
| 146 } | 135 } |
| 147 | 136 |
| 148 // static | 137 // static |
| 149 void ArcSessionManager::SetShelfDelegateForTesting( | |
| 150 ash::ShelfDelegate* shelf_delegate) { | |
| 151 g_shelf_delegate_for_testing = shelf_delegate; | |
| 152 } | |
| 153 | |
| 154 // static | |
| 155 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 138 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
| 156 g_enable_check_android_management_for_testing = true; | 139 g_enable_check_android_management_for_testing = true; |
| 157 } | 140 } |
| 158 | 141 |
| 159 void ArcSessionManager::OnSessionReady() { | 142 void ArcSessionManager::OnSessionReady() { |
| 160 for (auto& observer : arc_session_observer_list_) | 143 for (auto& observer : arc_session_observer_list_) |
| 161 observer.OnSessionReady(); | 144 observer.OnSessionReady(); |
| 162 } | 145 } |
| 163 | 146 |
| 164 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 147 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); | 502 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); |
| 520 if (!is_play_store_managed) { | 503 if (!is_play_store_managed) { |
| 521 // Update UMA only for non-Managed cases. | 504 // Update UMA only for non-Managed cases. |
| 522 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN | 505 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN |
| 523 : OptInActionType::OPTED_OUT); | 506 : OptInActionType::OPTED_OUT); |
| 524 | 507 |
| 525 if (!is_play_store_enabled) { | 508 if (!is_play_store_enabled) { |
| 526 // Remove the pinned Play Store icon launcher in Shelf. | 509 // Remove the pinned Play Store icon launcher in Shelf. |
| 527 // This is only for non-Managed cases. In managed cases, it is expected | 510 // This is only for non-Managed cases. In managed cases, it is expected |
| 528 // to be "disabled" rather than "removed", so keep it here. | 511 // to be "disabled" rather than "removed", so keep it here. |
| 529 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 512 auto* shelf_delegate = ash::WmShell::HasInstance() |
| 513 ? ash::WmShell::Get()->shelf_delegate() |
| 514 : nullptr; |
| 530 if (shelf_delegate) | 515 if (shelf_delegate) |
| 531 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 516 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
| 532 } | 517 } |
| 533 } | 518 } |
| 534 | 519 |
| 535 if (support_host_) | 520 if (support_host_) |
| 536 support_host_->SetArcManaged(is_play_store_managed); | 521 support_host_->SetArcManaged(is_play_store_managed); |
| 537 | 522 |
| 538 // Hide auth notification if it was opened before and arc.enabled pref was | 523 // Hide auth notification if it was opened before and arc.enabled pref was |
| 539 // explicitly set to true or false. | 524 // explicitly set to true or false. |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 969 |
| 985 #undef MAP_STATE | 970 #undef MAP_STATE |
| 986 | 971 |
| 987 // Some compilers report an error even if all values of an enum-class are | 972 // Some compilers report an error even if all values of an enum-class are |
| 988 // covered exhaustively in a switch statement. | 973 // covered exhaustively in a switch statement. |
| 989 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 974 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 990 return os; | 975 return os; |
| 991 } | 976 } |
| 992 | 977 |
| 993 } // namespace arc | 978 } // namespace arc |
| OLD | NEW |