diff options
author | noms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 03:30:38 +0000 |
---|---|---|
committer | noms@chromium.org <noms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 03:30:38 +0000 |
commit | de71ae9945e89ea1bf1eea94b3d3af9382febf68 (patch) | |
tree | b39dbdd36433de74510abd7c6ac3fdf0fc0b27d6 | |
parent | 703b7e15fc77b4f493bd1a808bd4ac02d7b8fbb0 (diff) | |
download | chromium_src-de71ae9945e89ea1bf1eea94b3d3af9382febf68.zip chromium_src-de71ae9945e89ea1bf1eea94b3d3af9382febf68.tar.gz chromium_src-de71ae9945e89ea1bf1eea94b3d3af9382febf68.tar.bz2 |
Refactor utility methods that don't use the ProfileManager directly out of the ProfileManager.
I only picked public, static, functions that look standalone
-- i.e. don't use any other functions in the ProfileManager,
and only interact with other classes (browser, file paths,
registry preferences)
BUG=none
TEST=existing unit and browser tests
Review URL: https://chromiumcodereview.appspot.com/18615010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212221 0039d316-1c4b-4281-b951-d872f2087c98
26 files changed, 232 insertions, 151 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 1f22e213..22e3d58 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -31,6 +31,7 @@ #include "chrome/browser/printing/print_dialog_cloud.h" #include "chrome/browser/profiles/profile_info_cache_observer.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/service/service_process_control.h" #include "chrome/browser/sessions/session_restore.h" #include "chrome/browser/sessions/session_service.h" @@ -1125,7 +1126,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { NSMenu* mainMenu = [NSApp mainMenu]; NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; - if (!ProfileManager::IsMultipleProfilesEnabled()) { + if (!profiles::IsMultipleProfilesEnabled()) { [mainMenu removeItem:profileMenu]; return; } diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 6d3e0fe..53fa3e0 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -78,6 +78,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profile_window.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" @@ -1057,8 +1059,7 @@ void TestingAutomationProvider::GetMultiProfileInfo( ProfileManager* profile_manager = g_browser_process->profile_manager(); const ProfileInfoCache& profile_info_cache = profile_manager->GetProfileInfoCache(); - return_value->SetBoolean("enabled", - profile_manager->IsMultipleProfilesEnabled()); + return_value->SetBoolean("enabled", profiles::IsMultipleProfilesEnabled()); ListValue* profiles = new ListValue; for (size_t index = 0; index < profile_info_cache.GetNumberOfProfiles(); @@ -1152,7 +1153,7 @@ void TestingAutomationProvider::OpenProfileWindow( } new BrowserOpenedWithExistingProfileNotificationObserver( this, reply_message, num_loads); - ProfileManager::FindOrCreateNewWindowForProfile( + profiles::FindOrCreateNewWindowForProfile( profile, chrome::startup::IS_NOT_PROCESS_STARTUP, chrome::startup::IS_NOT_FIRST_RUN, diff --git a/chrome/browser/chrome_browser_field_trials_desktop.cc b/chrome/browser/chrome_browser_field_trials_desktop.cc index 6ded512..339ee6b 100644 --- a/chrome/browser/chrome_browser_field_trials_desktop.cc +++ b/chrome/browser/chrome_browser_field_trials_desktop.cc @@ -17,7 +17,7 @@ #include "chrome/browser/gpu/chrome_gpu_util.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/prerender/prerender_field_trial.h" -#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" #include "chrome/browser/ui/sync/one_click_signin_helper.h" #include "chrome/common/chrome_switches.h" @@ -78,7 +78,7 @@ void DisableShowProfileSwitcherTrialIfNecessary() { avatar_menu_always_hidden = true; #endif base::FieldTrial* trial = base::FieldTrialList::Find("ShowProfileSwitcher"); - if (trial && (!ProfileManager::IsMultipleProfilesEnabled() || + if (trial && (!profiles::IsMultipleProfilesEnabled() || avatar_menu_always_hidden)) { trial->Disable(); } diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index fd43b60..bcc7b11 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -87,6 +87,7 @@ #include "chrome/browser/process_singleton.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" #include "chrome/browser/search_engines/search_engine_type.h" #include "chrome/browser/service/service_process_control.h" @@ -328,7 +329,7 @@ Profile* CreateProfile(const content::MainFunctionParams& parameters, const base::FilePath& user_data_dir, const CommandLine& parsed_command_line) { TRACE_EVENT0("startup", "ChromeBrowserMainParts::CreateProfile") - if (ProfileManager::IsMultipleProfilesEnabled() && + if (profiles::IsMultipleProfilesEnabled() && parsed_command_line.HasSwitch(switches::kProfileDirectory)) { g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc index 9cb785b..c5cd11f 100644 --- a/chrome/browser/first_run/first_run.cc +++ b/chrome/browser/first_run/first_run.cc @@ -11,6 +11,7 @@ #include "base/file_util.h" #include "base/files/file_path.h" #include "base/lazy_instance.h" +#include "base/message_loop.h" #include "base/metrics/histogram.h" #include "base/path_service.h" #include "base/prefs/pref_service.h" @@ -28,7 +29,7 @@ #include "chrome/browser/importer/importer_progress_observer.h" #include "chrome/browser/importer/importer_uma.h" #include "chrome/browser/importer/profile_writer.h" -#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/shell_integration.h" @@ -167,14 +168,14 @@ void DoDelayedInstallExtensionsIfNeeded( base::FilePath GetDefaultPrefFilePath(bool create_profile_dir, const base::FilePath& user_data_dir) { base::FilePath default_pref_dir = - ProfileManager::GetDefaultProfileDir(user_data_dir); + profiles::GetDefaultProfileDir(user_data_dir); if (create_profile_dir) { if (!base::PathExists(default_pref_dir)) { if (!file_util::CreateDirectory(default_pref_dir)) return base::FilePath(); } } - return ProfileManager::GetProfilePrefsPath(default_pref_dir); + return profiles::GetProfilePrefsPath(default_pref_dir); } // Sets the |items| bitfield according to whether the import data specified by diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 0756d52..b606a80 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -58,7 +58,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_impl.h" #include "chrome/browser/profiles/profile_info_cache.h" -#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h" #include "chrome/browser/renderer_host/web_cache_manager.h" #include "chrome/browser/search/search.h" @@ -206,7 +206,7 @@ void RegisterLocalState(PrefRegistrySimple* registry) { metrics::CachingPermutedEntropyProvider::RegisterPrefs(registry); PrefProxyConfigTrackerImpl::RegisterPrefs(registry); ProfileInfoCache::RegisterPrefs(registry); - ProfileManager::RegisterPrefs(registry); + profiles::RegisterPrefs(registry); PromoResourceService::RegisterPrefs(registry); RegisterPrefsForRecoveryComponent(registry); SigninManagerFactory::RegisterPrefs(registry); diff --git a/chrome/browser/profiles/avatar_menu_model.cc b/chrome/browser/profiles/avatar_menu_model.cc index 4a86e7f..55e2b89 100644 --- a/chrome/browser/profiles/avatar_menu_model.cc +++ b/chrome/browser/profiles/avatar_menu_model.cc @@ -18,6 +18,8 @@ #include "chrome/browser/profiles/profile_info_util.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" +#include "chrome/browser/profiles/profile_window.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" @@ -51,7 +53,7 @@ void OnProfileCreated(bool always_create, DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (status == Profile::CREATE_STATUS_INITIALIZED) { - ProfileManager::FindOrCreateNewWindowForProfile( + profiles::FindOrCreateNewWindowForProfile( profile, chrome::startup::IS_NOT_PROCESS_STARTUP, chrome::startup::IS_NOT_FIRST_RUN, @@ -140,7 +142,7 @@ AvatarMenuModel::Item::~Item() { } void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { - DCHECK(ProfileManager::IsMultipleProfilesEnabled() || + DCHECK(profiles::IsMultipleProfilesEnabled() || index == GetActiveProfileIndex()); const Item& item = GetItemAt(index); base::FilePath path = @@ -281,11 +283,11 @@ bool AvatarMenuModel::ShouldShowAvatarMenu() { if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) == kAlwaysShowSwitcherGroupName) { // We should only be in this group when multi-profiles is enabled. - DCHECK(ProfileManager::IsMultipleProfilesEnabled()); + DCHECK(profiles::IsMultipleProfilesEnabled()); return true; } - if (ProfileManager::IsMultipleProfilesEnabled()) { - return ProfileManager::IsNewProfileManagementEnabled() || + if (profiles::IsMultipleProfilesEnabled()) { + return profiles::IsNewProfileManagementEnabled() || (g_browser_process->profile_manager() && g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); } diff --git a/chrome/browser/profiles/avatar_menu_model_browsertest.cc b/chrome/browser/profiles/avatar_menu_model_browsertest.cc index aa02956..b980ef3 100644 --- a/chrome/browser/profiles/avatar_menu_model_browsertest.cc +++ b/chrome/browser/profiles/avatar_menu_model_browsertest.cc @@ -7,6 +7,7 @@ #include "base/path_service.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_paths.h" @@ -19,7 +20,7 @@ namespace { typedef InProcessBrowserTest AvatarMenuModelTest; IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SignOut) { - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; ProfileManager* profile_manager = g_browser_process->profile_manager(); diff --git a/chrome/browser/profiles/avatar_menu_model_unittest.cc b/chrome/browser/profiles/avatar_menu_model_unittest.cc index b012827..0a48e4a 100644 --- a/chrome/browser/profiles/avatar_menu_model_unittest.cc +++ b/chrome/browser/profiles/avatar_menu_model_unittest.cc @@ -11,7 +11,7 @@ #include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/profiles/avatar_menu_model_observer.h" #include "chrome/browser/profiles/profile_info_cache.h" -#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile_manager.h" #include "grit/generated_resources.h" @@ -182,7 +182,7 @@ TEST_F(AvatarMenuModelTest, ChangeOnNotify) { TEST_F(AvatarMenuModelTest, ShowAvatarMenuInTrial) { // If multiprofile mode is not enabled, the trial will not be enabled, so it // isn't tested. - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; base::FieldTrialList field_trial_list_(NULL); @@ -204,7 +204,7 @@ TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) { // If multiprofile mode is enabled, there are no other cases when we wouldn't // show the menu. - if (ProfileManager::IsMultipleProfilesEnabled()) + if (profiles::IsMultipleProfilesEnabled()) return; string16 name2(ASCIIToUTF16("Test 2")); @@ -216,7 +216,7 @@ TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) { TEST_F(AvatarMenuModelTest, ShowAvatarMenu) { // If multiprofile mode is not enabled then the menu is never shown. - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; string16 name1(ASCIIToUTF16("Test 1")); @@ -236,7 +236,7 @@ TEST_F(AvatarMenuModelTest, ShowAvatarMenu) { TEST_F(AvatarMenuModelTest, SyncState) { // If multiprofile mode is not enabled then the menu is never shown. - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index d0079b7..d8d480b 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -14,7 +14,6 @@ #include "base/files/file_enumerator.h" #include "base/files/file_path.h" #include "base/metrics/histogram.h" -#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" @@ -30,6 +29,7 @@ #include "chrome/browser/profiles/profile_destroyer.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_metrics.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/startup_task_runner_service.h" #include "chrome/browser/profiles/startup_task_runner_service_factory.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -61,10 +61,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/sessions/session_service_factory.h" -#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/startup/startup_browser_creator.h" #endif // !defined (OS_IOS) #if defined(OS_WIN) @@ -311,21 +308,6 @@ ProfileManager::ProfileManager(const base::FilePath& user_data_dir) ProfileManager::~ProfileManager() { } -base::FilePath ProfileManager::GetDefaultProfileDir( - const base::FilePath& user_data_dir) { - base::FilePath default_profile_dir(user_data_dir); - default_profile_dir = - default_profile_dir.AppendASCII(chrome::kInitialProfile); - return default_profile_dir; -} - -base::FilePath ProfileManager::GetProfilePrefsPath( - const base::FilePath &profile_dir) { - base::FilePath default_prefs_path(profile_dir); - default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); - return default_prefs_path; -} - base::FilePath ProfileManager::GetInitialProfileDir() { base::FilePath relative_profile_dir; #if defined(OS_CHROMEOS) @@ -420,7 +402,7 @@ Profile* ProfileManager::GetDefaultProfile( if (logged_in_) { default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); } else { - default_profile_dir = GetDefaultProfileDir(user_data_dir); + default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); } #else base::FilePath default_profile_dir(user_data_dir); @@ -443,7 +425,7 @@ Profile* ProfileManager::GetDefaultProfile( // Fallback to default off-the-record profile, if user profile has not fully // loaded yet. if (profile_info && !profile_info->created) - default_profile_dir = GetDefaultProfileDir(user_data_dir); + default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); #endif return GetProfile(default_profile_dir); } @@ -599,35 +581,6 @@ Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const { return profile_info ? profile_info->profile.get() : NULL; } -// static -void ProfileManager::FindOrCreateNewWindowForProfile( - Profile* profile, - chrome::startup::IsProcessStartup process_startup, - chrome::startup::IsFirstRun is_first_run, - chrome::HostDesktopType desktop_type, - bool always_create) { -#if defined(OS_IOS) - NOTREACHED(); -#else - DCHECK(profile); - - if (!always_create) { - Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); - if (browser) { - browser->window()->Activate(); - return; - } - } - - content::RecordAction(UserMetricsAction("NewWindow")); - CommandLine command_line(CommandLine::NO_PROGRAM); - int return_code; - StartupBrowserCreator browser_creator; - browser_creator.LaunchBrowser(command_line, profile, base::FilePath(), - process_startup, is_first_run, &return_code); -#endif // defined(OS_IOS) -} - void ProfileManager::Observe( int type, const content::NotificationSource& source, @@ -892,7 +845,7 @@ base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { PrefService* local_state = g_browser_process->local_state(); DCHECK(local_state); - DCHECK(IsMultipleProfilesEnabled()); + DCHECK(profiles::IsMultipleProfilesEnabled()); // Create the next profile in the next available directory slot. int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); @@ -938,13 +891,6 @@ base::FilePath ProfileManager::GetGuestProfilePath() { return guest_path.Append(chrome::kGuestProfileDir); } -// static -void ProfileManager::RegisterPrefs(PrefRegistrySimple* registry) { - registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); - registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); - registry->RegisterListPref(prefs::kProfilesLastActive); -} - size_t ProfileManager::GetNumberOfProfiles() { return GetProfileInfoCache().GetNumberOfProfiles(); } @@ -1027,7 +973,7 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) { UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); is_managed = cache.ProfileIsManagedAtIndex(profile_cache_index); } else if (profile->GetPath() == - GetDefaultProfileDir(cache.GetUserDataDir())) { + profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { avatar_index = 0; profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); } else { @@ -1062,7 +1008,7 @@ bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) { void ProfileManager::ScheduleProfileForDeletion( const base::FilePath& profile_dir, const CreateCallback& callback) { - DCHECK(IsMultipleProfilesEnabled()); + DCHECK(profiles::IsMultipleProfilesEnabled()); PrefService* local_state = g_browser_process->local_state(); ProfileInfoCache& cache = GetProfileInfoCache(); @@ -1168,25 +1114,6 @@ void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { cache.DeleteProfileFromCache(profile_dir); } -// static -bool ProfileManager::IsMultipleProfilesEnabled() { -#if defined(OS_ANDROID) - return false; -#endif -#if defined(OS_CHROMEOS) - if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) - return false; -#endif - - return true; -} - -// static -bool ProfileManager::IsNewProfileManagementEnabled() { - return CommandLine::ForCurrentProcess()->HasSwitch( - switches::kNewProfileManagement); -} - void ProfileManager::AutoloadProfiles() { // If running in the background is disabled for the browser, do not autoload // any profiles. diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index 816d33e..dea43de 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -21,8 +21,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" #include "chrome/browser/ui/browser_list_observer.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/startup/startup_types.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -150,34 +148,11 @@ class ProfileManager : public base::NonThreadSafe, // Indicate that the import process for |profile| has completed. void OnImportFinished(Profile* profile); - // ------------------ static utility functions ------------------- - - // Returns the path to the default profile directory, based on the given - // user data directory. - static base::FilePath GetDefaultProfileDir( - const base::FilePath& user_data_dir); - - // Returns the path to the preferences file given the user profile directory. - static base::FilePath GetProfilePrefsPath(const base::FilePath& profile_dir); - // If a profile with the given path is currently managed by this object, // return a pointer to the corresponding Profile object; // otherwise return NULL. Profile* GetProfileByPath(const base::FilePath& path) const; - // Activates a window for |profile| on the desktop specified by - // |desktop_type|. If no such window yet exists, or if |always_create| is - // true, this first creates a new window, then activates - // that. If activating an exiting window and multiple windows exists then the - // window that was most recently active is activated. This is used for - // creation of a window from the multi-profile dropdown menu. - static void FindOrCreateNewWindowForProfile( - Profile* profile, - chrome::startup::IsProcessStartup process_startup, - chrome::startup::IsFirstRun is_first_run, - chrome::HostDesktopType desktop_type, - bool always_create); - // Profile::Delegate implementation: virtual void OnProfileCreated(Profile* profile, bool success, @@ -205,9 +180,6 @@ class ProfileManager : public base::NonThreadSafe, // Returns the full path to be used for guest profiles. static base::FilePath GetGuestProfilePath(); - // Register multi-profile related preferences in Local State. - static void RegisterPrefs(PrefRegistrySimple* registry); - // Returns a ProfileInfoCache object which can be used to get information // about profiles without having to load them from disk. ProfileInfoCache& GetProfileInfoCache(); @@ -222,12 +194,6 @@ class ProfileManager : public base::NonThreadSafe, void ScheduleProfileForDeletion(const base::FilePath& profile_dir, const CreateCallback& callback); - // Checks if multiple profiles is enabled. - static bool IsMultipleProfilesEnabled(); - - // Checks if new profile management is enabled. - static bool IsNewProfileManagementEnabled(); - // Autoloads profiles if they are running background apps. void AutoloadProfiles(); diff --git a/chrome/browser/profiles/profile_window.cc b/chrome/browser/profiles/profile_window.cc new file mode 100644 index 0000000..fb3276f --- /dev/null +++ b/chrome/browser/profiles/profile_window.cc @@ -0,0 +1,51 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/profiles/profile_window.h" + +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "content/public/browser/user_metrics.h" + +#if !defined(OS_IOS) +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/startup/startup_browser_creator.h" +#endif // !defined (OS_IOS) + +using content::UserMetricsAction; + +namespace profiles { + +void FindOrCreateNewWindowForProfile( + Profile* profile, + chrome::startup::IsProcessStartup process_startup, + chrome::startup::IsFirstRun is_first_run, + chrome::HostDesktopType desktop_type, + bool always_create) { +#if defined(OS_IOS) + NOTREACHED(); +#else + DCHECK(profile); + + if (!always_create) { + Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); + if (browser) { + browser->window()->Activate(); + return; + } + } + + content::RecordAction(UserMetricsAction("NewWindow")); + CommandLine command_line(CommandLine::NO_PROGRAM); + int return_code; + StartupBrowserCreator browser_creator; + browser_creator.LaunchBrowser(command_line, profile, base::FilePath(), + process_startup, is_first_run, &return_code); +#endif // defined(OS_IOS) +} + +} // namespace profiles diff --git a/chrome/browser/profiles/profile_window.h b/chrome/browser/profiles/profile_window.h new file mode 100644 index 0000000..bf98403 --- /dev/null +++ b/chrome/browser/profiles/profile_window.h @@ -0,0 +1,30 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PROFILES_PROFILE_WINDOW_H_ +#define CHROME_BROWSER_PROFILES_PROFILE_WINDOW_H_ + +#include "chrome/browser/ui/host_desktop.h" +#include "chrome/browser/ui/startup/startup_types.h" + +class Profile; + +namespace profiles { + +// Activates a window for |profile| on the desktop specified by +// |desktop_type|. If no such window yet exists, or if |always_create| is +// true, this first creates a new window, then activates +// that. If activating an exiting window and multiple windows exists then the +// window that was most recently active is activated. This is used for +// creation of a window from the multi-profile dropdown menu. +void FindOrCreateNewWindowForProfile( + Profile* profile, + chrome::startup::IsProcessStartup process_startup, + chrome::startup::IsFirstRun is_first_run, + chrome::HostDesktopType desktop_type, + bool always_create); + +} // namespace profiles + +#endif // CHROME_BROWSER_PROFILES_PROFILE_WINDOW_H_ diff --git a/chrome/browser/profiles/profiles_state.cc b/chrome/browser/profiles/profiles_state.cc new file mode 100644 index 0000000..19409de --- /dev/null +++ b/chrome/browser/profiles/profiles_state.cc @@ -0,0 +1,54 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/profiles/profiles_state.h" + +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/prefs/pref_registry_simple.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" + +namespace profiles { + +bool IsMultipleProfilesEnabled() { +#if defined(OS_ANDROID) + return false; +#endif +#if defined(OS_CHROMEOS) + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) + return false; +#endif + + return true; +} + +bool IsNewProfileManagementEnabled() { + return CommandLine::ForCurrentProcess()->HasSwitch( + switches::kNewProfileManagement); +} + +base::FilePath GetDefaultProfileDir( + const base::FilePath& user_data_dir) { + base::FilePath default_profile_dir(user_data_dir); + default_profile_dir = + default_profile_dir.AppendASCII(chrome::kInitialProfile); + return default_profile_dir; +} + +base::FilePath GetProfilePrefsPath( + const base::FilePath &profile_dir) { + base::FilePath default_prefs_path(profile_dir); + default_prefs_path = default_prefs_path.Append(chrome::kPreferencesFilename); + return default_prefs_path; +} + +void RegisterPrefs(PrefRegistrySimple* registry) { + registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); + registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); + registry->RegisterListPref(prefs::kProfilesLastActive); +} + +} // namespace profiles diff --git a/chrome/browser/profiles/profiles_state.h b/chrome/browser/profiles/profiles_state.h new file mode 100644 index 0000000..2858e62 --- /dev/null +++ b/chrome/browser/profiles/profiles_state.h @@ -0,0 +1,31 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PROFILES_PROFILES_STATE_H_ +#define CHROME_BROWSER_PROFILES_PROFILES_STATE_H_ + +class PrefRegistrySimple; +namespace base { class FilePath; } + +namespace profiles { + +// Checks if multiple profiles is enabled. +bool IsMultipleProfilesEnabled(); + +// Checks if new profile management is enabled. +bool IsNewProfileManagementEnabled(); + +// Returns the path to the default profile directory, based on the given +// user data directory. +base::FilePath GetDefaultProfileDir(const base::FilePath& user_data_dir); + +// Returns the path to the preferences file given the user profile directory. +base::FilePath GetProfilePrefsPath(const base::FilePath& profile_dir); + +// Register multi-profile related preferences in Local State. +void RegisterPrefs(PrefRegistrySimple* registry); + +} // namespace profiles + +#endif // CHROME_BROWSER_PROFILES_PROFILES_STATE_H_ diff --git a/chrome/browser/ui/browser_command_controller_unittest.cc b/chrome/browser/ui/browser_command_controller_unittest.cc index 6d50522..b9e5516 100644 --- a/chrome/browser/ui/browser_command_controller_unittest.cc +++ b/chrome/browser/ui/browser_command_controller_unittest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/command_updater.h" #include "chrome/browser/profiles/profile_destroyer.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_window_state.h" @@ -141,7 +142,7 @@ TEST_F(BrowserCommandControllerTest, AppFullScreen) { } TEST_F(BrowserCommandControllerTest, AvatarMenuDisabledWhenOnlyOneProfile) { - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; TestingProfileManager testing_profile_manager( diff --git a/chrome/browser/ui/gtk/gtk_util.cc b/chrome/browser/ui/gtk/gtk_util.cc index 6c07e14..3166f5f 100644 --- a/chrome/browser/ui/gtk/gtk_util.cc +++ b/chrome/browser/ui/gtk/gtk_util.cc @@ -23,6 +23,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_iterator.h" @@ -151,7 +152,7 @@ GdkPixbuf* GetAvatarIcon(Profile* profile) { const ProfileInfoCache& cache = g_browser_process->profile_manager()->GetProfileInfoCache(); - if (!ProfileManager::IsMultipleProfilesEnabled() || + if (!profiles::IsMultipleProfilesEnabled() || cache.GetNumberOfProfiles() < 2) return NULL; diff --git a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc index 6b5c947..e26356b 100644 --- a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc +++ b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc @@ -17,6 +17,7 @@ #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_io_data.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profile_window.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -274,7 +275,7 @@ void OneClickSigninSyncStarter::CompleteInitForNewProfile( LoadPolicyWithCachedClient(); // Open the profile's first window, after all initialization. - ProfileManager::FindOrCreateNewWindowForProfile( + profiles::FindOrCreateNewWindowForProfile( new_profile, chrome::startup::IS_PROCESS_STARTUP, chrome::startup::IS_FIRST_RUN, diff --git a/chrome/browser/ui/views/avatar_menu_button.cc b/chrome/browser/ui/views/avatar_menu_button.cc index 323d2e1..f1b749d 100644 --- a/chrome/browser/ui/views/avatar_menu_button.cc +++ b/chrome/browser/ui/views/avatar_menu_button.cc @@ -10,8 +10,8 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/avatar_menu_model.h" #include "chrome/browser/profiles/profile_info_util.h" -#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" #include "chrome/browser/ui/views/frame/browser_view.h" @@ -96,7 +96,7 @@ void AvatarMenuButton::ShowAvatarBubble() { gfx::Point origin; views::View::ConvertPointToScreen(this, &origin); gfx::Rect bounds(origin, size()); - if (ProfileManager::IsNewProfileManagementEnabled()) { + if (profiles::IsNewProfileManagementEnabled()) { ProfileChooserView::ShowBubble( this, views::BubbleBorder::TOP_LEFT, views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bounds, browser_); diff --git a/chrome/browser/ui/views/avatar_menu_button_browsertest.cc b/chrome/browser/ui/views/avatar_menu_button_browsertest.cc index 9628c1d..05b180e 100644 --- a/chrome/browser/ui/views/avatar_menu_button_browsertest.cc +++ b/chrome/browser/ui/views/avatar_menu_button_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/profiles/avatar_menu_model.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" #include "chrome/browser/ui/views/frame/browser_view.h" @@ -102,7 +103,7 @@ void AvatarMenuButtonTest::StartAvatarMenu() { IN_PROC_BROWSER_TEST_P(AvatarMenuButtonTest, HideOnSecondClick) { - if (!ProfileManager::IsMultipleProfilesEnabled() || + if (!profiles::IsMultipleProfilesEnabled() || UsingNewProfileChooser()) { return; } @@ -124,7 +125,7 @@ IN_PROC_BROWSER_TEST_P(AvatarMenuButtonTest, HideOnSecondClick) { IN_PROC_BROWSER_TEST_P(AvatarMenuButtonTest, NewSignOut) { - if (!ProfileManager::IsMultipleProfilesEnabled() || + if (!profiles::IsMultipleProfilesEnabled() || !UsingNewProfileChooser()) { return; } diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index fb64e74..5152da9 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -38,6 +38,8 @@ #include "chrome/browser/profiles/profile_info_util.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" +#include "chrome/browser/profiles/profile_window.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" @@ -131,7 +133,7 @@ bool ShouldShowMultiProfilesUserList(chrome::HostDesktopType desktop_type) { #else if (desktop_type != chrome::HOST_DESKTOP_TYPE_NATIVE) return false; - return ProfileManager::IsMultipleProfilesEnabled(); + return profiles::IsMultipleProfilesEnabled(); #endif } @@ -160,7 +162,7 @@ void OpenNewWindowForProfile( if (status != Profile::CREATE_STATUS_INITIALIZED) return; - ProfileManager::FindOrCreateNewWindowForProfile( + profiles::FindOrCreateNewWindowForProfile( profile, chrome::startup::IS_PROCESS_STARTUP, chrome::startup::IS_FIRST_RUN, @@ -1090,7 +1092,7 @@ void BrowserOptionsHandler::CreateProfile(const ListValue* args) { return; #endif - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; DCHECK(profile_path_being_created_.empty()); @@ -1244,7 +1246,7 @@ void BrowserOptionsHandler::DeleteProfileAtPath(base::FilePath file_path) { return; #endif - if (!ProfileManager::IsMultipleProfilesEnabled()) + if (!profiles::IsMultipleProfilesEnabled()) return; ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); diff --git a/chrome/browser/ui/webui/options/browser_options_handler.h b/chrome/browser/ui/webui/options/browser_options_handler.h index 6acf28f..a9173f8 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.h +++ b/chrome/browser/ui/webui/options/browser_options_handler.h @@ -17,6 +17,7 @@ #include "chrome/browser/search_engines/template_url_service_observer.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/sync/profile_sync_service_observer.h" +#include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "ui/base/models/table_model_observer.h" #include "ui/shell_dialogs/select_file_dialog.h" diff --git a/chrome/browser/ui/webui/options/manage_profile_handler.cc b/chrome/browser/ui/webui/options/manage_profile_handler.cc index 6e15043..3bda4a6 100644 --- a/chrome/browser/ui/webui/options/manage_profile_handler.cc +++ b/chrome/browser/ui/webui/options/manage_profile_handler.cc @@ -22,6 +22,8 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" +#include "chrome/browser/profiles/profile_window.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/ui/browser_finder.h" @@ -66,7 +68,7 @@ void OnNewDefaultProfileCreated( Profile* profile, Profile::CreateStatus status) { if (status == Profile::CREATE_STATUS_INITIALIZED) { - ProfileManager::FindOrCreateNewWindowForProfile( + profiles::FindOrCreateNewWindowForProfile( profile, chrome::startup::IS_PROCESS_STARTUP, chrome::startup::IS_FIRST_RUN, @@ -323,7 +325,7 @@ void ManageProfileHandler::SetProfileIconAndName(const ListValue* args) { #if defined(ENABLE_SETTINGS_APP) void ManageProfileHandler::SwitchAppListProfile(const ListValue* args) { DCHECK(args); - DCHECK(ProfileManager::IsMultipleProfilesEnabled()); + DCHECK(profiles::IsMultipleProfilesEnabled()); const Value* file_path_value; base::FilePath profile_file_path; diff --git a/chrome/browser/ui/webui/options/managed_user_create_confirm_handler.cc b/chrome/browser/ui/webui/options/managed_user_create_confirm_handler.cc index 92d6524..6ded18b 100644 --- a/chrome/browser/ui/webui/options/managed_user_create_confirm_handler.cc +++ b/chrome/browser/ui/webui/options/managed_user_create_confirm_handler.cc @@ -11,6 +11,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profile_window.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_base.h" #include "chrome/browser/signin/signin_manager_factory.h" @@ -79,7 +80,7 @@ void ManagedUserCreateConfirmHandler::SwitchToProfile( if (browser) desktop_type = browser->host_desktop_type(); - ProfileManager::FindOrCreateNewWindowForProfile( + profiles::FindOrCreateNewWindowForProfile( profile, chrome::startup::IS_PROCESS_STARTUP, chrome::startup::IS_FIRST_RUN, diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ff41d12..3c8dea2 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1607,6 +1607,10 @@ 'browser/profiles/profile_shortcut_manager_stub.cc', 'browser/profiles/profile_shortcut_manager_win.cc', 'browser/profiles/profile_shortcut_manager_win.h', + 'browser/profiles/profile_window.cc', + 'browser/profiles/profile_window.h', + 'browser/profiles/profiles_state.cc', + 'browser/profiles/profiles_state.h', 'browser/profiles/startup_task_runner_service.cc', 'browser/profiles/startup_task_runner_service.h', 'browser/profiles/startup_task_runner_service_factory.cc', diff --git a/chrome_frame/test/net/fake_external_tab.cc b/chrome_frame/test/net/fake_external_tab.cc index 0b7d615..3b76c6f 100644 --- a/chrome_frame/test/net/fake_external_tab.cc +++ b/chrome_frame/test/net/fake_external_tab.cc @@ -39,6 +39,7 @@ #include "chrome/browser/process_singleton.h" #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/renderer_host/web_cache_manager.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_content_client.h" @@ -549,7 +550,7 @@ void FakeExternalTab::InitializePostThreadsCreated() { views::CreateDesktopScreen()); #endif base::FilePath profile_path( - ProfileManager::GetDefaultProfileDir(user_data())); + profiles::GetDefaultProfileDir(user_data())); Profile* profile = g_browser_process->profile_manager()->GetProfile(profile_path); } |