| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "chrome/browser/about_flags.h" | 18 #include "chrome/browser/about_flags.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/lifetime/application_lifetime.h" | 20 #include "chrome/browser/lifetime/application_lifetime.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 23 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 21 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/signin/account_reconcilor_factory.h" | 26 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 24 #include "chrome/browser/signin/account_tracker_service_factory.h" | 27 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/signin/signin_ui_util.h" | 29 #include "chrome/browser/signin/signin_ui_util.h" |
| 27 #include "chrome/browser/sync/profile_sync_service_factory.h" | 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 28 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_dialogs.h" | 32 #include "chrome/browser/ui/browser_dialogs.h" |
| 30 #include "chrome/browser/ui/profile_chooser_constants.h" | 33 #include "chrome/browser/ui/profile_chooser_constants.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // If this is a brand new profile, then start a first run window. | 138 // If this is a brand new profile, then start a first run window. |
| 136 if (is_new_profile) { | 139 if (is_new_profile) { |
| 137 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; | 140 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; |
| 138 is_first_run = chrome::startup::IS_FIRST_RUN; | 141 is_first_run = chrome::startup::IS_FIRST_RUN; |
| 139 } | 142 } |
| 140 | 143 |
| 141 #if defined(ENABLE_EXTENSIONS) | 144 #if defined(ENABLE_EXTENSIONS) |
| 142 // The signin bit will still be set if the profile is being unlocked and the | 145 // The signin bit will still be set if the profile is being unlocked and the |
| 143 // browser window for it is opening. As part of this unlock process, unblock | 146 // browser window for it is opening. As part of this unlock process, unblock |
| 144 // all the extensions. | 147 // all the extensions. |
| 145 const ProfileInfoCache& cache = | 148 if (!profile->IsGuestSession()) { |
| 146 g_browser_process->profile_manager()->GetProfileInfoCache(); | 149 ProfileAttributesEntry* entry; |
| 147 int index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 150 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 148 if (!profile->IsGuestSession() && | 151 GetProfileAttributesWithPath(profile->GetPath(), &entry) && |
| 149 cache.ProfileIsSigninRequiredAtIndex(index)) { | 152 entry->IsSigninRequired()) { |
| 150 UnblockExtensions(profile); | 153 UnblockExtensions(profile); |
| 154 } |
| 151 } | 155 } |
| 152 #endif // defined(ENABLE_EXTENSIONS) | 156 #endif // defined(ENABLE_EXTENSIONS) |
| 153 | 157 |
| 154 // If |always_create| is false, and we have a |callback| to run, check | 158 // If |always_create| is false, and we have a |callback| to run, check |
| 155 // whether a browser already exists so that we can run the callback. We don't | 159 // whether a browser already exists so that we can run the callback. We don't |
| 156 // want to rely on the observer listening to OnBrowserSetLastActive in this | 160 // want to rely on the observer listening to OnBrowserSetLastActive in this |
| 157 // case, as you could manually activate an incorrect browser and trigger | 161 // case, as you could manually activate an incorrect browser and trigger |
| 158 // a false positive. | 162 // a false positive. |
| 159 if (!always_create) { | 163 if (!always_create) { |
| 160 Browser* browser = chrome::FindTabbedBrowser(profile, false); | 164 Browser* browser = chrome::FindTabbedBrowser(profile, false); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) | 202 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) |
| 199 return; | 203 return; |
| 200 | 204 |
| 201 // Tell the webui which user should be focused. | 205 // Tell the webui which user should be focused. |
| 202 std::string page = switches::IsMaterialDesignUserManager() ? | 206 std::string page = switches::IsMaterialDesignUserManager() ? |
| 203 chrome::kChromeUIMdUserManagerUrl : chrome::kChromeUIUserManagerURL; | 207 chrome::kChromeUIMdUserManagerUrl : chrome::kChromeUIUserManagerURL; |
| 204 | 208 |
| 205 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { | 209 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { |
| 206 page += profiles::kUserManagerDisplayTutorial; | 210 page += profiles::kUserManagerDisplayTutorial; |
| 207 } else if (!profile_path_to_focus.empty()) { | 211 } else if (!profile_path_to_focus.empty()) { |
| 208 const ProfileInfoCache& cache = | 212 // TODO(anthonyvd) : Send |profile_path_to_focus| to the user manager |
| 209 g_browser_process->profile_manager()->GetProfileInfoCache(); | 213 // instead of the profile index. |
| 210 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); | 214 std::vector<ProfileAttributesEntry*> entries = |
| 211 if (index != std::string::npos) { | 215 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 212 page += "#"; | 216 GetAllProfilesAttributesSortedByName(); |
| 213 page += base::SizeTToString(index); | 217 size_t count = entries.size(); |
| 218 for (size_t i = 0; i < count; ++i) { |
| 219 if (profile_path_to_focus == entries[i]->GetPath()) { |
| 220 page += "#"; |
| 221 page += base::SizeTToString(i); |
| 222 break; |
| 223 } |
| 214 } | 224 } |
| 215 } else if (profile_open_action == | 225 } else if (profile_open_action == |
| 216 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) { | 226 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) { |
| 217 page += profiles::kUserManagerSelectProfileTaskManager; | 227 page += profiles::kUserManagerSelectProfileTaskManager; |
| 218 } else if (profile_open_action == | 228 } else if (profile_open_action == |
| 219 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) { | 229 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) { |
| 220 page += profiles::kUserManagerSelectProfileAboutChrome; | 230 page += profiles::kUserManagerSelectProfileAboutChrome; |
| 221 } else if (profile_open_action == | 231 } else if (profile_open_action == |
| 222 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS) { | 232 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS) { |
| 223 page += profiles::kUserManagerSelectProfileChromeSettings; | 233 page += profiles::kUserManagerSelectProfileChromeSettings; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 245 const char kUserManagerDisplayTutorial[] = "#tutorial"; | 255 const char kUserManagerDisplayTutorial[] = "#tutorial"; |
| 246 const char kUserManagerSelectProfileTaskManager[] = "#task-manager"; | 256 const char kUserManagerSelectProfileTaskManager[] = "#task-manager"; |
| 247 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome"; | 257 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome"; |
| 248 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings"; | 258 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings"; |
| 249 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher"; | 259 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher"; |
| 250 | 260 |
| 251 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager, | 261 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager, |
| 252 const std::string& email) { | 262 const std::string& email) { |
| 253 base::string16 profile_email = base::UTF8ToUTF16(email); | 263 base::string16 profile_email = base::UTF8ToUTF16(email); |
| 254 std::vector<ProfileAttributesEntry*> entries = | 264 std::vector<ProfileAttributesEntry*> entries = |
| 255 profile_manager->GetProfileInfoCache().GetAllProfilesAttributes(); | 265 profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 256 for (ProfileAttributesEntry* entry : entries) { | 266 for (ProfileAttributesEntry* entry : entries) { |
| 257 if (entry->GetUserName() == profile_email) | 267 if (entry->GetUserName() == profile_email) |
| 258 return entry->GetPath(); | 268 return entry->GetPath(); |
| 259 } | 269 } |
| 260 return base::FilePath(); | 270 return base::FilePath(); |
| 261 } | 271 } |
| 262 | 272 |
| 263 void FindOrCreateNewWindowForProfile( | 273 void FindOrCreateNewWindowForProfile( |
| 264 Profile* profile, | 274 Profile* profile, |
| 265 chrome::startup::IsProcessStartup process_startup, | 275 chrome::startup::IsProcessStartup process_startup, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 319 |
| 310 bool HasProfileSwitchTargets(Profile* profile) { | 320 bool HasProfileSwitchTargets(Profile* profile) { |
| 311 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; | 321 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; |
| 312 size_t number_of_profiles = | 322 size_t number_of_profiles = |
| 313 g_browser_process->profile_manager()->GetNumberOfProfiles(); | 323 g_browser_process->profile_manager()->GetNumberOfProfiles(); |
| 314 return number_of_profiles >= min_profiles; | 324 return number_of_profiles >= min_profiles; |
| 315 } | 325 } |
| 316 | 326 |
| 317 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback, | 327 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback, |
| 318 ProfileMetrics::ProfileAdd metric) { | 328 ProfileMetrics::ProfileAdd metric) { |
| 319 ProfileInfoCache& cache = | 329 ProfileAttributesStorage& storage = |
| 320 g_browser_process->profile_manager()->GetProfileInfoCache(); | 330 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 321 | 331 |
| 322 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); | 332 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 323 ProfileManager::CreateMultiProfileAsync( | 333 ProfileManager::CreateMultiProfileAsync( |
| 324 cache.ChooseNameForNewProfile(placeholder_avatar_index), | 334 storage.ChooseNameForNewProfile(placeholder_avatar_index), |
| 325 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), | 335 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), |
| 326 base::Bind(&OpenBrowserWindowForProfile, callback, true, true), | 336 base::Bind(&OpenBrowserWindowForProfile, callback, true, true), |
| 327 std::string()); | 337 std::string()); |
| 328 ProfileMetrics::LogProfileAddNewUser(metric); | 338 ProfileMetrics::LogProfileAddNewUser(metric); |
| 329 } | 339 } |
| 330 | 340 |
| 331 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { | 341 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { |
| 332 UserManager::Show(base::FilePath(), | 342 UserManager::Show(base::FilePath(), |
| 333 profiles::USER_MANAGER_NO_TUTORIAL, | 343 profiles::USER_MANAGER_NO_TUTORIAL, |
| 334 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 344 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 335 } | 345 } |
| 336 | 346 |
| 337 void CloseGuestProfileWindows() { | 347 void CloseGuestProfileWindows() { |
| 338 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 348 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 339 Profile* profile = profile_manager->GetProfileByPath( | 349 Profile* profile = profile_manager->GetProfileByPath( |
| 340 ProfileManager::GetGuestProfilePath()); | 350 ProfileManager::GetGuestProfilePath()); |
| 341 | 351 |
| 342 if (profile) { | 352 if (profile) { |
| 343 BrowserList::CloseAllBrowsersWithProfile( | 353 BrowserList::CloseAllBrowsersWithProfile( |
| 344 profile, base::Bind(&GuestBrowserCloseSuccess)); | 354 profile, base::Bind(&GuestBrowserCloseSuccess)); |
| 345 } | 355 } |
| 346 } | 356 } |
| 347 | 357 |
| 348 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { | 358 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { |
| 349 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 359 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 350 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache(); | 360 ProfileAttributesEntry* entry; |
| 351 | 361 bool has_entry = profile_manager->GetProfileAttributesStorage(). |
| 352 cache->SetProfileSigninRequiredAtIndex( | 362 GetProfileAttributesWithPath(profile_path, &entry); |
| 353 cache->GetIndexOfProfileWithPath(profile_path), true); | 363 DCHECK(has_entry); |
| 364 entry->SetIsSigninRequired(true); |
| 354 | 365 |
| 355 #if defined(ENABLE_EXTENSIONS) | 366 #if defined(ENABLE_EXTENSIONS) |
| 356 // Profile guaranteed to exist for it to have been locked. | 367 // Profile guaranteed to exist for it to have been locked. |
| 357 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); | 368 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); |
| 358 #endif // defined(ENABLE_EXTENSIONS) | 369 #endif // defined(ENABLE_EXTENSIONS) |
| 359 | 370 |
| 360 chrome::HideTaskManager(); | 371 chrome::HideTaskManager(); |
| 361 UserManager::Show(profile_path, | 372 UserManager::Show(profile_path, |
| 362 profiles::USER_MANAGER_NO_TUTORIAL, | 373 profiles::USER_MANAGER_NO_TUTORIAL, |
| 363 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 374 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 390 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); | 401 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
| 391 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; | 402 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; |
| 392 } | 403 } |
| 393 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, | 404 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, |
| 394 // prohibited users who use hosted domains (aside from google.com). | 405 // prohibited users who use hosted domains (aside from google.com). |
| 395 if (hosted_domain != Profile::kNoHostedDomainFound && | 406 if (hosted_domain != Profile::kNoHostedDomainFound && |
| 396 hosted_domain != "google.com") { | 407 hosted_domain != "google.com") { |
| 397 return false; | 408 return false; |
| 398 } | 409 } |
| 399 | 410 |
| 400 const ProfileInfoCache& cache = | 411 // Lock only when there is at least one supervised user on the machine. |
| 401 g_browser_process->profile_manager()->GetProfileInfoCache(); | 412 std::vector<ProfileAttributesEntry*> entries = |
| 402 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 413 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 403 if (cache.ProfileIsSupervisedAtIndex(i)) | 414 GetAllProfilesAttributes(); |
| 415 for (ProfileAttributesEntry* entry : entries) { |
| 416 if (entry->IsSupervised()) |
| 404 return true; | 417 return true; |
| 405 } | 418 } |
| 406 return false; | 419 return false; |
| 407 } | 420 } |
| 408 | 421 |
| 409 void CreateSystemProfileForUserManager( | 422 void CreateSystemProfileForUserManager( |
| 410 const base::FilePath& profile_path_to_focus, | 423 const base::FilePath& profile_path_to_focus, |
| 411 profiles::UserManagerTutorialMode tutorial_mode, | 424 profiles::UserManagerTutorialMode tutorial_mode, |
| 412 profiles::UserManagerProfileSelected profile_open_action, | 425 profiles::UserManagerProfileSelected profile_open_action, |
| 413 const base::Callback<void(Profile*, const std::string&)>& callback) { | 426 const base::Callback<void(Profile*, const std::string&)>& callback) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 PrefService* local_state = g_browser_process->local_state(); | 545 PrefService* local_state = g_browser_process->local_state(); |
| 533 const bool dismissed = local_state->GetBoolean( | 546 const bool dismissed = local_state->GetBoolean( |
| 534 prefs::kProfileAvatarRightClickTutorialDismissed); | 547 prefs::kProfileAvatarRightClickTutorialDismissed); |
| 535 | 548 |
| 536 // Don't show the tutorial if it's already been dismissed or if right-clicking | 549 // Don't show the tutorial if it's already been dismissed or if right-clicking |
| 537 // wouldn't show any targets. | 550 // wouldn't show any targets. |
| 538 return !dismissed && HasProfileSwitchTargets(profile); | 551 return !dismissed && HasProfileSwitchTargets(profile); |
| 539 } | 552 } |
| 540 | 553 |
| 541 } // namespace profiles | 554 } // namespace profiles |
| OLD | NEW |