Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/profiles/profile_manager.h

Issue 132713002: Getting rid of GetDefaultProfile(), clean up of ProfileManager (which was in a serious mess) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed macos build problems Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // 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 9
10 #include <list> 10 #include <list>
(...skipping 27 matching lines...) Expand all
38 virtual ~ProfileManager(); 38 virtual ~ProfileManager();
39 39
40 #if defined(ENABLE_SESSION_SERVICE) 40 #if defined(ENABLE_SESSION_SERVICE)
41 // Invokes SessionServiceFactory::ShutdownForProfile() for all profiles. 41 // Invokes SessionServiceFactory::ShutdownForProfile() for all profiles.
42 static void ShutdownSessionServices(); 42 static void ShutdownSessionServices();
43 #endif 43 #endif
44 44
45 // Physically remove deleted profile directories from disk. 45 // Physically remove deleted profile directories from disk.
46 static void NukeDeletedProfilesFromDisk(); 46 static void NukeDeletedProfilesFromDisk();
47 47
48 // Only to be used in ChromeOS: 48 // Same as instance method but provides the default user_data_dir as well.
49 // This is a temporary solution to get rid of the DEPRICATED GetDefaultProfile 49 // If the Profile is going to be used to open a new window then consider using
50 // functions below. Going forward we will do architectural changes to reduce 50 // GetLastUsedProfileAllowedByPolicy() instead.
51 // the Profile to get the browser context instead and by moving it into ash, 51 static Profile* GetLastUsedProfile();
52 // but for the short time fix we add these two functions here, enabling us to 52
53 // get rid of GetDefaultProfile as a first step. 53 // Same as GetLastUsedProfile() but returns the incognito Profile if
54 // TODO(skuhne): Move into ash's new user management function. 54 // incognito mode is forced. This should be used if the last used Profile
55 // will be used to open new browser windows.
56 static Profile* GetLastUsedProfileAllowedByPolicy();
57
58 // Same as instance method but provides the default user_data_dir as well.
59 static std::vector<Profile*> GetLastOpenedProfiles();
55 60
56 // Get the profile for the user which created the current session. 61 // Get the profile for the user which created the current session.
57 // Note that in case of a guest account this will return a 'suitable' profile. 62 // Note that in case of a guest account this will return a 'suitable' profile.
63 // This function is temporary and will soon be moved to ash. As such avoid
64 // using it at all cost.
65 // TODO(skuhne): Move into ash's new user management function.
58 static Profile* GetPrimaryUserProfile(); 66 static Profile* GetPrimaryUserProfile();
59 67
60 // Get the profile for the currently active user. 68 // Get the profile for the currently active user.
61 // Note that in case of a guest account this will return a 'suitable' profile. 69 // Note that in case of a guest account this will return a 'suitable' profile.
70 // This function is temporary and will soon be moved to ash. As such avoid
71 // using it at all cost.
72 // TODO(skuhne): Move into ash's new user management function.
62 static Profile* GetActiveUserProfile(); 73 static Profile* GetActiveUserProfile();
63 74
64 // DEPRECATED: DO NOT USE. Function will be removed soon (crbug.com/322682).
65 // Use GetPrimaryUserProfile or GetActiveUserProfile instead.
66 // Returns the default profile. This adds the profile to the
67 // ProfileManager if it doesn't already exist. This method returns NULL if
68 // the profile doesn't exist and we can't create it.
69 // The profile used can be overridden by using --login-profile on cros.
70 // Note that in case of a guest account this will return a 'suitable' profile.
71 static Profile* GetDefaultProfile();
72
73 // Returns a profile for a specific profile directory within the user data 75 // Returns a profile for a specific profile directory within the user data
74 // dir. This will return an existing profile it had already been created, 76 // dir. This will return an existing profile it had already been created,
75 // otherwise it will create and manage it. 77 // otherwise it will create and manage it.
76 Profile* GetProfile(const base::FilePath& profile_dir); 78 Profile* GetProfile(const base::FilePath& profile_dir);
77 79
78 // Returns total number of profiles available on this machine. 80 // Returns total number of profiles available on this machine.
79 size_t GetNumberOfProfiles(); 81 size_t GetNumberOfProfiles();
80 82
81 // Explicit asynchronous creation of a profile located at |profile_path|. 83 // Explicit asynchronous creation of a profile located at |profile_path|.
82 // If the profile has already been created then callback is called 84 // If the profile has already been created then callback is called
(...skipping 10 matching lines...) Expand all
93 95
94 // Returns the directory where the first created profile is stored, 96 // Returns the directory where the first created profile is stored,
95 // relative to the user data directory currently in use.. 97 // relative to the user data directory currently in use..
96 base::FilePath GetInitialProfileDir(); 98 base::FilePath GetInitialProfileDir();
97 99
98 // Get the Profile last used (the Profile to which owns the most recently 100 // Get the Profile last used (the Profile to which owns the most recently
99 // focused window) with this Chrome build. If no signed profile has been 101 // focused window) with this Chrome build. If no signed profile has been
100 // stored in Local State, hand back the Default profile. 102 // stored in Local State, hand back the Default profile.
101 Profile* GetLastUsedProfile(const base::FilePath& user_data_dir); 103 Profile* GetLastUsedProfile(const base::FilePath& user_data_dir);
102 104
103 // Same as instance method but provides the default user_data_dir as well.
104 // If the Profile is going to be used to open a new window then consider using
105 // GetLastUsedProfileAllowedByPolicy() instead.
106 static Profile* GetLastUsedProfile();
107
108 // Same as GetLastUsedProfile() but returns the incognito Profile if
109 // incognito mode is forced. This should be used if the last used Profile
110 // will be used to open new browser windows.
111 static Profile* GetLastUsedProfileAllowedByPolicy();
112
113 // Get the path of the last used profile, or if that's undefined, the default 105 // Get the path of the last used profile, or if that's undefined, the default
114 // profile. 106 // profile.
115 base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir); 107 base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir);
116 108
117 // Get the Profiles which are currently open, i.e., have open browsers, or 109 // Get the Profiles which are currently open, i.e., have open browsers, or
118 // were open the last time Chrome was running. The Profiles appear in the 110 // were open the last time Chrome was running. The Profiles appear in the
119 // order they were opened. The last used profile will be on the list, but its 111 // order they were opened. The last used profile will be on the list, but its
120 // index on the list will depend on when it was opened (it is not necessarily 112 // index on the list will depend on when it was opened (it is not necessarily
121 // the last one). 113 // the last one).
122 std::vector<Profile*> GetLastOpenedProfiles( 114 std::vector<Profile*> GetLastOpenedProfiles(
123 const base::FilePath& user_data_dir); 115 const base::FilePath& user_data_dir);
124 116
125 // Same as instance method but provides the default user_data_dir as well.
126 static std::vector<Profile*> GetLastOpenedProfiles();
127
128 // Returns created profiles. Note, profiles order is NOT guaranteed to be 117 // Returns created profiles. Note, profiles order is NOT guaranteed to be
129 // related with the creation order. 118 // related with the creation order.
130 std::vector<Profile*> GetLoadedProfiles() const; 119 std::vector<Profile*> GetLoadedProfiles() const;
131 120
132 // content::NotificationObserver implementation.
133 virtual void Observe(int type,
134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) OVERRIDE;
136
137 // If a profile with the given path is currently managed by this object, 121 // If a profile with the given path is currently managed by this object,
138 // return a pointer to the corresponding Profile object; 122 // return a pointer to the corresponding Profile object;
139 // otherwise return NULL. 123 // otherwise return NULL.
140 Profile* GetProfileByPath(const base::FilePath& path) const; 124 Profile* GetProfileByPath(const base::FilePath& path) const;
141 125
142 // Profile::Delegate implementation:
143 virtual void OnProfileCreated(Profile* profile,
144 bool success,
145 bool is_new_profile) OVERRIDE;
146
147 // Add or remove a profile launcher to/from the list of launchers waiting for
148 // new profiles to be created from the multi-profile menu.
149 void AddProfileLauncher(NewProfileLauncher* profile_launcher);
150 void RemoveProfileLauncher(NewProfileLauncher* profile_launcher);
151
152 // Creates a new profile in the next available multiprofile directory. 126 // Creates a new profile in the next available multiprofile directory.
153 // Directories are named "profile_1", "profile_2", etc., in sequence of 127 // Directories are named "profile_1", "profile_2", etc., in sequence of
154 // creation. (Because directories can be removed, however, it may be the case 128 // creation. (Because directories can be removed, however, it may be the case
155 // that at some point the list of numbered profiles is not continuous.) 129 // that at some point the list of numbered profiles is not continuous.)
156 // |callback| may be invoked multiple times (for CREATE_STATUS_INITIALIZED 130 // |callback| may be invoked multiple times (for CREATE_STATUS_INITIALIZED
157 // and CREATE_STATUS_CREATED) so binding parameters with bind::Passed() is 131 // and CREATE_STATUS_CREATED) so binding parameters with bind::Passed() is
158 // prohibited. Returns the file path to the profile that will be created 132 // prohibited. Returns the file path to the profile that will be created
159 // asynchronously. 133 // asynchronously.
160 static base::FilePath CreateMultiProfileAsync( 134 static base::FilePath CreateMultiProfileAsync(
161 const base::string16& name, 135 const base::string16& name,
(...skipping 27 matching lines...) Expand all
189 163
190 // Called on start-up if there are any stale ephemeral profiles to be deleted. 164 // Called on start-up if there are any stale ephemeral profiles to be deleted.
191 // This can be the case if the browser has crashed and the clean-up code had 165 // This can be the case if the browser has crashed and the clean-up code had
192 // no chance to run then. 166 // no chance to run then.
193 static void CleanUpStaleProfiles( 167 static void CleanUpStaleProfiles(
194 const std::vector<base::FilePath>& profile_paths); 168 const std::vector<base::FilePath>& profile_paths);
195 169
196 // Autoloads profiles if they are running background apps. 170 // Autoloads profiles if they are running background apps.
197 void AutoloadProfiles(); 171 void AutoloadProfiles();
198 172
199 // Sign-Out a profile against use until re-authentication.
200 void SignOutProfile(Profile* profile);
201
202 // Initializes user prefs of |profile|. This includes profile name and 173 // Initializes user prefs of |profile|. This includes profile name and
203 // avatar values. 174 // avatar values.
204 void InitProfileUserPrefs(Profile* profile); 175 void InitProfileUserPrefs(Profile* profile);
205 176
206 // Register and add testing profile to the ProfileManager. Use ONLY in tests. 177 // Register and add testing profile to the ProfileManager. Use ONLY in tests.
207 // This allows the creation of Profiles outside of the standard creation path 178 // This allows the creation of Profiles outside of the standard creation path
208 // for testing. If |addToCache|, adds to ProfileInfoCache as well. 179 // for testing. If |addToCache|, adds to ProfileInfoCache as well.
209 // If |start_deferred_task_runners|, starts the deferred task runners. 180 // If |start_deferred_task_runners|, starts the deferred task runners.
210 // Use ONLY in tests. 181 // Use ONLY in tests.
211 void RegisterTestingProfile(Profile* profile, 182 void RegisterTestingProfile(Profile* profile,
212 bool addToCache, 183 bool addToCache,
213 bool start_deferred_task_runners); 184 bool start_deferred_task_runners);
214 185
215 const base::FilePath& user_data_dir() const { return user_data_dir_; } 186 const base::FilePath& user_data_dir() const { return user_data_dir_; }
216 187
217 // For ChromeOS, determines if the user has logged in to a real profile. 188 // For ChromeOS, determines if the user has logged in to a real profile.
218 bool IsLoggedIn() const { return logged_in_; } 189 bool IsLoggedIn() const { return logged_in_; }
219 190
191 // content::NotificationObserver implementation.
192 virtual void Observe(int type,
193 const content::NotificationSource& source,
194 const content::NotificationDetails& details) OVERRIDE;
195
196 // Profile::Delegate implementation:
197 virtual void OnProfileCreated(Profile* profile,
198 bool success,
199 bool is_new_profile) OVERRIDE;
200
220 protected: 201 protected:
221 // Does final initial actions. 202 // Does final initial actions.
222 virtual void DoFinalInit(Profile* profile, bool go_off_the_record); 203 virtual void DoFinalInit(Profile* profile, bool go_off_the_record);
223 virtual void DoFinalInitForServices(Profile* profile, bool go_off_the_record); 204 virtual void DoFinalInitForServices(Profile* profile, bool go_off_the_record);
224 virtual void DoFinalInitLogging(Profile* profile); 205 virtual void DoFinalInitLogging(Profile* profile);
225 206
226 // Creates a new profile by calling into the profile's profile creation 207 // Creates a new profile by calling into the profile's profile creation
227 // method. Virtual so that unittests can return a TestingProfile instead 208 // method. Virtual so that unittests can return a TestingProfile instead
228 // of the Profile's result. 209 // of the Profile's result.
229 virtual Profile* CreateProfileHelper(const base::FilePath& path); 210 virtual Profile* CreateProfileHelper(const base::FilePath& path);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void FinishDeletingProfile(const base::FilePath& profile_dir); 258 void FinishDeletingProfile(const base::FilePath& profile_dir);
278 259
279 // Registers profile with given info. Returns pointer to created ProfileInfo 260 // Registers profile with given info. Returns pointer to created ProfileInfo
280 // entry. 261 // entry.
281 ProfileInfo* RegisterProfile(Profile* profile, bool created); 262 ProfileInfo* RegisterProfile(Profile* profile, bool created);
282 263
283 // Returns ProfileInfo associated with given |path|, registred earlier with 264 // Returns ProfileInfo associated with given |path|, registred earlier with
284 // RegisterProfile. 265 // RegisterProfile.
285 ProfileInfo* GetProfileInfoByPath(const base::FilePath& path) const; 266 ProfileInfo* GetProfileInfoByPath(const base::FilePath& path) const;
286 267
287 typedef std::pair<base::FilePath, base::string16> ProfilePathAndName;
288 typedef std::vector<ProfilePathAndName> ProfilePathAndNames;
289 ProfilePathAndNames GetSortedProfilesFromDirectoryMap();
290
291 static bool CompareProfilePathAndName(
292 const ProfileManager::ProfilePathAndName& pair1,
293 const ProfileManager::ProfilePathAndName& pair2);
294
295 // Adds |profile| to the profile info cache if it hasn't been added yet. 268 // Adds |profile| to the profile info cache if it hasn't been added yet.
296 void AddProfileToCache(Profile* profile); 269 void AddProfileToCache(Profile* profile);
297 270
298 // Apply settings for (desktop) Guest User profile. 271 // Apply settings for (desktop) Guest User profile.
299 void SetGuestProfilePrefs(Profile* profile); 272 void SetGuestProfilePrefs(Profile* profile);
300 273
301 // For ChromeOS, determines if profile should be otr. 274 // For ChromeOS, determines if profile should be otr.
302 bool ShouldGoOffTheRecord(Profile* profile); 275 bool ShouldGoOffTheRecord(Profile* profile);
303 276
304 void RunCallbacks(const std::vector<CreateCallback>& callbacks, 277 void RunCallbacks(const std::vector<CreateCallback>& callbacks,
305 Profile* profile, 278 Profile* profile,
306 Profile::CreateStatus status); 279 Profile::CreateStatus status);
307 280
308 // If the |loaded_profile| has been loaded succesfully (according to |status|) 281 #if !defined(OS_ANDROID) && !defined(OS_IOS)
309 // and isn't already scheduled for deletion, then finishes adding 282 class BrowserListObserver : public chrome::BrowserListObserver {
283 public:
284 explicit BrowserListObserver(ProfileManager* manager);
285 virtual ~BrowserListObserver();
286
287 // chrome::BrowserListObserver implementation.
288 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
289 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
290 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
291
292 private:
293 ProfileManager* profile_manager_;
294 DISALLOW_COPY_AND_ASSIGN(BrowserListObserver);
295 };
296 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
297
298 #if defined(OS_MACOSX)
299 // If the |loaded_profile| has been loaded successfully (according to
300 // |status|) and isn't already scheduled for deletion, then finishes adding
310 // |profile_to_delete_dir| to the queue of profiles to be deleted, and updates 301 // |profile_to_delete_dir| to the queue of profiles to be deleted, and updates
311 // the kProfileLastUsed preference based on |last_non_managed_profile_path|. 302 // the kProfileLastUsed preference based on |last_non_managed_profile_path|.
312 void OnNewActiveProfileLoaded( 303 void OnNewActiveProfileLoaded(
313 const base::FilePath& profile_to_delete_path, 304 const base::FilePath& profile_to_delete_path,
314 const base::FilePath& last_non_managed_profile_path, 305 const base::FilePath& last_non_managed_profile_path,
315 const CreateCallback& original_callback, 306 const CreateCallback& original_callback,
316 Profile* loaded_profile, 307 Profile* loaded_profile,
317 Profile::CreateStatus status); 308 Profile::CreateStatus status);
309 #endif
318 310
319 content::NotificationRegistrar registrar_; 311 content::NotificationRegistrar registrar_;
320 312
321 // The path to the user data directory (DIR_USER_DATA). 313 // The path to the user data directory (DIR_USER_DATA).
322 const base::FilePath user_data_dir_; 314 const base::FilePath user_data_dir_;
323 315
324 // Indicates that a user has logged in and that the profile specified 316 // Indicates that a user has logged in and that the profile specified
325 // in the --login-profile command line argument should be used as the 317 // in the --login-profile command line argument should be used as the
326 // default. 318 // default.
327 bool logged_in_; 319 bool logged_in_;
328 320
321 #if !defined(OS_ANDROID) && !defined(OS_IOS)
322 BrowserListObserver browser_list_observer_;
323 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
324
329 // Maps profile path to ProfileInfo (if profile has been created). Use 325 // Maps profile path to ProfileInfo (if profile has been created). Use
330 // RegisterProfile() to add into this map. This map owns all loaded profile 326 // RegisterProfile() to add into this map. This map owns all loaded profile
331 // objects in a running instance of Chrome. 327 // objects in a running instance of Chrome.
332 typedef std::map<base::FilePath, linked_ptr<ProfileInfo> > ProfilesInfoMap; 328 typedef std::map<base::FilePath, linked_ptr<ProfileInfo> > ProfilesInfoMap;
333 ProfilesInfoMap profiles_info_; 329 ProfilesInfoMap profiles_info_;
334 330
335 // Object to cache various information about profiles. Contains information 331 // Object to cache various information about profiles. Contains information
336 // about every profile which has been created for this instance of Chrome, 332 // about every profile which has been created for this instance of Chrome,
337 // if it has not been explicitly deleted. 333 // if it has not been explicitly deleted.
338 scoped_ptr<ProfileInfoCache> profile_info_cache_; 334 scoped_ptr<ProfileInfoCache> profile_info_cache_;
339 335
340 // Manages the process of creating, deleteing and updating Desktop shortcuts. 336 // Manages the process of creating, deleteing and updating Desktop shortcuts.
341 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_; 337 scoped_ptr<ProfileShortcutManager> profile_shortcut_manager_;
342 338
343 #if !defined(OS_ANDROID) && !defined(OS_IOS)
344 class BrowserListObserver : public chrome::BrowserListObserver {
345 public:
346 explicit BrowserListObserver(ProfileManager* manager);
347 virtual ~BrowserListObserver();
348
349 // chrome::BrowserListObserver implementation.
350 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
351 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
352 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
353
354 private:
355 ProfileManager* profile_manager_;
356 DISALLOW_COPY_AND_ASSIGN(BrowserListObserver);
357 };
358
359 BrowserListObserver browser_list_observer_;
360 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
361
362 // For keeping track of the last active profiles. 339 // For keeping track of the last active profiles.
363 std::map<Profile*, int> browser_counts_; 340 std::map<Profile*, int> browser_counts_;
364 // On startup we launch the active profiles in the order they became active 341 // On startup we launch the active profiles in the order they became active
365 // during the last run. This is why they are kept in a list, not in a set. 342 // during the last run. This is why they are kept in a list, not in a set.
366 std::vector<Profile*> active_profiles_; 343 std::vector<Profile*> active_profiles_;
367 bool closing_all_browsers_; 344 bool closing_all_browsers_;
368 345
369 DISALLOW_COPY_AND_ASSIGN(ProfileManager); 346 DISALLOW_COPY_AND_ASSIGN(ProfileManager);
370 }; 347 };
371 348
372 // Same as the ProfileManager, but doesn't initialize some services of the 349 // Same as the ProfileManager, but doesn't initialize some services of the
373 // profile. This one is useful in unittests. 350 // profile. This one is useful in unittests.
374 class ProfileManagerWithoutInit : public ProfileManager { 351 class ProfileManagerWithoutInit : public ProfileManager {
375 public: 352 public:
376 explicit ProfileManagerWithoutInit(const base::FilePath& user_data_dir); 353 explicit ProfileManagerWithoutInit(const base::FilePath& user_data_dir);
377 354
378 protected: 355 protected:
379 virtual void DoFinalInitForServices(Profile*, bool) OVERRIDE {} 356 virtual void DoFinalInitForServices(Profile*, bool) OVERRIDE {}
380 virtual void DoFinalInitLogging(Profile*) OVERRIDE {} 357 virtual void DoFinalInitLogging(Profile*) OVERRIDE {}
381 }; 358 };
382 359
383 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ 360 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698