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_PROFILE_WINDOW_H_
6 #define CHROME_BROWSER_PROFILES_PROFILE_WINDOW_H_
7 
8 #include <string>
9 
10 #include "base/callback_forward.h"
11 #include "build/build_config.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/profile_chooser_constants.h"
15 #include "chrome/browser/ui/startup/startup_types.h"
16 
17 #if defined(OS_ANDROID)
18 #error "Not used on Android"
19 #endif
20 
21 class Profile;
22 
23 namespace base { class FilePath; }
24 
25 namespace profiles {
26 
27 // Different actions to perform after the user manager selects a profile as well
28 // as actions to perform when user manager window opens. The former have a
29 // USER_MANAGER_SELECT_PROFILE_ prefix and the later a USER_MANAGER_OPEN_
30 // prefix.
31 enum UserManagerAction {
32   USER_MANAGER_OPEN_CREATE_USER_PAGE,
33   USER_MANAGER_SELECT_PROFILE_NO_ACTION,
34   USER_MANAGER_SELECT_PROFILE_TASK_MANAGER,
35   USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME,
36   USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS,
37 };
38 
39 extern const char kUserManagerOpenCreateUserPage[];
40 extern const char kUserManagerSelectProfileTaskManager[];
41 extern const char kUserManagerSelectProfileAboutChrome[];
42 extern const char kUserManagerSelectProfileChromeSettings[];
43 
44 // Returns the path of the profile connected to the given email.  If no profile
45 // is found an empty file path is returned.
46 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager,
47                                          const std::string& email);
48 
49 // Activates a window for |profile| on the desktop specified by
50 // |desktop_type|. If no such window yet exists, or if |always_create| is
51 // true, this first creates a new window, then activates
52 // that. If activating an exiting window and multiple windows exists then the
53 // window that was most recently active is activated. This is used for
54 // creation of a window from the multi-profile dropdown menu.
55 void FindOrCreateNewWindowForProfile(
56     Profile* profile,
57     chrome::startup::IsProcessStartup process_startup,
58     chrome::startup::IsFirstRun is_first_run,
59     bool always_create);
60 
61 // Opens a Browser for |profile|.
62 // If |always_create| is true a window is created even if one already exists.
63 // If |is_new_profile| is true a first run window is created.
64 // If |unblock_extensions| is true, all extensions are unblocked.
65 // When the browser is opened, |callback| will be run if it isn't null.
66 void OpenBrowserWindowForProfile(ProfileManager::CreateCallback callback,
67                                  bool always_create,
68                                  bool is_new_profile,
69                                  bool unblock_extensions,
70                                  Profile* profile,
71                                  Profile::CreateStatus status);
72 
73 // Loads the specified profile given by |path| asynchronously. Once profile is
74 // loaded and initialized it runs |callback| if it isn't null.
75 void LoadProfileAsync(const base::FilePath& path,
76                       ProfileManager::CreateCallback callback);
77 
78 // Opens a Browser with the specified profile given by |path|.
79 // If |always_create| is true then a new window is created
80 // even if a window for that profile already exists. When the browser is
81 // opened, |callback| will be run if it isn't null.
82 void SwitchToProfile(const base::FilePath& path,
83                      bool always_create,
84                      ProfileManager::CreateCallback callback);
85 
86 // Opens a Browser for the guest profile and runs |callback| if it isn't null.
87 void SwitchToGuestProfile(ProfileManager::CreateCallback callback);
88 
89 // Returns true if |profile| has potential profile switch targets, ie there's at
90 // least one other profile available to switch to, not counting guest. This is
91 // the case when there are more than 1 profiles available or when there's only
92 // one and the current window is a guest window.
93 bool HasProfileSwitchTargets(Profile* profile);
94 
95 // Closes all browser windows that belong to the guest profile and opens the
96 // user manager.
97 void CloseGuestProfileWindows();
98 
99 // Closes and locks all the browser windows for |profile| and opens the user
100 // manager.
101 void LockProfile(Profile* profile);
102 
103 // Close all the browser windows for |profile| and opens the user manager.
104 void CloseProfileWindows(Profile* profile);
105 
106 // Returns whether lock is available to this profile.
107 bool IsLockAvailable(Profile* profile);
108 
109 // Creates or reuses the system profile needed by the user manager.
110 // |profile_path_to_focus| could be used to specify which user should be
111 // focused. Depending on the value of |user_manager_action|, executes an action
112 // once the user manager displays or after a profile is opened. |callback| is
113 // run with the custom url to be displayed, as well as a pointer to the guest
114 // profile.
115 void CreateSystemProfileForUserManager(
116     const base::FilePath& profile_path_to_focus,
117     profiles::UserManagerAction user_manager_action,
118     base::RepeatingCallback<void(Profile*, const std::string&)> callback);
119 
120 // Converts from modes in the avatar menu to modes understood by
121 // ProfileMenuView.
122 void BubbleViewModeFromAvatarBubbleMode(BrowserWindow::AvatarBubbleMode mode,
123                                         Profile* profile,
124                                         BubbleViewMode* bubble_view_mode);
125 
126 // Handles running a callback when a new Browser for the given profile
127 // has been completely created.  This object deletes itself once the browser
128 // is created and the callback is executed.
129 class BrowserAddedForProfileObserver : public BrowserListObserver {
130  public:
131   BrowserAddedForProfileObserver(Profile* profile,
132                                  ProfileManager::CreateCallback callback);
133   BrowserAddedForProfileObserver(const BrowserAddedForProfileObserver&) =
134       delete;
135   BrowserAddedForProfileObserver& operator=(
136       const BrowserAddedForProfileObserver&) = delete;
137   ~BrowserAddedForProfileObserver() override;
138 
139  private:
140   // Overridden from BrowserListObserver:
141   void OnBrowserAdded(Browser* browser) override;
142 
143   // Profile for which the browser should be opened.
144   Profile* profile_;
145   ProfileManager::CreateCallback callback_;
146 };
147 
148 }  // namespace profiles
149 
150 #endif  // CHROME_BROWSER_PROFILES_PROFILE_WINDOW_H_
151