OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This class keeps track of the currently-active profiles in the runtime. | 5 // This class keeps track of the currently-active profiles in the runtime. |
6 | 6 |
7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ | 7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ |
8 #define CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ | 8 #define CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 class ProfileManagerObserver { | 29 class ProfileManagerObserver { |
30 public: | 30 public: |
31 // This method is called when profile is ready. If profile creation has | 31 // This method is called when profile is ready. If profile creation has |
32 // failed, method is called with |profile| equal to NULL. | 32 // failed, method is called with |profile| equal to NULL. |
33 virtual void OnProfileCreated(Profile* profile) = 0; | 33 virtual void OnProfileCreated(Profile* profile) = 0; |
34 | 34 |
35 // If true, delete the observer after the profile has been created. Default | 35 // If true, delete the observer after the profile has been created. Default |
36 // is false. | 36 // is false. |
37 virtual bool DeleteAfterCreation(); | 37 virtual bool DeleteAfterCreation(); |
| 38 |
| 39 virtual ~ProfileManagerObserver() {} |
38 }; | 40 }; |
39 | 41 |
40 class ProfileManager : public base::NonThreadSafe, | 42 class ProfileManager : public base::NonThreadSafe, |
41 public BrowserList::Observer, | 43 public BrowserList::Observer, |
42 public NotificationObserver, | 44 public NotificationObserver, |
43 public Profile::Delegate { | 45 public Profile::Delegate { |
44 public: | 46 public: |
45 ProfileManager(); | 47 ProfileManager(); |
46 virtual ~ProfileManager(); | 48 virtual ~ProfileManager(); |
47 | 49 |
48 // Invokes SessionServiceFactory::ShutdownForProfile() for all profiles. | 50 // Invokes SessionServiceFactory::ShutdownForProfile() for all profiles. |
49 static void ShutdownSessionServices(); | 51 static void ShutdownSessionServices(); |
50 | 52 |
51 // Returns the default profile. This adds the profile to the | 53 // Returns the default profile. This adds the profile to the |
52 // ProfileManager if it doesn't already exist. This method returns NULL if | 54 // ProfileManager if it doesn't already exist. This method returns NULL if |
53 // the profile doesn't exist and we can't create it. | 55 // the profile doesn't exist and we can't create it. |
54 // The profile used can be overridden by using --login-profile on cros. | 56 // The profile used can be overridden by using --login-profile on cros. |
55 Profile* GetDefaultProfile(const FilePath& user_data_dir); | 57 Profile* GetDefaultProfile(const FilePath& user_data_dir); |
56 | 58 |
57 // Same as instance method but provides the default user_data_dir as well. | 59 // Same as instance method but provides the default user_data_dir as well. |
58 static Profile* GetDefaultProfile(); | 60 static Profile* GetDefaultProfile(); |
59 | 61 |
60 // Returns a profile for a specific profile directory within the user data | 62 // Returns a profile for a specific profile directory within the user data |
61 // dir. This will return an existing profile it had already been created, | 63 // dir. This will return an existing profile it had already been created, |
62 // otherwise it will create and manage it. | 64 // otherwise it will create and manage it. |
63 Profile* GetProfile(const FilePath& profile_dir); | 65 Profile* GetProfile(const FilePath& profile_dir); |
64 | 66 |
| 67 // Multi-profile support. |
| 68 size_t GetNumberOfProfiles(); |
| 69 string16 GetNameOfProfileAtIndex(size_t index); |
| 70 FilePath GetFilePathOfProfileAtIndex(size_t index, |
| 71 const FilePath& user_data_dir); |
| 72 |
65 // Explicit asynchronous creation of the profile. |observer| is called | 73 // Explicit asynchronous creation of the profile. |observer| is called |
66 // when profile is created. If profile has already been created, observer | 74 // when profile is created. If profile has already been created, observer |
67 // is called immediately. Should be called on the UI thread. | 75 // is called immediately. Should be called on the UI thread. |
68 void CreateProfileAsync(const FilePath& user_data_dir, | 76 void CreateProfileAsync(const FilePath& user_data_dir, |
69 ProfileManagerObserver* observer); | 77 ProfileManagerObserver* observer); |
70 | 78 |
71 // Initiates default profile creation. If default profile has already been | 79 // Initiates default profile creation. If default profile has already been |
72 // created, observer is called immediately. Should be called on the UI thread. | 80 // created, observer is called immediately. Should be called on the UI thread. |
73 static void CreateDefaultProfileAsync(ProfileManagerObserver* observer); | 81 static void CreateDefaultProfileAsync(ProfileManagerObserver* observer); |
74 | 82 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // Adds a pre-existing Profile object to the set managed by this | 174 // Adds a pre-existing Profile object to the set managed by this |
167 // ProfileManager. This ProfileManager takes ownership of the Profile. | 175 // ProfileManager. This ProfileManager takes ownership of the Profile. |
168 // The Profile should not already be managed by this ProfileManager. | 176 // The Profile should not already be managed by this ProfileManager. |
169 // Returns true if the profile was added, false otherwise. | 177 // Returns true if the profile was added, false otherwise. |
170 bool AddProfile(Profile* profile); | 178 bool AddProfile(Profile* profile); |
171 | 179 |
172 // Registers profile with given info. Returns pointer to created ProfileInfo | 180 // Registers profile with given info. Returns pointer to created ProfileInfo |
173 // entry. | 181 // entry. |
174 ProfileInfo* RegisterProfile(Profile* profile, bool created); | 182 ProfileInfo* RegisterProfile(Profile* profile, bool created); |
175 | 183 |
| 184 typedef std::pair<FilePath, string16> ProfilePathAndName; |
| 185 typedef std::vector<ProfilePathAndName> ProfilePathAndNames; |
| 186 ProfilePathAndNames GetSortedProfilesFromDirectoryMap(); |
| 187 |
| 188 static bool CompareProfilePathAndName( |
| 189 const ProfileManager::ProfilePathAndName& pair1, |
| 190 const ProfileManager::ProfilePathAndName& pair2); |
| 191 |
176 NotificationRegistrar registrar_; | 192 NotificationRegistrar registrar_; |
177 | 193 |
178 // Indicates that a user has logged in and that the profile specified | 194 // Indicates that a user has logged in and that the profile specified |
179 // in the --login-profile command line argument should be used as the | 195 // in the --login-profile command line argument should be used as the |
180 // default. | 196 // default. |
181 bool logged_in_; | 197 bool logged_in_; |
182 | 198 |
183 // Maps profile path to ProfileInfo (if profile has been created). Use | 199 // Maps profile path to ProfileInfo (if profile has been created). Use |
184 // RegisterProfile() to add into this map. | 200 // RegisterProfile() to add into this map. |
185 typedef std::map<FilePath, linked_ptr<ProfileInfo> > ProfilesInfoMap; | 201 typedef std::map<FilePath, linked_ptr<ProfileInfo> > ProfilesInfoMap; |
186 ProfilesInfoMap profiles_info_; | 202 ProfilesInfoMap profiles_info_; |
187 | 203 |
188 DISALLOW_COPY_AND_ASSIGN(ProfileManager); | 204 DISALLOW_COPY_AND_ASSIGN(ProfileManager); |
189 }; | 205 }; |
190 | 206 |
191 // Same as the ProfileManager, but doesn't initialize some services of the | 207 // Same as the ProfileManager, but doesn't initialize some services of the |
192 // profile. This one is useful in unittests. | 208 // profile. This one is useful in unittests. |
193 class ProfileManagerWithoutInit : public ProfileManager { | 209 class ProfileManagerWithoutInit : public ProfileManager { |
194 protected: | 210 protected: |
195 virtual void DoFinalInit(Profile*) {} | 211 virtual void DoFinalInit(Profile*) {} |
196 }; | 212 }; |
197 | 213 |
198 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ | 214 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ |
OLD | NEW |