| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // If this is a brand new profile, then start a first run window. | 139 // If this is a brand new profile, then start a first run window. |
| 137 if (is_new_profile) { | 140 if (is_new_profile) { |
| 138 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; | 141 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; |
| 139 is_first_run = chrome::startup::IS_FIRST_RUN; | 142 is_first_run = chrome::startup::IS_FIRST_RUN; |
| 140 } | 143 } |
| 141 | 144 |
| 142 #if defined(ENABLE_EXTENSIONS) | 145 #if defined(ENABLE_EXTENSIONS) |
| 143 // The signin bit will still be set if the profile is being unlocked and the | 146 // The signin bit will still be set if the profile is being unlocked and the |
| 144 // browser window for it is opening. As part of this unlock process, unblock | 147 // browser window for it is opening. As part of this unlock process, unblock |
| 145 // all the extensions. | 148 // all the extensions. |
| 146 const ProfileInfoCache& cache = | 149 if (!profile->IsGuestSession()) { |
| 147 g_browser_process->profile_manager()->GetProfileInfoCache(); | 150 ProfileAttributesEntry* entry; |
| 148 int index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 151 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 149 if (!profile->IsGuestSession() && | 152 GetProfileAttributesWithPath(profile->GetPath(), &entry) && |
| 150 cache.ProfileIsSigninRequiredAtIndex(index)) { | 153 entry->IsSigninRequired()) { |
| 151 UnblockExtensions(profile); | 154 UnblockExtensions(profile); |
| 155 } |
| 152 } | 156 } |
| 153 #endif // defined(ENABLE_EXTENSIONS) | 157 #endif // defined(ENABLE_EXTENSIONS) |
| 154 | 158 |
| 155 // If |always_create| is false, and we have a |callback| to run, check | 159 // If |always_create| is false, and we have a |callback| to run, check |
| 156 // whether a browser already exists so that we can run the callback. We don't | 160 // whether a browser already exists so that we can run the callback. We don't |
| 157 // want to rely on the observer listening to OnBrowserSetLastActive in this | 161 // want to rely on the observer listening to OnBrowserSetLastActive in this |
| 158 // case, as you could manually activate an incorrect browser and trigger | 162 // case, as you could manually activate an incorrect browser and trigger |
| 159 // a false positive. | 163 // a false positive. |
| 160 if (!always_create) { | 164 if (!always_create) { |
| 161 Browser* browser = chrome::FindTabbedBrowser(profile, false); | 165 Browser* browser = chrome::FindTabbedBrowser(profile, false); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 const char kUserManagerDisplayTutorial[] = "#tutorial"; | 248 const char kUserManagerDisplayTutorial[] = "#tutorial"; |
| 245 const char kUserManagerSelectProfileTaskManager[] = "#task-manager"; | 249 const char kUserManagerSelectProfileTaskManager[] = "#task-manager"; |
| 246 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome"; | 250 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome"; |
| 247 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings"; | 251 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings"; |
| 248 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher"; | 252 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher"; |
| 249 | 253 |
| 250 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager, | 254 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager, |
| 251 const std::string& email) { | 255 const std::string& email) { |
| 252 base::string16 profile_email = base::UTF8ToUTF16(email); | 256 base::string16 profile_email = base::UTF8ToUTF16(email); |
| 253 std::vector<ProfileAttributesEntry*> entries = | 257 std::vector<ProfileAttributesEntry*> entries = |
| 254 profile_manager->GetProfileInfoCache().GetAllProfilesAttributes(); | 258 profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 255 for (ProfileAttributesEntry* entry : entries) { | 259 for (ProfileAttributesEntry* entry : entries) { |
| 256 if (entry->GetUserName() == profile_email) | 260 if (entry->GetUserName() == profile_email) |
| 257 return entry->GetPath(); | 261 return entry->GetPath(); |
| 258 } | 262 } |
| 259 return base::FilePath(); | 263 return base::FilePath(); |
| 260 } | 264 } |
| 261 | 265 |
| 262 void FindOrCreateNewWindowForProfile( | 266 void FindOrCreateNewWindowForProfile( |
| 263 Profile* profile, | 267 Profile* profile, |
| 264 chrome::startup::IsProcessStartup process_startup, | 268 chrome::startup::IsProcessStartup process_startup, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 312 |
| 309 bool HasProfileSwitchTargets(Profile* profile) { | 313 bool HasProfileSwitchTargets(Profile* profile) { |
| 310 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; | 314 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; |
| 311 size_t number_of_profiles = | 315 size_t number_of_profiles = |
| 312 g_browser_process->profile_manager()->GetNumberOfProfiles(); | 316 g_browser_process->profile_manager()->GetNumberOfProfiles(); |
| 313 return number_of_profiles >= min_profiles; | 317 return number_of_profiles >= min_profiles; |
| 314 } | 318 } |
| 315 | 319 |
| 316 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback, | 320 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback, |
| 317 ProfileMetrics::ProfileAdd metric) { | 321 ProfileMetrics::ProfileAdd metric) { |
| 318 ProfileInfoCache& cache = | 322 ProfileAttributesStorage& storage = |
| 319 g_browser_process->profile_manager()->GetProfileInfoCache(); | 323 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 320 | 324 |
| 321 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); | 325 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
| 322 ProfileManager::CreateMultiProfileAsync( | 326 ProfileManager::CreateMultiProfileAsync( |
| 323 cache.ChooseNameForNewProfile(placeholder_avatar_index), | 327 storage.ChooseNameForNewProfile(placeholder_avatar_index), |
| 324 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), | 328 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), |
| 325 base::Bind(&OpenBrowserWindowForProfile, callback, true, true), | 329 base::Bind(&OpenBrowserWindowForProfile, callback, true, true), |
| 326 std::string()); | 330 std::string()); |
| 327 ProfileMetrics::LogProfileAddNewUser(metric); | 331 ProfileMetrics::LogProfileAddNewUser(metric); |
| 328 } | 332 } |
| 329 | 333 |
| 330 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { | 334 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { |
| 331 UserManager::Show(base::FilePath(), | 335 UserManager::Show(base::FilePath(), |
| 332 profiles::USER_MANAGER_NO_TUTORIAL, | 336 profiles::USER_MANAGER_NO_TUTORIAL, |
| 333 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 337 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 334 } | 338 } |
| 335 | 339 |
| 336 void CloseGuestProfileWindows() { | 340 void CloseGuestProfileWindows() { |
| 337 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 341 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 338 Profile* profile = profile_manager->GetProfileByPath( | 342 Profile* profile = profile_manager->GetProfileByPath( |
| 339 ProfileManager::GetGuestProfilePath()); | 343 ProfileManager::GetGuestProfilePath()); |
| 340 | 344 |
| 341 if (profile) { | 345 if (profile) { |
| 342 BrowserList::CloseAllBrowsersWithProfile( | 346 BrowserList::CloseAllBrowsersWithProfile( |
| 343 profile, base::Bind(&GuestBrowserCloseSuccess)); | 347 profile, base::Bind(&GuestBrowserCloseSuccess)); |
| 344 } | 348 } |
| 345 } | 349 } |
| 346 | 350 |
| 347 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { | 351 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { |
| 348 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 352 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 349 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache(); | 353 ProfileAttributesEntry* entry; |
| 350 | 354 bool has_entry = profile_manager->GetProfileAttributesStorage(). |
| 351 cache->SetProfileSigninRequiredAtIndex( | 355 GetProfileAttributesWithPath(profile_path, &entry); |
| 352 cache->GetIndexOfProfileWithPath(profile_path), true); | 356 DCHECK(has_entry); |
| 357 entry->SetIsSigninRequired(true); |
| 353 | 358 |
| 354 #if defined(ENABLE_EXTENSIONS) | 359 #if defined(ENABLE_EXTENSIONS) |
| 355 // Profile guaranteed to exist for it to have been locked. | 360 // Profile guaranteed to exist for it to have been locked. |
| 356 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); | 361 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); |
| 357 #endif // defined(ENABLE_EXTENSIONS) | 362 #endif // defined(ENABLE_EXTENSIONS) |
| 358 | 363 |
| 359 chrome::HideTaskManager(); | 364 chrome::HideTaskManager(); |
| 360 UserManager::Show(profile_path, | 365 UserManager::Show(profile_path, |
| 361 profiles::USER_MANAGER_NO_TUTORIAL, | 366 profiles::USER_MANAGER_NO_TUTORIAL, |
| 362 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 367 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 389 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); | 394 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
| 390 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; | 395 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; |
| 391 } | 396 } |
| 392 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, | 397 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, |
| 393 // prohibited users who use hosted domains (aside from google.com). | 398 // prohibited users who use hosted domains (aside from google.com). |
| 394 if (hosted_domain != Profile::kNoHostedDomainFound && | 399 if (hosted_domain != Profile::kNoHostedDomainFound && |
| 395 hosted_domain != "google.com") { | 400 hosted_domain != "google.com") { |
| 396 return false; | 401 return false; |
| 397 } | 402 } |
| 398 | 403 |
| 399 const ProfileInfoCache& cache = | 404 // Lock only when there is at least one supervised user on the machine. |
| 400 g_browser_process->profile_manager()->GetProfileInfoCache(); | 405 std::vector<ProfileAttributesEntry*> entries = |
| 401 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 406 g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 402 if (cache.ProfileIsSupervisedAtIndex(i)) | 407 GetAllProfilesAttributes(); |
| 408 for (ProfileAttributesEntry* entry : entries) { |
| 409 if (entry->IsSupervised()) |
| 403 return true; | 410 return true; |
| 404 } | 411 } |
| 405 return false; | 412 return false; |
| 406 } | 413 } |
| 407 | 414 |
| 408 void CreateSystemProfileForUserManager( | 415 void CreateSystemProfileForUserManager( |
| 409 const base::FilePath& profile_path_to_focus, | 416 const base::FilePath& profile_path_to_focus, |
| 410 profiles::UserManagerTutorialMode tutorial_mode, | 417 profiles::UserManagerTutorialMode tutorial_mode, |
| 411 profiles::UserManagerProfileSelected profile_open_action, | 418 profiles::UserManagerProfileSelected profile_open_action, |
| 412 const base::Callback<void(Profile*, const std::string&)>& callback) { | 419 const base::Callback<void(Profile*, const std::string&)>& callback) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 PrefService* local_state = g_browser_process->local_state(); | 538 PrefService* local_state = g_browser_process->local_state(); |
| 532 const bool dismissed = local_state->GetBoolean( | 539 const bool dismissed = local_state->GetBoolean( |
| 533 prefs::kProfileAvatarRightClickTutorialDismissed); | 540 prefs::kProfileAvatarRightClickTutorialDismissed); |
| 534 | 541 |
| 535 // Don't show the tutorial if it's already been dismissed or if right-clicking | 542 // Don't show the tutorial if it's already been dismissed or if right-clicking |
| 536 // wouldn't show any targets. | 543 // wouldn't show any targets. |
| 537 return !dismissed && HasProfileSwitchTargets(profile); | 544 return !dismissed && HasProfileSwitchTargets(profile); |
| 538 } | 545 } |
| 539 | 546 |
| 540 } // namespace profiles | 547 } // namespace profiles |
| OLD | NEW |