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

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

Issue 2021253002: Skip profiles in GetLastOpenedProfiles that fail to initialize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed the bad DCHECK, updated comments Created 4 years, 6 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
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 <stddef.h> 10 #include <stddef.h>
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // This function is temporary and will soon be moved to ash. As such avoid 79 // This function is temporary and will soon be moved to ash. As such avoid
80 // using it at all cost. 80 // using it at all cost.
81 // TODO(skuhne): Move into ash's new user management function. 81 // TODO(skuhne): Move into ash's new user management function.
82 static Profile* GetActiveUserProfile(); 82 static Profile* GetActiveUserProfile();
83 83
84 // Returns a profile for a specific profile directory within the user data 84 // Returns a profile for a specific profile directory within the user data
85 // dir. This will return an existing profile it had already been created, 85 // dir. This will return an existing profile it had already been created,
86 // otherwise it will create and manage it. 86 // otherwise it will create and manage it.
87 // Because this method might synchronously create a new profile, it should 87 // Because this method might synchronously create a new profile, it should
88 // only be called for the initial profile or in tests, where blocking is 88 // only be called for the initial profile or in tests, where blocking is
89 // acceptable. 89 // acceptable. Returns nullptr if creation of the new profile fails.
90 // Callsites should always check for nullptr return before dereferencing. See
91 // crbug.com/383019 and crbug.com/614753 for related crashes.
Peter Kasting 2016/05/31 19:12:30 Nit: This last sentence is unnecessary given that
WC Leung 2016/06/01 18:56:55 Done. Anyway, I'll likely be as picky as you if I'
90 // TODO(bauerb): Migrate calls from other code to GetProfileByPath(), then 92 // TODO(bauerb): Migrate calls from other code to GetProfileByPath(), then
91 // make this method private. 93 // make this method private.
92 Profile* GetProfile(const base::FilePath& profile_dir); 94 Profile* GetProfile(const base::FilePath& profile_dir);
93 95
94 // Returns total number of profiles available on this machine. 96 // Returns total number of profiles available on this machine.
95 size_t GetNumberOfProfiles(); 97 size_t GetNumberOfProfiles();
96 98
97 // Asynchronously loads an existing profile given its |profile_name| within 99 // Asynchronously loads an existing profile given its |profile_name| within
98 // the user data directory, optionally in |incognito| mode. The |callback| 100 // the user data directory, optionally in |incognito| mode. The |callback|
99 // will be called with the Profile when it has been loaded, or with a nullptr 101 // will be called with the Profile when it has been loaded, or with a nullptr
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir); 135 base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir);
134 136
135 // Get the name of the last used profile, or if that's undefined, the default 137 // Get the name of the last used profile, or if that's undefined, the default
136 // profile. 138 // profile.
137 std::string GetLastUsedProfileName(); 139 std::string GetLastUsedProfileName();
138 140
139 // Get the Profiles which are currently open, i.e., have open browsers, or 141 // Get the Profiles which are currently open, i.e., have open browsers, or
140 // were open the last time Chrome was running. The Profiles appear in the 142 // were open the last time Chrome was running. The Profiles appear in the
141 // order they were opened. The last used profile will be on the list, but its 143 // order they were opened. The last used profile will be on the list, but its
142 // index on the list will depend on when it was opened (it is not necessarily 144 // index on the list will depend on when it was opened (it is not necessarily
143 // the last one). 145 // the last one). However profiles that fails to initialize (e.g. due to disk
146 // errors) are skipped.
Peter Kasting 2016/05/31 19:12:30 My comments on this sentence from the last patch s
WC Leung 2016/06/01 18:56:55 Can't find the comment in the last patch. Are you
Peter Kasting 2016/06/01 19:36:17 Don't worry, your newest version of the comment is
144 std::vector<Profile*> GetLastOpenedProfiles( 147 std::vector<Profile*> GetLastOpenedProfiles(
145 const base::FilePath& user_data_dir); 148 const base::FilePath& user_data_dir);
146 149
147 // Returns created and fully initialized profiles. Note, profiles order is NOT 150 // Returns created and fully initialized profiles. Note, profiles order is NOT
148 // guaranteed to be related with the creation order. 151 // guaranteed to be related with the creation order.
149 std::vector<Profile*> GetLoadedProfiles() const; 152 std::vector<Profile*> GetLoadedProfiles() const;
150 153
151 // If a profile with the given path is currently managed by this object and 154 // If a profile with the given path is currently managed by this object and
152 // fully initialized, return a pointer to the corresponding Profile object; 155 // fully initialized, return a pointer to the corresponding Profile object;
153 // otherwise return null. 156 // otherwise return null.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 bool is_new_profile) override; 248 bool is_new_profile) override;
246 249
247 protected: 250 protected:
248 // Does final initial actions. 251 // Does final initial actions.
249 virtual void DoFinalInit(Profile* profile, bool go_off_the_record); 252 virtual void DoFinalInit(Profile* profile, bool go_off_the_record);
250 virtual void DoFinalInitForServices(Profile* profile, bool go_off_the_record); 253 virtual void DoFinalInitForServices(Profile* profile, bool go_off_the_record);
251 virtual void DoFinalInitLogging(Profile* profile); 254 virtual void DoFinalInitLogging(Profile* profile);
252 255
253 // Creates a new profile by calling into the profile's profile creation 256 // Creates a new profile by calling into the profile's profile creation
254 // method. Virtual so that unittests can return a TestingProfile instead 257 // method. Virtual so that unittests can return a TestingProfile instead
255 // of the Profile's result. 258 // of the Profile's result. Returns nullptr if creation fails.
256 virtual Profile* CreateProfileHelper(const base::FilePath& path); 259 virtual Profile* CreateProfileHelper(const base::FilePath& path);
257 260
258 // Creates a new profile asynchronously by calling into the profile's 261 // Creates a new profile asynchronously by calling into the profile's
259 // asynchronous profile creation method. Virtual so that unittests can return 262 // asynchronous profile creation method. Virtual so that unittests can return
260 // a TestingProfile instead of the Profile's result. 263 // a TestingProfile instead of the Profile's result.
261 virtual Profile* CreateProfileAsyncHelper(const base::FilePath& path, 264 virtual Profile* CreateProfileAsyncHelper(const base::FilePath& path,
262 Delegate* delegate); 265 Delegate* delegate);
263 266
264 private: 267 private:
265 friend class TestingProfileManager; 268 friend class TestingProfileManager;
(...skipping 26 matching lines...) Expand all
292 Profile* GetActiveUserOrOffTheRecordProfileFromPath( 295 Profile* GetActiveUserOrOffTheRecordProfileFromPath(
293 const base::FilePath& user_data_dir); 296 const base::FilePath& user_data_dir);
294 297
295 // Adds a pre-existing Profile object to the set managed by this 298 // Adds a pre-existing Profile object to the set managed by this
296 // ProfileManager. This ProfileManager takes ownership of the Profile. 299 // ProfileManager. This ProfileManager takes ownership of the Profile.
297 // The Profile should not already be managed by this ProfileManager. 300 // The Profile should not already be managed by this ProfileManager.
298 // Returns true if the profile was added, false otherwise. 301 // Returns true if the profile was added, false otherwise.
299 bool AddProfile(Profile* profile); 302 bool AddProfile(Profile* profile);
300 303
301 // Synchronously creates and returns a profile. This handles both the full 304 // Synchronously creates and returns a profile. This handles both the full
302 // creation and adds it to the set managed by this ProfileManager. 305 // creation and adds it to the set managed by this ProfileManager. Returns
306 // nullptr when fails.
Peter Kasting 2016/05/31 19:12:30 Nit: when -> if creation
303 Profile* CreateAndInitializeProfile(const base::FilePath& profile_dir); 307 Profile* CreateAndInitializeProfile(const base::FilePath& profile_dir);
304 308
305 #if !defined(OS_ANDROID) 309 #if !defined(OS_ANDROID)
306 // Schedules the profile at the given path to be deleted on shutdown, 310 // Schedules the profile at the given path to be deleted on shutdown,
307 // and marks the new profile as active. 311 // and marks the new profile as active.
308 void FinishDeletingProfile(const base::FilePath& profile_dir, 312 void FinishDeletingProfile(const base::FilePath& profile_dir,
309 const base::FilePath& new_active_profile_dir); 313 const base::FilePath& new_active_profile_dir);
310 #endif 314 #endif
311 315
312 // Registers profile with given info. Returns pointer to created ProfileInfo 316 // Registers profile with given info. Returns pointer to created ProfileInfo
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 class ProfileManagerWithoutInit : public ProfileManager { 421 class ProfileManagerWithoutInit : public ProfileManager {
418 public: 422 public:
419 explicit ProfileManagerWithoutInit(const base::FilePath& user_data_dir); 423 explicit ProfileManagerWithoutInit(const base::FilePath& user_data_dir);
420 424
421 protected: 425 protected:
422 void DoFinalInitForServices(Profile*, bool) override {} 426 void DoFinalInitForServices(Profile*, bool) override {}
423 void DoFinalInitLogging(Profile*) override {} 427 void DoFinalInitLogging(Profile*) override {}
424 }; 428 };
425 429
426 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ 430 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698