Commit 12df9596 authored by skuhne@chromium.org's avatar skuhne@chromium.org

Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a serious mess)

Finally! GetDefaultProfile goes away for good!

With that I also cleaned up that class and ripped out ancient unneeded functions / type-defs. Re-ordered the function declarations and so on. I am sure that more could be done here, but please first get rid of this function before it gets more children...

BUG=322682
TEXT=covered by existing unit tests

Review URL: https://codereview.chromium.org/132713002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244241 0039d316-1c4b-4281-b951-d872f2087c98
parent 791c1228
This diff is collapsed.
...@@ -45,31 +45,33 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -45,31 +45,33 @@ class ProfileManager : public base::NonThreadSafe,
// Physically remove deleted profile directories from disk. // Physically remove deleted profile directories from disk.
static void NukeDeletedProfilesFromDisk(); static void NukeDeletedProfilesFromDisk();
// Only to be used in ChromeOS: // Same as instance method but provides the default user_data_dir as well.
// This is a temporary solution to get rid of the DEPRICATED GetDefaultProfile // If the Profile is going to be used to open a new window then consider using
// functions below. Going forward we will do architectural changes to reduce // GetLastUsedProfileAllowedByPolicy() instead.
// the Profile to get the browser context instead and by moving it into ash, static Profile* GetLastUsedProfile();
// but for the short time fix we add these two functions here, enabling us to
// get rid of GetDefaultProfile as a first step. // Same as GetLastUsedProfile() but returns the incognito Profile if
// TODO(skuhne): Move into ash's new user management function. // incognito mode is forced. This should be used if the last used Profile
// will be used to open new browser windows.
static Profile* GetLastUsedProfileAllowedByPolicy();
// Same as instance method but provides the default user_data_dir as well.
static std::vector<Profile*> GetLastOpenedProfiles();
// Get the profile for the user which created the current session. // Get the profile for the user which created the current session.
// Note that in case of a guest account this will return a 'suitable' profile. // Note that in case of a guest account this will return a 'suitable' profile.
// This function is temporary and will soon be moved to ash. As such avoid
// using it at all cost.
// TODO(skuhne): Move into ash's new user management function.
static Profile* GetPrimaryUserProfile(); static Profile* GetPrimaryUserProfile();
// Get the profile for the currently active user. // Get the profile for the currently active user.
// Note that in case of a guest account this will return a 'suitable' profile. // Note that in case of a guest account this will return a 'suitable' profile.
// This function is temporary and will soon be moved to ash. As such avoid
// using it at all cost.
// TODO(skuhne): Move into ash's new user management function.
static Profile* GetActiveUserProfile(); static Profile* GetActiveUserProfile();
// DEPRECATED: DO NOT USE. Function will be removed soon (crbug.com/322682).
// Use GetPrimaryUserProfile or GetActiveUserProfile instead.
// Returns the default profile. This adds the profile to the
// ProfileManager if it doesn't already exist. This method returns NULL if
// the profile doesn't exist and we can't create it.
// The profile used can be overridden by using --login-profile on cros.
// Note that in case of a guest account this will return a 'suitable' profile.
static Profile* GetDefaultProfile();
// Returns a profile for a specific profile directory within the user data // Returns a profile for a specific profile directory within the user data
// dir. This will return an existing profile it had already been created, // dir. This will return an existing profile it had already been created,
// otherwise it will create and manage it. // otherwise it will create and manage it.
...@@ -100,16 +102,6 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -100,16 +102,6 @@ class ProfileManager : public base::NonThreadSafe,
// stored in Local State, hand back the Default profile. // stored in Local State, hand back the Default profile.
Profile* GetLastUsedProfile(const base::FilePath& user_data_dir); Profile* GetLastUsedProfile(const base::FilePath& user_data_dir);
// Same as instance method but provides the default user_data_dir as well.
// If the Profile is going to be used to open a new window then consider using
// GetLastUsedProfileAllowedByPolicy() instead.
static Profile* GetLastUsedProfile();
// Same as GetLastUsedProfile() but returns the incognito Profile if
// incognito mode is forced. This should be used if the last used Profile
// will be used to open new browser windows.
static Profile* GetLastUsedProfileAllowedByPolicy();
// Get the path of the last used profile, or if that's undefined, the default // Get the path of the last used profile, or if that's undefined, the default
// profile. // profile.
base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir); base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir);
...@@ -122,33 +114,15 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -122,33 +114,15 @@ class ProfileManager : public base::NonThreadSafe,
std::vector<Profile*> GetLastOpenedProfiles( std::vector<Profile*> GetLastOpenedProfiles(
const base::FilePath& user_data_dir); const base::FilePath& user_data_dir);
// Same as instance method but provides the default user_data_dir as well.
static std::vector<Profile*> GetLastOpenedProfiles();
// Returns created profiles. Note, profiles order is NOT guaranteed to be // Returns created profiles. Note, profiles order is NOT guaranteed to be
// related with the creation order. // related with the creation order.
std::vector<Profile*> GetLoadedProfiles() const; std::vector<Profile*> GetLoadedProfiles() const;
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// If a profile with the given path is currently managed by this object, // If a profile with the given path is currently managed by this object,
// return a pointer to the corresponding Profile object; // return a pointer to the corresponding Profile object;
// otherwise return NULL. // otherwise return NULL.
Profile* GetProfileByPath(const base::FilePath& path) const; Profile* GetProfileByPath(const base::FilePath& path) const;
// Profile::Delegate implementation:
virtual void OnProfileCreated(Profile* profile,
bool success,
bool is_new_profile) OVERRIDE;
// Add or remove a profile launcher to/from the list of launchers waiting for
// new profiles to be created from the multi-profile menu.
void AddProfileLauncher(NewProfileLauncher* profile_launcher);
void RemoveProfileLauncher(NewProfileLauncher* profile_launcher);
// Creates a new profile in the next available multiprofile directory. // Creates a new profile in the next available multiprofile directory.
// Directories are named "profile_1", "profile_2", etc., in sequence of // Directories are named "profile_1", "profile_2", etc., in sequence of
// creation. (Because directories can be removed, however, it may be the case // creation. (Because directories can be removed, however, it may be the case
...@@ -196,9 +170,6 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -196,9 +170,6 @@ class ProfileManager : public base::NonThreadSafe,
// Autoloads profiles if they are running background apps. // Autoloads profiles if they are running background apps.
void AutoloadProfiles(); void AutoloadProfiles();
// Sign-Out a profile against use until re-authentication.
void SignOutProfile(Profile* profile);
// Initializes user prefs of |profile|. This includes profile name and // Initializes user prefs of |profile|. This includes profile name and
// avatar values. // avatar values.
void InitProfileUserPrefs(Profile* profile); void InitProfileUserPrefs(Profile* profile);
...@@ -217,6 +188,16 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -217,6 +188,16 @@ class ProfileManager : public base::NonThreadSafe,
// For ChromeOS, determines if the user has logged in to a real profile. // For ChromeOS, determines if the user has logged in to a real profile.
bool IsLoggedIn() const { return logged_in_; } bool IsLoggedIn() const { return logged_in_; }
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Profile::Delegate implementation:
virtual void OnProfileCreated(Profile* profile,
bool success,
bool is_new_profile) OVERRIDE;
protected: protected:
// Does final initial actions. // Does final initial actions.
virtual void DoFinalInit(Profile* profile, bool go_off_the_record); virtual void DoFinalInit(Profile* profile, bool go_off_the_record);
...@@ -284,14 +265,6 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -284,14 +265,6 @@ class ProfileManager : public base::NonThreadSafe,
// RegisterProfile. // RegisterProfile.
ProfileInfo* GetProfileInfoByPath(const base::FilePath& path) const; ProfileInfo* GetProfileInfoByPath(const base::FilePath& path) const;
typedef std::pair<base::FilePath, base::string16> ProfilePathAndName;
typedef std::vector<ProfilePathAndName> ProfilePathAndNames;
ProfilePathAndNames GetSortedProfilesFromDirectoryMap();
static bool CompareProfilePathAndName(
const ProfileManager::ProfilePathAndName& pair1,
const ProfileManager::ProfilePathAndName& pair2);
// Adds |profile| to the profile info cache if it hasn't been added yet. // Adds |profile| to the profile info cache if it hasn't been added yet.
void AddProfileToCache(Profile* profile); void AddProfileToCache(Profile* profile);
...@@ -305,8 +278,26 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -305,8 +278,26 @@ class ProfileManager : public base::NonThreadSafe,
Profile* profile, Profile* profile,
Profile::CreateStatus status); Profile::CreateStatus status);
// If the |loaded_profile| has been loaded succesfully (according to |status|) #if !defined(OS_ANDROID) && !defined(OS_IOS)
// and isn't already scheduled for deletion, then finishes adding class BrowserListObserver : public chrome::BrowserListObserver {
public:
explicit BrowserListObserver(ProfileManager* manager);
virtual ~BrowserListObserver();
// chrome::BrowserListObserver implementation.
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
private:
ProfileManager* profile_manager_;
DISALLOW_COPY_AND_ASSIGN(BrowserListObserver);
};
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
#if defined(OS_MACOSX)
// If the |loaded_profile| has been loaded successfully (according to
// |status|) and isn't already scheduled for deletion, then finishes adding
// |profile_to_delete_dir| to the queue of profiles to be deleted, and updates // |profile_to_delete_dir| to the queue of profiles to be deleted, and updates
// the kProfileLastUsed preference based on |last_non_managed_profile_path|. // the kProfileLastUsed preference based on |last_non_managed_profile_path|.
void OnNewActiveProfileLoaded( void OnNewActiveProfileLoaded(
...@@ -315,6 +306,7 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -315,6 +306,7 @@ class ProfileManager : public base::NonThreadSafe,
const CreateCallback& original_callback, const CreateCallback& original_callback,
Profile* loaded_profile, Profile* loaded_profile,
Profile::CreateStatus status); Profile::CreateStatus status);
#endif
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
...@@ -326,6 +318,10 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -326,6 +318,10 @@ class ProfileManager : public base::NonThreadSafe,
// default. // default.
bool logged_in_; bool logged_in_;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
BrowserListObserver browser_list_observer_;
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
// Maps profile path to ProfileInfo (if profile has been created). Use // Maps profile path to ProfileInfo (if profile has been created). Use
// RegisterProfile() to add into this map. This map owns all loaded profile // RegisterProfile() to add into this map. This map owns all loaded profile
// objects in a running instance of Chrome. // objects in a running instance of Chrome.
...@@ -340,25 +336,6 @@ class ProfileManager : public base::NonThreadSafe, ...@@ -340,25 +336,6 @@ class ProfileManager : public base::NonThreadSafe,
// Manages the process of creating, deleteing and updating Desktop shortcuts. // Manages the process of creating, deleteing and updating Desktop shortcuts.
scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
class BrowserListObserver : public chrome::BrowserListObserver {
public:
explicit BrowserListObserver(ProfileManager* manager);
virtual ~BrowserListObserver();
// chrome::BrowserListObserver implementation.
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
private:
ProfileManager* profile_manager_;
DISALLOW_COPY_AND_ASSIGN(BrowserListObserver);
};
BrowserListObserver browser_list_observer_;
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
// For keeping track of the last active profiles. // For keeping track of the last active profiles.
std::map<Profile*, int> browser_counts_; std::map<Profile*, int> browser_counts_;
// On startup we launch the active profiles in the order they became active // On startup we launch the active profiles in the order they became active
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment