| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_manager.h" | 5 #include "chrome/browser/profiles/profile_manager.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/deferred_sequenced_task_runner.h" | 12 #include "base/deferred_sequenced_task_runner.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_registry_simple.h" | |
| 18 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model.h" | 21 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 24 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 26 #include "chrome/browser/content_settings/host_content_settings_map.h" | 25 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 27 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 26 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 27 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 29 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" | 28 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" |
| 30 #include "chrome/browser/profiles/profile_destroyer.h" | 29 #include "chrome/browser/profiles/profile_destroyer.h" |
| 31 #include "chrome/browser/profiles/profile_info_cache.h" | 30 #include "chrome/browser/profiles/profile_info_cache.h" |
| 32 #include "chrome/browser/profiles/profile_metrics.h" | 31 #include "chrome/browser/profiles/profile_metrics.h" |
| 32 #include "chrome/browser/profiles/profiles_state.h" |
| 33 #include "chrome/browser/profiles/startup_task_runner_service.h" | 33 #include "chrome/browser/profiles/startup_task_runner_service.h" |
| 34 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 34 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
| 35 #include "chrome/browser/sync/profile_sync_service.h" | 35 #include "chrome/browser/sync/profile_sync_service.h" |
| 36 #include "chrome/browser/sync/profile_sync_service_factory.h" | 36 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 37 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 38 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
| 39 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
| 40 #include "chrome/common/chrome_paths_internal.h" | 40 #include "chrome/common/chrome_paths_internal.h" |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/logging_chrome.h" | 42 #include "chrome/common/logging_chrome.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 #if defined(ENABLE_MANAGED_USERS) | 55 #if defined(ENABLE_MANAGED_USERS) |
| 56 #include "chrome/browser/managed_mode/managed_user_service.h" | 56 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 57 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 57 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 #if !defined(OS_IOS) | 60 #if !defined(OS_IOS) |
| 61 #include "chrome/browser/extensions/extension_service.h" | 61 #include "chrome/browser/extensions/extension_service.h" |
| 62 #include "chrome/browser/extensions/extension_system.h" | 62 #include "chrome/browser/extensions/extension_system.h" |
| 63 #include "chrome/browser/sessions/session_service_factory.h" | 63 #include "chrome/browser/sessions/session_service_factory.h" |
| 64 #include "chrome/browser/ui/browser_finder.h" | |
| 65 #include "chrome/browser/ui/browser_list.h" | 64 #include "chrome/browser/ui/browser_list.h" |
| 66 #include "chrome/browser/ui/browser_window.h" | |
| 67 #include "chrome/browser/ui/startup/startup_browser_creator.h" | |
| 68 #endif // !defined (OS_IOS) | 65 #endif // !defined (OS_IOS) |
| 69 | 66 |
| 70 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
| 71 #include "base/win/metro.h" | 68 #include "base/win/metro.h" |
| 72 #include "chrome/installer/util/browser_distribution.h" | 69 #include "chrome/installer/util/browser_distribution.h" |
| 73 #endif | 70 #endif |
| 74 | 71 |
| 75 #if defined(OS_CHROMEOS) | 72 #if defined(OS_CHROMEOS) |
| 76 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 73 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| 77 #include "chrome/browser/chromeos/login/user.h" | 74 #include "chrome/browser/chromeos/login/user.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 content::NotificationService::AllSources()); | 301 content::NotificationService::AllSources()); |
| 305 | 302 |
| 306 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty()) | 303 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir_.empty()) |
| 307 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( | 304 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( |
| 308 this)); | 305 this)); |
| 309 } | 306 } |
| 310 | 307 |
| 311 ProfileManager::~ProfileManager() { | 308 ProfileManager::~ProfileManager() { |
| 312 } | 309 } |
| 313 | 310 |
| 314 base::FilePath ProfileManager::GetDefaultProfileDir( | |
| 315 const base::FilePath& user_data_dir) { | |
| 316 base::FilePath default_profile_dir(user_data_dir); | |
| 317 default_profile_dir = | |
| 318 default_profile_dir.AppendASCII(chrome::kInitialProfile); | |
| 319 return default_profile_dir; | |
| 320 } | |
| 321 | |
| 322 base::FilePath ProfileManager::GetProfilePrefsPath( | |
| 323 const base::FilePath &profile_dir) { | |
| 324 base::FilePath default_prefs_path(profile_dir); | |
| 325 default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); | |
| 326 return default_prefs_path; | |
| 327 } | |
| 328 | |
| 329 base::FilePath ProfileManager::GetInitialProfileDir() { | 311 base::FilePath ProfileManager::GetInitialProfileDir() { |
| 330 base::FilePath relative_profile_dir; | 312 base::FilePath relative_profile_dir; |
| 331 #if defined(OS_CHROMEOS) | 313 #if defined(OS_CHROMEOS) |
| 332 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 314 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 333 if (logged_in_) { | 315 if (logged_in_) { |
| 334 base::FilePath profile_dir; | 316 base::FilePath profile_dir; |
| 335 // If the user has logged in, pick up the new profile. | 317 // If the user has logged in, pick up the new profile. |
| 336 if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) { | 318 if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) { |
| 337 profile_dir = command_line.GetSwitchValuePath( | 319 profile_dir = command_line.GetSwitchValuePath( |
| 338 chromeos::switches::kLoginProfile); | 320 chromeos::switches::kLoginProfile); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 return to_return; | 395 return to_return; |
| 414 } | 396 } |
| 415 | 397 |
| 416 Profile* ProfileManager::GetDefaultProfile( | 398 Profile* ProfileManager::GetDefaultProfile( |
| 417 const base::FilePath& user_data_dir) { | 399 const base::FilePath& user_data_dir) { |
| 418 #if defined(OS_CHROMEOS) | 400 #if defined(OS_CHROMEOS) |
| 419 base::FilePath default_profile_dir(user_data_dir); | 401 base::FilePath default_profile_dir(user_data_dir); |
| 420 if (logged_in_) { | 402 if (logged_in_) { |
| 421 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | 403 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
| 422 } else { | 404 } else { |
| 423 default_profile_dir = GetDefaultProfileDir(user_data_dir); | 405 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
| 424 } | 406 } |
| 425 #else | 407 #else |
| 426 base::FilePath default_profile_dir(user_data_dir); | 408 base::FilePath default_profile_dir(user_data_dir); |
| 427 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); | 409 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); |
| 428 #endif | 410 #endif |
| 429 #if defined(OS_CHROMEOS) | 411 #if defined(OS_CHROMEOS) |
| 430 if (!logged_in_) { | 412 if (!logged_in_) { |
| 431 Profile* profile = GetProfile(default_profile_dir); | 413 Profile* profile = GetProfile(default_profile_dir); |
| 432 // For cros, return the OTR profile so we never accidentally keep | 414 // For cros, return the OTR profile so we never accidentally keep |
| 433 // user data in an unencrypted profile. But doing this makes | 415 // user data in an unencrypted profile. But doing this makes |
| 434 // many of the browser and ui tests fail. We do return the OTR profile | 416 // many of the browser and ui tests fail. We do return the OTR profile |
| 435 // if the login-profile switch is passed so that we can test this. | 417 // if the login-profile switch is passed so that we can test this. |
| 436 // TODO(davemoore) Fix the tests so they allow OTR profiles. | 418 // TODO(davemoore) Fix the tests so they allow OTR profiles. |
| 437 if (ShouldGoOffTheRecord(profile)) | 419 if (ShouldGoOffTheRecord(profile)) |
| 438 return profile->GetOffTheRecordProfile(); | 420 return profile->GetOffTheRecordProfile(); |
| 439 return profile; | 421 return profile; |
| 440 } | 422 } |
| 441 | 423 |
| 442 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); | 424 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); |
| 443 // Fallback to default off-the-record profile, if user profile has not fully | 425 // Fallback to default off-the-record profile, if user profile has not fully |
| 444 // loaded yet. | 426 // loaded yet. |
| 445 if (profile_info && !profile_info->created) | 427 if (profile_info && !profile_info->created) |
| 446 default_profile_dir = GetDefaultProfileDir(user_data_dir); | 428 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); |
| 447 #endif | 429 #endif |
| 448 return GetProfile(default_profile_dir); | 430 return GetProfile(default_profile_dir); |
| 449 } | 431 } |
| 450 | 432 |
| 451 bool ProfileManager::IsValidProfile(Profile* profile) { | 433 bool ProfileManager::IsValidProfile(Profile* profile) { |
| 452 for (ProfilesInfoMap::iterator iter = profiles_info_.begin(); | 434 for (ProfilesInfoMap::iterator iter = profiles_info_.begin(); |
| 453 iter != profiles_info_.end(); ++iter) { | 435 iter != profiles_info_.end(); ++iter) { |
| 454 if (iter->second->created) { | 436 if (iter->second->created) { |
| 455 Profile* candidate = iter->second->profile.get(); | 437 Profile* candidate = iter->second->profile.get(); |
| 456 if (candidate == profile || | 438 if (candidate == profile || |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 const base::FilePath& path) const { | 574 const base::FilePath& path) const { |
| 593 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 575 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
| 594 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); | 576 return (iter == profiles_info_.end()) ? NULL : iter->second.get(); |
| 595 } | 577 } |
| 596 | 578 |
| 597 Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const { | 579 Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const { |
| 598 ProfileInfo* profile_info = GetProfileInfoByPath(path); | 580 ProfileInfo* profile_info = GetProfileInfoByPath(path); |
| 599 return profile_info ? profile_info->profile.get() : NULL; | 581 return profile_info ? profile_info->profile.get() : NULL; |
| 600 } | 582 } |
| 601 | 583 |
| 602 // static | |
| 603 void ProfileManager::FindOrCreateNewWindowForProfile( | |
| 604 Profile* profile, | |
| 605 chrome::startup::IsProcessStartup process_startup, | |
| 606 chrome::startup::IsFirstRun is_first_run, | |
| 607 chrome::HostDesktopType desktop_type, | |
| 608 bool always_create) { | |
| 609 #if defined(OS_IOS) | |
| 610 NOTREACHED(); | |
| 611 #else | |
| 612 DCHECK(profile); | |
| 613 | |
| 614 if (!always_create) { | |
| 615 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); | |
| 616 if (browser) { | |
| 617 browser->window()->Activate(); | |
| 618 return; | |
| 619 } | |
| 620 } | |
| 621 | |
| 622 content::RecordAction(UserMetricsAction("NewWindow")); | |
| 623 CommandLine command_line(CommandLine::NO_PROGRAM); | |
| 624 int return_code; | |
| 625 StartupBrowserCreator browser_creator; | |
| 626 browser_creator.LaunchBrowser(command_line, profile, base::FilePath(), | |
| 627 process_startup, is_first_run, &return_code); | |
| 628 #endif // defined(OS_IOS) | |
| 629 } | |
| 630 | |
| 631 void ProfileManager::Observe( | 584 void ProfileManager::Observe( |
| 632 int type, | 585 int type, |
| 633 const content::NotificationSource& source, | 586 const content::NotificationSource& source, |
| 634 const content::NotificationDetails& details) { | 587 const content::NotificationDetails& details) { |
| 635 #if defined(OS_CHROMEOS) | 588 #if defined(OS_CHROMEOS) |
| 636 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 589 if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| 637 logged_in_ = true; | 590 logged_in_ = true; |
| 638 | 591 |
| 639 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 592 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 640 if (!command_line.HasSwitch(switches::kTestType)) { | 593 if (!command_line.HasSwitch(switches::kTestType)) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 // Invoke INITIALIZED or FAIL for all profiles. | 838 // Invoke INITIALIZED or FAIL for all profiles. |
| 886 RunCallbacks(callbacks, profile, | 839 RunCallbacks(callbacks, profile, |
| 887 profile ? Profile::CREATE_STATUS_INITIALIZED : | 840 profile ? Profile::CREATE_STATUS_INITIALIZED : |
| 888 Profile::CREATE_STATUS_LOCAL_FAIL); | 841 Profile::CREATE_STATUS_LOCAL_FAIL); |
| 889 } | 842 } |
| 890 | 843 |
| 891 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { | 844 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { |
| 892 PrefService* local_state = g_browser_process->local_state(); | 845 PrefService* local_state = g_browser_process->local_state(); |
| 893 DCHECK(local_state); | 846 DCHECK(local_state); |
| 894 | 847 |
| 895 DCHECK(IsMultipleProfilesEnabled()); | 848 DCHECK(profiles::IsMultipleProfilesEnabled()); |
| 896 | 849 |
| 897 // Create the next profile in the next available directory slot. | 850 // Create the next profile in the next available directory slot. |
| 898 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); | 851 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); |
| 899 std::string profile_name = chrome::kMultiProfileDirPrefix; | 852 std::string profile_name = chrome::kMultiProfileDirPrefix; |
| 900 profile_name.append(base::IntToString(next_directory)); | 853 profile_name.append(base::IntToString(next_directory)); |
| 901 base::FilePath new_path = user_data_dir_; | 854 base::FilePath new_path = user_data_dir_; |
| 902 #if defined(OS_WIN) | 855 #if defined(OS_WIN) |
| 903 new_path = new_path.Append(ASCIIToUTF16(profile_name)); | 856 new_path = new_path.Append(ASCIIToUTF16(profile_name)); |
| 904 #else | 857 #else |
| 905 new_path = new_path.Append(profile_name); | 858 new_path = new_path.Append(profile_name); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 931 // static | 884 // static |
| 932 base::FilePath ProfileManager::GetGuestProfilePath() { | 885 base::FilePath ProfileManager::GetGuestProfilePath() { |
| 933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 886 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 934 | 887 |
| 935 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 888 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 936 | 889 |
| 937 base::FilePath guest_path = profile_manager->user_data_dir(); | 890 base::FilePath guest_path = profile_manager->user_data_dir(); |
| 938 return guest_path.Append(chrome::kGuestProfileDir); | 891 return guest_path.Append(chrome::kGuestProfileDir); |
| 939 } | 892 } |
| 940 | 893 |
| 941 // static | |
| 942 void ProfileManager::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 943 registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); | |
| 944 registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | |
| 945 registry->RegisterListPref(prefs::kProfilesLastActive); | |
| 946 } | |
| 947 | |
| 948 size_t ProfileManager::GetNumberOfProfiles() { | 894 size_t ProfileManager::GetNumberOfProfiles() { |
| 949 return GetProfileInfoCache().GetNumberOfProfiles(); | 895 return GetProfileInfoCache().GetNumberOfProfiles(); |
| 950 } | 896 } |
| 951 | 897 |
| 952 bool ProfileManager::CompareProfilePathAndName( | 898 bool ProfileManager::CompareProfilePathAndName( |
| 953 const ProfileManager::ProfilePathAndName& pair1, | 899 const ProfileManager::ProfilePathAndName& pair1, |
| 954 const ProfileManager::ProfilePathAndName& pair2) { | 900 const ProfileManager::ProfilePathAndName& pair2) { |
| 955 int name_compare = pair1.second.compare(pair2.second); | 901 int name_compare = pair1.second.compare(pair2.second); |
| 956 if (name_compare < 0) { | 902 if (name_compare < 0) { |
| 957 return true; | 903 return true; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 size_t profile_cache_index = | 966 size_t profile_cache_index = |
| 1021 cache.GetIndexOfProfileWithPath(profile->GetPath()); | 967 cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 1022 // If the cache has an entry for this profile, use the cache data. | 968 // If the cache has an entry for this profile, use the cache data. |
| 1023 if (profile_cache_index != std::string::npos) { | 969 if (profile_cache_index != std::string::npos) { |
| 1024 avatar_index = | 970 avatar_index = |
| 1025 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); | 971 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); |
| 1026 profile_name = | 972 profile_name = |
| 1027 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); | 973 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); |
| 1028 is_managed = cache.ProfileIsManagedAtIndex(profile_cache_index); | 974 is_managed = cache.ProfileIsManagedAtIndex(profile_cache_index); |
| 1029 } else if (profile->GetPath() == | 975 } else if (profile->GetPath() == |
| 1030 GetDefaultProfileDir(cache.GetUserDataDir())) { | 976 profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { |
| 1031 avatar_index = 0; | 977 avatar_index = 0; |
| 1032 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); | 978 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); |
| 1033 } else { | 979 } else { |
| 1034 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); | 980 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); |
| 1035 profile_name = UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 981 profile_name = UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); |
| 1036 } | 982 } |
| 1037 } | 983 } |
| 1038 | 984 |
| 1039 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) | 985 if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileAvatarIndex)) |
| 1040 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); | 986 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, avatar_index); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1055 command_line.HasSwitch(chromeos::switches::kLoginProfile))) { | 1001 command_line.HasSwitch(chromeos::switches::kLoginProfile))) { |
| 1056 go_off_the_record = true; | 1002 go_off_the_record = true; |
| 1057 } | 1003 } |
| 1058 #endif | 1004 #endif |
| 1059 return go_off_the_record; | 1005 return go_off_the_record; |
| 1060 } | 1006 } |
| 1061 | 1007 |
| 1062 void ProfileManager::ScheduleProfileForDeletion( | 1008 void ProfileManager::ScheduleProfileForDeletion( |
| 1063 const base::FilePath& profile_dir, | 1009 const base::FilePath& profile_dir, |
| 1064 const CreateCallback& callback) { | 1010 const CreateCallback& callback) { |
| 1065 DCHECK(IsMultipleProfilesEnabled()); | 1011 DCHECK(profiles::IsMultipleProfilesEnabled()); |
| 1066 PrefService* local_state = g_browser_process->local_state(); | 1012 PrefService* local_state = g_browser_process->local_state(); |
| 1067 ProfileInfoCache& cache = GetProfileInfoCache(); | 1013 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 1068 | 1014 |
| 1069 if (profile_dir.BaseName().MaybeAsASCII() == | 1015 if (profile_dir.BaseName().MaybeAsASCII() == |
| 1070 local_state->GetString(prefs::kProfileLastUsed)) { | 1016 local_state->GetString(prefs::kProfileLastUsed)) { |
| 1071 // Update the last used profile pref before closing browser windows. This | 1017 // Update the last used profile pref before closing browser windows. This |
| 1072 // way the correct last used profile is set for any notification observers. | 1018 // way the correct last used profile is set for any notification observers. |
| 1073 base::FilePath last_non_managed_profile_path; | 1019 base::FilePath last_non_managed_profile_path; |
| 1074 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1020 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 1075 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1021 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 profile)) { | 1107 profile)) { |
| 1162 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 1108 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 1163 profile)->DisableForUser(); | 1109 profile)->DisableForUser(); |
| 1164 } | 1110 } |
| 1165 } | 1111 } |
| 1166 | 1112 |
| 1167 QueueProfileDirectoryForDeletion(profile_dir); | 1113 QueueProfileDirectoryForDeletion(profile_dir); |
| 1168 cache.DeleteProfileFromCache(profile_dir); | 1114 cache.DeleteProfileFromCache(profile_dir); |
| 1169 } | 1115 } |
| 1170 | 1116 |
| 1171 // static | |
| 1172 bool ProfileManager::IsMultipleProfilesEnabled() { | |
| 1173 #if defined(OS_ANDROID) | |
| 1174 return false; | |
| 1175 #endif | |
| 1176 #if defined(OS_CHROMEOS) | |
| 1177 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) | |
| 1178 return false; | |
| 1179 #endif | |
| 1180 | |
| 1181 return true; | |
| 1182 } | |
| 1183 | |
| 1184 // static | |
| 1185 bool ProfileManager::IsNewProfileManagementEnabled() { | |
| 1186 return CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1187 switches::kNewProfileManagement); | |
| 1188 } | |
| 1189 | |
| 1190 void ProfileManager::AutoloadProfiles() { | 1117 void ProfileManager::AutoloadProfiles() { |
| 1191 // If running in the background is disabled for the browser, do not autoload | 1118 // If running in the background is disabled for the browser, do not autoload |
| 1192 // any profiles. | 1119 // any profiles. |
| 1193 PrefService* local_state = g_browser_process->local_state(); | 1120 PrefService* local_state = g_browser_process->local_state(); |
| 1194 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || | 1121 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || |
| 1195 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { | 1122 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { |
| 1196 return; | 1123 return; |
| 1197 } | 1124 } |
| 1198 | 1125 |
| 1199 ProfileInfoCache& cache = GetProfileInfoCache(); | 1126 ProfileInfoCache& cache = GetProfileInfoCache(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 ProfileManager::ProfileInfo::ProfileInfo( | 1163 ProfileManager::ProfileInfo::ProfileInfo( |
| 1237 Profile* profile, | 1164 Profile* profile, |
| 1238 bool created) | 1165 bool created) |
| 1239 : profile(profile), | 1166 : profile(profile), |
| 1240 created(created) { | 1167 created(created) { |
| 1241 } | 1168 } |
| 1242 | 1169 |
| 1243 ProfileManager::ProfileInfo::~ProfileInfo() { | 1170 ProfileManager::ProfileInfo::~ProfileInfo() { |
| 1244 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1171 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
| 1245 } | 1172 } |
| OLD | NEW |