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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_UTIL_H_
7 
8 #include <stdint.h>
9 #include <memory>
10 
11 #include "base/callback_forward.h"
12 #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
13 #include "components/arc/session/arc_supervision_transition.h"
14 
15 // Most utility should be put in components/arc/arc_util.{h,cc}, rather than
16 // here. However, some utility implementation requires other modules defined in
17 // chrome/, so this file contains such utilities.
18 // Note that it is not allowed to have dependency from components/ to chrome/
19 // by DEPS.
20 
21 class AccountId;
22 class GURL;
23 class Profile;
24 
25 namespace aura {
26 class Window;
27 }  // namespace aura
28 
29 namespace base {
30 class FilePath;
31 }  // namespace base
32 
33 namespace content {
34 class WebContents;
35 }  // namespace content
36 
37 namespace user_manager {
38 class User;
39 }  // namespace user_manager
40 
41 namespace arc {
42 
43 // Values to be stored in the local state preference to keep track of the
44 // filesystem encryption migration status.
45 enum FileSystemCompatibilityState : int32_t {
46   // No migration has happened, user keeps using the old file system.
47   kFileSystemIncompatible = 0,
48   // Migration has happened. New filesystem is in use.
49   kFileSystemCompatible = 1,
50   // Migration has happened, and a notification about it was already shown.
51   // This pref value will not be written anymore since we stopped showing the
52   // notification, but existing profiles which had shown the notification can
53   // have this value in their pref.
54   kFileSystemCompatibleAndNotifiedDeprecated = 2,
55 
56   // Existing code assumes that kFileSystemIncompatible is the only state
57   // representing incompatibility and other values are all variants of
58   // "compatible" state. Be careful in the case adding a new enum value.
59 };
60 
61 // Returns false if |profile| is not a real user profile but some internal
62 // profile for service purposes, which should be ignored for ARC and metrics
63 // recording. Also returns false if |profile| is null.
64 bool IsRealUserProfile(const Profile* profile);
65 
66 // Returns true if ARC is allowed to run for the given profile.
67 // Otherwise, returns false, e.g. if the Profile is not for the primary user,
68 // ARC is not available on the device, it is in the flow to set up managed
69 // account creation.
70 // nullptr can be safely passed to this function. In that case, returns false.
71 bool IsArcAllowedForProfile(const Profile* profile);
72 
73 // Returns whether ARC was successfully provisioned and the Primary/Device
74 // Account has been signed into ARC.
75 bool IsArcProvisioned(const Profile* profile);
76 
77 // Returns true if the profile is temporarily blocked to run ARC in the current
78 // session, because the filesystem storing the profile is incompatible with the
79 // currently installed ARC version.
80 //
81 // The actual filesystem check is performed only when it is running on the
82 // Chrome OS device. Otherwise, it just returns the dummy value set by
83 // SetArcBlockedDueToIncompatibleFileSystemForTesting (false by default.)
84 bool IsArcBlockedDueToIncompatibleFileSystem(const Profile* profile);
85 
86 // Sets the result of IsArcBlockedDueToIncompatibleFileSystem for testing.
87 void SetArcBlockedDueToIncompatibleFileSystemForTesting(bool block);
88 
89 // Returns true if the user is already marked to be on a filesystem
90 // compatible to the currently installed ARC version. The check almost never
91 // is meaningful on test workstation. Usually it should be checked only when
92 // running on the real Chrome OS.
93 bool IsArcCompatibleFileSystemUsedForUser(const user_manager::User* user);
94 
95 // Disallows ARC for all profiles for testing.
96 // In most cases, disabling ARC should be done via commandline. However,
97 // there are some cases to be tested where ARC is available, but ARC is not
98 // supported for some reasons (e.g. incognito mode, supervised user,
99 // secondary profile). On the other hand, some test infra does not support
100 // such situations (e.g. API test). This is for workaround to emulate the
101 // case.
102 void DisallowArcForTesting();
103 
104 // Resets check if ARC allowed for the given |profile|.
105 void ResetArcAllowedCheckForTesting(const Profile* profile);
106 
107 // Returns whether the user has opted in (or is opting in now) to use Google
108 // Play Store on ARC.
109 // This is almost equivalent to the value of "arc.enabled" preference. However,
110 // in addition, if ARC is not allowed for the given |profile|, then returns
111 // false. Please see detailed condition for the comment of
112 // IsArcAllowedForProfile().
113 // Note: For historical reason, the preference name is not matched with the
114 // actual meaning.
115 bool IsArcPlayStoreEnabledForProfile(const Profile* profile);
116 
117 // Returns whether the preference "arc.enabled" is managed or not.
118 // It is requirement for a caller to ensure ARC is allowed for the user of
119 // the given |profile|.
120 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile);
121 
122 // Enables or disables Google Play Store on ARC. Currently, it is tied to
123 // ARC enabled state, too, so this also should trigger to enable or disable
124 // whole ARC system.
125 // If the preference is managed, then no-op.
126 // It is requirement for a caller to ensure ARC is allowed for the user of
127 // the given |profile|.
128 // TODO(hidehiko): De-couple the concept to enable ARC system and opt-in
129 // to use Google Play Store. Note that there is a plan to use ARC without
130 // Google Play Store, then ARC can run without opt-in. Returns false in case
131 // enabled state of the Play Store cannot be changed.
132 bool SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled);
133 
134 // Returns whether all ARC related OptIn preferences (i.e.
135 // ArcBackupRestoreEnabled and ArcLocationServiceEnabled) are managed or unused
136 // (e.g. for Active Directory users).
137 bool AreArcAllOptInPreferencesIgnorableForProfile(const Profile* profile);
138 
139 // Returns true iff there is a user associated with |profile|, and it is an
140 // Active Directory user.
141 bool IsActiveDirectoryUserForProfile(const Profile* profile);
142 
143 // Returns true if ChromeOS OOBE opt-in window is currently showing.
144 bool IsArcOobeOptInActive();
145 
146 // Returns true if opt-in during ChromeOS OOBE is triggered by configuration.
147 bool IsArcOobeOptInConfigurationBased();
148 
149 // Returns true if Terms of Service negotiation is needed. Otherwise false.
150 bool IsArcTermsOfServiceNegotiationNeeded(const Profile* profile);
151 
152 // Returns true if Terms of Service negotiation is needed in OOBE flow.
153 // Otherwise false. Similar to IsArcTermsOfServiceNegotiationNeeded but
154 // also checks set of preconditions and uses active user profile.
155 bool IsArcTermsOfServiceOobeNegotiationNeeded();
156 
157 // Returns true if stats reporting is enabled. Otherwise false.
158 bool IsArcStatsReportingEnabled();
159 
160 // Returns whether ARC opt-in in demo mode setup flow is in progress.
161 bool IsArcDemoModeSetupFlow();
162 
163 // Checks and updates the preference value whether the underlying filesystem
164 // for the profile is compatible with ARC, when necessary. After it's done (or
165 // skipped), |callback| is run either synchronously or asynchronously.
166 void UpdateArcFileSystemCompatibilityPrefIfNeeded(
167     const AccountId& account_id,
168     const base::FilePath& profile_path,
169     base::OnceClosure callback);
170 
171 // Returns the supervision transition status as stored in profile prefs.
172 ArcSupervisionTransition GetSupervisionTransition(const Profile* profile);
173 
174 // Returns true if Play Store package is present and can be launched in this
175 // session.
176 bool IsPlayStoreAvailable();
177 
178 // Returns whether adding secondary account to ARC++ is enabled for child user.
179 bool IsSecondaryAccountForChildEnabled();
180 
181 // Skip to show OOBE/in sesion UI asking users to set up ARC OptIn preferences,
182 // iff all of them are managed by the admin policy.
183 // Skips in session play terms of service for managed user and starts ARC
184 // directly. Leaves B&R/GLS off if not set by admin since users don't see
185 // the Tos page.
186 bool ShouldStartArcSilentlyForManagedProfile(const Profile* profile);
187 
188 // Returns an ARC window with the given task ID.
189 aura::Window* GetArcWindow(int32_t task_id);
190 
191 // Creates a web contents for an ARC Custom Tab using the given profile and url.
192 std::unique_ptr<content::WebContents> CreateArcCustomTabWebContents(
193     Profile* profile,
194     const GURL& url);
195 
196 // Adds a suffix to the name based on the account type. If profile is not
197 // provided, then defaults to the primary user profile.
198 std::string GetHistogramNameByUserType(const std::string& base_name,
199                                        const Profile* profile = nullptr);
200 
201 // Adds a suffix to the name based on the account type of the primary user
202 // profile.
203 std::string GetHistogramNameByUserTypeForPrimaryProfile(
204     const std::string& base_name);
205 }  // namespace arc
206 
207 #endif  // CHROME_BROWSER_CHROMEOS_ARC_ARC_UTIL_H_
208