| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_util.h" | 5 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chromeos/login/user_flow.h" | 8 #include "chrome/browser/chromeos/login/user_flow.h" |
| 9 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 9 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 10 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 10 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/arc/arc_util.h" | 13 #include "components/arc/arc_util.h" |
| 14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 15 #include "components/user_manager/user.h" | 15 #include "components/user_manager/user.h" |
| 16 #include "components/user_manager/user_manager.h" | 16 #include "components/user_manager/user_manager.h" |
| 17 | 17 |
| 18 namespace arc { | 18 namespace arc { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Let IsAllowedForProfile() return "false" for any profile. | 22 // Let IsAllowedForProfile() return "false" for any profile. |
| 23 bool g_disallow_for_testing = false; | 23 bool g_disallow_for_testing = false; |
| 24 | 24 |
| 25 // Let IsAllowedForProfile() return "true" for any profile in sync test. |
| 26 bool g_allow_for_sync_testing = false; |
| 27 |
| 25 } // namespace | 28 } // namespace |
| 26 | 29 |
| 27 bool IsArcAllowedForProfile(const Profile* profile) { | 30 bool IsArcAllowedForProfile(const Profile* profile) { |
| 31 if (g_allow_for_sync_testing) { |
| 32 VLOG(1) << "ARC is allowed for sync test."; |
| 33 return true; |
| 34 } |
| 35 |
| 28 if (g_disallow_for_testing) { | 36 if (g_disallow_for_testing) { |
| 29 VLOG(1) << "ARC is disallowed for testing."; | 37 VLOG(1) << "ARC is disallowed for testing."; |
| 30 return false; | 38 return false; |
| 31 } | 39 } |
| 32 | 40 |
| 33 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. | 41 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. |
| 34 // In that case IsArcKioskMode() should return true as profile is already | 42 // In that case IsArcKioskMode() should return true as profile is already |
| 35 // created. | 43 // created. |
| 36 if (!IsArcAvailable() && !(IsArcKioskMode() && IsArcKioskAvailable())) { | 44 if (!IsArcAvailable() && !(IsArcKioskMode() && IsArcKioskAvailable())) { |
| 37 VLOG(1) << "ARC is not available."; | 45 VLOG(1) << "ARC is not available."; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return false; | 99 return false; |
| 92 } | 100 } |
| 93 | 101 |
| 94 return true; | 102 return true; |
| 95 } | 103 } |
| 96 | 104 |
| 97 void DisallowArcForTesting() { | 105 void DisallowArcForTesting() { |
| 98 g_disallow_for_testing = true; | 106 g_disallow_for_testing = true; |
| 99 } | 107 } |
| 100 | 108 |
| 109 void SetArcAllowedForSyncTesting() { |
| 110 g_allow_for_sync_testing = true; |
| 111 } |
| 112 |
| 101 bool IsArcPlayStoreEnabledForProfile(const Profile* profile) { | 113 bool IsArcPlayStoreEnabledForProfile(const Profile* profile) { |
| 102 return IsArcAllowedForProfile(profile) && | 114 return IsArcAllowedForProfile(profile) && |
| 103 profile->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 115 profile->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| 104 } | 116 } |
| 105 | 117 |
| 106 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile) { | 118 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile) { |
| 107 if (!IsArcAllowedForProfile(profile)) { | 119 if (!IsArcAllowedForProfile(profile)) { |
| 108 LOG(DFATAL) << "ARC is not allowed for profile"; | 120 LOG(DFATAL) << "ARC is not allowed for profile"; |
| 109 return false; | 121 return false; |
| 110 } | 122 } |
| 111 return profile->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); | 123 return profile->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); |
| 112 } | 124 } |
| 113 | 125 |
| 114 void SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled) { | 126 void SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled) { |
| 115 DCHECK(IsArcAllowedForProfile(profile)); | 127 DCHECK(IsArcAllowedForProfile(profile)); |
| 116 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile)) { | 128 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile)) { |
| 117 VLOG(1) << "Do nothing, since the Google-Play-Store-enabled pref is " | 129 VLOG(1) << "Do nothing, since the Google-Play-Store-enabled pref is " |
| 118 << "managed."; | 130 << "managed."; |
| 119 return; | 131 return; |
| 120 } | 132 } |
| 121 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); | 133 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); |
| 122 } | 134 } |
| 123 | 135 |
| 124 } // namespace arc | 136 } // namespace arc |
| OLD | NEW |