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 25 matching lines...) Expand all Loading... |
36 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 36 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
37 #include "chrome/browser/ui/browser_commands.h" | 37 #include "chrome/browser/ui/browser_commands.h" |
38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
39 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
40 #include "chromeos/chromeos_switches.h" | 40 #include "chromeos/chromeos_switches.h" |
41 #include "chromeos/cryptohome/cryptohome_parameters.h" | 41 #include "chromeos/cryptohome/cryptohome_parameters.h" |
42 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
43 #include "chromeos/dbus/session_manager_client.h" | 43 #include "chromeos/dbus/session_manager_client.h" |
44 #include "components/arc/arc_bridge_service.h" | 44 #include "components/arc/arc_bridge_service.h" |
45 #include "components/arc/arc_session_runner.h" | 45 #include "components/arc/arc_session_runner.h" |
| 46 #include "components/arc/arc_util.h" |
46 #include "components/pref_registry/pref_registry_syncable.h" | 47 #include "components/pref_registry/pref_registry_syncable.h" |
47 #include "components/prefs/pref_service.h" | 48 #include "components/prefs/pref_service.h" |
48 #include "components/sync_preferences/pref_service_syncable.h" | 49 #include "components/sync_preferences/pref_service_syncable.h" |
49 #include "components/user_manager/user.h" | 50 #include "components/user_manager/user.h" |
50 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
51 #include "extensions/browser/extension_prefs.h" | 52 #include "extensions/browser/extension_prefs.h" |
52 | 53 |
53 namespace arc { | 54 namespace arc { |
54 | 55 |
55 namespace { | 56 namespace { |
56 | 57 |
57 // Weak pointer. This class is owned by ArcServiceManager. | 58 // Weak pointer. This class is owned by ArcServiceManager. |
58 ArcSessionManager* g_arc_session_manager = nullptr; | 59 ArcSessionManager* g_arc_session_manager = nullptr; |
59 | 60 |
60 // Skip creating UI in unit tests | 61 // Skip creating UI in unit tests |
61 bool g_disable_ui_for_testing = false; | 62 bool g_disable_ui_for_testing = false; |
62 | 63 |
63 // Use specified ash::ShelfDelegate for unit tests. | 64 // Use specified ash::ShelfDelegate for unit tests. |
64 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; | 65 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; |
65 | 66 |
66 // The Android management check is disabled by default, it's used only for | 67 // The Android management check is disabled by default, it's used only for |
67 // testing. | 68 // testing. |
68 bool g_enable_check_android_management_for_testing = false; | 69 bool g_enable_check_android_management_for_testing = false; |
69 | 70 |
| 71 // Let IsAllowedForProfile() return "false" for any profile. |
| 72 bool g_disallow_for_testing = false; |
| 73 |
70 // Maximum amount of time we'll wait for ARC to finish booting up. Once this | 74 // 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, | 75 // timeout expires, keep ARC running in case the user wants to file feedback, |
72 // but present the UI to try again. | 76 // but present the UI to try again. |
73 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); | 77 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); |
74 | 78 |
75 ash::ShelfDelegate* GetShelfDelegate() { | 79 ash::ShelfDelegate* GetShelfDelegate() { |
76 if (g_shelf_delegate_for_testing) | 80 if (g_shelf_delegate_for_testing) |
77 return g_shelf_delegate_for_testing; | 81 return g_shelf_delegate_for_testing; |
78 if (ash::WmShell::HasInstance()) { | 82 if (ash::WmShell::HasInstance()) { |
79 DCHECK(ash::WmShell::Get()->shelf_delegate()); | 83 DCHECK(ash::WmShell::Get()->shelf_delegate()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 chromeos::switches::kDisableArcOptInVerification); | 145 chromeos::switches::kDisableArcOptInVerification); |
142 } | 146 } |
143 | 147 |
144 // static | 148 // static |
145 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 149 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
146 g_enable_check_android_management_for_testing = true; | 150 g_enable_check_android_management_for_testing = true; |
147 } | 151 } |
148 | 152 |
149 // static | 153 // static |
150 bool ArcSessionManager::IsAllowedForProfile(const Profile* profile) { | 154 bool ArcSessionManager::IsAllowedForProfile(const Profile* profile) { |
151 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) { | 155 if (g_disallow_for_testing) { |
152 VLOG(1) << "Arc is not enabled."; | 156 VLOG(1) << "ARC is disallowed for testing."; |
153 return false; | 157 return false; |
154 } | 158 } |
155 | 159 |
| 160 if (!IsArcAvailable()) { |
| 161 VLOG(1) << "ARC is not available."; |
| 162 return false; |
| 163 } |
| 164 |
156 if (!profile) { | 165 if (!profile) { |
157 VLOG(1) << "ARC is not supported for systems without profile."; | 166 VLOG(1) << "ARC is not supported for systems without profile."; |
158 return false; | 167 return false; |
159 } | 168 } |
160 | 169 |
161 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile)) { | 170 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile)) { |
162 VLOG(1) << "Non-primary users are not supported in ARC."; | 171 VLOG(1) << "Non-primary users are not supported in ARC."; |
163 return false; | 172 return false; |
164 } | 173 } |
165 | 174 |
(...skipping 18 matching lines...) Expand all Loading... |
184 | 193 |
185 chromeos::UserFlow* user_flow = | 194 chromeos::UserFlow* user_flow = |
186 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); | 195 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); |
187 if (!user_flow || !user_flow->CanStartArc()) { | 196 if (!user_flow || !user_flow->CanStartArc()) { |
188 VLOG(1) << "ARC is not allowed in the current user flow."; | 197 VLOG(1) << "ARC is not allowed in the current user flow."; |
189 return false; | 198 return false; |
190 } | 199 } |
191 | 200 |
192 if (user_manager::UserManager::Get() | 201 if (user_manager::UserManager::Get() |
193 ->IsCurrentUserCryptohomeDataEphemeral()) { | 202 ->IsCurrentUserCryptohomeDataEphemeral()) { |
194 VLOG(2) << "Users with ephemeral data are not supported in Arc."; | 203 VLOG(2) << "Users with ephemeral data are not supported in ARC."; |
195 return false; | 204 return false; |
196 } | 205 } |
197 | 206 |
198 return true; | 207 return true; |
199 } | 208 } |
200 | 209 |
201 // static | 210 // static |
| 211 void ArcSessionManager::DisallowForTesting() { |
| 212 g_disallow_for_testing = true; |
| 213 } |
| 214 |
| 215 // static |
202 bool ArcSessionManager::IsArcKioskMode() { | 216 bool ArcSessionManager::IsArcKioskMode() { |
203 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); | 217 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); |
204 } | 218 } |
205 | 219 |
206 void ArcSessionManager::OnSessionReady() { | 220 void ArcSessionManager::OnSessionReady() { |
207 for (auto& observer : arc_session_observer_list_) | 221 for (auto& observer : arc_session_observer_list_) |
208 observer.OnSessionReady(); | 222 observer.OnSessionReady(); |
209 } | 223 } |
210 | 224 |
211 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 225 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 return os << "ACTIVE"; | 1020 return os << "ACTIVE"; |
1007 } | 1021 } |
1008 | 1022 |
1009 // Some compiler reports an error even if all values of an enum-class are | 1023 // Some compiler reports an error even if all values of an enum-class are |
1010 // covered indivisually in a switch statement. | 1024 // covered indivisually in a switch statement. |
1011 NOTREACHED(); | 1025 NOTREACHED(); |
1012 return os; | 1026 return os; |
1013 } | 1027 } |
1014 | 1028 |
1015 } // namespace arc | 1029 } // namespace arc |
OLD | NEW |