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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
801 // static | 805 // static |
802 void ProfileManager::CreateMultiProfileAsync( | 806 void ProfileManager::CreateMultiProfileAsync( |
803 const string16& name, | 807 const string16& name, |
804 const string16& icon_url, | 808 const string16& icon_url, |
805 const CreateCallback& callback) { | 809 const CreateCallback& callback, |
810 chrome::HostDesktopType desktop_type) { | |
806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
807 | 812 |
808 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 813 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
809 | 814 |
810 FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 815 FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
811 | 816 |
812 profile_manager->CreateProfileAsync(new_path, | 817 profile_manager->CreateProfileAsync(new_path, |
813 base::Bind(&OnOpenWindowForNewProfile, | 818 base::Bind(&OnOpenWindowForNewProfile, |
814 callback), | 819 desktop_type, |
815 name, icon_url); | 820 callback), |
821 name, | |
822 icon_url); | |
816 } | 823 } |
817 | 824 |
818 // static | 825 // static |
819 void ProfileManager::RegisterPrefs(PrefService* prefs) { | 826 void ProfileManager::RegisterPrefs(PrefService* prefs) { |
820 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); | 827 prefs->RegisterStringPref(prefs::kProfileLastUsed, ""); |
821 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); | 828 prefs->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); |
822 prefs->RegisterListPref(prefs::kProfilesLastActive); | 829 prefs->RegisterListPref(prefs::kProfilesLastActive); |
823 } | 830 } |
824 | 831 |
825 size_t ProfileManager::GetNumberOfProfiles() { | 832 size_t ProfileManager::GetNumberOfProfiles() { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 921 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
915 if (!logged_in_ && | 922 if (!logged_in_ && |
916 (!command_line.HasSwitch(switches::kTestType) || | 923 (!command_line.HasSwitch(switches::kTestType) || |
917 command_line.HasSwitch(switches::kLoginProfile))) { | 924 command_line.HasSwitch(switches::kLoginProfile))) { |
918 go_off_the_record = true; | 925 go_off_the_record = true; |
919 } | 926 } |
920 #endif | 927 #endif |
921 return go_off_the_record; | 928 return go_off_the_record; |
922 } | 929 } |
923 | 930 |
924 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { | 931 void ProfileManager::ScheduleProfileForDeletion( |
932 const FilePath& profile_dir, | |
933 chrome::HostDesktopType desktop_type) { | |
Ben Goodger (Google)
2012/10/03 19:16:56
it's unfortunate to have ProfileManager have to kn
robertshield
2012/10/03 19:58:17
Yeah, that would be much better. ProfileManager re
| |
925 DCHECK(IsMultipleProfilesEnabled()); | 934 DCHECK(IsMultipleProfilesEnabled()); |
926 | 935 |
927 // If we're deleting the last profile, then create a new profile in its | 936 // If we're deleting the last profile, then create a new profile in its |
928 // place. | 937 // place. |
929 ProfileInfoCache& cache = GetProfileInfoCache(); | 938 ProfileInfoCache& cache = GetProfileInfoCache(); |
930 if (cache.GetNumberOfProfiles() == 1) { | 939 if (cache.GetNumberOfProfiles() == 1) { |
931 FilePath new_path = GenerateNextProfileDirectoryPath(); | 940 FilePath new_path = GenerateNextProfileDirectoryPath(); |
932 | 941 |
933 CreateProfileAsync(new_path, base::Bind(&OnOpenWindowForNewProfile, | 942 // TODO(robertshield): This desktop type needs to come from the invoker, |
934 CreateCallback()), string16(), string16()); | 943 // currently that involves plumbing this through web UI. |
944 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | |
945 CreateProfileAsync(new_path, | |
946 base::Bind(&OnOpenWindowForNewProfile, | |
947 desktop_type, | |
948 CreateCallback()), | |
949 string16(), | |
950 string16()); | |
935 } | 951 } |
936 | 952 |
937 // Update the last used profile pref before closing browser windows. This way | 953 // Update the last used profile pref before closing browser windows. This way |
938 // the correct last used profile is set for any notification observers. | 954 // the correct last used profile is set for any notification observers. |
939 PrefService* local_state = g_browser_process->local_state(); | 955 PrefService* local_state = g_browser_process->local_state(); |
940 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); | 956 std::string last_profile = local_state->GetString(prefs::kProfileLastUsed); |
941 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { | 957 if (profile_dir.BaseName().MaybeAsASCII() == last_profile) { |
942 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 958 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
943 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 959 FilePath cur_path = cache.GetPathOfProfileAtIndex(i); |
944 if (cur_path != profile_dir) { | 960 if (cur_path != profile_dir) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1020 ProfileManager::ProfileInfo::ProfileInfo( | 1036 ProfileManager::ProfileInfo::ProfileInfo( |
1021 Profile* profile, | 1037 Profile* profile, |
1022 bool created) | 1038 bool created) |
1023 : profile(profile), | 1039 : profile(profile), |
1024 created(created) { | 1040 created(created) { |
1025 } | 1041 } |
1026 | 1042 |
1027 ProfileManager::ProfileInfo::~ProfileInfo() { | 1043 ProfileManager::ProfileInfo::~ProfileInfo() { |
1028 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1044 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
1029 } | 1045 } |
OLD | NEW |