1 // Copyright 2013 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_PROFILES_PROFILES_STATE_H_
6 #define CHROME_BROWSER_PROFILES_PROFILES_STATE_H_
7 
8 #include <string>
9 
10 #include "base/strings/string16.h"
11 #include "build/build_config.h"
12 
13 #if !defined(OS_CHROMEOS)
14 #include <vector>
15 
16 #include "chrome/browser/profiles/avatar_menu.h"
17 #endif
18 
19 struct AccountInfo;
20 class Browser;
21 class PrefRegistrySimple;
22 class PrefService;
23 class Profile;
24 
25 namespace base {
26 class CommandLine;
27 class FilePath;
28 }  // namespace base
29 
30 namespace profiles {
31 
32 // Assortment of methods for dealing with profiles.
33 // TODO(michaelpg): Most of these functions can be inlined or moved to more
34 // appropriate locations.
35 
36 // Checks if multiple profiles is enabled.
37 bool IsMultipleProfilesEnabled();
38 
39 // Returns the path to the default profile directory, based on the given
40 // user data directory.
41 base::FilePath GetDefaultProfileDir(const base::FilePath& user_data_dir);
42 
43 // Register multi-profile related preferences in Local State.
44 void RegisterPrefs(PrefRegistrySimple* registry);
45 
46 // Sets the last used profile pref to |profile_dir|, unless |profile_dir| is the
47 // System Profile directory, which is an invalid last used profile.
48 void SetLastUsedProfile(const std::string& profile_dir);
49 
50 #if !defined(OS_ANDROID)
51 // Returns the display name of the specified on-the-record profile (or guest),
52 // specified by |profile_path|, used in the avatar button or user manager. If
53 // |profile_path| is the guest path, it will return IDS_GUEST_PROFILE_NAME. If
54 // there is only one local profile present, it will return
55 // IDS_SINGLE_PROFILE_DISPLAY_NAME, unless the profile has a user entered
56 // custom name.
57 base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path);
58 
59 #if !defined(OS_CHROMEOS)
60 // Returns the string to use in the fast user switcher menu for the specified
61 // menu item. Adds a supervision indicator to the profile name if appropriate.
62 base::string16 GetProfileSwitcherTextForItem(const AvatarMenu::Item& item);
63 
64 // Update the name of |profile| to |new_profile_name|. This updates the profile
65 // preferences, which triggers an update in the ProfileAttributesStorage. This
66 // method should be called when the user is explicitely changing the profile
67 // name, as it will always set |prefs::kProfileUsingDefaultName| to false.
68 void UpdateProfileName(Profile* profile,
69                        const base::string16& new_profile_name);
70 
71 #endif  // !defined(OS_CHROMEOS)
72 
73 // Returns whether the |browser|'s profile is not incognito (a regular profile
74 // or a guest session).
75 // The distinction is needed because guest profiles and incognito profiles are
76 // implemented as off-the-record profiles.
77 bool IsRegularOrGuestSession(Browser* browser);
78 
79 // Returns true if starting in guest mode is requested at startup (e.g. through
80 // command line argument). If |show_warning| is true, send a warning if guest
81 // mode is requested but not allowed by policy.
82 bool IsGuestModeRequested(const base::CommandLine& command_line,
83                           PrefService* local_state,
84                           bool show_warning);
85 
86 // Returns true if sign in is required to browse as this profile.  Call with
87 // profile->GetPath() if you have a profile pointer.
88 // TODO(mlerman): Refactor appropriate calls to
89 // ProfileAttributesStorage::IsSigninRequired to call here instead.
90 bool IsProfileLocked(const base::FilePath& profile_path);
91 
92 #if !defined(OS_CHROMEOS)
93 // If the lock-enabled information for this profile is not up to date, starts
94 // an update for the Gaia profile info.
95 void UpdateIsProfileLockEnabledIfNeeded(Profile* profile);
96 
97 // Starts an update for a new version of the Gaia profile picture and other
98 // profile info.
99 void UpdateGaiaProfileInfoIfNeeded(Profile* profile);
100 
101 // If the current active profile (given by prefs::kProfileLastUsed) is locked,
102 // changes the active profile to the Guest profile. Returns true if the active
103 // profile had been Guest before calling or became Guest as a result of this
104 // method.
105 bool SetActiveProfileToGuestIfLocked();
106 #endif  // !defined(OS_CHROMEOS)
107 
108 // If the profile given by |profile_path| is loaded in the ProfileManager, use
109 // a BrowsingDataRemover to delete all the Profile's data.
110 void RemoveBrowsingDataForProfile(const base::FilePath& profile_path);
111 
112 #if !defined(OS_CHROMEOS)
113 // Returns true if there exists at least one non-supervised or non-child profile
114 // and they are all locked.
115 bool AreAllNonChildNonSupervisedProfilesLocked();
116 #endif
117 
118 // Returns whether a public session is being run currently.
119 bool IsPublicSession();
120 
121 // Returns whether public session restrictions are enabled.
122 bool ArePublicSessionRestrictionsEnabled();
123 
124 #if !defined(OS_CHROMEOS)
125 // Returns the default name for a new signed-in profile, based on
126 // `account_info`.
127 base::string16 GetDefaultNameForNewSignedInProfile(
128     const AccountInfo& account_info);
129 #endif  // !defined(OS_CHROMEOS)
130 
131 #endif  // !defined(OS_ANDROID)
132 
133 }  // namespace profiles
134 
135 #endif  // CHROME_BROWSER_PROFILES_PROFILES_STATE_H_
136