OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/profiles/profile_window.h" | 5 #include "chrome/browser/profiles/profile_window.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
| 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/url_constants.h" |
14 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
16 | 20 |
17 #if !defined(OS_IOS) | 21 #if !defined(OS_IOS) |
18 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
19 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
20 #include "chrome/browser/ui/browser_list_observer.h" | 24 #include "chrome/browser/ui/browser_list_observer.h" |
21 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 26 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
23 #endif // !defined (OS_IOS) | 27 #endif // !defined (OS_IOS) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Passing true for |always_create| means we won't duplicate the code that | 115 // Passing true for |always_create| means we won't duplicate the code that |
112 // tries to find a browser. | 116 // tries to find a browser. |
113 profiles::FindOrCreateNewWindowForProfile( | 117 profiles::FindOrCreateNewWindowForProfile( |
114 profile, | 118 profile, |
115 is_process_startup, | 119 is_process_startup, |
116 is_first_run, | 120 is_first_run, |
117 desktop_type, | 121 desktop_type, |
118 true); | 122 true); |
119 } | 123 } |
120 | 124 |
| 125 // Called after a |guest_profile| is available to be used by the user manager. |
| 126 // Based on the value of |tutorial_mode| we determine a url to be displayed |
| 127 // by the webui and run the |callback|, if it exists. |
| 128 void OnUserManagerGuestProfileCreated( |
| 129 const base::FilePath& profile_path_to_focus, |
| 130 profiles::UserManagerTutorialMode tutorial_mode, |
| 131 const base::Callback<void(Profile*, const std::string&)>& callback, |
| 132 Profile* guest_profile, |
| 133 Profile::CreateStatus status) { |
| 134 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) |
| 135 return; |
| 136 |
| 137 // Tell the webui which user should be focused. |
| 138 std::string page = chrome::kChromeUIUserManagerURL; |
| 139 |
| 140 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { |
| 141 page += "#tutorial"; |
| 142 } else if (!profile_path_to_focus.empty()) { |
| 143 const ProfileInfoCache& cache = |
| 144 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 145 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); |
| 146 if (index != std::string::npos) { |
| 147 page += "#"; |
| 148 page += base::IntToString(index); |
| 149 } |
| 150 } |
| 151 |
| 152 callback.Run(guest_profile, page); |
| 153 } |
| 154 |
121 } // namespace | 155 } // namespace |
122 | 156 |
123 namespace profiles { | 157 namespace profiles { |
124 | 158 |
125 void FindOrCreateNewWindowForProfile( | 159 void FindOrCreateNewWindowForProfile( |
126 Profile* profile, | 160 Profile* profile, |
127 chrome::startup::IsProcessStartup process_startup, | 161 chrome::startup::IsProcessStartup process_startup, |
128 chrome::startup::IsFirstRun is_first_run, | 162 chrome::startup::IsFirstRun is_first_run, |
129 chrome::HostDesktopType desktop_type, | 163 chrome::HostDesktopType desktop_type, |
130 bool always_create) { | 164 bool always_create) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 DCHECK(profile); | 246 DCHECK(profile); |
213 ProfileInfoCache& cache = | 247 ProfileInfoCache& cache = |
214 g_browser_process->profile_manager()->GetProfileInfoCache(); | 248 g_browser_process->profile_manager()->GetProfileInfoCache(); |
215 | 249 |
216 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 250 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
217 cache.SetProfileSigninRequiredAtIndex(index, true); | 251 cache.SetProfileSigninRequiredAtIndex(index, true); |
218 chrome::ShowUserManager(profile->GetPath()); | 252 chrome::ShowUserManager(profile->GetPath()); |
219 BrowserList::CloseAllBrowsersWithProfile(profile); | 253 BrowserList::CloseAllBrowsersWithProfile(profile); |
220 } | 254 } |
221 | 255 |
| 256 void CreateGuestProfileForUserManager( |
| 257 const base::FilePath& profile_path_to_focus, |
| 258 profiles::UserManagerTutorialMode tutorial_mode, |
| 259 const base::Callback<void(Profile*, const std::string&)>& callback) { |
| 260 // Create the guest profile, if necessary, and open the User Manager |
| 261 // from the guest profile. |
| 262 g_browser_process->profile_manager()->CreateProfileAsync( |
| 263 ProfileManager::GetGuestProfilePath(), |
| 264 base::Bind(&OnUserManagerGuestProfileCreated, |
| 265 profile_path_to_focus, |
| 266 tutorial_mode, |
| 267 callback), |
| 268 base::string16(), |
| 269 base::string16(), |
| 270 std::string()); |
| 271 } |
| 272 |
| 273 void ShowUserManagerMaybeWithTutorial(Profile* profile) { |
| 274 if (!profile) { |
| 275 chrome::ShowUserManager(base::FilePath()); |
| 276 return; |
| 277 } |
| 278 // Show the tutorial if the profile has not shown it before. |
| 279 PrefService* pref_service = profile->GetPrefs(); |
| 280 bool tutorial_shown = pref_service->GetBoolean( |
| 281 prefs::kProfileUserManagerTutorialShown); |
| 282 if (!tutorial_shown) |
| 283 pref_service->SetBoolean(prefs::kProfileUserManagerTutorialShown, true); |
| 284 |
| 285 if (tutorial_shown) { |
| 286 chrome::ShowUserManager(profile->GetPath()); |
| 287 } else { |
| 288 chrome::ShowUserManagerWithTutorial( |
| 289 profiles::USER_MANAGER_TUTORIAL_OVERVIEW); |
| 290 } |
| 291 } |
| 292 |
222 } // namespace profiles | 293 } // namespace profiles |
OLD | NEW |