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

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

Issue 929073002: Only return fully initialized profiles in ProfileManager::GetProfileByPath. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: cleanup Created 5 years, 10 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 <list> 10 #include <list>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Get the profile for the currently active user. 67 // Get the profile for the currently active user.
68 // Note that in case of a guest account this will return a 'suitable' profile. 68 // Note that in case of a guest account this will return a 'suitable' profile.
69 // This function is temporary and will soon be moved to ash. As such avoid 69 // This function is temporary and will soon be moved to ash. As such avoid
70 // using it at all cost. 70 // using it at all cost.
71 // TODO(skuhne): Move into ash's new user management function. 71 // TODO(skuhne): Move into ash's new user management function.
72 static Profile* GetActiveUserProfile(); 72 static Profile* GetActiveUserProfile();
73 73
74 // Returns a profile for a specific profile directory within the user data 74 // Returns a profile for a specific profile directory within the user data
75 // dir. This will return an existing profile it had already been created, 75 // dir. This will return an existing profile it had already been created,
76 // otherwise it will create and manage it. 76 // otherwise it will create and manage it.
77 // Because this method might synchronously create a new profile, it should
78 // only be called for the initial profile or in tests, where blocking is
79 // acceptable.
80 // TODO(bauerb): Migrate calls from other code to GetProfileByPath(), then
81 // make this method private.
77 Profile* GetProfile(const base::FilePath& profile_dir); 82 Profile* GetProfile(const base::FilePath& profile_dir);
78 83
79 // Returns total number of profiles available on this machine. 84 // Returns total number of profiles available on this machine.
80 size_t GetNumberOfProfiles(); 85 size_t GetNumberOfProfiles();
81 86
82 // Explicit asynchronous creation of a profile located at |profile_path|. 87 // Explicit asynchronous creation of a profile located at |profile_path|.
83 // If the profile has already been created then callback is called 88 // If the profile has already been created then callback is called
84 // immediately. Should be called on the UI thread. 89 // immediately. Should be called on the UI thread.
85 void CreateProfileAsync(const base::FilePath& profile_path, 90 void CreateProfileAsync(const base::FilePath& profile_path,
86 const CreateCallback& callback, 91 const CreateCallback& callback,
(...skipping 19 matching lines...) Expand all
106 base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir); 111 base::FilePath GetLastUsedProfileDir(const base::FilePath& user_data_dir);
107 112
108 // Get the Profiles which are currently open, i.e., have open browsers, or 113 // Get the Profiles which are currently open, i.e., have open browsers, or
109 // were open the last time Chrome was running. The Profiles appear in the 114 // were open the last time Chrome was running. The Profiles appear in the
110 // order they were opened. The last used profile will be on the list, but its 115 // order they were opened. The last used profile will be on the list, but its
111 // index on the list will depend on when it was opened (it is not necessarily 116 // index on the list will depend on when it was opened (it is not necessarily
112 // the last one). 117 // the last one).
113 std::vector<Profile*> GetLastOpenedProfiles( 118 std::vector<Profile*> GetLastOpenedProfiles(
114 const base::FilePath& user_data_dir); 119 const base::FilePath& user_data_dir);
115 120
116 // Returns created profiles. Note, profiles order is NOT guaranteed to be 121 // Returns created and fully initialized profiles. Note, profiles order is NOT
117 // related with the creation order. 122 // guaranteed to be related with the creation order.
118 std::vector<Profile*> GetLoadedProfiles() const; 123 std::vector<Profile*> GetLoadedProfiles() const;
119 124
120 // If a profile with the given path is currently managed by this object, 125 // If a profile with the given path is currently managed by this object and
121 // return a pointer to the corresponding Profile object; 126 // fully initialized, return a pointer to the corresponding Profile object;
122 // otherwise return NULL. 127 // otherwise return null.
123 Profile* GetProfileByPath(const base::FilePath& path) const; 128 Profile* GetProfileByPath(const base::FilePath& path) const;
124 129
125 // Creates a new profile in the next available multiprofile directory. 130 // Creates a new profile in the next available multiprofile directory.
126 // Directories are named "profile_1", "profile_2", etc., in sequence of 131 // Directories are named "profile_1", "profile_2", etc., in sequence of
127 // creation. (Because directories can be removed, however, it may be the case 132 // creation. (Because directories can be removed, however, it may be the case
128 // that at some point the list of numbered profiles is not continuous.) 133 // that at some point the list of numbered profiles is not continuous.)
129 // |callback| may be invoked multiple times (for CREATE_STATUS_INITIALIZED 134 // |callback| may be invoked multiple times (for CREATE_STATUS_INITIALIZED
130 // and CREATE_STATUS_CREATED) so binding parameters with bind::Passed() is 135 // and CREATE_STATUS_CREATED) so binding parameters with bind::Passed() is
131 // prohibited. Returns the file path to the profile that will be created 136 // prohibited. Returns the file path to the profile that will be created
132 // asynchronously. 137 // asynchronously.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 private: 246 private:
242 DISALLOW_COPY_AND_ASSIGN(ProfileInfo); 247 DISALLOW_COPY_AND_ASSIGN(ProfileInfo);
243 }; 248 };
244 249
245 // Returns the profile of the active user and / or the off the record profile 250 // Returns the profile of the active user and / or the off the record profile
246 // if needed. This adds the profile to the ProfileManager if it doesn't 251 // if needed. This adds the profile to the ProfileManager if it doesn't
247 // already exist. The method will return NULL if the profile doesn't exist 252 // already exist. The method will return NULL if the profile doesn't exist
248 // and we can't create it. 253 // and we can't create it.
249 // The profile used can be overridden by using --login-profile on cros. 254 // The profile used can be overridden by using --login-profile on cros.
250 Profile* GetActiveUserOrOffTheRecordProfileFromPath( 255 Profile* GetActiveUserOrOffTheRecordProfileFromPath(
251 const base::FilePath& user_data_dir); 256 const base::FilePath& user_data_dir);
252 257
253 // Adds a pre-existing Profile object to the set managed by this 258 // Adds a pre-existing Profile object to the set managed by this
254 // ProfileManager. This ProfileManager takes ownership of the Profile. 259 // ProfileManager. This ProfileManager takes ownership of the Profile.
255 // The Profile should not already be managed by this ProfileManager. 260 // The Profile should not already be managed by this ProfileManager.
256 // Returns true if the profile was added, false otherwise. 261 // Returns true if the profile was added, false otherwise.
257 bool AddProfile(Profile* profile); 262 bool AddProfile(Profile* profile);
258 263
259 // Synchronously creates and returns a profile. This handles both the full 264 // Synchronously creates and returns a profile. This handles both the full
260 // creation and adds it to the set managed by this ProfileManager. 265 // creation and adds it to the set managed by this ProfileManager.
261 Profile* CreateAndInitializeProfile(const base::FilePath& profile_dir); 266 Profile* CreateAndInitializeProfile(const base::FilePath& profile_dir);
262 267
263 // Schedules the profile at the given path to be deleted on shutdown. 268 // Schedules the profile at the given path to be deleted on shutdown.
264 void FinishDeletingProfile(const base::FilePath& profile_dir); 269 void FinishDeletingProfile(const base::FilePath& profile_dir);
265 270
266 // Registers profile with given info. Returns pointer to created ProfileInfo 271 // Registers profile with given info. Returns pointer to created ProfileInfo
267 // entry. 272 // entry.
268 ProfileInfo* RegisterProfile(Profile* profile, bool created); 273 ProfileInfo* RegisterProfile(Profile* profile, bool created);
269 274
270 // Returns ProfileInfo associated with given |path|, registred earlier with 275 // Returns ProfileInfo associated with given |path|, registered earlier with
271 // RegisterProfile. 276 // RegisterProfile.
272 ProfileInfo* GetProfileInfoByPath(const base::FilePath& path) const; 277 ProfileInfo* GetProfileInfoByPath(const base::FilePath& path) const;
273 278
279 // Returns a registered profile. In contrast to GetProfileByPath(), this will
280 // also return a profile that is not fully initialized yet, so this method
281 // should be used carefully.
282 Profile* GetProfileByPathInternal(const base::FilePath& path) const;
283
274 // Adds |profile| to the profile info cache if it hasn't been added yet. 284 // Adds |profile| to the profile info cache if it hasn't been added yet.
275 void AddProfileToCache(Profile* profile); 285 void AddProfileToCache(Profile* profile);
276 286
277 // Apply settings for (desktop) Guest User profile. 287 // Apply settings for (desktop) Guest User profile.
278 void SetGuestProfilePrefs(Profile* profile); 288 void SetGuestProfilePrefs(Profile* profile);
279 289
280 // For ChromeOS, determines if profile should be otr. 290 // For ChromeOS, determines if profile should be otr.
281 bool ShouldGoOffTheRecord(Profile* profile); 291 bool ShouldGoOffTheRecord(Profile* profile);
282 292
283 void RunCallbacks(const std::vector<CreateCallback>& callbacks, 293 void RunCallbacks(const std::vector<CreateCallback>& callbacks,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 class ProfileManagerWithoutInit : public ProfileManager { 374 class ProfileManagerWithoutInit : public ProfileManager {
365 public: 375 public:
366 explicit ProfileManagerWithoutInit(const base::FilePath& user_data_dir); 376 explicit ProfileManagerWithoutInit(const base::FilePath& user_data_dir);
367 377
368 protected: 378 protected:
369 void DoFinalInitForServices(Profile*, bool) override {} 379 void DoFinalInitForServices(Profile*, bool) override {}
370 void DoFinalInitLogging(Profile*) override {} 380 void DoFinalInitLogging(Profile*) override {}
371 }; 381 };
372 382
373 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_ 383 #endif // CHROME_BROWSER_PROFILES_PROFILE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698