Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/chromeos/arc/arc_util.cc

Issue 2711033002: Fix Arc integration test. (Closed)
Patch Set: Address hidehiko's comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
lgcheng 2017/02/25 01:40:38 Comments for type are in util.h.
21 21 ArcAllowedForTestType g_arc_allowed_for_test_type = NOTSET;
22 // Let IsAllowedForProfile() return "false" for any profile.
23 bool g_disallow_for_testing = false;
24
25 } // namespace 22 } // namespace
26 23
27 bool IsArcAllowedForProfile(const Profile* profile) { 24 bool IsArcAllowedForProfile(const Profile* profile) {
28 if (g_disallow_for_testing) { 25 switch (g_arc_allowed_for_test_type) {
29 VLOG(1) << "ARC is disallowed for testing."; 26 case ALLOWEDFORSYNCTEST:
30 return false; 27 return true;
28 case DISALLOWEDFORTEST:
29 return false;
30 // Goes through regular checks.
31 case NOTSET:
32 default:
hidehiko 2017/03/02 17:45:39 No default section please. cf) arc++chromium-style
lgcheng 2017/03/02 23:45:10 Modification for this file is abandoned.
33 break;
31 } 34 }
32 35
33 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. 36 // 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 37 // In that case IsArcKioskMode() should return true as profile is already
35 // created. 38 // created.
36 if (!IsArcAvailable() && !(IsArcKioskMode() && IsArcKioskAvailable())) { 39 if (!IsArcAvailable() && !(IsArcKioskMode() && IsArcKioskAvailable())) {
37 VLOG(1) << "ARC is not available."; 40 VLOG(1) << "ARC is not available.";
38 return false; 41 return false;
39 } 42 }
40 43
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Do not allow for Ephemeral data user. cf) b/26402681 90 // Do not allow for Ephemeral data user. cf) b/26402681
88 if (user_manager::UserManager::Get() 91 if (user_manager::UserManager::Get()
89 ->IsCurrentUserCryptohomeDataEphemeral()) { 92 ->IsCurrentUserCryptohomeDataEphemeral()) {
90 VLOG(1) << "Users with ephemeral data are not supported in ARC."; 93 VLOG(1) << "Users with ephemeral data are not supported in ARC.";
91 return false; 94 return false;
92 } 95 }
93 96
94 return true; 97 return true;
95 } 98 }
96 99
97 void DisallowArcForTesting() { 100 void SetArcAllowedForTesting(ArcAllowedForTestType type) {
98 g_disallow_for_testing = true; 101 g_arc_allowed_for_test_type = type;
99 } 102 }
100 103
101 bool IsArcPlayStoreEnabledForProfile(const Profile* profile) { 104 bool IsArcPlayStoreEnabledForProfile(const Profile* profile) {
102 return IsArcAllowedForProfile(profile) && 105 return IsArcAllowedForProfile(profile) &&
103 profile->GetPrefs()->GetBoolean(prefs::kArcEnabled); 106 profile->GetPrefs()->GetBoolean(prefs::kArcEnabled);
104 } 107 }
105 108
106 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile) { 109 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile) {
107 if (!IsArcAllowedForProfile(profile)) { 110 if (!IsArcAllowedForProfile(profile)) {
108 LOG(DFATAL) << "ARC is not allowed for profile"; 111 LOG(DFATAL) << "ARC is not allowed for profile";
109 return false; 112 return false;
110 } 113 }
111 return profile->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); 114 return profile->GetPrefs()->IsManagedPreference(prefs::kArcEnabled);
112 } 115 }
113 116
114 void SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled) { 117 void SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled) {
115 DCHECK(IsArcAllowedForProfile(profile)); 118 DCHECK(IsArcAllowedForProfile(profile));
116 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile)) { 119 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile)) {
117 VLOG(1) << "Do nothing, since the Google-Play-Store-enabled pref is " 120 VLOG(1) << "Do nothing, since the Google-Play-Store-enabled pref is "
118 << "managed."; 121 << "managed.";
119 return; 122 return;
120 } 123 }
121 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); 124 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled);
122 } 125 }
123 126
124 } // namespace arc 127 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698