| 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) |
| 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 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 if (!callback.is_null()) |
| 153 callback.Run(guest_profile, page); |
| 154 } |
| 155 |
| 121 } // namespace | 156 } // namespace |
| 122 | 157 |
| 123 namespace profiles { | 158 namespace profiles { |
| 124 | 159 |
| 125 void FindOrCreateNewWindowForProfile( | 160 void FindOrCreateNewWindowForProfile( |
| 126 Profile* profile, | 161 Profile* profile, |
| 127 chrome::startup::IsProcessStartup process_startup, | 162 chrome::startup::IsProcessStartup process_startup, |
| 128 chrome::startup::IsFirstRun is_first_run, | 163 chrome::startup::IsFirstRun is_first_run, |
| 129 chrome::HostDesktopType desktop_type, | 164 chrome::HostDesktopType desktop_type, |
| 130 bool always_create) { | 165 bool always_create) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 DCHECK(profile); | 247 DCHECK(profile); |
| 213 ProfileInfoCache& cache = | 248 ProfileInfoCache& cache = |
| 214 g_browser_process->profile_manager()->GetProfileInfoCache(); | 249 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 215 | 250 |
| 216 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 251 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 217 cache.SetProfileSigninRequiredAtIndex(index, true); | 252 cache.SetProfileSigninRequiredAtIndex(index, true); |
| 218 chrome::ShowUserManager(profile->GetPath()); | 253 chrome::ShowUserManager(profile->GetPath()); |
| 219 BrowserList::CloseAllBrowsersWithProfile(profile); | 254 BrowserList::CloseAllBrowsersWithProfile(profile); |
| 220 } | 255 } |
| 221 | 256 |
| 257 void CreateGuestProfileForUserManager( |
| 258 const base::FilePath& profile_path_to_focus, |
| 259 profiles::UserManagerTutorialMode tutorial_mode, |
| 260 const base::Callback<void(Profile*, const std::string&)>& callback) { |
| 261 |
| 262 // Create the guest profile, if necessary, and open the User Manager |
| 263 // from the guest profile. |
| 264 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 265 profile_manager->CreateProfileAsync( |
| 266 ProfileManager::GetGuestProfilePath(), |
| 267 base::Bind(&OnUserManagerGuestProfileCreated, |
| 268 profile_path_to_focus, |
| 269 tutorial_mode, |
| 270 callback), |
| 271 base::string16(), |
| 272 base::string16(), |
| 273 std::string()); |
| 274 } |
| 275 |
| 276 void ShowUserManagerMaybeWithTutorial(Profile* profile) { |
| 277 // Show the tutorial if the profile has not shown it before. |
| 278 PrefService* pref_service = profile->GetPrefs(); |
| 279 bool tutorial_shown = pref_service->GetBoolean( |
| 280 prefs::kProfileUserManagerTutorialShown); |
| 281 if (!tutorial_shown) |
| 282 pref_service->SetBoolean(prefs::kProfileUserManagerTutorialShown, true); |
| 283 |
| 284 if (tutorial_shown) { |
| 285 chrome::ShowUserManager(profile->GetPath()); |
| 286 } else { |
| 287 chrome::ShowUserManagerWithTutorial( |
| 288 profiles::USER_MANAGER_TUTORIAL_OVERVIEW); |
| 289 } |
| 290 } |
| 291 |
| 222 } // namespace profiles | 292 } // namespace profiles |
| OLD | NEW |