| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // TODO(hidehiko): When the dependency to ArcAuthNotification from this | 135 // TODO(hidehiko): When the dependency to ArcAuthNotification from this |
| 147 // class is removed, we should remove this as well. | 136 // class is removed, we should remove this as well. |
| 148 ArcAuthNotification::DisableForTesting(); | 137 ArcAuthNotification::DisableForTesting(); |
| 149 } | 138 } |
| 150 | 139 |
| 151 // static | 140 // static |
| 152 void ArcSessionManager::SetShelfDelegateForTesting( | |
| 153 ash::ShelfDelegate* shelf_delegate) { | |
| 154 g_shelf_delegate_for_testing = shelf_delegate; | |
| 155 } | |
| 156 | |
| 157 // static | |
| 158 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 141 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
| 159 g_enable_check_android_management_for_testing = true; | 142 g_enable_check_android_management_for_testing = true; |
| 160 } | 143 } |
| 161 | 144 |
| 162 void ArcSessionManager::OnSessionReady() { | 145 void ArcSessionManager::OnSessionReady() { |
| 163 for (auto& observer : arc_session_observer_list_) | 146 for (auto& observer : arc_session_observer_list_) |
| 164 observer.OnSessionReady(); | 147 observer.OnSessionReady(); |
| 165 } | 148 } |
| 166 | 149 |
| 167 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 150 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); | 512 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); |
| 530 if (!is_play_store_managed) { | 513 if (!is_play_store_managed) { |
| 531 // Update UMA only for non-Managed cases. | 514 // Update UMA only for non-Managed cases. |
| 532 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN | 515 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN |
| 533 : OptInActionType::OPTED_OUT); | 516 : OptInActionType::OPTED_OUT); |
| 534 | 517 |
| 535 if (!is_play_store_enabled) { | 518 if (!is_play_store_enabled) { |
| 536 // Remove the pinned Play Store icon launcher in Shelf. | 519 // Remove the pinned Play Store icon launcher in Shelf. |
| 537 // This is only for non-Managed cases. In managed cases, it is expected | 520 // This is only for non-Managed cases. In managed cases, it is expected |
| 538 // to be "disabled" rather than "removed", so keep it here. | 521 // to be "disabled" rather than "removed", so keep it here. |
| 539 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | 522 auto* shelf_delegate = ash::WmShell::HasInstance() |
| 523 ? ash::WmShell::Get()->shelf_delegate() |
| 524 : nullptr; |
| 540 if (shelf_delegate) | 525 if (shelf_delegate) |
| 541 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 526 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
| 542 } | 527 } |
| 543 } | 528 } |
| 544 | 529 |
| 545 if (support_host_) | 530 if (support_host_) |
| 546 support_host_->SetArcManaged(is_play_store_managed); | 531 support_host_->SetArcManaged(is_play_store_managed); |
| 547 | 532 |
| 548 // Hide auth notification if it was opened before and arc.enabled pref was | 533 // Hide auth notification if it was opened before and arc.enabled pref was |
| 549 // explicitly set to true or false. | 534 // explicitly set to true or false. |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 985 |
| 1001 #undef MAP_STATE | 986 #undef MAP_STATE |
| 1002 | 987 |
| 1003 // Some compilers report an error even if all values of an enum-class are | 988 // Some compilers report an error even if all values of an enum-class are |
| 1004 // covered exhaustively in a switch statement. | 989 // covered exhaustively in a switch statement. |
| 1005 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 990 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 1006 return os; | 991 return os; |
| 1007 } | 992 } |
| 1008 | 993 |
| 1009 } // namespace arc | 994 } // namespace arc |
| OLD | NEW |