| 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 | 147 |
| 148 void QueueProfileDirectoryForDeletion(const FilePath& path) { | 148 void QueueProfileDirectoryForDeletion(const FilePath& path) { |
| 149 ProfilesToDelete().push_back(path); | 149 ProfilesToDelete().push_back(path); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Called upon completion of profile creation. This function takes care of | 152 // Called upon completion of profile creation. This function takes care of |
| 153 // launching a new browser window and signing the user in to their Google | 153 // launching a new browser window and signing the user in to their Google |
| 154 // account. | 154 // account. |
| 155 void OnOpenWindowForNewProfile( | 155 void OnOpenWindowForNewProfile( |
| 156 chrome::HostDesktopType desktop_type, |
| 156 const ProfileManager::CreateCallback& callback, | 157 const ProfileManager::CreateCallback& callback, |
| 157 Profile* profile, | 158 Profile* profile, |
| 158 Profile::CreateStatus status) { | 159 Profile::CreateStatus status) { |
| 159 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 160 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
| 161 |
| 160 ProfileManager::FindOrCreateNewWindowForProfile( | 162 ProfileManager::FindOrCreateNewWindowForProfile( |
| 161 profile, | 163 profile, |
| 162 chrome::startup::IS_PROCESS_STARTUP, | 164 chrome::startup::IS_PROCESS_STARTUP, |
| 163 chrome::startup::IS_FIRST_RUN, | 165 chrome::startup::IS_FIRST_RUN, |
| 166 desktop_type, |
| 164 false); | 167 false); |
| 165 } | 168 } |
| 166 if (!callback.is_null()) | 169 if (!callback.is_null()) |
| 167 callback.Run(profile, status); | 170 callback.Run(profile, status); |
| 168 } | 171 } |
| 169 | 172 |
| 170 #if defined(OS_CHROMEOS) | 173 #if defined(OS_CHROMEOS) |
| 171 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, | 174 void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status, |
| 172 bool is_mounted) { | 175 bool is_mounted) { |
| 173 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | 176 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 this, | 270 this, |
| 268 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 271 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
| 269 content::NotificationService::AllSources()); | 272 content::NotificationService::AllSources()); |
| 270 registrar_.Add( | 273 registrar_.Add( |
| 271 this, | 274 this, |
| 272 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, | 275 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 273 content::NotificationService::AllSources()); | 276 content::NotificationService::AllSources()); |
| 274 | 277 |
| 275 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir.empty()) | 278 if (ProfileShortcutManager::IsFeatureEnabled() && !user_data_dir.empty()) |
| 276 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( | 279 profile_shortcut_manager_.reset(ProfileShortcutManager::Create( |
| 277 this)); | 280 this)); |
| 278 } | 281 } |
| 279 | 282 |
| 280 ProfileManager::~ProfileManager() { | 283 ProfileManager::~ProfileManager() { |
| 281 } | 284 } |
| 282 | 285 |
| 283 FilePath ProfileManager::GetDefaultProfileDir( | 286 FilePath ProfileManager::GetDefaultProfileDir( |
| 284 const FilePath& user_data_dir) { | 287 const FilePath& user_data_dir) { |
| 285 FilePath default_profile_dir(user_data_dir); | 288 FilePath default_profile_dir(user_data_dir); |
| 286 default_profile_dir = | 289 default_profile_dir = |
| 287 default_profile_dir.AppendASCII(chrome::kInitialProfile); | 290 default_profile_dir.AppendASCII(chrome::kInitialProfile); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { | 508 Profile* ProfileManager::GetProfileByPath(const FilePath& path) const { |
| 506 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); | 509 ProfilesInfoMap::const_iterator iter = profiles_info_.find(path); |
| 507 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); | 510 return (iter == profiles_info_.end()) ? NULL : iter->second->profile.get(); |
| 508 } | 511 } |
| 509 | 512 |
| 510 // static | 513 // static |
| 511 void ProfileManager::FindOrCreateNewWindowForProfile( | 514 void ProfileManager::FindOrCreateNewWindowForProfile( |
| 512 Profile* profile, | 515 Profile* profile, |
| 513 chrome::startup::IsProcessStartup process_startup, | 516 chrome::startup::IsProcessStartup process_startup, |
| 514 chrome::startup::IsFirstRun is_first_run, | 517 chrome::startup::IsFirstRun is_first_run, |
| 518 chrome::HostDesktopType desktop_type, |
| 515 bool always_create) { | 519 bool always_create) { |
| 516 DCHECK(profile); | 520 DCHECK(profile); |
| 517 | 521 |
| 518 if (!always_create) { | 522 if (!always_create) { |
| 519 Browser* browser = browser::FindTabbedBrowser(profile, false); | 523 Browser* browser = browser::FindTabbedBrowser(profile, false, desktop_type); |
| 520 if (browser) { | 524 if (browser) { |
| 521 browser->window()->Activate(); | 525 browser->window()->Activate(); |
| 522 return; | 526 return; |
| 523 } | 527 } |
| 524 } | 528 } |
| 525 | 529 |
| 526 content::RecordAction(UserMetricsAction("NewWindow")); | 530 content::RecordAction(UserMetricsAction("NewWindow")); |
| 527 CommandLine command_line(CommandLine::NO_PROGRAM); | 531 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 528 int return_code; | 532 int return_code; |
| 529 StartupBrowserCreator browser_creator; | 533 StartupBrowserCreator browser_creator; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 FilePath new_path = user_data_dir_; | 795 FilePath new_path = user_data_dir_; |
| 792 #if defined(OS_WIN) | 796 #if defined(OS_WIN) |
| 793 new_path = new_path.Append(ASCIIToUTF16(profile_name)); | 797 new_path = new_path.Append(ASCIIToUTF16(profile_name)); |
| 794 #else | 798 #else |
| 795 new_path = new_path.Append(profile_name); | 799 new_path = new_path.Append(profile_name); |
| 796 #endif | 800 #endif |
| 797 local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory); | 801 local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory); |
| 798 return new_path; | 802 return new_path; |
| 799 } | 803 } |
| 800 | 804 |
| 805 // TODO(robertshield): ProfileManager should not be opening windows and should |
| 806 // not have to care about HostDesktopType. See http://crbug.com/153864 |
| 801 // static | 807 // static |
| 802 void ProfileManager::CreateMultiProfileAsync( | 808 void ProfileManager::CreateMultiProfileAsync( |
| 803 const string16& name, | 809 const string16& name, |
| 804 const string16& icon_url, | 810 const string16& icon_url, |
| 805 const CreateCallback& callback) { | 811 const CreateCallback& callback, |
| 812 chrome::HostDesktopType desktop_type) { |
| 806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 807 | 814 |
| 808 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 815 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 809 | 816 |
| 810 FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 817 FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
| 811 | 818 |
| 812 profile_manager->CreateProfileAsync(new_path, | 819 profile_manager->CreateProfileAsync(new_path, |
| 813 base::Bind(&OnOpenWindowForNewProfile, | 820 base::Bind(&OnOpenWindowForNewProfile, |
| 814 callback), | 821 desktop_type, |
| 815 name, icon_url); | 822 callback), |
| 823 name, |
| 824 icon_url); |
| 816 } | 825 } |
| 817 | 826 |
| 818 // static | 827 // static |
| 819 void ProfileManager::RegisterPrefs(PrefService* prefs) { | 828 void ProfileManager::RegisterPrefs(PrefService* prefs) { |
| 820 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); | 829 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); |
| 821 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 830 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
| 822 prefs->RegisterListPref(prefs::kProfilesLastActive); | 831 prefs->RegisterListPref(prefs::kProfilesLastActive); |
| 823 } | 832 } |
| 824 | 833 |
| 825 size_t ProfileManager::GetNumberOfProfiles() { | 834 size_t ProfileManager::GetNumberOfProfiles() { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 923 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 915 if (!logged_in_ && | 924 if (!logged_in_ && |
| 916 (!command_line.HasSwitch(switches::kTestType) || | 925 (!command_line.HasSwitch(switches::kTestType) || |
| 917 command_line.HasSwitch(switches::kLoginProfile))) { | 926 command_line.HasSwitch(switches::kLoginProfile))) { |
| 918 go_off_the_record = true; | 927 go_off_the_record = true; |
| 919 } | 928 } |
| 920 #endif | 929 #endif |
| 921 return go_off_the_record; | 930 return go_off_the_record; |
| 922 } | 931 } |
| 923 | 932 |
| 924 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { | 933 // TODO(robertshield): ProfileManager should not be opening windows and should |
| 934 // not have to care about HostDesktopType. See http://crbug.com/153864 |
| 935 void ProfileManager::ScheduleProfileForDeletion( |
| 936 const FilePath& profile_dir, |
| 937 chrome::HostDesktopType desktop_type) { |
| 925 DCHECK(IsMultipleProfilesEnabled()); | 938 DCHECK(IsMultipleProfilesEnabled()); |
| 926 | 939 |
| 927 // If we're deleting the last profile, then create a new profile in its | 940 // If we're deleting the last profile, then create a new profile in its |
| 928 // place. | 941 // place. |
| 929 ProfileInfoCache& cache = GetProfileInfoCache(); | 942 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 930 if (cache.GetNumberOfProfiles() == 1) { | 943 if (cache.GetNumberOfProfiles() == 1) { |
| 931 FilePath new_path = GenerateNextProfileDirectoryPath(); | 944 FilePath new_path = GenerateNextProfileDirectoryPath(); |
| 932 | 945 |
| 933 CreateProfileAsync(new_path, base::Bind(&OnOpenWindowForNewProfile, | 946 // TODO(robertshield): This desktop type needs to come from the invoker, |
| 934 CreateCallback()), string16(), string16()); | 947 // currently that involves plumbing this through web UI. |
| 948 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 949 CreateProfileAsync(new_path, |
| 950 base::Bind(&OnOpenWindowForNewProfile, |
| 951 desktop_type, |
| 952 CreateCallback()), |
| 953 string16(), |
| 954 string16()); |
| 935 } | 955 } |
| 936 | 956 |
| 937 // Update the last used profile pref before closing browser windows. This way | 957 // Update the last used profile pref before closing browser windows. This way |
| 938 // the correct last used profile is set for any notification observers. | 958 // the correct last used profile is set for any notification observers. |
| 939 PrefService* local_state = g_browser_process->local_state(); | 959 PrefService* local_state = g_browser_process->local_state(); |
| 940 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); | 960 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); |
| 941 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { | 961 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { |
| 942 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 962 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 943 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 963 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
| 944 if (cur_path != profile_dir) { | 964 if (cur_path != profile_dir) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 ProfileManager::ProfileInfo::ProfileInfo( | 1040 ProfileManager::ProfileInfo::ProfileInfo( |
| 1021 Profile* profile, | 1041 Profile* profile, |
| 1022 bool created) | 1042 bool created) |
| 1023 : profile(profile), | 1043 : profile(profile), |
| 1024 created(created) { | 1044 created(created) { |
| 1025 } | 1045 } |
| 1026 | 1046 |
| 1027 ProfileManager::ProfileInfo::~ProfileInfo() { | 1047 ProfileManager::ProfileInfo::~ProfileInfo() { |
| 1028 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1048 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
| 1029 } | 1049 } |
| OLD | NEW |