Chromium Code Reviews| 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" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/about_flags.h" | 12 #include "chrome/browser/about_flags.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
| 15 #include "chrome/browser/pref_service_flags_storage.h" | 15 #include "chrome/browser/pref_service_flags_storage.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
| 18 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
| 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/signin/account_reconcilor_factory.h" | 21 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 20 #include "chrome/browser/signin/account_tracker_service_factory.h" | 22 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/browser/signin/signin_ui_util.h" | 24 #include "chrome/browser/signin/signin_ui_util.h" |
| 23 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
| 24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 25 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_dialogs.h" | 28 #include "chrome/browser/ui/browser_dialogs.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 // If this is a brand new profile, then start a first run window. | 126 // If this is a brand new profile, then start a first run window. |
| 125 if (is_new_profile) { | 127 if (is_new_profile) { |
| 126 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; | 128 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; |
| 127 is_first_run = chrome::startup::IS_FIRST_RUN; | 129 is_first_run = chrome::startup::IS_FIRST_RUN; |
| 128 } | 130 } |
| 129 | 131 |
| 130 #if defined(ENABLE_EXTENSIONS) | 132 #if defined(ENABLE_EXTENSIONS) |
| 131 // The signin bit will still be set if the profile is being unlocked and the | 133 // The signin bit will still be set if the profile is being unlocked and the |
| 132 // browser window for it is opening. As part of this unlock process, unblock | 134 // browser window for it is opening. As part of this unlock process, unblock |
| 133 // all the extensions. | 135 // all the extensions. |
| 134 const ProfileInfoCache& cache = | 136 ProfileAttributesStorage& storage = |
| 135 g_browser_process->profile_manager()->GetProfileInfoCache(); | 137 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 136 int index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 138 ProfileAttributesEntry* entry = nullptr; |
| 137 if (!profile->IsGuestSession() && | 139 if (!profile->IsGuestSession() && |
| 138 cache.ProfileIsSigninRequiredAtIndex(index)) { | 140 !storage.GetProfileAttributesWithPath(profile->GetPath(), &entry)) { |
| 141 NOTREACHED(); | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 if (!profile->IsGuestSession() && entry->IsSigninRequired()) { | |
|
Mike Lerman
2015/08/06 16:06:20
you don't need to verify IsGuestSession() twice (h
| |
| 139 UnblockExtensions(profile); | 146 UnblockExtensions(profile); |
| 140 } | 147 } |
| 141 #endif // defined(ENABLE_EXTENSIONS) | 148 #endif // defined(ENABLE_EXTENSIONS) |
| 142 | 149 |
| 143 // If |always_create| is false, and we have a |callback| to run, check | 150 // If |always_create| is false, and we have a |callback| to run, check |
| 144 // whether a browser already exists so that we can run the callback. We don't | 151 // whether a browser already exists so that we can run the callback. We don't |
| 145 // want to rely on the observer listening to OnBrowserSetLastActive in this | 152 // want to rely on the observer listening to OnBrowserSetLastActive in this |
| 146 // case, as you could manually activate an incorrect browser and trigger | 153 // case, as you could manually activate an incorrect browser and trigger |
| 147 // a false positive. | 154 // a false positive. |
| 148 if (!always_create) { | 155 if (!always_create) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 Profile::CreateStatus status) { | 197 Profile::CreateStatus status) { |
| 191 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) | 198 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) |
| 192 return; | 199 return; |
| 193 | 200 |
| 194 // Tell the webui which user should be focused. | 201 // Tell the webui which user should be focused. |
| 195 std::string page = chrome::kChromeUIUserManagerURL; | 202 std::string page = chrome::kChromeUIUserManagerURL; |
| 196 | 203 |
| 197 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { | 204 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { |
| 198 page += profiles::kUserManagerDisplayTutorial; | 205 page += profiles::kUserManagerDisplayTutorial; |
| 199 } else if (!profile_path_to_focus.empty()) { | 206 } else if (!profile_path_to_focus.empty()) { |
| 200 const ProfileInfoCache& cache = | 207 |
| 201 g_browser_process->profile_manager()->GetProfileInfoCache(); | 208 ProfileAttributesStorage& storage = |
| 202 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); | 209 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 203 if (index != std::string::npos) { | 210 std::vector<ProfileAttributesEntry*> entries = |
| 211 storage.GetAllProfilesAttributes(); | |
| 212 ProfileAttributesEntry* entry_to_focus; | |
| 213 if (storage.GetProfileAttributesWithPath(profile_path_to_focus, | |
| 214 &entry_to_focus)) { | |
| 215 // The index of an entry in an hypothetically sorted collection is equal | |
| 216 // to the count of items that compare as smaller than said entry, since | |
| 217 // it's impossible for entries to compare as equal. | |
| 218 auto index_to_focus = std::count_if(entries.begin(), entries.end(), | |
| 219 [&entry_to_focus] (ProfileAttributesEntry* other) { | |
| 220 return other->LessThan(*entry_to_focus); | |
| 221 }); | |
| 204 page += "#"; | 222 page += "#"; |
| 205 page += base::IntToString(index); | 223 page += base::IntToString(index_to_focus); |
|
Mike Lerman
2015/08/06 16:06:20
well... this is annoying. We probably shouldn't us
| |
| 206 } | 224 } |
| 207 } else if (profile_open_action == | 225 } else if (profile_open_action == |
| 208 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) { | 226 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) { |
| 209 page += profiles::kUserManagerSelectProfileTaskManager; | 227 page += profiles::kUserManagerSelectProfileTaskManager; |
| 210 } else if (profile_open_action == | 228 } else if (profile_open_action == |
| 211 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) { | 229 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) { |
| 212 page += profiles::kUserManagerSelectProfileAboutChrome; | 230 page += profiles::kUserManagerSelectProfileAboutChrome; |
| 213 } else if (profile_open_action == | 231 } else if (profile_open_action == |
| 214 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS) { | 232 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS) { |
| 215 page += profiles::kUserManagerSelectProfileChromeSettings; | 233 page += profiles::kUserManagerSelectProfileChromeSettings; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 bool HasProfileSwitchTargets(Profile* profile) { | 330 bool HasProfileSwitchTargets(Profile* profile) { |
| 313 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; | 331 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; |
| 314 size_t number_of_profiles = | 332 size_t number_of_profiles = |
| 315 g_browser_process->profile_manager()->GetNumberOfProfiles(); | 333 g_browser_process->profile_manager()->GetNumberOfProfiles(); |
| 316 return number_of_profiles >= min_profiles; | 334 return number_of_profiles >= min_profiles; |
| 317 } | 335 } |
| 318 | 336 |
| 319 void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type, | 337 void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type, |
| 320 ProfileManager::CreateCallback callback, | 338 ProfileManager::CreateCallback callback, |
| 321 ProfileMetrics::ProfileAdd metric) { | 339 ProfileMetrics::ProfileAdd metric) { |
| 322 ProfileInfoCache& cache = | 340 ProfileAttributesStorage& storage = |
| 323 g_browser_process->profile_manager()->GetProfileInfoCache(); | 341 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 324 | 342 |
| 325 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); | 343 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 326 ProfileManager::CreateMultiProfileAsync( | 344 ProfileManager::CreateMultiProfileAsync( |
| 327 cache.ChooseNameForNewProfile(placeholder_avatar_index), | 345 storage.ChooseNameForNewProfile(placeholder_avatar_index), |
| 328 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl( | 346 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl( |
| 329 placeholder_avatar_index)), | 347 placeholder_avatar_index)), |
| 330 base::Bind(&OpenBrowserWindowForProfile, | 348 base::Bind(&OpenBrowserWindowForProfile, |
| 331 callback, | 349 callback, |
| 332 true, | 350 true, |
| 333 true, | 351 true, |
| 334 desktop_type), | 352 desktop_type), |
| 335 std::string()); | 353 std::string()); |
| 336 ProfileMetrics::LogProfileAddNewUser(metric); | 354 ProfileMetrics::LogProfileAddNewUser(metric); |
| 337 } | 355 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 348 ProfileManager::GetGuestProfilePath()); | 366 ProfileManager::GetGuestProfilePath()); |
| 349 | 367 |
| 350 if (profile) { | 368 if (profile) { |
| 351 BrowserList::CloseAllBrowsersWithProfile( | 369 BrowserList::CloseAllBrowsersWithProfile( |
| 352 profile, base::Bind(&GuestBrowserCloseSuccess)); | 370 profile, base::Bind(&GuestBrowserCloseSuccess)); |
| 353 } | 371 } |
| 354 } | 372 } |
| 355 | 373 |
| 356 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { | 374 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { |
| 357 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 375 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 358 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache(); | |
| 359 | 376 |
| 360 cache->SetProfileSigninRequiredAtIndex( | 377 ProfileAttributesStorage& storage = |
| 361 cache->GetIndexOfProfileWithPath(profile_path), true); | 378 profile_manager->GetProfileAttributesStorage(); |
| 379 ProfileAttributesEntry* entry; | |
| 380 if (storage.GetProfileAttributesWithPath(profile_path, &entry)) { | |
| 381 entry->SetIsSigninRequired(true); | |
| 382 } | |
| 362 | 383 |
| 363 #if defined(ENABLE_EXTENSIONS) | 384 #if defined(ENABLE_EXTENSIONS) |
| 364 // Profile guaranteed to exist for it to have been locked. | 385 // Profile guaranteed to exist for it to have been locked. |
| 365 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); | 386 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); |
| 366 #endif // defined(ENABLE_EXTENSIONS) | 387 #endif // defined(ENABLE_EXTENSIONS) |
| 367 | 388 |
| 368 chrome::HideTaskManager(); | 389 chrome::HideTaskManager(); |
| 369 UserManager::Show(profile_path, | 390 UserManager::Show(profile_path, |
| 370 profiles::USER_MANAGER_NO_TUTORIAL, | 391 profiles::USER_MANAGER_NO_TUTORIAL, |
| 371 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 392 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 398 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); | 419 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
| 399 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; | 420 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; |
| 400 } | 421 } |
| 401 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, | 422 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, |
| 402 // prohibited users who use hosted domains (aside from google.com). | 423 // prohibited users who use hosted domains (aside from google.com). |
| 403 if (hosted_domain != Profile::kNoHostedDomainFound && | 424 if (hosted_domain != Profile::kNoHostedDomainFound && |
| 404 hosted_domain != "google.com") { | 425 hosted_domain != "google.com") { |
| 405 return false; | 426 return false; |
| 406 } | 427 } |
| 407 | 428 |
| 408 const ProfileInfoCache& cache = | 429 ProfileAttributesStorage& storage = |
| 409 g_browser_process->profile_manager()->GetProfileInfoCache(); | 430 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 410 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 431 std::vector<ProfileAttributesEntry*> entries = |
| 411 if (cache.ProfileIsSupervisedAtIndex(i)) | 432 storage.GetAllProfilesAttributes(); |
| 433 for (ProfileAttributesEntry* entry: entries) { | |
|
Mike Lerman
2015/08/06 16:06:20
entry<space>:
| |
| 434 if (entry->IsSupervised()) | |
| 412 return true; | 435 return true; |
| 413 } | 436 } |
| 414 return false; | 437 return false; |
| 415 } | 438 } |
| 416 | 439 |
| 417 void CreateSystemProfileForUserManager( | 440 void CreateSystemProfileForUserManager( |
| 418 const base::FilePath& profile_path_to_focus, | 441 const base::FilePath& profile_path_to_focus, |
| 419 profiles::UserManagerTutorialMode tutorial_mode, | 442 profiles::UserManagerTutorialMode tutorial_mode, |
| 420 profiles::UserManagerProfileSelected profile_open_action, | 443 profiles::UserManagerProfileSelected profile_open_action, |
| 421 const base::Callback<void(Profile*, const std::string&)>& callback) { | 444 const base::Callback<void(Profile*, const std::string&)>& callback) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 PrefService* local_state = g_browser_process->local_state(); | 565 PrefService* local_state = g_browser_process->local_state(); |
| 543 const bool dismissed = local_state->GetBoolean( | 566 const bool dismissed = local_state->GetBoolean( |
| 544 prefs::kProfileAvatarRightClickTutorialDismissed); | 567 prefs::kProfileAvatarRightClickTutorialDismissed); |
| 545 | 568 |
| 546 // Don't show the tutorial if it's already been dismissed or if right-clicking | 569 // Don't show the tutorial if it's already been dismissed or if right-clicking |
| 547 // wouldn't show any targets. | 570 // wouldn't show any targets. |
| 548 return !dismissed && HasProfileSwitchTargets(profile); | 571 return !dismissed && HasProfileSwitchTargets(profile); |
| 549 } | 572 } |
| 550 | 573 |
| 551 } // namespace profiles | 574 } // namespace profiles |
| OLD | NEW |